Skip to content

Commit 4cad4df

Browse files
committed
Merge branch 'master' into joao/compressed-trees
2 parents 0a15552 + 492def2 commit 4cad4df

94 files changed

Lines changed: 1357 additions & 779 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/gulpfile.extensions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const tasks = compilations.map(function (tsconfigFile) {
119119
const watchTask = task.define(`watch-extension:${name}`, task.series(cleanTask, () => {
120120
const pipeline = createPipeline(false);
121121
const input = pipeline.tsProjectSrc();
122-
const watchInput = watcher(src, srcOpts);
122+
const watchInput = watcher(src, { ...srcOpts, ...{ readDelay: 200 } });
123123

124124
return watchInput
125125
.pipe(util.incremental(pipeline, input))

build/gulpfile.vscode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const optimizeVSCodeTask = task.define('optimize-vscode', task.series(
9393
resources: vscodeResources,
9494
loaderConfig: common.loaderConfig(nodeModules),
9595
out: 'out-vscode',
96+
inlineAmdImages: true,
9697
bundleInfo: undefined
9798
})
9899
));

build/gulpfile.vscode.linux.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ function prepareSnapPackage(arch) {
238238

239239
function buildSnapPackage(arch) {
240240
const snapBuildPath = getSnapBuildPath(arch);
241-
return shell.task(`cd ${snapBuildPath} && snapcraft build`);
241+
// Default target for snapcraft runs: pull, build, stage and prime, and finally assembles the snap.
242+
return shell.task(`cd ${snapBuildPath} && snapcraft`);
242243
}
243244

244245
const BUILD_TARGETS = [

build/gulpfile.vscode.web.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const nodeModules = Object.keys(product.dependencies || {})
3434
const vscodeWebResources = [
3535

3636
// Workbench
37-
'out-build/vs/{base,platform,editor,workbench}/**/*.{svg,png,html}',
37+
'out-build/vs/{base,platform,editor,workbench}/**/*.{svg,png}',
38+
'out-build/vs/code/browser/workbench/workbench.html',
3839
'out-build/vs/base/browser/ui/octiconLabel/octicons/**',
3940
'out-build/vs/**/markdown.css',
4041

build/lib/compilation.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function getTypeScriptCompilerOptions(src) {
3636
function createCompile(src, build, emitError) {
3737
const projectPath = path.join(__dirname, '../../', src, 'tsconfig.json');
3838
const overrideOptions = Object.assign(Object.assign({}, getTypeScriptCompilerOptions(src)), { inlineSources: Boolean(build) });
39-
const ts = tsb.create(projectPath, overrideOptions, false, err => reporter(err));
40-
return function (token) {
39+
const compilation = tsb.create(projectPath, overrideOptions, false, err => reporter(err));
40+
function pipeline(token) {
4141
const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
4242
const tsFilter = util.filter(data => /\.ts$/.test(data.path));
4343
const noDeclarationsFilter = util.filter(data => !(/\.d\.ts$/.test(data.path)));
@@ -48,7 +48,7 @@ function createCompile(src, build, emitError) {
4848
.pipe(utf8Filter.restore)
4949
.pipe(tsFilter)
5050
.pipe(util.loadSourcemaps())
51-
.pipe(ts(token))
51+
.pipe(compilation(token))
5252
.pipe(noDeclarationsFilter)
5353
.pipe(build ? nls() : es.through())
5454
.pipe(noDeclarationsFilter.restore)
@@ -60,7 +60,11 @@ function createCompile(src, build, emitError) {
6060
.pipe(tsFilter.restore)
6161
.pipe(reporter.end(!!emitError));
6262
return es.duplex(input, output);
63+
}
64+
pipeline.tsProjectSrc = () => {
65+
return compilation.src({ base: src });
6366
};
67+
return pipeline;
6468
}
6569
function compileTask(src, out, build) {
6670
return function () {
@@ -81,7 +85,7 @@ function watchTask(out, build) {
8185
return function () {
8286
const compile = createCompile('src', build);
8387
const src = gulp.src('src/**', { base: 'src' });
84-
const watchSrc = watch('src/**', { base: 'src' });
88+
const watchSrc = watch('src/**', { base: 'src', readDelay: 200 });
8589
let generator = new MonacoGenerator(true);
8690
generator.execute();
8791
return watchSrc

build/lib/compilation.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ function getTypeScriptCompilerOptions(src: string): ts.CompilerOptions {
3939
return options;
4040
}
4141

42-
function createCompile(src: string, build: boolean, emitError?: boolean): (token?: util.ICancellationToken) => NodeJS.ReadWriteStream {
42+
function createCompile(src: string, build: boolean, emitError?: boolean) {
4343
const projectPath = path.join(__dirname, '../../', src, 'tsconfig.json');
4444
const overrideOptions = { ...getTypeScriptCompilerOptions(src), inlineSources: Boolean(build) };
4545

46-
const ts = tsb.create(projectPath, overrideOptions, false, err => reporter(err));
46+
const compilation = tsb.create(projectPath, overrideOptions, false, err => reporter(err));
4747

48-
return function (token?: util.ICancellationToken) {
48+
function pipeline(token?: util.ICancellationToken) {
4949

5050
const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
5151
const tsFilter = util.filter(data => /\.ts$/.test(data.path));
@@ -58,7 +58,7 @@ function createCompile(src: string, build: boolean, emitError?: boolean): (token
5858
.pipe(utf8Filter.restore)
5959
.pipe(tsFilter)
6060
.pipe(util.loadSourcemaps())
61-
.pipe(ts(token))
61+
.pipe(compilation(token))
6262
.pipe(noDeclarationsFilter)
6363
.pipe(build ? nls() : es.through())
6464
.pipe(noDeclarationsFilter.restore)
@@ -71,16 +71,18 @@ function createCompile(src: string, build: boolean, emitError?: boolean): (token
7171
.pipe(reporter.end(!!emitError));
7272

7373
return es.duplex(input, output);
74+
}
75+
pipeline.tsProjectSrc = () => {
76+
return compilation.src({ base: src });
7477
};
78+
return pipeline;
7579
}
7680

7781
export function compileTask(src: string, out: string, build: boolean): () => NodeJS.ReadWriteStream {
7882

7983
return function () {
8084
const compile = createCompile(src, build, true);
81-
8285
const srcPipe = gulp.src(`${src}/**`, { base: `${src}` });
83-
8486
let generator = new MonacoGenerator(false);
8587
if (src === 'src') {
8688
generator.execute();
@@ -99,7 +101,7 @@ export function watchTask(out: string, build: boolean): () => NodeJS.ReadWriteSt
99101
const compile = createCompile('src', build);
100102

101103
const src = gulp.src('src/**', { base: 'src' });
102-
const watchSrc = watch('src/**', { base: 'src' });
104+
const watchSrc = watch('src/**', { base: 'src', readDelay: 200 });
103105

104106
let generator = new MonacoGenerator(true);
105107
generator.execute();

build/lib/optimize.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66
Object.defineProperty(exports, "__esModule", { value: true });
77
const es = require("event-stream");
8+
const fs = require("fs");
89
const gulp = require("gulp");
910
const concat = require("gulp-concat");
1011
const minifyCSS = require("gulp-cssnano");
@@ -132,6 +133,14 @@ function optimizeTask(opts) {
132133
if (err || !result) {
133134
return bundlesStream.emit('error', JSON.stringify(err));
134135
}
136+
if (opts.inlineAmdImages) {
137+
try {
138+
result = inlineAmdImages(src, result);
139+
}
140+
catch (err) {
141+
return bundlesStream.emit('error', JSON.stringify(err));
142+
}
143+
}
135144
toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream);
136145
// Remove css inlined resources
137146
const filteredResources = resources.slice();
@@ -167,6 +176,39 @@ function optimizeTask(opts) {
167176
};
168177
}
169178
exports.optimizeTask = optimizeTask;
179+
function inlineAmdImages(src, result) {
180+
for (const outputFile of result.files) {
181+
for (const sourceFile of outputFile.sources) {
182+
if (sourceFile.path && /\.js$/.test(sourceFile.path)) {
183+
sourceFile.contents = sourceFile.contents.replace(/\([^.]+\.registerAndGetAmdImageURL\(([^)]+)\)\)/g, (_, m0) => {
184+
let imagePath = m0;
185+
// remove `` or ''
186+
if ((imagePath.charAt(0) === '`' && imagePath.charAt(imagePath.length - 1) === '`')
187+
|| (imagePath.charAt(0) === '\'' && imagePath.charAt(imagePath.length - 1) === '\'')) {
188+
imagePath = imagePath.substr(1, imagePath.length - 2);
189+
}
190+
if (!/\.(png|svg)$/.test(imagePath)) {
191+
console.log(`original: ${_}`);
192+
return _;
193+
}
194+
const repoLocation = path.join(src, imagePath);
195+
const absoluteLocation = path.join(REPO_ROOT_PATH, repoLocation);
196+
if (!fs.existsSync(absoluteLocation)) {
197+
const message = `Invalid amd image url in file ${sourceFile.path}: ${imagePath}`;
198+
console.log(message);
199+
throw new Error(message);
200+
}
201+
const fileContents = fs.readFileSync(absoluteLocation);
202+
const mime = /\.svg$/.test(imagePath) ? 'image/svg+xml' : 'image/png';
203+
// Mark the file as inlined so we don't ship it by itself
204+
result.cssInlinedResources.push(repoLocation);
205+
return `("data:${mime};base64,${fileContents.toString('base64')}")`;
206+
});
207+
}
208+
}
209+
}
210+
return result;
211+
}
170212
/**
171213
* Wrap around uglify and allow the preserveComments function
172214
* to have a file "context" to include our copyright only once per file.
@@ -202,9 +244,6 @@ function uglifyWithCopyrights() {
202244
const output = input
203245
.pipe(flatmap((stream, f) => {
204246
return stream.pipe(minify({
205-
compress: {
206-
hoist_funs: true // required due to https://github.com/microsoft/vscode/issues/80202
207-
},
208247
output: {
209248
comments: preserveComments(f),
210249
max_line_len: 1024

build/lib/optimize.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
import * as es from 'event-stream';
9+
import * as fs from 'fs';
910
import * as gulp from 'gulp';
1011
import * as concat from 'gulp-concat';
1112
import * as minifyCSS from 'gulp-cssnano';
@@ -159,6 +160,10 @@ export interface IOptimizeTaskOpts {
159160
* (emit bundleInfo.json file)
160161
*/
161162
bundleInfo: boolean;
163+
/**
164+
* replace calls to `registerAndGetAmdImageURL` with data uris
165+
*/
166+
inlineAmdImages: boolean;
162167
/**
163168
* (out folder name)
164169
*/
@@ -192,6 +197,14 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
192197
bundle.bundle(entryPoints, loaderConfig, function (err, result) {
193198
if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); }
194199

200+
if (opts.inlineAmdImages) {
201+
try {
202+
result = inlineAmdImages(src, result);
203+
} catch (err) {
204+
return bundlesStream.emit('error', JSON.stringify(err));
205+
}
206+
}
207+
195208
toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream);
196209

197210
// Remove css inlined resources
@@ -236,6 +249,42 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
236249
};
237250
}
238251

252+
function inlineAmdImages(src: string, result: bundle.IBundleResult): bundle.IBundleResult {
253+
for (const outputFile of result.files) {
254+
for (const sourceFile of outputFile.sources) {
255+
if (sourceFile.path && /\.js$/.test(sourceFile.path)) {
256+
sourceFile.contents = sourceFile.contents.replace(/\([^.]+\.registerAndGetAmdImageURL\(([^)]+)\)\)/g, (_, m0) => {
257+
let imagePath = m0;
258+
// remove `` or ''
259+
if ((imagePath.charAt(0) === '`' && imagePath.charAt(imagePath.length - 1) === '`')
260+
|| (imagePath.charAt(0) === '\'' && imagePath.charAt(imagePath.length - 1) === '\'')) {
261+
imagePath = imagePath.substr(1, imagePath.length - 2);
262+
}
263+
if (!/\.(png|svg)$/.test(imagePath)) {
264+
console.log(`original: ${_}`);
265+
return _;
266+
}
267+
const repoLocation = path.join(src, imagePath);
268+
const absoluteLocation = path.join(REPO_ROOT_PATH, repoLocation);
269+
if (!fs.existsSync(absoluteLocation)) {
270+
const message = `Invalid amd image url in file ${sourceFile.path}: ${imagePath}`;
271+
console.log(message);
272+
throw new Error(message);
273+
}
274+
const fileContents = fs.readFileSync(absoluteLocation);
275+
const mime = /\.svg$/.test(imagePath) ? 'image/svg+xml' : 'image/png';
276+
277+
// Mark the file as inlined so we don't ship it by itself
278+
result.cssInlinedResources.push(repoLocation);
279+
280+
return `("data:${mime};base64,${fileContents.toString('base64')}")`;
281+
});
282+
}
283+
}
284+
}
285+
return result;
286+
}
287+
239288
declare class FileWithCopyright extends VinylFile {
240289
public __hasOurCopyright: boolean;
241290
}
@@ -278,9 +327,6 @@ function uglifyWithCopyrights(): NodeJS.ReadWriteStream {
278327
const output = input
279328
.pipe(flatmap((stream, f) => {
280329
return stream.pipe(minify({
281-
compress: {
282-
hoist_funs: true // required due to https://github.com/microsoft/vscode/issues/80202
283-
},
284330
output: {
285331
comments: preserveComments(<FileWithCopyright>f),
286332
max_line_len: 1024

build/lib/typings/gulp-tsb.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ declare module "gulp-tsb" {
88

99
export interface IncrementalCompiler {
1010
(token?: ICancellationToken): NodeJS.ReadWriteStream;
11-
src(): NodeJS.ReadStream;
11+
src(opts?: {
12+
cwd?: string;
13+
base?: string;
14+
}): NodeJS.ReadStream;
1215
}
1316
export function create(projectPath: string, existingOptions: any, verbose?: boolean, onError?: (message: any) => void): IncrementalCompiler;
1417

build/lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function loadSourcemaps() {
121121
return;
122122
}
123123
if (!f.contents) {
124-
cb(new Error('empty file'));
124+
cb(undefined, f);
125125
return;
126126
}
127127
const contents = f.contents.toString('utf8');

0 commit comments

Comments
 (0)