2015-11-23 19:28:42 +00:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2018-03-07 08:38:59 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const path = require('path');
|
|
|
|
const util = require('./lib/util');
|
|
|
|
const common = require('./lib/optimize');
|
|
|
|
const es = require('event-stream');
|
|
|
|
const File = require('vinyl');
|
|
|
|
const i18n = require('./lib/i18n');
|
|
|
|
const standalone = require('./lib/standalone');
|
|
|
|
const cp = require('child_process');
|
2018-07-19 19:05:38 +00:00
|
|
|
const compilation = require('./lib/compilation');
|
2018-07-20 09:25:46 +00:00
|
|
|
const monacoapi = require('./monaco/api');
|
|
|
|
const fs = require('fs');
|
2015-11-23 19:28:42 +00:00
|
|
|
|
|
|
|
var root = path.dirname(__dirname);
|
2016-05-31 14:29:52 +00:00
|
|
|
var sha1 = util.getVersion(root);
|
|
|
|
var semver = require('./monaco/package.json').version;
|
|
|
|
var headerVersion = semver + '(' + sha1 + ')';
|
2015-11-23 19:28:42 +00:00
|
|
|
|
|
|
|
// Build
|
|
|
|
|
2016-09-18 08:50:11 +00:00
|
|
|
var editorEntryPoints = [
|
|
|
|
{
|
|
|
|
name: 'vs/editor/editor.main',
|
|
|
|
include: [],
|
2018-02-12 11:40:53 +00:00
|
|
|
exclude: ['vs/css', 'vs/nls'],
|
|
|
|
prepend: ['out-build/vs/css.js', 'out-build/vs/nls.js'],
|
2016-09-18 08:50:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'vs/base/common/worker/simpleWorker',
|
2018-02-12 11:40:53 +00:00
|
|
|
include: ['vs/editor/common/services/editorSimpleWorker'],
|
|
|
|
prepend: ['vs/loader.js'],
|
|
|
|
append: ['vs/base/worker/workerMain'],
|
2016-09-18 20:05:42 +00:00
|
|
|
dest: 'vs/base/worker/workerMain.js'
|
2016-10-07 15:55:12 +00:00
|
|
|
}
|
2016-09-21 08:14:37 +00:00
|
|
|
];
|
2015-11-23 19:28:42 +00:00
|
|
|
|
|
|
|
var editorResources = [
|
|
|
|
'out-build/vs/{base,editor}/**/*.{svg,png}',
|
2016-06-07 16:46:41 +00:00
|
|
|
'!out-build/vs/base/browser/ui/splitview/**/*',
|
|
|
|
'!out-build/vs/base/browser/ui/toolbar/**/*',
|
|
|
|
'!out-build/vs/base/browser/ui/octiconLabel/**/*',
|
2015-11-23 19:28:42 +00:00
|
|
|
'!out-build/vs/workbench/**',
|
|
|
|
'!**/test/**'
|
|
|
|
];
|
|
|
|
|
|
|
|
var editorOtherSources = [
|
|
|
|
];
|
|
|
|
|
|
|
|
var BUNDLED_FILE_HEADER = [
|
|
|
|
'/*!-----------------------------------------------------------',
|
2016-02-24 13:27:53 +00:00
|
|
|
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
2016-03-06 11:37:24 +00:00
|
|
|
' * Version: ' + headerVersion,
|
2015-11-23 19:28:42 +00:00
|
|
|
' * Released under the MIT license',
|
|
|
|
' * https://github.com/Microsoft/vscode/blob/master/LICENSE.txt',
|
|
|
|
' *-----------------------------------------------------------*/',
|
|
|
|
''
|
|
|
|
].join('\n');
|
|
|
|
|
2018-03-07 08:38:59 +00:00
|
|
|
const languages = i18n.defaultLanguages.concat([]); // i18n.defaultLanguages.concat(process.env.VSCODE_QUALITY !== 'stable' ? i18n.extraLanguages : []);
|
|
|
|
|
2018-07-19 15:43:17 +00:00
|
|
|
gulp.task('clean-editor-src', util.rimraf('out-editor-src'));
|
2018-07-20 09:25:46 +00:00
|
|
|
gulp.task('extract-editor-src', ['clean-editor-src'], function () {
|
|
|
|
console.log(`If the build fails, consider tweaking shakeLevel below to a lower value.`);
|
|
|
|
const apiusages = monacoapi.execute().usageContent;
|
|
|
|
const extrausages = fs.readFileSync(path.join(root, 'build', 'monaco', 'monaco.usage.recipe')).toString();
|
2018-07-19 15:43:17 +00:00
|
|
|
standalone.extractEditor({
|
|
|
|
sourcesRoot: path.join(root, 'src'),
|
|
|
|
entryPoints: [
|
|
|
|
'vs/editor/editor.main',
|
|
|
|
'vs/editor/editor.worker',
|
2018-07-20 08:38:56 +00:00
|
|
|
'vs/base/worker/workerMain',
|
2018-07-20 09:25:46 +00:00
|
|
|
],
|
|
|
|
inlineEntryPoints: [
|
|
|
|
apiusages,
|
|
|
|
extrausages
|
2018-07-19 15:43:17 +00:00
|
|
|
],
|
|
|
|
libs: [
|
|
|
|
`lib.d.ts`,
|
|
|
|
`lib.es2015.collection.d.ts`
|
|
|
|
],
|
|
|
|
redirects: {
|
|
|
|
'vs/base/browser/ui/octiconLabel/octiconLabel': 'vs/base/browser/ui/octiconLabel/octiconLabel.mock',
|
|
|
|
},
|
|
|
|
compilerOptions: {
|
|
|
|
module: 2, // ModuleKind.AMD
|
|
|
|
},
|
2018-07-20 09:25:46 +00:00
|
|
|
shakeLevel: 2, // 0-Files, 1-InnerFile, 2-ClassMembers
|
2018-07-19 15:43:17 +00:00
|
|
|
importIgnorePattern: /^vs\/css!/,
|
|
|
|
destRoot: path.join(root, 'out-editor-src')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-19 19:05:38 +00:00
|
|
|
// Full compile, including nls and inline sources in sourcemaps, for build
|
|
|
|
gulp.task('clean-editor-build', util.rimraf('out-editor-build'));
|
|
|
|
gulp.task('compile-editor-build', ['clean-editor-build', 'extract-editor-src'], compilation.compileTask('out-editor-src', 'out-editor-build', true));
|
|
|
|
|
2018-07-20 09:25:46 +00:00
|
|
|
gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
|
|
|
|
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-editor-build'], common.optimizeTask({
|
2018-07-20 08:38:56 +00:00
|
|
|
src: 'out-editor-build',
|
|
|
|
entryPoints: editorEntryPoints,
|
|
|
|
otherSources: editorOtherSources,
|
|
|
|
resources: editorResources,
|
|
|
|
loaderConfig: {
|
|
|
|
paths: {
|
|
|
|
'vs': 'out-editor-build/vs',
|
|
|
|
'vscode': 'empty:'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bundleLoader: false,
|
|
|
|
header: BUNDLED_FILE_HEADER,
|
|
|
|
bundleInfo: true,
|
|
|
|
out: 'out-editor',
|
|
|
|
languages: languages
|
|
|
|
}));
|
|
|
|
|
2015-11-23 19:28:42 +00:00
|
|
|
gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
|
2016-09-13 07:41:47 +00:00
|
|
|
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor'));
|
2016-05-31 14:29:52 +00:00
|
|
|
|
2018-03-07 08:38:59 +00:00
|
|
|
gulp.task('clean-editor-esm', util.rimraf('out-editor-esm'));
|
2018-08-10 07:27:06 +00:00
|
|
|
gulp.task('extract-editor-esm', ['clean-editor-esm', 'clean-editor-distro', 'extract-editor-src'], function () {
|
|
|
|
standalone.createESMSourcesAndResources2({
|
|
|
|
srcFolder: './out-editor-src',
|
2018-03-07 08:38:59 +00:00
|
|
|
outFolder: './out-editor-esm/src',
|
|
|
|
outResourcesFolder: './out-monaco-editor-core/esm',
|
2018-08-10 07:27:06 +00:00
|
|
|
ignores: [
|
|
|
|
'inlineEntryPoint:0.ts',
|
|
|
|
'inlineEntryPoint:1.ts',
|
2018-08-10 11:57:35 +00:00
|
|
|
'vs/loader.js',
|
2018-08-10 07:27:06 +00:00
|
|
|
'vs/nls.ts',
|
2018-08-10 11:57:35 +00:00
|
|
|
'vs/nls.build.js',
|
2018-08-10 07:27:06 +00:00
|
|
|
'vs/nls.d.ts',
|
2018-08-10 11:57:35 +00:00
|
|
|
'vs/css.js',
|
|
|
|
'vs/css.build.js',
|
2018-08-10 07:27:06 +00:00
|
|
|
'vs/css.d.ts',
|
|
|
|
'vs/base/worker/workerMain.ts',
|
|
|
|
],
|
|
|
|
renames: {
|
|
|
|
'vs/nls.mock.ts': 'vs/nls.ts'
|
2018-03-07 08:38:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-04-05 08:00:50 +00:00
|
|
|
gulp.task('compile-editor-esm', ['extract-editor-esm', 'clean-editor-distro'], function () {
|
2018-03-07 08:38:59 +00:00
|
|
|
const result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
|
|
|
|
cwd: path.join(__dirname, '../out-editor-esm')
|
|
|
|
});
|
|
|
|
console.log(result.stdout.toString());
|
|
|
|
});
|
|
|
|
|
2018-05-15 09:10:05 +00:00
|
|
|
function toExternalDTS(contents) {
|
|
|
|
let lines = contents.split('\n');
|
|
|
|
let killNextCloseCurlyBrace = false;
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
let line = lines[i];
|
|
|
|
|
|
|
|
if (killNextCloseCurlyBrace) {
|
|
|
|
if ('}' === line) {
|
|
|
|
lines[i] = '';
|
|
|
|
killNextCloseCurlyBrace = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.indexOf(' ') === 0) {
|
|
|
|
lines[i] = line.substr(4);
|
|
|
|
} else if (line.charAt(0) === '\t') {
|
|
|
|
lines[i] = line.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('declare namespace monaco {' === line) {
|
|
|
|
lines[i] = '';
|
|
|
|
killNextCloseCurlyBrace = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.indexOf('declare namespace monaco.') === 0) {
|
|
|
|
lines[i] = line.replace('declare namespace monaco.', 'export namespace ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines.join('\n');
|
|
|
|
}
|
|
|
|
|
2016-05-31 14:29:52 +00:00
|
|
|
gulp.task('clean-editor-distro', util.rimraf('out-monaco-editor-core'));
|
2018-03-07 08:38:59 +00:00
|
|
|
gulp.task('editor-distro', ['clean-editor-distro', 'compile-editor-esm', 'minify-editor', 'optimize-editor'], function () {
|
2016-05-31 14:29:52 +00:00
|
|
|
return es.merge(
|
|
|
|
// other assets
|
|
|
|
es.merge(
|
|
|
|
gulp.src('build/monaco/LICENSE'),
|
|
|
|
gulp.src('build/monaco/ThirdPartyNotices.txt'),
|
|
|
|
gulp.src('src/vs/monaco.d.ts')
|
|
|
|
).pipe(gulp.dest('out-monaco-editor-core')),
|
|
|
|
|
2018-04-25 09:46:17 +00:00
|
|
|
// place the .d.ts in the esm folder
|
|
|
|
gulp.src('src/vs/monaco.d.ts')
|
|
|
|
.pipe(es.through(function (data) {
|
|
|
|
this.emit('data', new File({
|
|
|
|
path: data.path.replace(/monaco\.d\.ts/, 'editor.api.d.ts'),
|
|
|
|
base: data.base,
|
2018-05-15 09:10:05 +00:00
|
|
|
contents: new Buffer(toExternalDTS(data.contents.toString()))
|
2018-04-25 09:46:17 +00:00
|
|
|
}));
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('out-monaco-editor-core/esm/vs/editor')),
|
|
|
|
|
2016-06-06 14:44:28 +00:00
|
|
|
// package.json
|
|
|
|
gulp.src('build/monaco/package.json')
|
2018-02-12 11:40:53 +00:00
|
|
|
.pipe(es.through(function (data) {
|
2016-06-06 14:44:28 +00:00
|
|
|
var json = JSON.parse(data.contents.toString());
|
|
|
|
json.private = false;
|
2018-02-26 12:09:47 +00:00
|
|
|
data.contents = Buffer.from(JSON.stringify(json, null, ' '));
|
2016-06-06 14:44:28 +00:00
|
|
|
this.emit('data', data);
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('out-monaco-editor-core')),
|
|
|
|
|
2016-06-09 09:20:03 +00:00
|
|
|
// README.md
|
|
|
|
gulp.src('build/monaco/README-npm.md')
|
2018-02-12 11:40:53 +00:00
|
|
|
.pipe(es.through(function (data) {
|
2016-06-09 09:20:03 +00:00
|
|
|
this.emit('data', new File({
|
|
|
|
path: data.path.replace(/README-npm\.md/, 'README.md'),
|
|
|
|
base: data.base,
|
|
|
|
contents: data.contents
|
|
|
|
}));
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('out-monaco-editor-core')),
|
|
|
|
|
2016-05-31 14:29:52 +00:00
|
|
|
// dev folder
|
|
|
|
es.merge(
|
|
|
|
gulp.src('out-editor/**/*')
|
|
|
|
).pipe(gulp.dest('out-monaco-editor-core/dev')),
|
|
|
|
|
|
|
|
// min folder
|
|
|
|
es.merge(
|
|
|
|
gulp.src('out-editor-min/**/*')
|
2018-02-12 11:40:53 +00:00
|
|
|
).pipe(filterStream(function (path) {
|
2016-05-31 14:29:52 +00:00
|
|
|
// no map files
|
2016-06-09 08:50:11 +00:00
|
|
|
return !/(\.js\.map$)|(nls\.metadata\.json$)|(bundleInfo\.json$)/.test(path);
|
2018-02-12 11:40:53 +00:00
|
|
|
})).pipe(es.through(function (data) {
|
2016-05-31 14:29:52 +00:00
|
|
|
// tweak the sourceMappingURL
|
|
|
|
if (!/\.js$/.test(data.path)) {
|
|
|
|
this.emit('data', data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var relativePathToMap = path.relative(path.join(data.relative), path.join('min-maps', data.relative + '.map'));
|
|
|
|
|
|
|
|
var strContents = data.contents.toString();
|
|
|
|
var newStr = '//# sourceMappingURL=' + relativePathToMap.replace(/\\/g, '/');
|
|
|
|
strContents = strContents.replace(/\/\/\# sourceMappingURL=[^ ]+$/, newStr);
|
|
|
|
|
2018-02-26 12:09:47 +00:00
|
|
|
data.contents = Buffer.from(strContents);
|
2016-05-31 14:29:52 +00:00
|
|
|
this.emit('data', data);
|
|
|
|
})).pipe(gulp.dest('out-monaco-editor-core/min')),
|
|
|
|
|
|
|
|
// min-maps folder
|
|
|
|
es.merge(
|
|
|
|
gulp.src('out-editor-min/**/*')
|
2018-02-12 11:40:53 +00:00
|
|
|
).pipe(filterStream(function (path) {
|
2016-05-31 14:29:52 +00:00
|
|
|
// no map files
|
2016-05-31 14:37:47 +00:00
|
|
|
return /\.js\.map$/.test(path);
|
2016-05-31 14:29:52 +00:00
|
|
|
})).pipe(gulp.dest('out-monaco-editor-core/min-maps'))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-02-12 11:40:53 +00:00
|
|
|
gulp.task('analyze-editor-distro', function () {
|
2018-07-19 15:43:17 +00:00
|
|
|
// @ts-ignore
|
2016-06-08 18:59:08 +00:00
|
|
|
var bundleInfo = require('../out-editor/bundleInfo.json');
|
|
|
|
var graph = bundleInfo.graph;
|
|
|
|
var bundles = bundleInfo.bundles;
|
|
|
|
|
|
|
|
var inverseGraph = {};
|
2018-02-12 11:40:53 +00:00
|
|
|
Object.keys(graph).forEach(function (module) {
|
2016-06-08 18:59:08 +00:00
|
|
|
var dependencies = graph[module];
|
2018-02-12 11:40:53 +00:00
|
|
|
dependencies.forEach(function (dep) {
|
2016-06-08 18:59:08 +00:00
|
|
|
inverseGraph[dep] = inverseGraph[dep] || [];
|
|
|
|
inverseGraph[dep].push(module);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var detailed = {};
|
2018-02-12 11:40:53 +00:00
|
|
|
Object.keys(bundles).forEach(function (entryPoint) {
|
2016-06-08 18:59:08 +00:00
|
|
|
var included = bundles[entryPoint];
|
|
|
|
var includedMap = {};
|
2018-02-12 11:40:53 +00:00
|
|
|
included.forEach(function (included) {
|
2016-06-08 18:59:08 +00:00
|
|
|
includedMap[included] = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var explanation = [];
|
2018-02-12 11:40:53 +00:00
|
|
|
included.map(function (included) {
|
2016-06-08 18:59:08 +00:00
|
|
|
if (included.indexOf('!') >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-12 11:40:53 +00:00
|
|
|
var reason = (inverseGraph[included] || []).filter(function (mod) {
|
2016-06-08 18:59:08 +00:00
|
|
|
return !!includedMap[mod];
|
|
|
|
});
|
|
|
|
explanation.push({
|
|
|
|
module: included,
|
|
|
|
reason: reason
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
detailed[entryPoint] = explanation;
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(JSON.stringify(detailed, null, '\t'));
|
|
|
|
});
|
|
|
|
|
2016-05-31 14:29:52 +00:00
|
|
|
function filterStream(testFunc) {
|
2018-02-12 11:40:53 +00:00
|
|
|
return es.through(function (data) {
|
2016-05-31 14:29:52 +00:00
|
|
|
if (!testFunc(data.relative)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.emit('data', data);
|
|
|
|
});
|
|
|
|
}
|
2018-04-05 08:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
//#region monaco type checking
|
|
|
|
|
|
|
|
function createTscCompileTask(watch) {
|
|
|
|
return () => {
|
|
|
|
const createReporter = require('./lib/reporter').createReporter;
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2018-04-05 12:36:21 +00:00
|
|
|
const args = ['./node_modules/.bin/tsc', '-p', './src/tsconfig.monaco.json', '--noEmit'];
|
2018-04-05 08:00:50 +00:00
|
|
|
if (watch) {
|
|
|
|
args.push('-w');
|
|
|
|
}
|
2018-04-05 12:36:21 +00:00
|
|
|
const child = cp.spawn(`node`, args, {
|
2018-04-05 08:00:50 +00:00
|
|
|
cwd: path.join(__dirname, '..'),
|
2018-04-05 12:36:21 +00:00
|
|
|
// stdio: [null, 'pipe', 'inherit']
|
2018-04-05 08:00:50 +00:00
|
|
|
});
|
|
|
|
let errors = [];
|
|
|
|
let reporter = createReporter();
|
|
|
|
let report;
|
2018-04-05 09:33:28 +00:00
|
|
|
let magic = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; // https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings
|
2018-04-05 08:00:50 +00:00
|
|
|
|
|
|
|
child.stdout.on('data', data => {
|
|
|
|
let str = String(data);
|
|
|
|
str = str.replace(magic, '').trim();
|
|
|
|
if (str.indexOf('Starting compilation') >= 0 || str.indexOf('File change detected') >= 0) {
|
|
|
|
errors.length = 0;
|
|
|
|
report = reporter.end(false);
|
|
|
|
|
|
|
|
} else if (str.indexOf('Compilation complete') >= 0) {
|
|
|
|
report.end();
|
|
|
|
|
|
|
|
} else if (str) {
|
|
|
|
let match = /(.*\(\d+,\d+\): )(.*: )(.*)/.exec(str);
|
|
|
|
if (match) {
|
|
|
|
// trying to massage the message so that it matches the gulp-tsb error messages
|
|
|
|
// e.g. src/vs/base/common/strings.ts(663,5): error TS2322: Type '1234' is not assignable to type 'string'.
|
|
|
|
let fullpath = path.join(root, match[1]);
|
|
|
|
let message = match[3];
|
2018-04-05 12:36:21 +00:00
|
|
|
// @ts-ignore
|
2018-04-05 08:00:50 +00:00
|
|
|
reporter(fullpath + message);
|
|
|
|
} else {
|
2018-04-05 12:36:21 +00:00
|
|
|
// @ts-ignore
|
2018-04-05 08:00:50 +00:00
|
|
|
reporter(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
child.on('exit', resolve);
|
|
|
|
child.on('error', reject);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('monaco-typecheck-watch', createTscCompileTask(true));
|
|
|
|
gulp.task('monaco-typecheck', createTscCompileTask(false));
|
|
|
|
|
|
|
|
//#endregion
|