fix(esbuild): resolve paths from absWorkingDir instead of process.cwd() - #5148
Conversation
🦋 Changeset detectedLatest commit: c5ae170 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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/metro-plugin-rock
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@module-federation/observability-plugin
@module-federation/playground
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/rstest
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
Bundle Size Report7 package(s) changed, 36 unchanged. Package dist + ESM entry
Bundle targets
Consumer scenarios
Total dist (raw): 23.41 MB (+692 B (+0.0%)) Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as |
esbuild reports metafile output paths relative to absWorkingDir. The plugin resolved them, and the manifest's shared package.json lookups, from process.cwd(), so a build with a different absWorkingDir failed with ENOENT on dist/remoteEntry.js or wrote its manifest next to the process.
15ee09c to
c5ae170
Compare
Description
esbuild reports every metafile output path relative to
absWorkingDir. The plugin resolved those paths, and the manifest's sharedpackage.jsonlookups, fromprocess.cwd(). A build whoseabsWorkingDiris not the process directory failed inonEndwithENOENT: no such file or directory, open 'dist/remoteEntry.js'. When both directories happened to have adist, the manifest was written next to the process instead of the build, and shared versions came from the process directory'snode_modules.The plugin now reads
absWorkingDironce insetup, defaulting toprocess.cwd()as esbuild does, and resolves the remote entry, the manifest path, and the sharedpackage.jsonlookups against it. Builds that do not setabsWorkingDirare unchanged.The RFC #5036 stack carries the output-path half of this fix in #5097. Main bugs found in stack work get their own PR, so this is it.
Tests
packages/esbuild/__tests__/abs-working-dir.spec.mjsbuilds from a temp directory underos.tmpdir(), with a shareddep@1.2.3installed only there. It first asserts that the temp directory is not the process directory. Then it asserts that the module map is rewritten in the tempdist/remoteEntry.js, thatmf-manifest.jsonis written next to it and listsdep@1.2.3, and that no manifest lands under the process directory.main'splugin.tsandmanifest.ts, the build fails with theENOENTabove. With only the shared-version lookup reverted, the test fails withversion: undefinedwhere'1.2.3'is expected. With the fix, it passes."test": "node --test __tests__/*.spec.mjs". The turbotesttask depends onbuild, so the test runs againstdist/plugin.mjs, the published entry.pnpm --filter @module-federation/esbuild run lintpasses.Not tested: Windows paths, and
write: falsebuilds (see below).Not in this PR
These share the family but not the mechanism or the correct base directory, so each is its own change:
manifest.tsresolves the build name from/package.json, an absolute root path. It fails on every machine and falls back toconfig.name. Fixing it changesbuildNamefor every build.getExportsincollect-exports.tsresolves the shared module fromprocess.cwd(). Its correct base is esbuild'sresolveDirfor the importer, whichonLoadalready receives, notabsWorkingDir.share-utils.tsreadsprocess.cwd()while normalizing config, before a build exists.write: falsebuilds. The plugin reads the remote entry back from disk to fill in__MODULE_MAP__, so nothing is there to read. The map should be generated in the container'sonLoadinstead of patched after the write.Types of changes
Checklist