Skip to content

Commit

Permalink
Revert "πŸ—οΈπŸš€ Babel compile with sourcemaps (#27447)"
Browse files Browse the repository at this point in the history
This reverts commit bcde1ec.
  • Loading branch information
calebcordry committed Apr 27, 2020
1 parent 39d3c1c commit 097955b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 72 deletions.
4 changes: 2 additions & 2 deletions build-system/compile/compile.js
Expand Up @@ -367,8 +367,8 @@ function compile(
if (options.typeCheckOnly) {
return gulp
.src(srcs, {base: '.'})
.pipe(sourcemaps.init())
.pipe(preClosureBabel())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpClosureCompile(compilerOptionsArray, checkTypesNailgunPort))
.on('error', err => {
handleTypeCheckError();
Expand All @@ -380,8 +380,8 @@ function compile(
timeInfo.startTime = Date.now();
return gulp
.src(srcs, {base: '.'})
.pipe(sourcemaps.init())
.pipe(preClosureBabel())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpClosureCompile(compilerOptionsArray, distNailgunPort))
.on('error', err => {
handleCompilerError(outputFilename);
Expand Down
80 changes: 23 additions & 57 deletions build-system/compile/pre-closure-babel.js
Expand Up @@ -16,13 +16,15 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const babel = require('@babel/core');
const conf = require('./build.conf');
const crypto = require('crypto');
const globby = require('globby');
const gulpBabel = require('gulp-babel');
const path = require('path');
const through = require('through2');
const {BABEL_SRC_GLOBS, THIRD_PARTY_TRANSFORM_GLOBS} = require('./sources');

const ROOT_DIR = path.resolve(__dirname, '../../');

/**
* Files on which to run pre-closure babel transforms.
*
Expand All @@ -35,7 +37,7 @@ const filesToTransform = getFilesToTransform();
*
* @private @const {!Object<string, string>}
*/
const cache = Object.create(null);
const cachedTransforms = {};

/**
* Computes the set of files on which to run pre-closure babel transforms.
Expand All @@ -48,16 +50,6 @@ function getFilesToTransform() {
.concat(globby.sync(THIRD_PARTY_TRANSFORM_GLOBS));
}

/**
* @param {!Buffer} contents
* @return {string}
*/
function sha256(contents) {
const hash = crypto.createHash('sha256');
hash.update(contents);
return hash.digest('hex');
}

/**
* Apply babel transforms prior to closure compiler pass.
*
Expand All @@ -68,52 +60,26 @@ function sha256(contents) {
* @return {!Promise}
*/
function preClosureBabel() {
const babelPlugins = conf.plugins({
isForTesting: !!argv.fortesting,
isEsmBuild: !!argv.esm,
isSinglePass: !!argv.single_pass,
isChecktypes: argv._.includes('check-types'),
});
const babel = gulpBabel({
plugins: babelPlugins,
retainLines: true,
compact: false,
});

return through.obj((file, enc, next) => {
const {relative, path} = file;
if (!filesToTransform.includes(relative)) {
return next(null, file);
}

const hash = sha256(file.contents);
const cached = cache[path];
if (cached && cached.hash === hash) {
return next(null, cached.file.clone());
const cachedTransform = cachedTransforms[file.path];
if (cachedTransform) {
file.contents = Buffer.from(cachedTransform);
} else if (filesToTransform.includes(path.relative(ROOT_DIR, file.path))) {
const babelPlugins = conf.plugins({
isForTesting: !!argv.fortesting,
isEsmBuild: !!argv.esm,
isSinglePass: !!argv.single_pass,
isChecktypes: argv._.includes('check-types'),
});
const {code} = babel.transformFileSync(file.path, {
plugins: babelPlugins,
retainLines: true,
compact: false,
});
cachedTransforms[file.path] = code;
file.contents = Buffer.from(code);
}

let data, err;
function onData(d) {
babel.off('error', onError);
data = d;
}
function onError(e) {
babel.off('data', onData);
err = e;
}
babel.once('data', onData);
babel.once('error', onError);
babel.write(file, enc, () => {
if (err) {
return next(err);
}

cache[path] = {
file: data,
hash,
};
next(null, data.clone());
});
return next(null, file);
});
}

Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/single-pass.js
Expand Up @@ -686,8 +686,8 @@ function compile(flagsArray) {
return new Promise(function(resolve, reject) {
gulp
.src(srcs, {base: '.'})
.pipe(sourcemaps.init())
.pipe(preClosureBabel())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpClosureCompile(flagsArray))
.on('error', err => {
handleSinglePassCompilerError();
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -94,7 +94,6 @@
"gulp": "4.0.2",
"gulp-append-prepend": "1.0.8",
"gulp-ava": "3.0.0",
"gulp-babel": "8.0.0",
"gulp-connect": "5.7.0",
"gulp-eslint": "6.0.0",
"gulp-eslint-if-fixed": "1.0.0",
Expand Down Expand Up @@ -182,8 +181,8 @@
"typescript": "3.8.3",
"uglifyify": "5.0.2",
"vinyl-buffer": "1.0.1",
"vinyl-source-stream": "2.0.0",
"vinyl-sourcemaps-apply": "0.2.1",
"vinyl-source-stream": "2.0.0",
"watchify": "3.11.1"
},
"filesize": {
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Expand Up @@ -7831,16 +7831,6 @@ gulp-ava@3.0.0:
resolve-cwd "^3.0.0"
through2 "^3.0.0"

gulp-babel@8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/gulp-babel/-/gulp-babel-8.0.0.tgz#e0da96f4f2ec4a88dd3a3030f476e38ab2126d87"
integrity sha512-oomaIqDXxFkg7lbpBou/gnUkX51/Y/M2ZfSjL2hdqXTAlSWZcgZtd2o0cOH0r/eE8LWD0+Q/PsLsr2DKOoqToQ==
dependencies:
plugin-error "^1.0.1"
replace-ext "^1.0.0"
through2 "^2.0.0"
vinyl-sourcemaps-apply "^0.2.0"

gulp-cli@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/gulp-cli/-/gulp-cli-2.2.0.tgz#5533126eeb7fe415a7e3e84a297d334d5cf70ebc"
Expand Down

0 comments on commit 097955b

Please sign in to comment.