Skip to content

Commit

Permalink
Fix missing content key in symbol prop when asset is removed (#9627)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles authored Apr 8, 2024
1 parent 0b77a56 commit 2aa753c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/core/core/src/requests/AssetGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class AssetGraphBuilder {
queue: PromiseQueue<mixed>;
changedAssets: Map<string, Asset>;
changedAssetsPropagation: Set<string>;
prevChangedAssetsPropagation: ?Set<string>;
optionsRef: SharedReference;
options: ParcelOptions;
api: RunAPI<AssetGraphRequestResult>;
Expand Down Expand Up @@ -146,8 +147,9 @@ export class AssetGraphBuilder {
this.previousSymbolPropagationErrors =
prevResult?.previousSymbolPropagationErrors ?? new Map();
this.changedAssets = prevResult?.changedAssets ?? new Map();
this.changedAssetsPropagation =
prevResult?.changedAssetsPropagation ?? new Set();
this.changedAssetsPropagation = new Set();
this.prevChangedAssetsPropagation = prevResult?.changedAssetsPropagation;

this.assetGraph = assetGraph;
this.optionsRef = optionsRef;
this.options = options;
Expand Down Expand Up @@ -230,6 +232,17 @@ export class AssetGraphBuilder {
visit(rootNodeId);
await this.queue.run();

if (this.prevChangedAssetsPropagation) {
// Add any previously seen Assets that have not been propagated yet to
// 'this.changedAssetsPropagation', but only if they still remain in the graph
// as they could have been removed since the last build
for (let assetId of this.prevChangedAssetsPropagation) {
if (this.assetGraph.hasContentKey(assetId)) {
this.changedAssetsPropagation.add(assetId);
}
}
}

if (errors.length) {
this.api.storeResult(
{
Expand Down
33 changes: 33 additions & 0 deletions packages/core/integration-tests/test/symbol-propagation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'assert';
import path from 'path';
import {bundler, run, overlayFS, fsFixture} from '@parcel/test-utils';

describe('symbol propagation', () => {
it('should handle removed assets from previous failed builds', async () => {
await fsFixture(overlayFS, __dirname)`
broken.js:
module.exports = require('./missing.js');
working.js:
module.exports = 'ITS WORKING';
index.js:
module.exports = require('./broken.js');`;

let b = bundler(path.join(__dirname, 'index.js'), {
inputFS: overlayFS,
shouldDisableCache: false,
});

await assert.rejects(() => b.run(), {
message: `Failed to resolve './missing.js' from './broken.js'`,
});

await overlayFS.writeFile(
path.join(__dirname, 'index.js'),
`module.exports = require('./working.js');`,
);

let {bundleGraph} = await b.run();

assert(await run(bundleGraph), 'ITS WORKING');
});
});

0 comments on commit 2aa753c

Please sign in to comment.