Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lazy/eager cache key to avoid invalid change when switching modes #9518

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/core/src/PackagerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ export default class PackagerRunner {
bundleGraph.getHash(bundle) +
JSON.stringify(configResults) +
JSON.stringify(globalInfoResults) +
this.options.mode,
this.options.mode +
`${this.options.shouldBuildLazily ? 'lazy' : 'eager'}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/nit but this doesn't really need to be a template string.. (but I get that you probably just copied what you did in all the other places, no big deal..)

JakeLane marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/core/src/RequestTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,9 @@ export function getWatcherOptions(options: ParcelOptions): WatcherOptions {
}

function getCacheKey(options) {
return `${PARCEL_VERSION}:${JSON.stringify(options.entries)}:${options.mode}`;
return `${PARCEL_VERSION}:${JSON.stringify(options.entries)}:${
options.mode
}:${options.shouldBuildLazily ? 'lazy' : 'eager'}`;
}

async function loadRequestGraph(options): Async<RequestGraph> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/requests/AssetGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class AssetGraphBuilder {
hashString(
`${PARCEL_VERSION}${name}${JSON.stringify(entries) ?? ''}${
options.mode
}`,
}${options.shouldBuildLazily ? 'lazy' : 'eager'}`,
) + '-AssetGraph';

this.isSingleChangeRebuild =
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/requests/BundleGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class BundlerRunner {
hashString(
`${PARCEL_VERSION}:BundleGraph:${
JSON.stringify(options.entries) ?? ''
}${options.mode}`,
}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`,
) + '-BundleGraph';
}

Expand Down
45 changes: 43 additions & 2 deletions packages/core/integration-tests/test/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6200,7 +6200,7 @@ describe('cache', function () {
loadConfig({config, options}) {
return DefaultBundler[CONFIG].loadConfig({config, options});
},

bundle({bundleGraph, config}) {
DefaultBundler[CONFIG].bundle({bundleGraph, config});
},
Expand All @@ -6218,7 +6218,9 @@ describe('cache', function () {
hashString(
`${version}:BundleGraph:${
JSON.stringify(resolvedOptions.entries) ?? ''
}${resolvedOptions.mode}`,
}${resolvedOptions.mode}${
resolvedOptions.shouldBuildLazily ? 'lazy' : 'eager'
}`,
) + '-BundleGraph';

assert(
Expand Down Expand Up @@ -6788,4 +6790,43 @@ describe('cache', function () {
let res = await run(build.bundleGraph);
assert.deepEqual(res, {default: 'foo'});
});

it('invalidates correctly when switching from lazy to eager modes', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this was a failing test before your changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it was!

let overlayFSPackageManager = new NodePackageManager(overlayFS, __dirname);
let entry = 'source/index.js';
let options = {
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
packageManager: overlayFSPackageManager,
shouldContentHash: false,
shouldDisableCache: false,
inputFS: overlayFS,
cacheDir: path.join(__dirname, '.parcel-cache'),
};

await fsFixture(overlayFS)`
source
lazy.js:

export default 'lazy-file';
index.js:
import('./lazy');

export default 'index-file';
`;

let lazyBundleGraph = await bundle(entry, {
...options,
shouldBuildLazily: true,
});
assert.equal(lazyBundleGraph.getBundles().length, 1);

let eagerBundleGraph = await bundle(entry, {
...options,
shouldBuildLazily: false,
});
assert.equal(eagerBundleGraph.getBundles().length, 2);
});
});
Loading