Skip to content

Commit

Permalink
Fix assets outside project root with Manual Shared Bundles. (#9734)
Browse files Browse the repository at this point in the history
* Add failing integration test for assets outside project root

* Use path.relative for relative path for MSB checks
  • Loading branch information
marcins authored May 23, 2024
1 parent 3549c91 commit f833a24
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/bundlers/default/src/DefaultBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ function createIdealGraph(
node.type === 'asset' &&
(!Array.isArray(c.types) || c.types.includes(node.value.type))
) {
// +1 accounts for leading slash
let projectRelativePath = node.value.filePath.slice(
config.projectRoot.length + 1,
let projectRelativePath = path.relative(
config.projectRoot,
node.value.filePath,
);
if (!assetRegexes.some(regex => regex.test(projectRelativePath))) {
return;
Expand Down
58 changes: 58 additions & 0 deletions packages/core/integration-tests/test/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,64 @@ describe('bundler', function () {
},
]);
});

it('should support globs matching outside of the project root', async function () {
const rootDir = path.join(dir, 'root');
overlayFS.mkdirp(rootDir);
await fsFixture(overlayFS, rootDir)`
yarn.lock:
// Required for config loading
package.json:
{
"@parcel/bundler-default": {
"minBundleSize": 0,
"manualSharedBundles": [{
"name": "vendor",
"root": "vendor.js",
"assets": [
"in-project.js",
"../outside-project.js"
]
}]
}
}
index.html:
<script type="module" src="./index.js"></script>
in-project.js:
export default 'in-project';
vendor.js:
export * from './in-project';
export * from '../outside-project';
index.js:
import * as vendor from './vendor';
console.log(vendor.inProj);
console.log(vendor.outProj);`;

await fsFixture(overlayFS, dir)`
outside-project.js:
export default 'outside-project';`;

let b = await bundle(path.join(rootDir, 'index.html'), {
defaultTargetOptions: {
shouldScopeHoist: false,
shouldOptimize: false,
sourceMaps: false,
},
inputFS: overlayFS,
});

assertBundles(b, [
{assets: ['index.html']},
{assets: ['in-project.js', 'outside-project.js']},
{assets: ['esmodule-helpers.js', 'index.js', 'vendor.js']},
]);
});
});

it('should reuse type change bundles from parent bundle groups', async function () {
Expand Down

0 comments on commit f833a24

Please sign in to comment.