diff --git a/.gitignore b/.gitignore index 5c902cc558683..08adb4af663a6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ out/ out-build/ out-editor/ out-editor-src/ +out-editor-build/ out-editor-esm/ out-editor-min/ out-monaco-editor-core/ diff --git a/build/gulpfile.editor.js b/build/gulpfile.editor.js index a6883d2cfe318..5e43659fcaaf4 100644 --- a/build/gulpfile.editor.js +++ b/build/gulpfile.editor.js @@ -12,6 +12,7 @@ const File = require('vinyl'); const i18n = require('./lib/i18n'); const standalone = require('./lib/standalone'); const cp = require('child_process'); +const compilation = require('./lib/compilation'); var root = path.dirname(__dirname); var sha1 = util.getVersion(root); @@ -115,6 +116,10 @@ gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-client-build'], languages: languages })); +// 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)); + gulp.task('clean-minified-editor', util.rimraf('out-editor-min')); gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor')); diff --git a/build/lib/compilation.js b/build/lib/compilation.js index 998ebb4f37933..ad73e2dcf7309 100644 --- a/build/lib/compilation.js +++ b/build/lib/compilation.js @@ -18,18 +18,21 @@ var _ = require("underscore"); var monacodts = require("../monaco/api"); var fs = require("fs"); var reporter = reporter_1.createReporter(); -var rootDir = path.join(__dirname, '../../src'); -var options = require('../../src/tsconfig.json').compilerOptions; -options.verbose = false; -options.sourceMap = true; -if (process.env['VSCODE_NO_SOURCEMAP']) { // To be used by developers in a hurry - options.sourceMap = false; +function getTypeScriptCompilerOptions(src) { + var rootDir = path.join(__dirname, "../../" + src); + var options = require("../../" + src + "/tsconfig.json").compilerOptions; + options.verbose = false; + options.sourceMap = true; + if (process.env['VSCODE_NO_SOURCEMAP']) { // To be used by developers in a hurry + options.sourceMap = false; + } + options.rootDir = rootDir; + options.sourceRoot = util.toFileUri(rootDir); + options.newLine = /\r\n/.test(fs.readFileSync(__filename, 'utf8')) ? 'CRLF' : 'LF'; + return options; } -options.rootDir = rootDir; -options.sourceRoot = util.toFileUri(rootDir); -options.newLine = /\r\n/.test(fs.readFileSync(__filename, 'utf8')) ? 'CRLF' : 'LF'; -function createCompile(build, emitError) { - var opts = _.clone(options); +function createCompile(src, build, emitError) { + var opts = _.clone(getTypeScriptCompilerOptions(src)); opts.inlineSources = !!build; opts.noFilesystemLookup = true; var ts = tsb.create(opts, null, null, function (err) { return reporter(err.toString()); }); @@ -51,31 +54,31 @@ function createCompile(build, emitError) { .pipe(sourcemaps.write('.', { addComment: false, includeContent: !!build, - sourceRoot: options.sourceRoot + sourceRoot: opts.sourceRoot })) .pipe(tsFilter.restore) .pipe(reporter.end(emitError)); return es.duplex(input, output); }; } -function compileTask(out, build) { +function compileTask(src, out, build) { return function () { - var compile = createCompile(build, true); - var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts')); + var compile = createCompile(src, build, true); + var srcPipe = es.merge(gulp.src(src + "/**", { base: "" + src }), gulp.src('node_modules/typescript/lib/lib.d.ts')); // Do not write .d.ts files to disk, as they are not needed there. var dtsFilter = util.filter(function (data) { return !/\.d\.ts$/.test(data.path); }); - return src + return srcPipe .pipe(compile()) .pipe(dtsFilter) .pipe(gulp.dest(out)) .pipe(dtsFilter.restore) - .pipe(monacodtsTask(out, false)); + .pipe(src !== 'src' ? es.through() : monacodtsTask(out, false)); }; } exports.compileTask = compileTask; function watchTask(out, build) { return function () { - var compile = createCompile(build); + var compile = createCompile('src', build); var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts')); var watchSrc = watch('src/**', { base: 'src' }); // Do not write .d.ts files to disk, as they are not needed there. @@ -122,6 +125,7 @@ function monacodtsTask(out, isWatch) { fs.writeFileSync(result.filePath, result.content); } else { + fs.writeFileSync(result.filePath, result.content); resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.'); } } diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index cedcb4155b678..33d8c11169093 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -21,19 +21,22 @@ import * as fs from 'fs'; const reporter = createReporter(); -const rootDir = path.join(__dirname, '../../src'); -const options = require('../../src/tsconfig.json').compilerOptions; -options.verbose = false; -options.sourceMap = true; -if (process.env['VSCODE_NO_SOURCEMAP']) { // To be used by developers in a hurry - options.sourceMap = false; +function getTypeScriptCompilerOptions(src: string) { + const rootDir = path.join(__dirname, `../../${src}`); + const options = require(`../../${src}/tsconfig.json`).compilerOptions; + options.verbose = false; + options.sourceMap = true; + if (process.env['VSCODE_NO_SOURCEMAP']) { // To be used by developers in a hurry + options.sourceMap = false; + } + options.rootDir = rootDir; + options.sourceRoot = util.toFileUri(rootDir); + options.newLine = /\r\n/.test(fs.readFileSync(__filename, 'utf8')) ? 'CRLF' : 'LF'; + return options; } -options.rootDir = rootDir; -options.sourceRoot = util.toFileUri(rootDir); -options.newLine = /\r\n/.test(fs.readFileSync(__filename, 'utf8')) ? 'CRLF' : 'LF'; -function createCompile(build: boolean, emitError?: boolean): (token?: util.ICancellationToken) => NodeJS.ReadWriteStream { - const opts = _.clone(options); +function createCompile(src: string, build: boolean, emitError?: boolean): (token?: util.ICancellationToken) => NodeJS.ReadWriteStream { + const opts = _.clone(getTypeScriptCompilerOptions(src)); opts.inlineSources = !!build; opts.noFilesystemLookup = true; @@ -59,7 +62,7 @@ function createCompile(build: boolean, emitError?: boolean): (token?: util.ICanc .pipe(sourcemaps.write('.', { addComment: false, includeContent: !!build, - sourceRoot: options.sourceRoot + sourceRoot: opts.sourceRoot })) .pipe(tsFilter.restore) .pipe(reporter.end(emitError)); @@ -68,32 +71,32 @@ function createCompile(build: boolean, emitError?: boolean): (token?: util.ICanc }; } -export function compileTask(out: string, build: boolean): () => NodeJS.ReadWriteStream { +export function compileTask(src: string, out: string, build: boolean): () => NodeJS.ReadWriteStream { return function () { - const compile = createCompile(build, true); + const compile = createCompile(src, build, true); - const src = es.merge( - gulp.src('src/**', { base: 'src' }), + const srcPipe = es.merge( + gulp.src(`${src}/**`, { base: `${src}` }), gulp.src('node_modules/typescript/lib/lib.d.ts'), ); // Do not write .d.ts files to disk, as they are not needed there. const dtsFilter = util.filter(data => !/\.d\.ts$/.test(data.path)); - return src + return srcPipe .pipe(compile()) .pipe(dtsFilter) .pipe(gulp.dest(out)) .pipe(dtsFilter.restore) - .pipe(monacodtsTask(out, false)); + .pipe(src !== 'src' ? es.through() : monacodtsTask(out, false)); }; } export function watchTask(out: string, build: boolean): () => NodeJS.ReadWriteStream { return function () { - const compile = createCompile(build); + const compile = createCompile('src', build); const src = es.merge( gulp.src('src/**', { base: 'src' }), @@ -150,6 +153,7 @@ function monacodtsTask(out: string, isWatch: boolean): NodeJS.ReadWriteStream { if (isWatch) { fs.writeFileSync(result.filePath, result.content); } else { + fs.writeFileSync(result.filePath, result.content); resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.'); } } diff --git a/build/lib/standalone.js b/build/lib/standalone.js index 06b57482ca9bc..885d3e789f5ba 100644 --- a/build/lib/standalone.js +++ b/build/lib/standalone.js @@ -42,7 +42,7 @@ function extractEditor(options) { copied[fileName] = true; var srcPath = path.join(options.sourcesRoot, fileName); var dstPath = path.join(options.destRoot, fileName); - fs.writeFileSync(dstPath, fs.readFileSync(srcPath)); + writeFile(dstPath, fs.readFileSync(srcPath)); }; var writeOutputFile = function (fileName, contents) { writeFile(path.join(options.destRoot, fileName), contents); @@ -74,8 +74,10 @@ function extractEditor(options) { } } } + var tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.json')).toString()); + tsConfig.compilerOptions.noUnusedLocals = false; + writeOutputFile('tsconfig.json', JSON.stringify(tsConfig, null, '\t')); [ - 'tsconfig.json', 'vs/css.build.js', 'vs/css.d.ts', 'vs/css.js', @@ -85,6 +87,10 @@ function extractEditor(options) { 'vs/nls.d.ts', 'vs/nls.js', 'vs/nls.mock.ts', + 'typings/lib.ie11_safe_es6.d.ts', + 'typings/thenable.d.ts', + 'typings/es6-promise.d.ts', + 'typings/require.d.ts', ].forEach(copyFile); } exports.extractEditor = extractEditor; diff --git a/build/lib/standalone.ts b/build/lib/standalone.ts index 9378dd3e7d953..7931737fadbb2 100644 --- a/build/lib/standalone.ts +++ b/build/lib/standalone.ts @@ -14,7 +14,7 @@ const OUT_EDITOR = path.join(REPO_ROOT, 'out-editor'); let dirCache: { [dir: string]: boolean; } = {}; -function writeFile(filePath: string, contents: string): void { +function writeFile(filePath: string, contents: Buffer | string): void { function ensureDirs(dirPath: string): void { if (dirCache[dirPath]) { return; @@ -46,7 +46,7 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str copied[fileName] = true; const srcPath = path.join(options.sourcesRoot, fileName); const dstPath = path.join(options.destRoot, fileName); - fs.writeFileSync(dstPath, fs.readFileSync(srcPath)); + writeFile(dstPath, fs.readFileSync(srcPath)); }; const writeOutputFile = (fileName: string, contents: string) => { writeFile(path.join(options.destRoot, fileName), contents); @@ -80,8 +80,11 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str } } + const tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.json')).toString()); + tsConfig.compilerOptions.noUnusedLocals = false; + writeOutputFile('tsconfig.json', JSON.stringify(tsConfig, null, '\t')); + [ - 'tsconfig.json', 'vs/css.build.js', 'vs/css.d.ts', 'vs/css.js', @@ -91,6 +94,10 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str 'vs/nls.d.ts', 'vs/nls.js', 'vs/nls.mock.ts', + 'typings/lib.ie11_safe_es6.d.ts', + 'typings/thenable.d.ts', + 'typings/es6-promise.d.ts', + 'typings/require.d.ts', ].forEach(copyFile); } diff --git a/gulpfile.js b/gulpfile.js index db6d924ae734a..ebdca25bcb4a0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -15,12 +15,12 @@ const compilation = require('./build/lib/compilation'); // Fast compile for development time gulp.task('clean-client', util.rimraf('out')); -gulp.task('compile-client', ['clean-client'], compilation.compileTask('out', false)); +gulp.task('compile-client', ['clean-client'], compilation.compileTask('src', 'out', false)); gulp.task('watch-client', ['clean-client'], compilation.watchTask('out', false)); // Full compile, including nls and inline sources in sourcemaps, for build gulp.task('clean-client-build', util.rimraf('out-build')); -gulp.task('compile-client-build', ['clean-client-build'], compilation.compileTask('out-build', true)); +gulp.task('compile-client-build', ['clean-client-build'], compilation.compileTask('src', 'out-build', true)); gulp.task('watch-client-build', ['clean-client-build'], compilation.watchTask('out-build', true)); // Default