Repository navigation
fix: name build outputs after the exports map paths - #243
Open
unrevised6419 wants to merge 1 commit into
Open
unrevised6419 wants to merge 1 commit into
unrevised6419 wants to merge 1 commit into
Conversation
The build only used the `import` / `require` paths to choose the output directory and always wrote `index.mjs` and `index.js`. In a `"type": "module"` plugin the CommonJS output then landed in a `.js` file that Node loads as ESM, and a `.cjs` require path was never written. Each output file is now written to the path its exports condition points at. `./strapi-admin` and `./strapi-server` need only one of `import` or `require`, which allows ESM-only plugins. The build warns when an extension makes Node load a file in the wrong module format. Closes strapi#242 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 24659d4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What does it do?
Writes each build output to the path its exports condition points at, instead of always writing
index.mjs(ESM) andindex.js(CommonJS).createViteConfigtakes the output file names frombundle.output.esm/bundle.output.cjs(theimport/requirepaths), relative to the output directory.buildandwatchboth use it, so both behave the same../strapi-adminand./strapi-servernow need only one ofimportorrequire, not both. ESM-only and CJS-only plugins can now be built.verifyalready allowed this.buildwarns when an extension makes Node load a file in the wrong module format:require→.jsin a"type": "module"package, orimport→.jsin a package that isn't"type": "module". It's a warning, not an error, so existing builds keep working.importandrequirepoint to different directories, the build now fails with a clear error. Before, it silently wrote both files into therequiredirectory. Supporting split directories would need a separate Vite build per format, becauseemptyOutDirmust not clear a shared parent such asdist.initstill writes"type": "commonjs"withindex.mjs/index.js, which stays correct. Plugins that follow that layout get exactly the same files as before.Why is it needed?
"type": "module"plugins can't be built correctly today. CommonJS always lands inindex.js, which Node loads as ESM in such a package, so Strapi fails at boot withexports is not defined in ES module scope. Arequire: ./dist/server/index.cjspath is never written, and ESM-only plugins are rejected by validation (exports["./strapi-server"].require is a required field). Details and repro are in #242.How to test it?
pnpm checkcovers it. New tests:src/__tests__/e2e/build.test.ts"type": "module"plugin withimport: ./dist/server/index.jsandrequire: ./dist/server/index.cjsbuilds exactlyindex.cjsandindex.js, and a child Node process loads both, throughrequireandimport;.jsCommonJS warning is logged for a"type": "module"package;dist/server/index.js, and it loads throughimport.src/__tests__/e2e/verify.test.ts:verifypasses for the built ESM-only plugin.esm-type-plugin,esm-only-plugin.Without the source changes, 5 of the new tests fail. Existing tests are unchanged and pass.
Related issue(s)/PR(s)
Closes #242
Related: #241 (type declarations have the same one-file-for-both-formats problem; not addressed here). It touches the same files as #239 (
--bundle). Whichever merges second needs a small rebase: #239 renamesBundleConfig.typetoname, and the new messages here usebundle.type.🤖 Generated with Claude Code