diff --git a/packages/wp-build/CHANGELOG.md b/packages/wp-build/CHANGELOG.md index f2f36d1e9ef236..cc642577b5624a 100644 --- a/packages/wp-build/CHANGELOG.md +++ b/packages/wp-build/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug Fixes - Add the `@babel/core` dependency, a peer of `esbuild-plugin-babel` ([#83765](https://github.com/WordPress/gutenberg/pull/83765)). +- Keep the build machine's absolute paths out of worker source maps when `wpWorkers` redirects a module with `resolve`, so the output is reproducible across checkouts ([#84163](https://github.com/WordPress/gutenberg/pull/84163)). ### Internal diff --git a/packages/wp-build/lib/worker-build.mjs b/packages/wp-build/lib/worker-build.mjs index a820a11525bc52..696c2db4123c49 100644 --- a/packages/wp-build/lib/worker-build.mjs +++ b/packages/wp-build/lib/worker-build.mjs @@ -55,11 +55,20 @@ function createModuleRedirectPlugin( resolveMap ) { matchedKey, resolveMap[ matchedKey ] ); + const resolveDir = path.dirname( args.path ); + // A relative specifier keeps the checkout path out of the source map. + const specifier = + './' + + path + .relative( resolveDir, targetPath ) + .split( path.sep ) + .join( '/' ); return { contents: `export { default } from ${ JSON.stringify( - targetPath + specifier ) };`, loader: 'js', + resolveDir, }; } ); },