From b28b83295fb2c843daedeb66efd5733339a2f3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 6 Nov 2019 14:59:17 -0500 Subject: [PATCH 1/4] infra: build standalone against src --- packages/babel-core/package.json | 5 +++++ scripts/gulp-tasks.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index 4da69a87d404..25229fadc740 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -3,6 +3,7 @@ "version": "7.7.2", "description": "Babel compiler core.", "main": "lib/index.js", + "_main:used-by-babel-standalone": "src/index.js", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", "license": "MIT", @@ -36,6 +37,10 @@ "./lib/config/files/index.js": "./lib/config/files/index-browser.js", "./lib/transform-file.js": "./lib/transform-file-browser.js" }, + "_browser:used-by-babel-standalone": { + "./src/config/files/index.js": "./src/config/files/index-browser.js", + "./src/transform-file.js": "./src/transform-file-browser.js" + }, "dependencies": { "@babel/code-frame": "^7.5.5", "@babel/generator": "^7.7.2", diff --git a/scripts/gulp-tasks.js b/scripts/gulp-tasks.js index 73c1f7db2e3f..09d04e33fdb4 100644 --- a/scripts/gulp-tasks.js +++ b/scripts/gulp-tasks.js @@ -11,6 +11,7 @@ * to make standalone builds of other Babel plugins/presets (such as babel-minify) */ +const fs = require("fs"); const path = require("path"); const pump = require("pump"); const chalk = require("chalk"); @@ -24,6 +25,22 @@ const WarningsToErrorsPlugin = require("warnings-to-errors-webpack-plugin"); const webpackStream = require("webpack-stream"); const uglify = require("gulp-uglify"); +function generateResolveAlias() { + const alias = {}; + const packagePath = path.resolve(process.cwd(), "packages"); + fs.readdirSync(packagePath).forEach(folder => { + if (["babel-core"].includes(folder)) { + return; + } + alias[folder.replace("babel-", "@babel/")] = path.resolve( + packagePath, + folder, + "src" + ); + }); + return alias; +} + function webpackBuild(opts) { const plugins = opts.plugins || []; let babelVersion = require("../packages/babel-core/package.json").version; @@ -82,6 +99,10 @@ function webpackBuild(opts) { new webpack.optimize.ModuleConcatenationPlugin(), ].concat(plugins), resolve: { + //todo: remove resolve.alias when babel packages offer ESModule entry + alias: generateResolveAlias(), + aliasFields: ["_browser:used-by-babel-standalone", "browser"], + mainFields: ["_main:used-by-babel-standalone", "main"], plugins: [ // Dedupe packages that are used across multiple plugins. // This replaces DedupePlugin from Webpack 1.x From d26561741f0d8a84db1134b5d2d4fac025709b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 6 Nov 2019 15:02:02 -0500 Subject: [PATCH 2/4] infra: add absoluteRuntime # Conflicts: # babel.config.js --- babel.config.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/babel.config.js b/babel.config.js index 34a382f130ab..2715d650aa35 100644 --- a/babel.config.js +++ b/babel.config.js @@ -11,6 +11,7 @@ module.exports = function(api) { exclude: ["transform-typeof-symbol"], }; const envOpts = Object.assign({}, envOptsNoTargets); + let transformRuntimeOpts = null; let convertESM = true; let ignoreLib = true; @@ -50,6 +51,17 @@ module.exports = function(api) { break; } + if (includeRuntime) { + const babelRuntimePackageJSONPath = require.resolve( + "@babel/runtime/package.json" + ); + const path = require("path"); + transformRuntimeOpts = { + version: require(babelRuntimePackageJSONPath).version, + absoluteRuntime: path.dirname(babelRuntimePackageJSONPath), + }; + } + const config = { // Our dependencies are all standard CommonJS, along with all sorts of // other random files in Babel's codebase, so we use script as the default, @@ -123,10 +135,7 @@ module.exports = function(api) { ], plugins: [ includeRuntime - ? [ - "@babel/transform-runtime", - { version: require("@babel/runtime/package").version }, - ] + ? ["@babel/transform-runtime", transformRuntimeOpts] : null, ].filter(Boolean), }, From b714c77d2bffb68b1129dc0be616e10088b3b76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 6 Nov 2019 15:51:42 -0500 Subject: [PATCH 3/4] chore: remove `process.env` replace --- scripts/gulp-tasks.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/gulp-tasks.js b/scripts/gulp-tasks.js index 09d04e33fdb4..42ebf5b6917a 100644 --- a/scripts/gulp-tasks.js +++ b/scripts/gulp-tasks.js @@ -88,7 +88,6 @@ function webpackBuild(opts) { }), new webpack.DefinePlugin({ "process.env.NODE_ENV": '"production"', - "process.env": JSON.stringify({ NODE_ENV: "production" }), BABEL_VERSION: JSON.stringify(babelVersion), VERSION: JSON.stringify(version), }), From 1c1119f7d52b7211b5b6b4353b320990bdd43fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 12 Nov 2019 20:56:54 -0500 Subject: [PATCH 4/4] add $ to signify exact match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit credits to Nicolò --- packages/babel-core/package.json | 5 +---- scripts/gulp-tasks.js | 7 +------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index 25229fadc740..f22326d78eb3 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -3,7 +3,6 @@ "version": "7.7.2", "description": "Babel compiler core.", "main": "lib/index.js", - "_main:used-by-babel-standalone": "src/index.js", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", "license": "MIT", @@ -35,9 +34,7 @@ }, "browser": { "./lib/config/files/index.js": "./lib/config/files/index-browser.js", - "./lib/transform-file.js": "./lib/transform-file-browser.js" - }, - "_browser:used-by-babel-standalone": { + "./lib/transform-file.js": "./lib/transform-file-browser.js", "./src/config/files/index.js": "./src/config/files/index-browser.js", "./src/transform-file.js": "./src/transform-file-browser.js" }, diff --git a/scripts/gulp-tasks.js b/scripts/gulp-tasks.js index 42ebf5b6917a..8118932a8899 100644 --- a/scripts/gulp-tasks.js +++ b/scripts/gulp-tasks.js @@ -29,10 +29,7 @@ function generateResolveAlias() { const alias = {}; const packagePath = path.resolve(process.cwd(), "packages"); fs.readdirSync(packagePath).forEach(folder => { - if (["babel-core"].includes(folder)) { - return; - } - alias[folder.replace("babel-", "@babel/")] = path.resolve( + alias[folder.replace("babel-", "@babel/") + "$"] = path.resolve( packagePath, folder, "src" @@ -100,8 +97,6 @@ function webpackBuild(opts) { resolve: { //todo: remove resolve.alias when babel packages offer ESModule entry alias: generateResolveAlias(), - aliasFields: ["_browser:used-by-babel-standalone", "browser"], - mainFields: ["_main:used-by-babel-standalone", "main"], plugins: [ // Dedupe packages that are used across multiple plugins. // This replaces DedupePlugin from Webpack 1.x