Skip to content

Commit a85a6a2

Browse files
committed
👷 update build files
1 parent 92ee0d1 commit a85a6a2

15 files changed

Lines changed: 2620 additions & 2666 deletions

build/lib/bundle.js

Lines changed: 451 additions & 452 deletions
Large diffs are not rendered by default.

build/lib/compilation.js

Lines changed: 170 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,170 @@
1-
/*---------------------------------------------------------------------------------------------
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for license information.
4-
*--------------------------------------------------------------------------------------------*/
5-
'use strict';
6-
Object.defineProperty(exports, "__esModule", { value: true });
7-
var gulp = require("gulp");
8-
var tsb = require("gulp-tsb");
9-
var es = require("event-stream");
10-
var watch = require('./watch');
11-
var nls = require("./nls");
12-
var util = require("./util");
13-
var reporter_1 = require("./reporter");
14-
var path = require("path");
15-
var bom = require("gulp-bom");
16-
var sourcemaps = require("gulp-sourcemaps");
17-
var _ = require("underscore");
18-
var monacodts = require("../monaco/api");
19-
var fs = require("fs");
20-
var reporter = reporter_1.createReporter();
21-
var rootDir = path.join(__dirname, '../../src');
22-
var options = require('../../src/tsconfig.json').compilerOptions;
23-
options.verbose = false;
24-
options.sourceMap = true;
25-
options.rootDir = rootDir;
26-
options.sourceRoot = util.toFileUri(rootDir);
27-
function createCompile(build, emitError) {
28-
var opts = _.clone(options);
29-
opts.inlineSources = !!build;
30-
opts.noFilesystemLookup = true;
31-
var ts = tsb.create(opts, null, null, function (err) { return reporter(err.toString()); });
32-
return function (token) {
33-
var utf8Filter = util.filter(function (data) { return /(\/|\\)test(\/|\\).*utf8/.test(data.path); });
34-
var tsFilter = util.filter(function (data) { return /\.ts$/.test(data.path); });
35-
var noDeclarationsFilter = util.filter(function (data) { return !(/\.d\.ts$/.test(data.path)); });
36-
var input = es.through();
37-
var output = input
38-
.pipe(utf8Filter)
39-
.pipe(bom())
40-
.pipe(utf8Filter.restore)
41-
.pipe(tsFilter)
42-
.pipe(util.loadSourcemaps())
43-
.pipe(ts(token))
44-
.pipe(build ? reloadTypeScriptNodeModule() : es.through())
45-
.pipe(noDeclarationsFilter)
46-
.pipe(build ? nls() : es.through())
47-
.pipe(noDeclarationsFilter.restore)
48-
.pipe(sourcemaps.write('.', {
49-
addComment: false,
50-
includeContent: !!build,
51-
sourceRoot: options.sourceRoot
52-
}))
53-
.pipe(tsFilter.restore)
54-
.pipe(reporter.end(emitError));
55-
return es.duplex(input, output);
56-
};
57-
}
58-
function compileTask(out, build) {
59-
return function () {
60-
var compile = createCompile(build, true);
61-
var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts'), gulp.src('node_modules/@types/**/index.d.ts'));
62-
return src
63-
.pipe(compile())
64-
.pipe(gulp.dest(out))
65-
.pipe(monacodtsTask(out, false));
66-
};
67-
}
68-
exports.compileTask = compileTask;
69-
function watchTask(out, build) {
70-
return function () {
71-
var compile = createCompile(build);
72-
var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts'), gulp.src('node_modules/@types/**/index.d.ts'));
73-
var watchSrc = watch('src/**', { base: 'src' });
74-
return watchSrc
75-
.pipe(util.incremental(compile, src, true))
76-
.pipe(gulp.dest(out))
77-
.pipe(monacodtsTask(out, true));
78-
};
79-
}
80-
exports.watchTask = watchTask;
81-
function reloadTypeScriptNodeModule() {
82-
var util = require('gulp-util');
83-
function log(message) {
84-
var rest = [];
85-
for (var _i = 1; _i < arguments.length; _i++) {
86-
rest[_i - 1] = arguments[_i];
87-
}
88-
util.log.apply(util, [util.colors.cyan('[memory watch dog]'), message].concat(rest));
89-
}
90-
function heapUsed() {
91-
return (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + ' MB';
92-
}
93-
return es.through(function (data) {
94-
this.emit('data', data);
95-
}, function () {
96-
log('memory usage after compilation finished: ' + heapUsed());
97-
// It appears we are running into some variant of
98-
// https://bugs.chromium.org/p/v8/issues/detail?id=2073
99-
//
100-
// Even though all references are dropped, some
101-
// optimized methods in the TS compiler end up holding references
102-
// to the entire TypeScript language host (>600MB)
103-
//
104-
// The idea is to force v8 to drop references to these
105-
// optimized methods, by "reloading" the typescript node module
106-
log('Reloading typescript node module...');
107-
var resolvedName = require.resolve('typescript');
108-
var originalModule = require.cache[resolvedName];
109-
delete require.cache[resolvedName];
110-
var newExports = require('typescript');
111-
require.cache[resolvedName] = originalModule;
112-
for (var prop in newExports) {
113-
if (newExports.hasOwnProperty(prop)) {
114-
originalModule.exports[prop] = newExports[prop];
115-
}
116-
}
117-
log('typescript node module reloaded.');
118-
this.emit('end');
119-
});
120-
}
121-
function monacodtsTask(out, isWatch) {
122-
var neededFiles = {};
123-
monacodts.getFilesToWatch(out).forEach(function (filePath) {
124-
filePath = path.normalize(filePath);
125-
neededFiles[filePath] = true;
126-
});
127-
var inputFiles = {};
128-
for (var filePath in neededFiles) {
129-
if (/\bsrc(\/|\\)vs\b/.test(filePath)) {
130-
// This file is needed from source => simply read it now
131-
inputFiles[filePath] = fs.readFileSync(filePath).toString();
132-
}
133-
}
134-
var setInputFile = function (filePath, contents) {
135-
if (inputFiles[filePath] === contents) {
136-
// no change
137-
return;
138-
}
139-
inputFiles[filePath] = contents;
140-
var neededInputFilesCount = Object.keys(neededFiles).length;
141-
var availableInputFilesCount = Object.keys(inputFiles).length;
142-
if (neededInputFilesCount === availableInputFilesCount) {
143-
run();
144-
}
145-
};
146-
var run = function () {
147-
var result = monacodts.run(out, inputFiles);
148-
if (!result.isTheSame) {
149-
if (isWatch) {
150-
fs.writeFileSync(result.filePath, result.content);
151-
}
152-
else {
153-
resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
154-
}
155-
}
156-
};
157-
var resultStream;
158-
if (isWatch) {
159-
watch('build/monaco/*').pipe(es.through(function () {
160-
run();
161-
}));
162-
}
163-
resultStream = es.through(function (data) {
164-
var filePath = path.normalize(data.path);
165-
if (neededFiles[filePath]) {
166-
setInputFile(filePath, data.contents.toString());
167-
}
168-
this.emit('data', data);
169-
});
170-
return resultStream;
171-
}
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
var gulp = require("gulp");
7+
var tsb = require("gulp-tsb");
8+
var es = require("event-stream");
9+
var watch = require('./watch');
10+
var nls = require("./nls");
11+
var util = require("./util");
12+
var reporter_1 = require("./reporter");
13+
var path = require("path");
14+
var bom = require("gulp-bom");
15+
var sourcemaps = require("gulp-sourcemaps");
16+
var _ = require("underscore");
17+
var monacodts = require("../monaco/api");
18+
var fs = require("fs");
19+
var reporter = reporter_1.createReporter();
20+
var rootDir = path.join(__dirname, '../../src');
21+
var options = require('../../src/tsconfig.json').compilerOptions;
22+
options.verbose = false;
23+
options.sourceMap = true;
24+
options.rootDir = rootDir;
25+
options.sourceRoot = util.toFileUri(rootDir);
26+
function createCompile(build, emitError) {
27+
var opts = _.clone(options);
28+
opts.inlineSources = !!build;
29+
opts.noFilesystemLookup = true;
30+
var ts = tsb.create(opts, null, null, function (err) { return reporter(err.toString()); });
31+
return function (token) {
32+
var utf8Filter = util.filter(function (data) { return /(\/|\\)test(\/|\\).*utf8/.test(data.path); });
33+
var tsFilter = util.filter(function (data) { return /\.ts$/.test(data.path); });
34+
var noDeclarationsFilter = util.filter(function (data) { return !(/\.d\.ts$/.test(data.path)); });
35+
var input = es.through();
36+
var output = input
37+
.pipe(utf8Filter)
38+
.pipe(bom())
39+
.pipe(utf8Filter.restore)
40+
.pipe(tsFilter)
41+
.pipe(util.loadSourcemaps())
42+
.pipe(ts(token))
43+
.pipe(build ? reloadTypeScriptNodeModule() : es.through())
44+
.pipe(noDeclarationsFilter)
45+
.pipe(build ? nls() : es.through())
46+
.pipe(noDeclarationsFilter.restore)
47+
.pipe(sourcemaps.write('.', {
48+
addComment: false,
49+
includeContent: !!build,
50+
sourceRoot: options.sourceRoot
51+
}))
52+
.pipe(tsFilter.restore)
53+
.pipe(reporter.end(emitError));
54+
return es.duplex(input, output);
55+
};
56+
}
57+
function compileTask(out, build) {
58+
return function () {
59+
var compile = createCompile(build, true);
60+
var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts'), gulp.src('node_modules/@types/**/index.d.ts'));
61+
return src
62+
.pipe(compile())
63+
.pipe(gulp.dest(out))
64+
.pipe(monacodtsTask(out, false));
65+
};
66+
}
67+
exports.compileTask = compileTask;
68+
function watchTask(out, build) {
69+
return function () {
70+
var compile = createCompile(build);
71+
var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts'), gulp.src('node_modules/@types/**/index.d.ts'));
72+
var watchSrc = watch('src/**', { base: 'src' });
73+
return watchSrc
74+
.pipe(util.incremental(compile, src, true))
75+
.pipe(gulp.dest(out))
76+
.pipe(monacodtsTask(out, true));
77+
};
78+
}
79+
exports.watchTask = watchTask;
80+
function reloadTypeScriptNodeModule() {
81+
var util = require('gulp-util');
82+
function log(message) {
83+
var rest = [];
84+
for (var _i = 1; _i < arguments.length; _i++) {
85+
rest[_i - 1] = arguments[_i];
86+
}
87+
util.log.apply(util, [util.colors.cyan('[memory watch dog]'), message].concat(rest));
88+
}
89+
function heapUsed() {
90+
return (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + ' MB';
91+
}
92+
return es.through(function (data) {
93+
this.emit('data', data);
94+
}, function () {
95+
log('memory usage after compilation finished: ' + heapUsed());
96+
// It appears we are running into some variant of
97+
// https://bugs.chromium.org/p/v8/issues/detail?id=2073
98+
//
99+
// Even though all references are dropped, some
100+
// optimized methods in the TS compiler end up holding references
101+
// to the entire TypeScript language host (>600MB)
102+
//
103+
// The idea is to force v8 to drop references to these
104+
// optimized methods, by "reloading" the typescript node module
105+
log('Reloading typescript node module...');
106+
var resolvedName = require.resolve('typescript');
107+
var originalModule = require.cache[resolvedName];
108+
delete require.cache[resolvedName];
109+
var newExports = require('typescript');
110+
require.cache[resolvedName] = originalModule;
111+
for (var prop in newExports) {
112+
if (newExports.hasOwnProperty(prop)) {
113+
originalModule.exports[prop] = newExports[prop];
114+
}
115+
}
116+
log('typescript node module reloaded.');
117+
this.emit('end');
118+
});
119+
}
120+
function monacodtsTask(out, isWatch) {
121+
var neededFiles = {};
122+
monacodts.getFilesToWatch(out).forEach(function (filePath) {
123+
filePath = path.normalize(filePath);
124+
neededFiles[filePath] = true;
125+
});
126+
var inputFiles = {};
127+
for (var filePath in neededFiles) {
128+
if (/\bsrc(\/|\\)vs\b/.test(filePath)) {
129+
// This file is needed from source => simply read it now
130+
inputFiles[filePath] = fs.readFileSync(filePath).toString();
131+
}
132+
}
133+
var setInputFile = function (filePath, contents) {
134+
if (inputFiles[filePath] === contents) {
135+
// no change
136+
return;
137+
}
138+
inputFiles[filePath] = contents;
139+
var neededInputFilesCount = Object.keys(neededFiles).length;
140+
var availableInputFilesCount = Object.keys(inputFiles).length;
141+
if (neededInputFilesCount === availableInputFilesCount) {
142+
run();
143+
}
144+
};
145+
var run = function () {
146+
var result = monacodts.run(out, inputFiles);
147+
if (!result.isTheSame) {
148+
if (isWatch) {
149+
fs.writeFileSync(result.filePath, result.content);
150+
}
151+
else {
152+
resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
153+
}
154+
}
155+
};
156+
var resultStream;
157+
if (isWatch) {
158+
watch('build/monaco/*').pipe(es.through(function () {
159+
run();
160+
}));
161+
}
162+
resultStream = es.through(function (data) {
163+
var filePath = path.normalize(data.path);
164+
if (neededFiles[filePath]) {
165+
setInputFile(filePath, data.contents.toString());
166+
}
167+
this.emit('data', data);
168+
});
169+
return resultStream;
170+
}

0 commit comments

Comments
 (0)