diff --git a/packages/bundlers/default/src/DefaultBundler.js b/packages/bundlers/default/src/DefaultBundler.js index 23a7282028e..f5e0d4987c4 100644 --- a/packages/bundlers/default/src/DefaultBundler.js +++ b/packages/bundlers/default/src/DefaultBundler.js @@ -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; diff --git a/packages/core/integration-tests/test/bundler.js b/packages/core/integration-tests/test/bundler.js index c72d44b2f3f..293f0bfa16a 100644 --- a/packages/core/integration-tests/test/bundler.js +++ b/packages/core/integration-tests/test/bundler.js @@ -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: + + + 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 () {