From 8f89722964dc9503d18d9a39784533f1cc818c0e Mon Sep 17 00:00:00 2001 From: mattcompiles Date: Thu, 9 Nov 2023 18:19:00 +1100 Subject: [PATCH 1/3] Mark previously deferred assets as dirty for symbol prop --- packages/core/core/src/requests/AssetGraphRequest.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 0895418ac59..2790c5a10cf 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -369,6 +369,13 @@ export class AssetGraphBuilder { if (!previouslyDeferred && childNode.deferred) { this.assetGraph.markParentsWithHasDeferred(childNodeId); } else if (previouslyDeferred && !childNode.deferred) { + // Mark Asset and Dependency as dirty for symbol propagation as it was + // previously deferred and it's used symbols may have changed + this.changedAssetsPropagation.add(node.id); + node.usedSymbolsDownDirty = true; + this.changedAssetsPropagation.add(childNode.id); + childNode.usedSymbolsDownDirty = true; + this.assetGraph.unmarkParentsWithHasDeferred(childNodeId); } From 97b1feb01fcd0de28cf313bb85f93210353ae05e Mon Sep 17 00:00:00 2001 From: mattcompiles Date: Fri, 10 Nov 2023 09:04:57 +1100 Subject: [PATCH 2/3] Add test --- .../integration-tests/test/lazy-compile.js | 84 ++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/packages/core/integration-tests/test/lazy-compile.js b/packages/core/integration-tests/test/lazy-compile.js index ac431fb91f6..c1313b2b409 100644 --- a/packages/core/integration-tests/test/lazy-compile.js +++ b/packages/core/integration-tests/test/lazy-compile.js @@ -8,10 +8,23 @@ import { assertBundles, removeDistDirectory, run, + fsFixture, + overlayFS, } from '@parcel/test-utils'; const findBundle = (bundleGraph, nameRegex) => { - return bundleGraph.getBundles().find(b => nameRegex.test(b.name)); + const result = bundleGraph.getBundles().find(b => nameRegex.test(b.name)); + + if (!result) { + throw new Error( + `Couldn't find bundle matching '${nameRegex}'. Available bundles are ${bundleGraph + ?.getBundles() + .map(b => b.name) + .join(', ')}`, + ); + } + + return result; }; const distDirIncludes = async matches => { @@ -261,4 +274,73 @@ describe('lazy compile', function () { ]); subscription.unsubscribe(); }); + + it.only('should lazy compile properly when an assets needs to be re-visited in symbol propagation', async () => { + await fsFixture(overlayFS, __dirname)` + lazy-compile-import-symbols + index.js: + import { shared, async } from './main'; + export default Promise.all([shared(), async()]); + + main.js: + export function shared() { + return import('./shared'); + } + export function async() { + return import('./async'); + } + + async.js: + // Trigger more deps so a full 'propagateSymbolsUp' pass is executed + import './a'; + import './b'; + import './c'; + import { other } from './shared'; + export default other; + + shared.js: + export const main = 'main'; + export const other = 'other'; + + a.js: + sideEffectNoop(); + b.js: + sideEffectNoop(); + c.js: + sideEffectNoop(); + `; + + const b = await bundler( + path.join(__dirname, 'lazy-compile-import-symbols/index.js'), + { + shouldBuildLazily: true, + mode: 'development', + shouldContentHash: false, + inputFS: overlayFS, + }, + ); + + await removeDistDirectory(); + + const subscription = await b.watch(); + let result = await getNextBuild(b); + result = await result.requestBundle( + findBundle(result.bundleGraph, /^index\.js/), + ); + result = await result.requestBundle( + findBundle(result.bundleGraph, /^async\./), + ); + + let output = await run(result.bundleGraph); + assert.deepEqual(await output.default, [ + { + main: 'main', + other: 'other', + }, + { + default: 'other', + }, + ]); + subscription.unsubscribe(); + }); }); From bc47f12147ba12fc80b85725d1a17d926ee408e5 Mon Sep 17 00:00:00 2001 From: mattcompiles Date: Fri, 10 Nov 2023 10:19:47 +1100 Subject: [PATCH 3/3] Remove .only --- packages/core/integration-tests/test/lazy-compile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/integration-tests/test/lazy-compile.js b/packages/core/integration-tests/test/lazy-compile.js index c1313b2b409..6f72b57d0cf 100644 --- a/packages/core/integration-tests/test/lazy-compile.js +++ b/packages/core/integration-tests/test/lazy-compile.js @@ -275,7 +275,7 @@ describe('lazy compile', function () { subscription.unsubscribe(); }); - it.only('should lazy compile properly when an assets needs to be re-visited in symbol propagation', async () => { + it('should lazy compile properly when an assets needs to be re-visited in symbol propagation', async () => { await fsFixture(overlayFS, __dirname)` lazy-compile-import-symbols index.js: