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

Updating cosmiconfig to not cache .js config files when told not to #5558

Merged
merged 6 commits into from Nov 29, 2018
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 @@ -24,7 +24,7 @@
"camelcase": "4.1.0",
"chalk": "2.1.0",
"cjk-regex": "2.0.0",
"cosmiconfig": "5.0.6",
"cosmiconfig": "5.0.7",
"dashify": "0.2.2",
"dedent": "0.7.0",
"diff": "3.2.0",
Expand Down
24 changes: 19 additions & 5 deletions scripts/build/babel-plugins/transform-custom-require.js
Expand Up @@ -4,10 +4,12 @@
// BEFORE:
// eval("require")("./path/to/file")
// eval("require")(identifier)
// eval("require").cache
//
// AFTER:
// require("./file")
// require(identifier)
// require.cache
//

module.exports = function(babel) {
Expand All @@ -17,25 +19,37 @@ module.exports = function(babel) {
visitor: {
CallExpression(path) {
const node = path.node;
if (isEvalRequire(node)) {
if (isEvalRequire(node.callee) && node.arguments.length === 1) {
let arg = node.arguments[0];
if (t.isLiteral(arg) && arg.value.startsWith(".")) {
const value = "." + arg.value.substring(arg.value.lastIndexOf("/"));
arg = t.stringLiteral(value);
}
path.replaceWith(t.callExpression(t.identifier("require"), [arg]));
}
},
MemberExpression(path) {
const node = path.node;
if (isEvalRequire(node.object)) {
path.replaceWith(
t.memberExpression(
t.identifier("require"),
node.property,
node.compute,
node.optional
)
);
}
}
}
};

function isEvalRequire(node) {
return (
t.isCallExpression(node.callee) &&
t.isCallExpression(node) &&
t.isIdentifier(node.callee, { name: "eval" }) &&
node.arguments.length === 1 &&
t.isIdentifier(node.callee.callee, { name: "eval" }) &&
node.callee.arguments.length === 1 &&
t.isLiteral(node.callee.arguments[0], { value: "require" })
t.isLiteral(node.arguments[0], { value: "require" })
);
}
};
2 changes: 1 addition & 1 deletion scripts/build/build.js
Expand Up @@ -99,7 +99,7 @@ async function run(params) {
await execa("rm", ["-rf", ".cache"]);
}

const bundleCache = new Cache(".cache/", "v8");
const bundleCache = new Cache(".cache/", "v9");
await bundleCache.load();

console.log(chalk.inverse(" Building packages "));
Expand Down
5 changes: 3 additions & 2 deletions scripts/build/config.js
Expand Up @@ -125,9 +125,10 @@ const coreBundles = [
type: "core",
target: "node",
replace: {
// cosmiconfig@5 uses `require` to resolve js config, which caused Error:
// cosmiconfig@5 -> import-fresh uses `require` to resolve js config, which caused Error:
// Dynamic requires are not currently supported by rollup-plugin-commonjs.
"require(filepath)": "eval('require')(filepath)"
"require(filePath)": "eval('require')(filePath)",
"require.cache": "eval('require').cache"
}
}
];
Expand Down
64 changes: 55 additions & 9 deletions yarn.lock
Expand Up @@ -739,8 +739,9 @@ are-we-there-yet@~1.1.2:
readable-stream "^2.0.6"

argparse@^1.0.7:
version "1.0.9"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86"
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
dependencies:
sprintf-js "~1.0.2"

Expand Down Expand Up @@ -1243,12 +1244,26 @@ cache-base@^1.0.1:
union-value "^1.0.0"
unset-value "^1.0.0"

caller-callsite@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/caller-callsite/-/caller-callsite-2.0.0.tgz#847e0fce0a223750a9a027c54b33731ad3154134"
integrity sha1-hH4PzgoiN1CpoCfFSzNzGtMVQTQ=
dependencies:
callsites "^2.0.0"

caller-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f"
dependencies:
callsites "^0.2.0"

caller-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-2.0.0.tgz#468f83044e369ab2010fac5f06ceee15bb2cb1f4"
integrity sha1-Ro+DBE42mrIBD6xfBs7uFbsssfQ=
dependencies:
caller-callsite "^2.0.0"

callsites@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca"
Expand Down Expand Up @@ -1540,10 +1555,12 @@ core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"

cosmiconfig@5.0.6:
version "5.0.6"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.6.tgz#dca6cf680a0bd03589aff684700858c81abeeb39"
cosmiconfig@5.0.7:
version "5.0.7"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.7.tgz#39826b292ee0d78eda137dfa3173bd1c21a43b04"
integrity sha512-PcLqxTKiDmNT6pSpy4N6KtuPwb53W+2tzNvwOZw0WH9N6O0vLIBq0x8aj8Oj75ere4YcGi48bDFCL+3fRJdlNA==
dependencies:
import-fresh "^2.0.0"
is-directory "^0.3.1"
js-yaml "^3.9.0"
parse-json "^4.0.0"
Expand Down Expand Up @@ -1875,12 +1892,19 @@ errno@^0.1.3:
dependencies:
prr "~0.0.0"

error-ex@^1.2.0, error-ex@^1.3.1:
error-ex@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc"
dependencies:
is-arrayish "^0.2.1"

error-ex@^1.3.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
integrity sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==
dependencies:
is-arrayish "^0.2.1"

es-abstract@^1.5.1, es-abstract@^1.7.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.12.0.tgz#9dbbdd27c6856f0001421ca18782d786bf8a6165"
Expand Down Expand Up @@ -2112,8 +2136,9 @@ esprima@^3.1.3:
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"

esprima@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==

esquery@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -2796,6 +2821,14 @@ ignore@3.3.7, ignore@^3.3.3, ignore@^3.3.5:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"

import-fresh@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-2.0.0.tgz#d81355c15612d386c61f9ddd3922d4304822a546"
integrity sha1-2BNVwVYS04bGH53dOSLUMEgipUY=
dependencies:
caller-path "^2.0.0"
resolve-from "^3.0.0"

import-local@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/import-local/-/import-local-1.0.0.tgz#5e4ffdc03f4fe6c009c6729beb29631c2f8227bc"
Expand Down Expand Up @@ -2903,6 +2936,7 @@ is-alphanumerical@^1.0.0:
is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=

is-binary-path@^1.0.0:
version "1.0.1"
Expand Down Expand Up @@ -2969,6 +3003,7 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2:
is-directory@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=

is-dotfile@^1.0.0:
version "1.0.3"
Expand Down Expand Up @@ -3585,13 +3620,21 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

js-yaml@^3.7.0, js-yaml@^3.9.0, js-yaml@^3.9.1:
js-yaml@^3.7.0, js-yaml@^3.9.1:
version "3.10.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.9.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
integrity sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
Expand Down Expand Up @@ -3650,6 +3693,7 @@ json-loader@^0.5.4:
json-parse-better-errors@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==

json-schema-traverse@^0.3.0:
version "0.3.1"
Expand Down Expand Up @@ -4384,6 +4428,7 @@ parse-json@^2.2.0:
parse-json@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
integrity sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=
dependencies:
error-ex "^1.3.1"
json-parse-better-errors "^1.0.1"
Expand Down Expand Up @@ -5371,6 +5416,7 @@ split-string@^3.0.1, split-string@^3.0.2:
sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=

sshpk@^1.7.0:
version "1.13.1"
Expand Down