Skip to content

Commit 49ba432

Browse files
authored
[mercury] The Mercury implementation is divided into the @genexus/mercury-build and @genexus/mercury-cli packages. Additionally, the @genexus/vite-plugin-mercury package has been added to facilitate configuration in Vite-based environments (#646)
* Set bundle mappings in the window This will help us to avoid issues when the Mercury dependency is duplicated. Also, this help us to set this mapping inline in the HTML. * Add an utility to calculate the gzip size of files that are downloaded to the browser * Improve how the bundle sizes are printed to the output * Add the `viteMercury` plugin for Vite environments This plugin replaces the need for using the CLI in Vite environments. * Add tests for validating the bundle size * Add tests for validating the gzipped size * Add support to inline css bundles in the html head * Improve path normalization * Add support to preload CSS bundles Also, inline the base/base bundle by default and preload the base/icons bundle by default. * Add support to specify the fetch priority Also, fix default values for mercuryOptions * Add comment for an upcoming feature (lightningcss) * Inline the "resets/box-sizing" css bundle by default * Split the Mercury DS implementation into the mercury-build, mercury-cli and vite-mercury-plugin packages Now, @genexus/mercury only contains the core of Mercury, and we have packages for bulding Mercury, using it through out a CLI, and a plugin to work with Vite. Breaking changes: - The default path for the fonts is now "/assets/fonts/" instead of "./assets/fonts/" - The default path for the icons is now "/assets/icons/" instead of "./assets/icons/" * Add support to build the Mercury CSS bundles * Fix Mercury build * More fixes for the Mercury build * Update eslint.config.js * Remove comments * Copy assets when building the css We are no longer splitting the scss build with the assets copy, so we can centralize the Mercury build process * Improve build output style * Improve script names * Fixes for building the dist for Mercury * Update validate-args.ts * Remove bulding scripts for the showcase in the Mercury package * Move assets file to the src folder * Update tsconfig.json * New dev server for the showcase * Add missing commits * Fix wrong placeholder values * Add missing commit * Refresh the showcase when rebuilding Mercury * Improve main readme for local development * Avoid memory leaks when the build crashes * Fix dev server not working properly * Build Mercury for usage * Remove no longer required code for the mercury-cli package * Properly build mercury for the distribution of the showcase * Remove --outDir argument Now, all the generated CSS files are located in the "node_modules/.genexus/mercury/assets/css" folder * Copy the fonts and icons when building Mercury for usage * Move Mercury plugins to the mercury-plugins folder * Use TS GO for faster dev builds * Force "hoisted" installs by adding bunfig.toml file * Complete the implementation for vite-mercury-plugin * Fix conflicts between NodeJS' threads and Vite's build process * Don't clear fonts and icons folders to let multiple plugins add assets in those destinations * Improvements for the React installation docs * Add readme for the @genexus/mercury-build package * Improve package.json description * Fix ESM only export not working for require * Delete unused script * Use bun for running build-scss-and-copy-assets script and delete unused script * Fix showcase dev server * Fix tests not working in common package * More fixes for running tests in the common package * Rename "vite-mercury-plugin" to "vite-plugin-mercury" * Try to fix workflows * Fix missing "bun" runner in workflows * Try to fix workflow * Try to fix workflows again * Comment out workflow to test ci * Comment out workflow step * Update install-and-deploy.yml * Fix tests * Fix code scanning result issue * Remove unused "start.watch" script * Fix typo in react docs * Use TS and bun for all scripts * Update NextJS installation guide * Update installation-for-react.md * Move the bundle-to-hash-mapping.ts file to the "node_modules/.genexus/mercury/" folder * Improve all installation readmes * Improve/add readmes for the new packages * Fix image path * More improvements for readmes * Fix typo * Add workflows for the new packages * Remove "mercury" binnary from the mercury core * Update bun.lock * Improve the visualization of the bundle size table
1 parent e58ba5e commit 49ba432

File tree

132 files changed

+4348
-2080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+4348
-2080
lines changed

.github/workflows/install-and-deploy.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: actions/cache@2f8e54208210a422b2efd51efaa6bd6d7ca8920f
6363
with:
6464
path: ~/.bun/install/cache
65-
key: ${{ runner.os }}-bun-${{ hashFiles('''**/bun.lockb''') }}
65+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
6666
restore-keys: |
6767
${{ runner.os }}-bun-
6868
@@ -76,6 +76,26 @@ jobs:
7676
# if: ${{ inputs.common-tests == true }}
7777
# run: bun test.common.ci
7878

79+
# We need to pre-build Mercury, because the mercury-build package needs it.
80+
# TODO: We should eliminate this "cycle dependency" in the future.
81+
- name: Prebuild Mercury
82+
run: bun build.js
83+
working-directory: "packages/mercury"
84+
85+
# Test if the @genexus/mercury-build, @genexus/mercury-cli, and @genexus/vite-plugin-mercury packages are built correctly.
86+
- name: Build genexus/mercury-build
87+
run: bun dev
88+
working-directory: "packages/mercury-build"
89+
90+
- name: Build genexus/mercury-cli
91+
run: bun dev
92+
working-directory: "packages/mercury-cli"
93+
94+
- name: Build genexus/vite-plugin-mercury
95+
run: bun dev
96+
working-directory: "packages/mercury-plugins/vite-plugin-mercury"
97+
98+
# The validate.ci for Mercury needs to be run after building the three packages above.
7999
- name: Run tests
80100
run: bun validate.ci
81101
working-directory: ${{ inputs.package }}

.github/workflows/node.js.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ jobs:
2727
publish: false
2828
package: "packages/mercury"
2929

30+
mercury-build:
31+
uses: ./.github/workflows/install-and-deploy.yml
32+
with:
33+
node-version: "22.x"
34+
cache: true
35+
common-tests: false
36+
publish: false
37+
package: "packages/mercury-build"
38+
39+
mercury-cli:
40+
uses: ./.github/workflows/install-and-deploy.yml
41+
with:
42+
node-version: "22.x"
43+
cache: true
44+
common-tests: false
45+
publish: false
46+
package: "packages/mercury-cli"
47+
3048
svg-sass-generator:
3149
uses: ./.github/workflows/install-and-deploy.yml
3250
with:
@@ -35,3 +53,13 @@ jobs:
3553
common-tests: false
3654
publish: false
3755
package: "packages/svg-sass-generator"
56+
57+
vite-plugin-mercury:
58+
uses: ./.github/workflows/install-and-deploy.yml
59+
with:
60+
node-version: "22.x"
61+
cache: true
62+
common-tests: false
63+
publish: false
64+
package: "packages/mercury-plugins/vite-plugin-mercury"
65+

.github/workflows/npmpublish.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ jobs:
1111
outputs:
1212
unanimo-changed: ${{ steps.check-unanimo.outputs.version-changed }}
1313
mercury-changed: ${{ steps.check-mercury.outputs.version-changed }}
14+
mercury-build-changed: ${{ steps.check-mercury-build.outputs.version-changed }}
15+
mercury-cli-changed: ${{ steps.check-mercury-cli.outputs.version-changed }}
1416
svg-sass-generator-changed: ${{ steps.check-svg-sass-generator.outputs.version-changed }}
17+
vite-plugin-mercury-changed: ${{ steps.check-vite-plugin-mercury.outputs.version-changed }}
1518
steps:
1619
# Pinning to a specific commit hash for security reasons.
1720
# This hash corresponds to version 4.3.0 of the actions/checkout action.
@@ -34,18 +37,42 @@ jobs:
3437
LATEST_MERCURY_VERSION=$(curl -s https://registry.npmjs.org/$PACKAGE_NAME | jq -r '.["dist-tags"].latest')
3538
echo "latest_mercury_version=$LATEST_MERCURY_VERSION" >> $GITHUB_ENV
3639
40+
- name: Get the latest mercury-build version
41+
id: get-latest-mercury-build-version
42+
run: |
43+
PACKAGE_NAME=@genexus/mercury-build
44+
LATEST_MERCURY_BUILD_VERSION=$(curl -s https://registry.npmjs.org/$PACKAGE_NAME | jq -r '.["dist-tags"].latest')
45+
echo "latest_mercury_build_version=$LATEST_MERCURY_BUILD_VERSION" >> $GITHUB_ENV
46+
47+
- name: Get the latest mercury-cli version
48+
id: get-latest-mercury-cli-version
49+
run: |
50+
PACKAGE_NAME=@genexus/mercury-cli
51+
LATEST_MERCURY_CLI_VERSION=$(curl -s https://registry.npmjs.org/$PACKAGE_NAME | jq -r '.["dist-tags"].latest')
52+
echo "latest_mercury_cli_version=$LATEST_MERCURY_CLI_VERSION" >> $GITHUB_ENV
53+
3754
- name: Get the latest SVG_Generator version
3855
id: get-latest-svg_generator-version
3956
run: |
4057
PACKAGE_NAME=@genexus/svg-sass-generator
4158
LATEST_SVG_GENERATOR_VERSION=$(curl -s https://registry.npmjs.org/$PACKAGE_NAME | jq -r '.["dist-tags"].latest')
4259
echo "latest_svg_generator_version=$LATEST_SVG_GENERATOR_VERSION" >> $GITHUB_ENV
4360
61+
- name: Get the latest vite-plugin-mercury version
62+
id: get-latest-vite-plugin-mercury-version
63+
run: |
64+
PACKAGE_NAME=@genexus/vite-plugin-mercury
65+
LATEST_VITE_PLUGIN_MERCURY_VERSION=$(curl -s https://registry.npmjs.org/$PACKAGE_NAME | jq -r '.["dist-tags"].latest')
66+
echo "latest_vite_plugin_mercury_version=$LATEST_VITE_PLUGIN_MERCURY_VERSION" >> $GITHUB_ENV
67+
4468
- name: Print last published versions
4569
run: |
4670
echo "The latest Unanimo version is ${{ env.latest_unanimo_version }}"
4771
echo "The latest Mercury version is ${{ env.latest_mercury_version }}"
72+
echo "The latest mercury-build version is ${{ env.latest_mercury_build_version }}"
73+
echo "The latest mercury-cli version is ${{ env.latest_mercury_cli_version }}"
4874
echo "The latest SVG Generator version is ${{ env.latest_svg_generator_version }}"
75+
echo "The latest vite-plugin-mercury version is ${{ env.latest_vite_plugin_mercury_version }}"
4976
5077
- name: Check if `unanimo` version changed
5178
id: check-unanimo
@@ -71,6 +98,30 @@ jobs:
7198
echo "version-changed=false" >> $GITHUB_OUTPUT
7299
fi
73100
101+
- name: Check if `mercury-build` version changed
102+
id: check-mercury-build
103+
run: |
104+
CURRENT_VERSION=$(jq -r .version packages/mercury-build/package.json)
105+
PREVIOUS_VERSION=${{ env.latest_mercury_build_version }}
106+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
107+
echo "Version changed!"
108+
echo "version-changed=true" >> $GITHUB_OUTPUT
109+
else
110+
echo "version-changed=false" >> $GITHUB_OUTPUT
111+
fi
112+
113+
- name: Check if `mercury-cli` version changed
114+
id: check-mercury-cli
115+
run: |
116+
CURRENT_VERSION=$(jq -r .version packages/mercury-cli/package.json)
117+
PREVIOUS_VERSION=${{ env.latest_mercury_cli_version }}
118+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
119+
echo "Version changed!"
120+
echo "version-changed=true" >> $GITHUB_OUTPUT
121+
else
122+
echo "version-changed=false" >> $GITHUB_OUTPUT
123+
fi
124+
74125
- name: Check if `svg-sass-generator` version changed
75126
id: check-svg-sass-generator
76127
run: |
@@ -83,6 +134,18 @@ jobs:
83134
echo "version-changed=false" >> $GITHUB_OUTPUT
84135
fi
85136
137+
- name: Check if `vite-plugin-mercury` version changed
138+
id: check-vite-plugin-mercury
139+
run: |
140+
CURRENT_VERSION=$(jq -r .version packages/mercury-plugins/vite-plugin-mercury/package.json)
141+
PREVIOUS_VERSION=${{ env.latest_vite_plugin_mercury_version }}
142+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
143+
echo "Version changed!"
144+
echo "version-changed=true" >> $GITHUB_OUTPUT
145+
else
146+
echo "version-changed=false" >> $GITHUB_OUTPUT
147+
fi
148+
86149
publish-unanimo:
87150
needs: check-version
88151
if: needs.check-version.outputs.unanimo-changed == 'true'
@@ -107,6 +170,30 @@ jobs:
107170
package: "packages/mercury"
108171
secrets: inherit
109172

173+
publish-mercury-build:
174+
needs: check-version
175+
if: needs.check-version.outputs.mercury-build-changed == 'true'
176+
uses: ./.github/workflows/install-and-deploy.yml
177+
with:
178+
node-version: "22.x"
179+
cache: false
180+
common-tests: false
181+
publish: true
182+
package: "packages/mercury-build"
183+
secrets: inherit
184+
185+
publish-mercury-cli:
186+
needs: check-version
187+
if: needs.check-version.outputs.mercury-cli-changed == 'true'
188+
uses: ./.github/workflows/install-and-deploy.yml
189+
with:
190+
node-version: "22.x"
191+
cache: false
192+
common-tests: false
193+
publish: true
194+
package: "packages/mercury-cli"
195+
secrets: inherit
196+
110197
publish-svg-sass-generator:
111198
needs: check-version
112199
if: needs.check-version.outputs.svg-sass-generator-changed == 'true'
@@ -118,3 +205,16 @@ jobs:
118205
publish: true
119206
package: "packages/svg-sass-generator"
120207
secrets: inherit
208+
209+
publish-vite-plugin-mercury:
210+
needs: check-version
211+
if: needs.check-version.outputs.vite-plugin-mercury-changed == 'true'
212+
uses: ./.github/workflows/install-and-deploy.yml
213+
with:
214+
node-version: "22.x"
215+
cache: false
216+
common-tests: false
217+
publish: true
218+
package: "packages/mercury-plugins/vite-plugin-mercury"
219+
secrets: inherit
220+

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ To see the documentation and examples of how to use Mercury, visit the [showcase
2424
npm i bun -g
2525
```
2626

27-
- To start the showcase, run:
27+
- To start the showcase which automatically rebuilds Mercury, run:
2828

2929
```bash
30-
bun start.watch
31-
```
32-
33-
- To automatically build Mercury, run:
34-
35-
```bash
36-
bun build.mer.watch
30+
bun start
3731
```
3832

3933
- To automatically build Unanimo, run:

0 commit comments

Comments
 (0)