Skip to content

Commit

Permalink
Fix another case of parcelRequire being added to multi-target librari…
Browse files Browse the repository at this point in the history
…es (#9904)
  • Loading branch information
devongovett authored Aug 28, 2024
1 parent 7228931 commit 9c95c1b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/core/src/BundleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,9 @@ export default class BundleGraph {
// If the asset is available in multiple bundles in the same target, it's referenced.
if (
this.getBundlesWithAsset(asset).filter(
b => b.target.distDir === bundle.target.distDir,
b =>
b.target.name === bundle.target.name &&
b.target.distDir === bundle.target.distDir,
).length > 1
) {
return true;
Expand Down
54 changes: 54 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5132,6 +5132,60 @@ describe('javascript', function () {
},
);

it.v2(
`should not wrap assets that are duplicated in different targets in the same dist dir`,
async function () {
const dir = path.join(__dirname, 'multi-target-duplicates-dist');
overlayFS.mkdirp(dir);

await fsFixture(overlayFS, dir)`
package.json:
{
"main": "dist/main.cjs",
"browser": "dist/browser.cjs",
"targets": {
"main": {
"source": "node.js",
"context": "browser",
"engines": {
"browsers": "chrome >= 70"
}
},
"browser": {
"source": "browser.js",
"engines": {
"browsers": "chrome >= 70"
}
}
}
}
node.js:
import shared from './shared';
export default shared + 2;
browser.js:
import shared from './shared';
export default shared + 2;
shared.js:
export default 2;
`;

let b = await bundle(dir, {
inputFS: overlayFS,
});

for (let bundle of b.getBundles()) {
let contents = await outputFS.readFile(bundle.filePath, 'utf8');
assert(
!contents.includes('parcelRequire'),
'should not include parcelRequire',
);
}
},
);

it.v2(`should also fail on recoverable parse errors`, async () => {
await fsFixture(overlayFS, __dirname)`
js-recoverable-parse-errors
Expand Down

0 comments on commit 9c95c1b

Please sign in to comment.