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

Tests and improvements to babel config invalidation #5256

Merged
merged 7 commits into from Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,7 @@
"release": "lerna publish -y from-package --dist-tag=next --no-git-tag-version --no-push"
},
"devDependencies": {
"@babel/core": "^7.8.7",
"@babel/core": "^7.12.0",
"cross-env": "^7.0.0",
"doctoc": "^1.4.0",
"eslint": "^6.0.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/core/src/ParcelConfig.schema.js
Expand Up @@ -110,9 +110,7 @@ export default {
},
bundler: {
type: 'string',
__validate: (validatePluginName('bundler', 'bundler'): (
val: string,
) => void),
__validate: (validatePluginName('bundler', 'bundler'): string => void),
},
resolvers: (pipelineSchema('resolver', 'resolvers'): SchemaEntity),
transformers: (mapPipelineSchema(
Expand Down
21 changes: 21 additions & 0 deletions packages/core/core/src/worker.js
Expand Up @@ -150,3 +150,24 @@ export async function runPackage(
runner.getBundleInfo(bundle, bundleGraph, cacheKeys, configs)
);
}

const PKG_RE = /node_modules[/\\]((?:@[^/\\]+\/[^/\\]+)|[^/\\]+)(?!.*[/\\]node_modules[/\\])/;
export function invalidateRequireCache(workerApi: WorkerApi, file: string) {
if (process.env.PARCEL_BUILD_ENV === 'test') {
// Delete this module and all children in the same node_modules folder
let module = require.cache[file];
if (module) {
delete require.cache[file];

let pkg = file.match(PKG_RE)?.[1];
for (let child of module.children) {
if (pkg === child.id.match(PKG_RE)?.[1]) {
invalidateRequireCache(workerApi, child.id);
}
}
}
return;
}

throw new Error('invalidateRequireCache is only for tests');
}
2 changes: 1 addition & 1 deletion packages/core/integration-tests/package.json
Expand Up @@ -12,7 +12,7 @@
"test-ci": "yarn test --reporter mocha-multi-reporters --reporter-options configFile=./test/mochareporters.json"
},
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/core": "^7.12.0",
"@babel/plugin-syntax-export-default-from": "^7.2.0",
"@babel/plugin-syntax-export-namespace-from": "^7.2.0",
"@babel/plugin-syntax-module-attributes": "^7.10.4",
Expand Down