Skip to content

Commit

Permalink
Tests and improvements to babel config invalidation (#5256)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Nov 22, 2020
1 parent 5510b03 commit da12643
Show file tree
Hide file tree
Showing 28 changed files with 1,258 additions and 277 deletions.
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

0 comments on commit da12643

Please sign in to comment.