Skip to content

fix(build): define build-time constants in ESM and UMD bundles - #5930

Open
HawkForge wants to merge 2 commits into
swagger-api:mainfrom
HawkForge:fix/umd-esm-build-defines
Open

HawkForge wants to merge 2 commits into
swagger-api:mainfrom
HawkForge:fix/umd-esm-build-defines

Conversation

@HawkForge

Copy link
Copy Markdown

Closes #5893. Thanks @jem3523 for the detailed report and the bisect.

Since #5874 the splash screen renders PACKAGE_VERSION directly, and the versions plugin reads PACKAGE_VERSION, GIT_COMMIT, GIT_DIRTY and BUILD_TIME. Only vite.config.js and vite.config.app.js pass buildDefines() to Vite, so the library bundles keep the bare identifiers. Rendering the splash screen then throws ReferenceError: PACKAGE_VERSION is not defined and the editor never mounts.

The issue reports this for the UMD bundle, but the ESM bundle has the same problem: dist/esm/plugins/splash-screen/index.js in the published 5.9.0 package contains children: PACKAGE_VERSION. Consumers who import the ESM build hit the same error unless their own bundler defines the constant.

This change adds define: buildDefines() to the main config in vite.config.esm.js and vite.config.umd.js, matching the other two configs.

How I checked it (there is no unit test harness for the build configs, and CI doesn't build the bundles):

  • npm run build:bundle:umd and npm run build:bundle:esm on main both output an unsubstituted PACKAGE_VERSION in the splash screen. With this change the UMD bundle has children:`5.9.0` and dist/esm no longer contains any of the four identifiers outside source maps.
  • I server-rendered the SplashScreen component from the built dist/esm/plugins/splash-screen/index.js with react-dom/server. On main it throws ReferenceError: PACKAGE_VERSION is not defined. With this change it renders <figcaption>5.9.0</figcaption>.
  • npx eslint and prettier --check pass on both changed files, and npm run test:run passes.

This does not cover #5894 (require is not defined in the UMD bundle), which is a separate problem.


Replaces #5907, which got closed when my fork was accidentally detached.

The splash screen renders PACKAGE_VERSION directly since swagger-api#5874, but
only the dev server and app configs passed buildDefines() to Vite.
The ESM and UMD bundles shipped the bare identifier, so rendering
the splash screen threw a ReferenceError and the editor never mounted.

Closes swagger-api#5893

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SwaggerEditor@5: PACKAGE_VERSION is not substituted in the UMD build, breaking the Monaco editor (regression in 5.8.6)

1 participant