From 4124e7ea26bef24e1b7e44ff3b3e824a42c76042 Mon Sep 17 00:00:00 2001 From: cpojer Date: Thu, 24 Aug 2017 15:25:55 +0100 Subject: [PATCH] Do not apply the inline-require transform to blacklisted modules. --- .babelrc | 14 +-------- package.json | 4 +-- scripts/build.js | 22 ++++++++++++-- yarn.lock | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 18 deletions(-) diff --git a/.babelrc b/.babelrc index 5ef398a3f49c..ae49879f0aab 100644 --- a/.babelrc +++ b/.babelrc @@ -5,19 +5,7 @@ "transform-es2015-destructuring", "transform-es2015-parameters", "transform-async-to-generator", - "transform-strict-mode", - ["transform-inline-imports-commonjs", {"allowTopLevelThis": true, "excludeModules": [ - "jest-circus", - "jest-diff", - "jest-get-type", - "jest-jasmine2", - "jest-matcher-utils", - "jest-matchers", - "jest-message-util", - "jest-regex-util", - "jest-snapshot", - "pretty-format" - ]}] + "transform-strict-mode" ], "retainLines": true } diff --git a/package.json b/package.json index fae51ff438ca..eb7518c712ba 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "babel-plugin-syntax-trailing-function-commas": "^6.13.0", "babel-plugin-transform-async-to-generator": "^6.16.0", "babel-plugin-transform-es2015-destructuring": "^6.23.0", + "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", "babel-plugin-transform-es2015-parameters": "^6.23.0", "babel-plugin-transform-flow-strip-types": "^6.18.0", "babel-plugin-transform-inline-imports-commonjs": "^1.2.0", @@ -139,6 +140,5 @@ "testMatch": [ "**/*.test.js" ] - }, - "dependencies": {} + } } diff --git a/scripts/build.js b/scripts/build.js index c4a40d2bf681..a5bd07b36a6d 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -41,10 +41,12 @@ const JS_FILES_PATTERN = '**/*.js'; const IGNORE_PATTERN = '**/__tests__/**'; const PACKAGES_DIR = path.resolve(__dirname, '../packages'); -const babelNodeOptions = JSON.parse( +const INLINE_REQUIRE_BLACKLIST = /packages\/(jest-(circus|diff|get-type|jasmine2|matcher-utils|matchers|message-util|regex-util|snapshot))|pretty-format\//; + +const transformOptions = JSON.parse( fs.readFileSync(path.resolve(__dirname, '..', '.babelrc'), 'utf8') ); -babelNodeOptions.babelrc = false; +transformOptions.babelrc = false; const adjustToTerminalWidth = str => { const columns = process.stdout.columns || 80; @@ -136,7 +138,21 @@ function buildFile(file, silent) { '\n' ); } else { - const transformed = babel.transformFileSync(file, babelNodeOptions).code; + const options = Object.assign({}, transformOptions); + options.plugins = options.plugins.slice(); + + if (INLINE_REQUIRE_BLACKLIST.test(file)) { + options.plugins.push('transform-es2015-modules-commonjs'); + } else { + options.plugins.push([ + 'transform-inline-imports-commonjs', + { + allowTopLevelThis: true, + }, + ]); + } + + const transformed = babel.transformFileSync(file, options).code; fs.writeFileSync(destPath, transformed); silent || process.stdout.write( diff --git a/yarn.lock b/yarn.lock index 6c1233ba66b9..a45a4817eca7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -307,6 +307,14 @@ babel-code-frame@^6.22.0: esutils "^2.0.2" js-tokens "^3.0.0" +babel-code-frame@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" + dependencies: + chalk "^1.1.3" + esutils "^2.0.2" + js-tokens "^3.0.2" + babel-core@6, babel-core@^6.23.1, babel-core@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.24.1.tgz#8c428564dce1e1f41fb337ec34f4c3b022b5ad83" @@ -669,6 +677,15 @@ babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-e babel-template "^6.24.1" babel-types "^6.24.1" +babel-plugin-transform-es2015-modules-commonjs@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz#0d8394029b7dc6abe1a97ef181e00758dd2e5d8a" + dependencies: + babel-plugin-transform-strict-mode "^6.24.1" + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-types "^6.26.0" + babel-plugin-transform-es2015-modules-systemjs@^6.23.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" @@ -930,6 +947,13 @@ babel-runtime@^6.18.0, babel-runtime@^6.22.0: core-js "^2.4.0" regenerator-runtime "^0.10.0" +babel-runtime@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.11.0" + babel-template@^6.16.0, babel-template@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.24.1.tgz#04ae514f1f93b3a2537f2a0f60a5a45fb8308333" @@ -950,6 +974,16 @@ babel-template@^6.25.0: babylon "^6.17.2" lodash "^4.2.0" +babel-template@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" + dependencies: + babel-runtime "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + lodash "^4.17.4" + babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.24.1.tgz#ab36673fd356f9a0948659e7b338d5feadb31695" @@ -978,6 +1012,20 @@ babel-traverse@^6.25.0: invariant "^2.2.0" lodash "^4.2.0" +babel-traverse@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" + dependencies: + babel-code-frame "^6.26.0" + babel-messages "^6.23.0" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + debug "^2.6.8" + globals "^9.18.0" + invariant "^2.2.2" + lodash "^4.17.4" + babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.23.0, babel-types@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.24.1.tgz#a136879dc15b3606bda0d90c1fc74304c2ff0975" @@ -996,10 +1044,23 @@ babel-types@^6.25.0: lodash "^4.2.0" to-fast-properties "^1.0.1" +babel-types@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" + dependencies: + babel-runtime "^6.26.0" + esutils "^2.0.2" + lodash "^4.17.4" + to-fast-properties "^1.0.3" + babylon@^6.11.0, babylon@^6.14.1, babylon@^6.15.0, babylon@^6.17.0, babylon@^6.17.2, babylon@^6.17.4: version "6.17.4" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.4.tgz#3e8b7402b88d22c3423e137a1577883b15ff869a" +babylon@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" + backo2@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" @@ -2935,6 +2996,10 @@ globals@^9.0.0, globals@^9.17.0: version "9.17.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.17.0.tgz#0c0ca696d9b9bb694d2e5470bd37777caad50286" +globals@^9.18.0: + version "9.18.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" + globby@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/globby/-/globby-5.0.0.tgz#ebd84667ca0dbb330b99bcfc68eac2bc54370e0d" @@ -3619,6 +3684,10 @@ js-tokens@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7" +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.8.4: version "3.8.4" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6" @@ -5071,6 +5140,10 @@ regenerator-runtime@^0.10.0, regenerator-runtime@^0.10.3: version "0.10.3" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.3.tgz#8c4367a904b51ea62a908ac310bf99ff90a82a3e" +regenerator-runtime@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" + regenerator-transform@0.9.11: version "0.9.11" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.9.11.tgz#3a7d067520cb7b7176769eb5ff868691befe1283" @@ -5860,6 +5933,10 @@ to-fast-properties@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.2.tgz#f3f5c0c3ba7299a7ef99427e44633257ade43320" +to-fast-properties@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" + tough-cookie@^2.3.2, tough-cookie@~2.3.0: version "2.3.2" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a"