Skip to content

Commit

Permalink
Clean up browserify task, remove unused 'debugMode.js' script
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jun 25, 2018
1 parent 6cd27a3 commit 5ed96ec
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 208 deletions.
98 changes: 16 additions & 82 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ const insert = require("gulp-insert");
const { append } = require("gulp-insert");
const sourcemaps = require("gulp-sourcemaps");
const del = require("del");
const browserify = require("browserify");
const through2 = require("through2");
const fold = require("travis-fold");
const rename = require("gulp-rename");
const convertMap = require("convert-source-map");
const sorcery = require("sorcery");
const Vinyl = require("vinyl");
const mkdirp = require("./scripts/build/mkdirp");
const gulp = require("./scripts/build/gulp");
const getDirSize = require("./scripts/build/getDirSize");
Expand All @@ -28,7 +23,7 @@ const getDiffTool = require("./scripts/build/getDiffTool");
const baselineAccept = require("./scripts/build/baselineAccept");
const cmdLineOptions = require("./scripts/build/options");
const exec = require("./scripts/build/exec");
const _debugMode = require("./scripts/build/debugMode");
const browserify = require("./scripts/build/browserify");
const { libraryTargets, generateLibs } = require("./scripts/build/lib");
const { runConsoleTests, cleanTestDirs, writeTestConfigFile, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require("./scripts/build/tests");

Expand Down Expand Up @@ -72,7 +67,7 @@ gulp.task(
"publish-nightly",
"Runs `npm publish --tag next` to create a new nightly build on npm",
["LKG"],
() => runSequence("clean", "useDebugMode", "runtests-parallel",
() => runSequence("clean", "runtests-parallel",
() => exec("npm", ["publish", "--tag", "next"])));

const importDefinitelyTypedTestsProject = "scripts/importDefinitelyTypedTests/tsconfig.json";
Expand Down Expand Up @@ -187,6 +182,10 @@ const tscProject = "src/tsc/tsconfig.json";
const tscJs = "built/local/tsc.js";
gulp.task(tscJs, /*help*/ false, [typescriptServicesJs], () => project.compile(tscProject, { typescript: "built" }));

const tscReleaseProject = "src/tsc/tsconfig.release.json";
const tscReleaseJs = "built/local/tsc.release.js";
gulp.task(tscReleaseJs, /*help*/ false, () => project.compile(tscReleaseProject));

const cancellationTokenProject = "src/cancellationToken/tsconfig.json";
const cancellationTokenJs = "built/local/cancellationToken.js";
gulp.task(cancellationTokenJs, /*help*/ false, [typescriptServicesJs], () => project.compile(cancellationTokenProject, { typescript: "built" }));
Expand Down Expand Up @@ -258,9 +257,9 @@ gulp.task(
"Generates a Markdown version of the Language Specification",
[specMd]);

gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJs, typingsInstallerJs, watchGuardJs], () => {
gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJs, typingsInstallerJs, watchGuardJs, tscReleaseJs], () => {
const expectedFiles = [
tscJs,
tscReleaseJs,
typescriptServicesJs,
tsserverJs,
typescriptJs,
Expand Down Expand Up @@ -289,7 +288,7 @@ gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJ
gulp.task(
"LKG",
"Makes a new LKG out of the built js files",
() => runSequence("clean-built", "dontUseDebugMode", "produce-LKG"));
() => runSequence("clean-built", "produce-LKG"));

// Task to build the tests infrastructure using the built compiler
const testRunnerProject = "src/testRunner/tsconfig.json";
Expand All @@ -301,11 +300,6 @@ gulp.task(
"Builds the test infrastructure using the built compiler",
[runJs]);

gulp.task(
"tests-debug",
"Builds the test sources and automation in debug mode",
() => runSequence("useDebugMode", "tests"));

gulp.task(
"runtests-parallel",
"Runs all the tests in parallel using the built run.js file. Optional arguments are: --t[ests]=category1|category2|... --d[ebug]=true.",
Expand All @@ -325,77 +319,17 @@ gulp.task("clean:" + webTestServerJs, /*help*/ false, () => project.clean(webTes

const bundlePath = path.resolve("built/local/bundle.js");

// TODO(rbuckton): Clean up browserify logic
gulp.task(
"browserify",
"Runs browserify on run.js to produce a file suitable for running tests in the browser",
[runJs],
(done) => {
/** @type {*} */
let originalMap;
/** @type {string} */
let prebundledContent;
browserify(gulp.src([runJs])
.pipe(newer(bundlePath))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(through2.obj((file, enc, next) => {
if (originalMap) {
throw new Error("Should only recieve one file!");
}
log(`Saving sourcemaps for ${file.path}`);
originalMap = file.sourceMap;
prebundledContent = file.contents.toString();
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
originalMap.sources = originalMap.sources.map(s => path.resolve(path.join("src/harness", s)));
// browserify names input files this when they are streamed in, so this is what it puts in the sourcemap
originalMap.file = "built/local/_stream_0.js";

next(/*err*/ undefined, file.contents);
}))
.on("error", err => {
return done(err);
}), { debug: true, basedir: __dirname }) // Attach error handler to inner stream
.bundle((err, contents) => {
if (err) {
if (err.message.match(/Cannot find module '.*_stream_0.js'/)) {
return done(); // Browserify errors when we pass in no files when `newer` filters the input, we should count that as a success, though
}
return done(err);
}
const stringContent = contents.toString();
const file = new Vinyl({ contents, path: bundlePath });
log(`Fixing sourcemaps for ${file.path}`);
// assumes contents is a Buffer, since that's what browserify yields
const maps = convertMap.fromSource(stringContent).toObject();
delete maps.sourceRoot;
maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s));
// Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
file.contents = new Buffer(convertMap.removeComments(stringContent));
const chain = sorcery.loadSync(bundlePath, {
content: {
"built/local/_stream_0.js": prebundledContent,
[bundlePath]: stringContent
},
sourcemaps: {
"built/local/_stream_0.js": originalMap,
[bundlePath]: maps,
"node_modules/source-map-support/source-map-support.js": undefined,
}
});
const finalMap = chain.apply();
file.sourceMap = finalMap;

const stream = through2.obj((file, enc, callback) => {
return callback(/*err*/ undefined, file);
});
stream.pipe(sourcemaps.write(".", { includeContent: false }))
.pipe(gulp.dest("."))
.on("end", done)
.on("error", done);
stream.write(file);
stream.end();
});
});
() => gulp.src([runJs], { base: "built/local" })
.pipe(newer(bundlePath))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(browserify())
.pipe(rename("bundle.js"))
.pipe(sourcemaps.write(".", /**@type {*}*/({ includeContent: false, destPath: "built/local" })))
.pipe(gulp.dest("built/local")));

gulp.task(
"runtests-browser",
Expand Down
9 changes: 9 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Paths.builtLocal = "built/local";
Paths.builtLocalCompiler = "built/local/tsc.js";
Paths.builtLocalTSServer = "built/local/tsserver.js";
Paths.builtLocalRun = "built/local/run.js";
Paths.releaseCompiler = "built/local/tsc.release.js";
Paths.typesMapOutput = "built/local/typesMap.json";
Paths.typescriptFile = "built/local/typescript.js";
Paths.servicesFile = "built/local/typescriptServices.js";
Expand Down Expand Up @@ -95,6 +96,7 @@ Paths.versionFile = "src/compiler/core.ts";

const ConfigFileFor = {
tsc: "src/tsc",
tscRelease: "src/tsc/tsconfig.release.json",
tsserver: "src/tsserver",
runjs: "src/testRunner",
lint: "scripts/tslint",
Expand Down Expand Up @@ -157,6 +159,12 @@ task(TaskNames.scripts, [TaskNames.coreBuild], function() {
});
}, { async: true });

task(Paths.releaseCompiler, function () {
tsbuild([ConfigFileFor.tscRelease], true, () => {
complete();
});
}, { async: true });

// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc("Makes a new LKG out of the built js files");
task(TaskNames.lkg, [
Expand All @@ -165,6 +173,7 @@ task(TaskNames.lkg, [
TaskNames.local,
Paths.servicesDefinitionFile,
Paths.tsserverLibraryDefinitionFile,
Paths.releaseCompiler,
...libraryTargets
], () => {
const sizeBefore = getDirSize(Paths.lkg);
Expand Down
Loading

0 comments on commit 5ed96ec

Please sign in to comment.