Skip to content

Commit bc3268b

Browse files
authored
Merge pull request microsoft#25211 from Microsoft/gulpBrowserify
Clean up browserify task, remove unused 'debugMode.js' script
2 parents 78bf10a + 5ed96ec commit bc3268b

File tree

10 files changed

+213
-208
lines changed

10 files changed

+213
-208
lines changed

Gulpfile.js

Lines changed: 16 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ const insert = require("gulp-insert");
1010
const { append } = require("gulp-insert");
1111
const sourcemaps = require("gulp-sourcemaps");
1212
const del = require("del");
13-
const browserify = require("browserify");
14-
const through2 = require("through2");
1513
const fold = require("travis-fold");
1614
const rename = require("gulp-rename");
17-
const convertMap = require("convert-source-map");
18-
const sorcery = require("sorcery");
19-
const Vinyl = require("vinyl");
2015
const mkdirp = require("./scripts/build/mkdirp");
2116
const gulp = require("./scripts/build/gulp");
2217
const getDirSize = require("./scripts/build/getDirSize");
@@ -28,7 +23,7 @@ const getDiffTool = require("./scripts/build/getDiffTool");
2823
const baselineAccept = require("./scripts/build/baselineAccept");
2924
const cmdLineOptions = require("./scripts/build/options");
3025
const exec = require("./scripts/build/exec");
31-
const _debugMode = require("./scripts/build/debugMode");
26+
const browserify = require("./scripts/build/browserify");
3227
const { libraryTargets, generateLibs } = require("./scripts/build/lib");
3328
const { runConsoleTests, cleanTestDirs, writeTestConfigFile, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require("./scripts/build/tests");
3429

@@ -72,7 +67,7 @@ gulp.task(
7267
"publish-nightly",
7368
"Runs `npm publish --tag next` to create a new nightly build on npm",
7469
["LKG"],
75-
() => runSequence("clean", "useDebugMode", "runtests-parallel",
70+
() => runSequence("clean", "runtests-parallel",
7671
() => exec("npm", ["publish", "--tag", "next"])));
7772

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

185+
const tscReleaseProject = "src/tsc/tsconfig.release.json";
186+
const tscReleaseJs = "built/local/tsc.release.js";
187+
gulp.task(tscReleaseJs, /*help*/ false, () => project.compile(tscReleaseProject));
188+
190189
const cancellationTokenProject = "src/cancellationToken/tsconfig.json";
191190
const cancellationTokenJs = "built/local/cancellationToken.js";
192191
gulp.task(cancellationTokenJs, /*help*/ false, [typescriptServicesJs], () => project.compile(cancellationTokenProject, { typescript: "built" }));
@@ -258,9 +257,9 @@ gulp.task(
258257
"Generates a Markdown version of the Language Specification",
259258
[specMd]);
260259

261-
gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJs, typingsInstallerJs, watchGuardJs], () => {
260+
gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJs, typingsInstallerJs, watchGuardJs, tscReleaseJs], () => {
262261
const expectedFiles = [
263-
tscJs,
262+
tscReleaseJs,
264263
typescriptServicesJs,
265264
tsserverJs,
266265
typescriptJs,
@@ -289,7 +288,7 @@ gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJ
289288
gulp.task(
290289
"LKG",
291290
"Makes a new LKG out of the built js files",
292-
() => runSequence("clean-built", "dontUseDebugMode", "produce-LKG"));
291+
() => runSequence("clean-built", "produce-LKG"));
293292

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

304-
gulp.task(
305-
"tests-debug",
306-
"Builds the test sources and automation in debug mode",
307-
() => runSequence("useDebugMode", "tests"));
308-
309303
gulp.task(
310304
"runtests-parallel",
311305
"Runs all the tests in parallel using the built run.js file. Optional arguments are: --t[ests]=category1|category2|... --d[ebug]=true.",
@@ -325,77 +319,17 @@ gulp.task("clean:" + webTestServerJs, /*help*/ false, () => project.clean(webTes
325319

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

328-
// TODO(rbuckton): Clean up browserify logic
329322
gulp.task(
330323
"browserify",
331324
"Runs browserify on run.js to produce a file suitable for running tests in the browser",
332325
[runJs],
333-
(done) => {
334-
/** @type {*} */
335-
let originalMap;
336-
/** @type {string} */
337-
let prebundledContent;
338-
browserify(gulp.src([runJs])
339-
.pipe(newer(bundlePath))
340-
.pipe(sourcemaps.init({ loadMaps: true }))
341-
.pipe(through2.obj((file, enc, next) => {
342-
if (originalMap) {
343-
throw new Error("Should only recieve one file!");
344-
}
345-
log(`Saving sourcemaps for ${file.path}`);
346-
originalMap = file.sourceMap;
347-
prebundledContent = file.contents.toString();
348-
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
349-
originalMap.sources = originalMap.sources.map(s => path.resolve(path.join("src/harness", s)));
350-
// browserify names input files this when they are streamed in, so this is what it puts in the sourcemap
351-
originalMap.file = "built/local/_stream_0.js";
352-
353-
next(/*err*/ undefined, file.contents);
354-
}))
355-
.on("error", err => {
356-
return done(err);
357-
}), { debug: true, basedir: __dirname }) // Attach error handler to inner stream
358-
.bundle((err, contents) => {
359-
if (err) {
360-
if (err.message.match(/Cannot find module '.*_stream_0.js'/)) {
361-
return done(); // Browserify errors when we pass in no files when `newer` filters the input, we should count that as a success, though
362-
}
363-
return done(err);
364-
}
365-
const stringContent = contents.toString();
366-
const file = new Vinyl({ contents, path: bundlePath });
367-
log(`Fixing sourcemaps for ${file.path}`);
368-
// assumes contents is a Buffer, since that's what browserify yields
369-
const maps = convertMap.fromSource(stringContent).toObject();
370-
delete maps.sourceRoot;
371-
maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s));
372-
// Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
373-
file.contents = new Buffer(convertMap.removeComments(stringContent));
374-
const chain = sorcery.loadSync(bundlePath, {
375-
content: {
376-
"built/local/_stream_0.js": prebundledContent,
377-
[bundlePath]: stringContent
378-
},
379-
sourcemaps: {
380-
"built/local/_stream_0.js": originalMap,
381-
[bundlePath]: maps,
382-
"node_modules/source-map-support/source-map-support.js": undefined,
383-
}
384-
});
385-
const finalMap = chain.apply();
386-
file.sourceMap = finalMap;
387-
388-
const stream = through2.obj((file, enc, callback) => {
389-
return callback(/*err*/ undefined, file);
390-
});
391-
stream.pipe(sourcemaps.write(".", { includeContent: false }))
392-
.pipe(gulp.dest("."))
393-
.on("end", done)
394-
.on("error", done);
395-
stream.write(file);
396-
stream.end();
397-
});
398-
});
326+
() => gulp.src([runJs], { base: "built/local" })
327+
.pipe(newer(bundlePath))
328+
.pipe(sourcemaps.init({ loadMaps: true }))
329+
.pipe(browserify())
330+
.pipe(rename("bundle.js"))
331+
.pipe(sourcemaps.write(".", /**@type {*}*/({ includeContent: false, destPath: "built/local" })))
332+
.pipe(gulp.dest("built/local")));
399333

400334
gulp.task(
401335
"runtests-browser",

Jakefile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Paths.builtLocal = "built/local";
5959
Paths.builtLocalCompiler = "built/local/tsc.js";
6060
Paths.builtLocalTSServer = "built/local/tsserver.js";
6161
Paths.builtLocalRun = "built/local/run.js";
62+
Paths.releaseCompiler = "built/local/tsc.release.js";
6263
Paths.typesMapOutput = "built/local/typesMap.json";
6364
Paths.typescriptFile = "built/local/typescript.js";
6465
Paths.servicesFile = "built/local/typescriptServices.js";
@@ -95,6 +96,7 @@ Paths.versionFile = "src/compiler/core.ts";
9596

9697
const ConfigFileFor = {
9798
tsc: "src/tsc",
99+
tscRelease: "src/tsc/tsconfig.release.json",
98100
tsserver: "src/tsserver",
99101
runjs: "src/testRunner",
100102
lint: "scripts/tslint",
@@ -157,6 +159,12 @@ task(TaskNames.scripts, [TaskNames.coreBuild], function() {
157159
});
158160
}, { async: true });
159161

162+
task(Paths.releaseCompiler, function () {
163+
tsbuild([ConfigFileFor.tscRelease], true, () => {
164+
complete();
165+
});
166+
}, { async: true });
167+
160168
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
161169
desc("Makes a new LKG out of the built js files");
162170
task(TaskNames.lkg, [
@@ -165,6 +173,7 @@ task(TaskNames.lkg, [
165173
TaskNames.local,
166174
Paths.servicesDefinitionFile,
167175
Paths.tsserverLibraryDefinitionFile,
176+
Paths.releaseCompiler,
168177
...libraryTargets
169178
], () => {
170179
const sizeBefore = getDirSize(Paths.lkg);

0 commit comments

Comments
 (0)