Fix babel-standalone for realz (#6137)
* Fix babel-standalone * Fix infinite loop in Makefile (oops) * Override Node.js module resolution to handle babel-core
This commit is contained in:
parent
62c22c7b5d
commit
93cf26abca
@ -9,7 +9,6 @@ const watch = require("gulp-watch");
|
||||
const gutil = require("gulp-util");
|
||||
const gulp = require("gulp");
|
||||
const path = require("path");
|
||||
const registerBabelStandaloneTasks = require("./packages/babel-standalone/src/gulpTasks");
|
||||
|
||||
const base = path.join(__dirname, "packages");
|
||||
const scripts = "./packages/*/src/**/*.js";
|
||||
@ -60,5 +59,3 @@ gulp.task("watch", ["build"], function() {
|
||||
gulp.start("build");
|
||||
});
|
||||
});
|
||||
|
||||
registerBabelStandaloneTasks(gulp);
|
||||
|
||||
5
Makefile
5
Makefile
@ -11,9 +11,12 @@ build: clean
|
||||
rm -rf packages/*/lib
|
||||
./node_modules/.bin/gulp build
|
||||
ifneq ($(BABEL_ENV), "cov")
|
||||
./node_modules/.bin/gulp build-babel-standalone
|
||||
make build-standalone
|
||||
endif
|
||||
|
||||
build-standalone:
|
||||
./node_modules/.bin/gulp build-babel-standalone --cwd=packages/babel-standalone/
|
||||
|
||||
build-dist: build
|
||||
cd packages/babel-polyfill; \
|
||||
scripts/build-dist.sh
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
"babel-cli": "7.0.0-alpha.18",
|
||||
"babel-core": "7.0.0-alpha.18",
|
||||
"babel-eslint": "8.0.0-alpha.15",
|
||||
"babel-loader": "^7.1.1",
|
||||
"babel-plugin-istanbul": "^4.1.4",
|
||||
"babel-preset-env": "2.0.0-alpha.18",
|
||||
"babel-preset-flow": "7.0.0-alpha.18",
|
||||
|
||||
6
packages/babel-standalone/Gulpfile.js
Normal file
6
packages/babel-standalone/Gulpfile.js
Normal file
@ -0,0 +1,6 @@
|
||||
const registerBabelStandaloneTask = require("./src/gulpTasks")
|
||||
.registerBabelStandaloneTask;
|
||||
const gulp = require("gulp");
|
||||
|
||||
const version = require("./package.json").version;
|
||||
registerBabelStandaloneTask(gulp, "babel", "Babel", __dirname, version);
|
||||
@ -4,8 +4,14 @@
|
||||
* 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;
|
||||
@ -100,24 +106,27 @@ function webpackBuild(filename, libraryName, version) {
|
||||
});*/
|
||||
}
|
||||
|
||||
function registerGulpTasks(gulp) {
|
||||
gulp.task("build-babel-standalone", ["build"], cb => {
|
||||
function registerBabelStandaloneTask(gulp, name, exportName, path, version) {
|
||||
gulp.task("build-" + name + "-standalone", cb => {
|
||||
pump(
|
||||
[
|
||||
gulp.src(__dirname + "/index.js"),
|
||||
gulp.src(path + "/src/index.js"),
|
||||
webpackBuild(
|
||||
"babel.js",
|
||||
"Babel",
|
||||
require(__dirname + "/../package.json").version
|
||||
name + ".js",
|
||||
exportName,
|
||||
version
|
||||
),
|
||||
gulp.dest(__dirname + "/../"),
|
||||
gulp.dest(path),
|
||||
uglify(),
|
||||
rename({ extname: ".min.js" }),
|
||||
gulp.dest(__dirname + "/../"),
|
||||
gulp.dest(path),
|
||||
],
|
||||
cb
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = registerGulpTasks;
|
||||
module.exports = {
|
||||
webpackBuild: webpackBuild,
|
||||
registerBabelStandaloneTask: registerBabelStandaloneTask,
|
||||
}
|
||||
|
||||
24
packages/babel-standalone/src/overrideModuleResolution.js
Normal file
24
packages/babel-standalone/src/overrideModuleResolution.js
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
};
|
||||
@ -563,7 +563,7 @@ babel-helpers@7.0.0-alpha.18:
|
||||
dependencies:
|
||||
babel-template "7.0.0-alpha.18"
|
||||
|
||||
babel-loader@7.1.1, babel-loader@^7.1.1:
|
||||
babel-loader@7.1.1:
|
||||
version "7.1.1"
|
||||
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.1.tgz#b87134c8b12e3e4c2a94e0546085bc680a2b8488"
|
||||
dependencies:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user