Skip to content

Commit f833a24

Browse files
authored
Fix assets outside project root with Manual Shared Bundles. (#9734)
* Add failing integration test for assets outside project root * Use path.relative for relative path for MSB checks
1 parent 3549c91 commit f833a24

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

packages/bundlers/default/src/DefaultBundler.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,9 @@ function createIdealGraph(
476476
node.type === 'asset' &&
477477
(!Array.isArray(c.types) || c.types.includes(node.value.type))
478478
) {
479-
// +1 accounts for leading slash
480-
let projectRelativePath = node.value.filePath.slice(
481-
config.projectRoot.length + 1,
479+
let projectRelativePath = path.relative(
480+
config.projectRoot,
481+
node.value.filePath,
482482
);
483483
if (!assetRegexes.some(regex => regex.test(projectRelativePath))) {
484484
return;

packages/core/integration-tests/test/bundler.js

+58
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,64 @@ describe('bundler', function () {
17691769
},
17701770
]);
17711771
});
1772+
1773+
it('should support globs matching outside of the project root', async function () {
1774+
const rootDir = path.join(dir, 'root');
1775+
overlayFS.mkdirp(rootDir);
1776+
await fsFixture(overlayFS, rootDir)`
1777+
yarn.lock:
1778+
// Required for config loading
1779+
1780+
package.json:
1781+
{
1782+
"@parcel/bundler-default": {
1783+
"minBundleSize": 0,
1784+
"manualSharedBundles": [{
1785+
"name": "vendor",
1786+
"root": "vendor.js",
1787+
"assets": [
1788+
"in-project.js",
1789+
"../outside-project.js"
1790+
]
1791+
}]
1792+
}
1793+
}
1794+
1795+
index.html:
1796+
<script type="module" src="./index.js"></script>
1797+
1798+
in-project.js:
1799+
export default 'in-project';
1800+
1801+
vendor.js:
1802+
export * from './in-project';
1803+
export * from '../outside-project';
1804+
1805+
index.js:
1806+
import * as vendor from './vendor';
1807+
1808+
console.log(vendor.inProj);
1809+
console.log(vendor.outProj);`;
1810+
1811+
await fsFixture(overlayFS, dir)`
1812+
outside-project.js:
1813+
export default 'outside-project';`;
1814+
1815+
let b = await bundle(path.join(rootDir, 'index.html'), {
1816+
defaultTargetOptions: {
1817+
shouldScopeHoist: false,
1818+
shouldOptimize: false,
1819+
sourceMaps: false,
1820+
},
1821+
inputFS: overlayFS,
1822+
});
1823+
1824+
assertBundles(b, [
1825+
{assets: ['index.html']},
1826+
{assets: ['in-project.js', 'outside-project.js']},
1827+
{assets: ['esmodule-helpers.js', 'index.js', 'vendor.js']},
1828+
]);
1829+
});
17721830
});
17731831

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

0 commit comments

Comments
 (0)