Move babel-standalone's build scripts to the repo root. (#6383)
This commit is contained in:
parent
36d8a13f4d
commit
70a5b77943
100
Gulpfile.js
100
Gulpfile.js
@ -3,6 +3,9 @@
|
|||||||
const plumber = require("gulp-plumber");
|
const plumber = require("gulp-plumber");
|
||||||
const through = require("through2");
|
const through = require("through2");
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
|
const pump = require("pump");
|
||||||
|
const uglify = require("gulp-uglify");
|
||||||
|
const rename = require("gulp-rename");
|
||||||
const newer = require("gulp-newer");
|
const newer = require("gulp-newer");
|
||||||
const babel = require("gulp-babel");
|
const babel = require("gulp-babel");
|
||||||
const watch = require("gulp-watch");
|
const watch = require("gulp-watch");
|
||||||
@ -10,6 +13,10 @@ const gutil = require("gulp-util");
|
|||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const merge = require("merge-stream");
|
const merge = require("merge-stream");
|
||||||
|
const RootMostResolvePlugin = require("webpack-dependency-suite")
|
||||||
|
.RootMostResolvePlugin;
|
||||||
|
const webpack = require("webpack");
|
||||||
|
const webpackStream = require("webpack-stream");
|
||||||
|
|
||||||
const sources = ["codemods", "packages"];
|
const sources = ["codemods", "packages"];
|
||||||
|
|
||||||
@ -70,3 +77,96 @@ gulp.task("watch", ["build"], function() {
|
|||||||
gulp.start("build");
|
gulp.start("build");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task("build-babel-standalone", cb => {
|
||||||
|
pump(
|
||||||
|
[
|
||||||
|
gulp.src(__dirname + "/packages/babel-standalone/src/index.js"),
|
||||||
|
webpackBuild(),
|
||||||
|
gulp.dest(__dirname + "/packages/babel-standalone"),
|
||||||
|
uglify(),
|
||||||
|
rename({ extname: ".min.js" }),
|
||||||
|
gulp.dest(__dirname + "/packages/babel-standalone"),
|
||||||
|
],
|
||||||
|
cb
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function webpackBuild() {
|
||||||
|
let version = require("./packages/babel-core/package.json").version;
|
||||||
|
|
||||||
|
// If this build is part of a pull request, include the pull request number in
|
||||||
|
// the version number.
|
||||||
|
if (process.env.CIRCLE_PR_NUMBER) {
|
||||||
|
version += "+pr." + process.env.CIRCLE_PR_NUMBER;
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
include: /node_modules/,
|
||||||
|
loader: "babel-loader",
|
||||||
|
options: {
|
||||||
|
// Some of the node_modules may have their own "babel" section in
|
||||||
|
// their project.json (or a ".babelrc" file). We need to ignore
|
||||||
|
// those as we're using our own Babel options.
|
||||||
|
babelrc: false,
|
||||||
|
presets: ["env"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: "babel-loader",
|
||||||
|
options: {
|
||||||
|
// Some of the node_modules may have their own "babel" section in
|
||||||
|
// their project.json (or a ".babelrc" file). We need to ignore
|
||||||
|
// those as we're using our own Babel options.
|
||||||
|
babelrc: false,
|
||||||
|
presets: ["env", "stage-0"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
node: {
|
||||||
|
// Mock Node.js modules that Babel require()s but that we don't
|
||||||
|
// particularly care about.
|
||||||
|
fs: "empty",
|
||||||
|
module: "empty",
|
||||||
|
net: "empty",
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
filename: "babel.js",
|
||||||
|
library: "Babel",
|
||||||
|
libraryTarget: "umd",
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
"process.env.NODE_ENV": '"production"',
|
||||||
|
BABEL_VERSION: JSON.stringify(version),
|
||||||
|
VERSION: JSON.stringify(version),
|
||||||
|
}),
|
||||||
|
/*new webpack.NormalModuleReplacementPlugin(
|
||||||
|
/..\/..\/package/,
|
||||||
|
"../../../../src/babel-package-shim"
|
||||||
|
),*/
|
||||||
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
||||||
|
],
|
||||||
|
resolve: {
|
||||||
|
plugins: [
|
||||||
|
// Dedupe packages that are used across multiple plugins.
|
||||||
|
// This replaces DedupePlugin from Webpack 1.x
|
||||||
|
new RootMostResolvePlugin(__dirname, true),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return webpackStream(config, webpack);
|
||||||
|
// To write JSON for debugging:
|
||||||
|
/*return webpackStream(config, webpack, (err, stats) => {
|
||||||
|
require('gulp-util').log(stats.toString({colors: true}));
|
||||||
|
require('fs').writeFileSync('webpack-debug.json', JSON.stringify(stats.toJson()));
|
||||||
|
});*/
|
||||||
|
}
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -17,7 +17,7 @@ ifneq ("$(BABEL_ENV)", "cov")
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
build-standalone:
|
build-standalone:
|
||||||
./node_modules/.bin/gulp build-babel-standalone --cwd=packages/babel-standalone/
|
./node_modules/.bin/gulp build-babel-standalone
|
||||||
|
|
||||||
build-dist: build
|
build-dist: build
|
||||||
cd packages/babel-polyfill; \
|
cd packages/babel-polyfill; \
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
"babel-cli": "7.0.0-beta.2",
|
"babel-cli": "7.0.0-beta.2",
|
||||||
"babel-core": "7.0.0-beta.2",
|
"babel-core": "7.0.0-beta.2",
|
||||||
"babel-eslint": "8.0.0-alpha.15",
|
"babel-eslint": "8.0.0-alpha.15",
|
||||||
|
"babel-loader": "7.1.1",
|
||||||
"babel-plugin-istanbul": "^4.1.4",
|
"babel-plugin-istanbul": "^4.1.4",
|
||||||
"babel-preset-env": "2.0.0-beta.2",
|
"babel-preset-env": "2.0.0-beta.2",
|
||||||
"babel-preset-flow": "7.0.0-beta.2",
|
"babel-preset-flow": "7.0.0-beta.2",
|
||||||
@ -34,6 +35,8 @@
|
|||||||
"gulp-babel": "^7.0.0",
|
"gulp-babel": "^7.0.0",
|
||||||
"gulp-newer": "^1.0.0",
|
"gulp-newer": "^1.0.0",
|
||||||
"gulp-plumber": "^1.0.1",
|
"gulp-plumber": "^1.0.1",
|
||||||
|
"gulp-rename": "^1.2.2",
|
||||||
|
"gulp-uglify": "^3.0.0",
|
||||||
"gulp-util": "^3.0.7",
|
"gulp-util": "^3.0.7",
|
||||||
"gulp-watch": "^4.3.5",
|
"gulp-watch": "^4.3.5",
|
||||||
"husky": "^0.14.3",
|
"husky": "^0.14.3",
|
||||||
@ -46,10 +49,14 @@
|
|||||||
"nyc": "^11.0.3",
|
"nyc": "^11.0.3",
|
||||||
"output-file-sync": "^2.0.0",
|
"output-file-sync": "^2.0.0",
|
||||||
"prettier": "1.7.3",
|
"prettier": "1.7.3",
|
||||||
|
"pump": "^1.0.2",
|
||||||
"rimraf": "^2.4.3",
|
"rimraf": "^2.4.3",
|
||||||
"semver": "^5.0.0",
|
"semver": "^5.0.0",
|
||||||
"through2": "^2.0.0",
|
"through2": "^2.0.0",
|
||||||
"uglify-js": "^2.4.16"
|
"uglify-js": "^2.4.16",
|
||||||
|
"webpack": "^3.4.1",
|
||||||
|
"webpack-dependency-suite": "^2.4.4",
|
||||||
|
"webpack-stream": "^4.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 4.x <= 8.x",
|
"node": ">= 4.x <= 8.x",
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
const registerBabelStandaloneTask = require("./src/gulpTasks")
|
|
||||||
.registerBabelStandaloneTask;
|
|
||||||
const gulp = require("gulp");
|
|
||||||
|
|
||||||
const version = require("./package.json").version;
|
|
||||||
registerBabelStandaloneTask(gulp, "babel", "Babel", __dirname, version);
|
|
||||||
@ -10,8 +10,6 @@
|
|||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "7.0.0-beta.2",
|
"babel-core": "7.0.0-beta.2",
|
||||||
"babel-helper-builder-react-jsx": "7.0.0-beta.2",
|
|
||||||
"babel-loader": "7.1.1",
|
|
||||||
"babel-plugin-check-es2015-constants": "7.0.0-beta.2",
|
"babel-plugin-check-es2015-constants": "7.0.0-beta.2",
|
||||||
"babel-plugin-external-helpers": "7.0.0-beta.2",
|
"babel-plugin-external-helpers": "7.0.0-beta.2",
|
||||||
"babel-plugin-inline-replace-variables": "1.3.1",
|
"babel-plugin-inline-replace-variables": "1.3.1",
|
||||||
@ -97,16 +95,7 @@
|
|||||||
"babel-preset-stage-1": "7.0.0-beta.2",
|
"babel-preset-stage-1": "7.0.0-beta.2",
|
||||||
"babel-preset-stage-2": "7.0.0-beta.2",
|
"babel-preset-stage-2": "7.0.0-beta.2",
|
||||||
"babel-preset-stage-3": "7.0.0-beta.2",
|
"babel-preset-stage-3": "7.0.0-beta.2",
|
||||||
"babel-preset-typescript": "7.0.0-beta.2",
|
"babel-preset-typescript": "7.0.0-beta.2"
|
||||||
"gulp-rename": "^1.2.2",
|
|
||||||
"gulp-uglify": "^3.0.0",
|
|
||||||
"json-loader": "^0.5.7",
|
|
||||||
"lazypipe": "^1.0.1",
|
|
||||||
"pump": "^1.0.2",
|
|
||||||
"react": "^16.0.0-beta.3",
|
|
||||||
"webpack": "^3.4.1",
|
|
||||||
"webpack-dependency-suite": "^2.4.4",
|
|
||||||
"webpack-stream": "^4.0.0"
|
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"babel",
|
"babel",
|
||||||
@ -120,11 +109,5 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/babel/babel-standalone/issues"
|
"url": "https://github.com/babel/babel-standalone/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/babel/babel-standalone#readme",
|
"homepage": "https://github.com/babel/babel-standalone#readme"
|
||||||
"jest": {
|
|
||||||
"transformIgnorePatterns": [
|
|
||||||
"/node_modules/",
|
|
||||||
"babel.js"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,132 +0,0 @@
|
|||||||
/**
|
|
||||||
* This file contains the Gulp tasks for babel-standalone. Note that
|
|
||||||
* babel-standalone is compiled using Webpack, and performs its own Babel
|
|
||||||
* compilation of all the JavaScript files. This is because it targets web
|
|
||||||
* browsers, so more transforms are needed than the regular Babel builds that
|
|
||||||
* only target Node.js.
|
|
||||||
*
|
|
||||||
* The tasks in this file are designed to be reusable, so that they can be used
|
|
||||||
* to make standalone builds of other Babel plugins/presets (such as babel-minify)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Must run first
|
|
||||||
require("./overrideModuleResolution")();
|
|
||||||
|
|
||||||
const pump = require("pump");
|
|
||||||
const rename = require("gulp-rename");
|
|
||||||
const RootMostResolvePlugin = require("webpack-dependency-suite").RootMostResolvePlugin;
|
|
||||||
const webpack = require("webpack");
|
|
||||||
const webpackStream = require("webpack-stream");
|
|
||||||
const uglify = require("gulp-uglify");
|
|
||||||
|
|
||||||
function webpackBuild(filename, libraryName, version) {
|
|
||||||
// If this build is part of a pull request, include the pull request number in
|
|
||||||
// the version number.
|
|
||||||
if (process.env.CIRCLE_PR_NUMBER) {
|
|
||||||
version += '+pr.' + process.env.CIRCLE_PR_NUMBER;
|
|
||||||
}
|
|
||||||
const typeofPlugin = require("babel-plugin-transform-es2015-typeof-symbol")
|
|
||||||
.default;
|
|
||||||
|
|
||||||
// babel-plugin-transform-es2015-typeof-symbol is not idempotent, and something
|
|
||||||
// else is already running it, so we need to exclude it from the transform.
|
|
||||||
const preset2015 = require("babel-preset-es2015").default();
|
|
||||||
const es2015WithoutTypeof = {
|
|
||||||
plugins: preset2015.plugins.filter(plugin => plugin !== typeofPlugin),
|
|
||||||
};
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
//exclude: /node_modules/,
|
|
||||||
test: /\.js$/,
|
|
||||||
loader: "babel-loader",
|
|
||||||
options: {
|
|
||||||
// Some of the node_modules may have their own "babel" section in
|
|
||||||
// their project.json (or a ".babelrc" file). We need to ignore
|
|
||||||
// those as we're using our own Babel options.
|
|
||||||
babelrc: false,
|
|
||||||
presets: [es2015WithoutTypeof, require("babel-preset-stage-0")],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
node: {
|
|
||||||
// Mock Node.js modules that Babel require()s but that we don't
|
|
||||||
// particularly care about.
|
|
||||||
fs: "empty",
|
|
||||||
module: "empty",
|
|
||||||
net: "empty",
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
filename: filename,
|
|
||||||
library: libraryName,
|
|
||||||
libraryTarget: "umd",
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
"process.env.NODE_ENV": '"production"',
|
|
||||||
BABEL_VERSION:
|
|
||||||
JSON.stringify(require("babel-core/package.json").version),
|
|
||||||
VERSION: JSON.stringify(version),
|
|
||||||
}),
|
|
||||||
// Use browser version of visionmedia-debug
|
|
||||||
new webpack.NormalModuleReplacementPlugin(
|
|
||||||
/debug\/node/,
|
|
||||||
"debug/src/browser"
|
|
||||||
),
|
|
||||||
/*new webpack.NormalModuleReplacementPlugin(
|
|
||||||
/..\/..\/package/,
|
|
||||||
"../../../../src/babel-package-shim"
|
|
||||||
),*/
|
|
||||||
new webpack.optimize.ModuleConcatenationPlugin(),
|
|
||||||
],
|
|
||||||
resolve: {
|
|
||||||
plugins: [
|
|
||||||
// Dedupe packages that are used across multiple plugins.
|
|
||||||
// This replaces DedupePlugin from Webpack 1.x
|
|
||||||
new RootMostResolvePlugin(__dirname + '/../../../', true),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (libraryName !== "Babel") {
|
|
||||||
// This is a secondary package (eg. Babili), we should expect that Babel
|
|
||||||
// was already loaded, rather than bundling it in here too.
|
|
||||||
config.externals = {
|
|
||||||
"babel-standalone": "Babel",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return webpackStream(config, webpack);
|
|
||||||
// To write JSON for debugging:
|
|
||||||
/*return webpackStream(config, webpack, (err, stats) => {
|
|
||||||
require('gulp-util').log(stats.toString({colors: true}));
|
|
||||||
require('fs').writeFileSync('webpack-debug.json', JSON.stringify(stats.toJson()));
|
|
||||||
});*/
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerBabelStandaloneTask(gulp, name, exportName, path, version) {
|
|
||||||
gulp.task("build-" + name + "-standalone", cb => {
|
|
||||||
pump(
|
|
||||||
[
|
|
||||||
gulp.src(path + "/src/index.js"),
|
|
||||||
webpackBuild(
|
|
||||||
name + ".js",
|
|
||||||
exportName,
|
|
||||||
version
|
|
||||||
),
|
|
||||||
gulp.dest(path),
|
|
||||||
uglify(),
|
|
||||||
rename({ extname: ".min.js" }),
|
|
||||||
gulp.dest(path),
|
|
||||||
],
|
|
||||||
cb
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
webpackBuild: webpackBuild,
|
|
||||||
registerBabelStandaloneTask: registerBabelStandaloneTask,
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* babel-loader causes problems as it's not part of the monorepo. It pulls in
|
|
||||||
* an older version of babel-core (the version referenced by the root
|
|
||||||
* package.json), rather than the version of babel-core that's in the repo. The
|
|
||||||
* only way to solve this without moving babel-loader into the monorepo is to
|
|
||||||
* override Node's module resolution algorithm to specify a custom resolver for
|
|
||||||
* babel-core to *force* it to use our version.
|
|
||||||
*
|
|
||||||
* Here be dragons.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const Module = require("module");
|
|
||||||
|
|
||||||
module.exports = function overrideModuleResolution() {
|
|
||||||
const originalLoader = Module._load.bind(Module);
|
|
||||||
|
|
||||||
Module._load = function babelStandaloneLoader(request, parent, isMain) {
|
|
||||||
// Redirect babel-core to version in the repo.
|
|
||||||
if (request === "babel-core") {
|
|
||||||
request = __dirname + "/../../babel-core";
|
|
||||||
}
|
|
||||||
return originalLoader(request, parent, isMain);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Loading…
x
Reference in New Issue
Block a user