Skip to content

Commit b5ce601

Browse files
committed
Improve output in case of errors and generate an analysis folder with the source content (for easy diffing)
1 parent 27770ed commit b5ce601

7 files changed

Lines changed: 112 additions & 11 deletions

File tree

build/gulpfile.editor.js

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ var BUNDLED_FILE_HEADER = [
5757
const languages = i18n.defaultLanguages.concat([]); // i18n.defaultLanguages.concat(process.env.VSCODE_QUALITY !== 'stable' ? i18n.extraLanguages : []);
5858

5959
const extractEditorSrcTask = task.define('extract-editor-src', () => {
60-
console.log(`If the build fails, consider tweaking shakeLevel below to a lower value.`);
6160
const apiusages = monacoapi.execute().usageContent;
6261
const extrausages = fs.readFileSync(path.join(root, 'build', 'monaco', 'monaco.usage.recipe')).toString();
6362
standalone.extractEditor({
@@ -130,18 +129,70 @@ const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () =>
130129
});
131130

132131
const compileEditorESMTask = task.define('compile-editor-esm', () => {
132+
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-editor-esm')}...`);
133+
let result;
133134
if (process.platform === 'win32') {
134-
const result = cp.spawnSync(`..\\node_modules\\.bin\\tsc.cmd`, {
135+
result = cp.spawnSync(`..\\node_modules\\.bin\\tsc.cmd`, {
135136
cwd: path.join(__dirname, '../out-editor-esm')
136137
});
137-
console.log(result.stdout.toString());
138-
console.log(result.stderr.toString());
139138
} else {
140-
const result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
139+
result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
141140
cwd: path.join(__dirname, '../out-editor-esm')
142141
});
143-
console.log(result.stdout.toString());
144-
console.log(result.stderr.toString());
142+
}
143+
144+
console.log(result.stdout.toString());
145+
console.log(result.stderr.toString());
146+
147+
if (result.status !== 0) {
148+
console.log(`The TS Compilation failed, preparing analysis folder...`);
149+
const destPath = path.join(__dirname, '../../vscode-monaco-editor-esm-analysis');
150+
return util.rimraf(destPath)().then(() => {
151+
fs.mkdirSync(destPath);
152+
153+
// initialize a new repository
154+
cp.spawnSync(`git`, [`init`], {
155+
cwd: destPath
156+
});
157+
158+
// build a list of files to copy
159+
const files = util.rreddir(path.join(__dirname, '../out-editor-esm'));
160+
161+
// copy files from src
162+
for (const file of files) {
163+
const srcFilePath = path.join(__dirname, '../src', file);
164+
const dstFilePath = path.join(destPath, file);
165+
if (fs.existsSync(srcFilePath)) {
166+
util.ensureDir(path.dirname(dstFilePath));
167+
const contents = fs.readFileSync(srcFilePath).toString().replace(/\r\n|\r|\n/g, '\n');
168+
fs.writeFileSync(dstFilePath, contents);
169+
}
170+
}
171+
172+
// create an initial commit to diff against
173+
cp.spawnSync(`git`, [`add`, `.`], {
174+
cwd: destPath
175+
});
176+
177+
// create the commit
178+
cp.spawnSync(`git`, [`commit`, `-m`, `"original sources"`, `--no-gpg-sign`], {
179+
cwd: destPath
180+
});
181+
182+
// copy files from esm
183+
for (const file of files) {
184+
const srcFilePath = path.join(__dirname, '../out-editor-esm', file);
185+
const dstFilePath = path.join(destPath, file);
186+
if (fs.existsSync(srcFilePath)) {
187+
util.ensureDir(path.dirname(dstFilePath));
188+
const contents = fs.readFileSync(srcFilePath).toString().replace(/\r\n|\r|\n/g, '\n');
189+
fs.writeFileSync(dstFilePath, contents);
190+
}
191+
}
192+
193+
console.log(`Open in VS Code the folder at '${destPath}' and you can alayze the compilation error`);
194+
throw new Error('Standalone Editor compilation failed. If this is the build machine, simply launch `yarn run gulp editor-distro` on your machine to further analyze the compilation problem.');
195+
});
145196
}
146197
});
147198

build/lib/standalone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function extractEditor(options) {
4343
compilerOptions.declaration = false;
4444
compilerOptions.moduleResolution = ts.ModuleResolutionKind.Classic;
4545
options.compilerOptions = compilerOptions;
46-
console.log(`Running with shakeLevel ${tss.toStringShakeLevel(options.shakeLevel)}`);
46+
console.log(`Running tree shaker with shakeLevel ${tss.toStringShakeLevel(options.shakeLevel)}`);
4747
// Take the extra included .d.ts files from `tsconfig.monaco.json`
4848
options.typings = tsConfig.include.filter(includedFile => /\.d\.ts$/.test(includedFile));
4949
let result = tss.shake(options);

build/lib/standalone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str
5050

5151
options.compilerOptions = compilerOptions;
5252

53-
console.log(`Running with shakeLevel ${tss.toStringShakeLevel(options.shakeLevel)}`);
53+
console.log(`Running tree shaker with shakeLevel ${tss.toStringShakeLevel(options.shakeLevel)}`);
5454

5555
// Take the extra included .d.ts files from `tsconfig.monaco.json`
5656
options.typings = (<string[]>tsConfig.include).filter(includedFile => /\.d\.ts$/.test(includedFile));

build/lib/treeshaking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ function markNodes(languageService, options) {
358358
++step;
359359
let node;
360360
if (step % 100 === 0) {
361-
console.log(`${step}/${step + black_queue.length + gray_queue.length} (${black_queue.length}, ${gray_queue.length})`);
361+
console.log(`Treeshaking - ${Math.floor(100 * step / (step + black_queue.length + gray_queue.length))}% - ${step}/${step + black_queue.length + gray_queue.length} (${black_queue.length}, ${gray_queue.length})`);
362362
}
363363
if (black_queue.length === 0) {
364364
for (let i = 0; i < gray_queue.length; i++) {

build/lib/treeshaking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
471471
let node: ts.Node;
472472

473473
if (step % 100 === 0) {
474-
console.log(`${step}/${step + black_queue.length + gray_queue.length} (${black_queue.length}, ${gray_queue.length})`);
474+
console.log(`Treeshaking - ${Math.floor(100 * step / (step + black_queue.length + gray_queue.length))}% - ${step}/${step + black_queue.length + gray_queue.length} (${black_queue.length}, ${gray_queue.length})`);
475475
}
476476

477477
if (black_queue.length === 0) {

build/lib/util.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,31 @@ function rimraf(dir) {
185185
return result;
186186
}
187187
exports.rimraf = rimraf;
188+
function _rreaddir(dirPath, prepend, result) {
189+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
190+
for (const entry of entries) {
191+
if (entry.isDirectory()) {
192+
_rreaddir(path.join(dirPath, entry.name), `${prepend}/${entry.name}`, result);
193+
}
194+
else {
195+
result.push(`${prepend}/${entry.name}`);
196+
}
197+
}
198+
}
199+
function rreddir(dirPath) {
200+
let result = [];
201+
_rreaddir(dirPath, '', result);
202+
return result;
203+
}
204+
exports.rreddir = rreddir;
205+
function ensureDir(dirPath) {
206+
if (fs.existsSync(dirPath)) {
207+
return;
208+
}
209+
ensureDir(path.dirname(dirPath));
210+
fs.mkdirSync(dirPath);
211+
}
212+
exports.ensureDir = ensureDir;
188213
function getVersion(root) {
189214
let version = process.env['BUILD_SOURCEVERSION'];
190215
if (!version || !/^[0-9a-f]{40}$/i.test(version)) {

build/lib/util.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ export function rimraf(dir: string): () => Promise<void> {
243243
return result;
244244
}
245245

246+
function _rreaddir(dirPath: string, prepend: string, result: string[]): void {
247+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
248+
for (const entry of entries) {
249+
if (entry.isDirectory()) {
250+
_rreaddir(path.join(dirPath, entry.name), `${prepend}/${entry.name}`, result);
251+
} else {
252+
result.push(`${prepend}/${entry.name}`);
253+
}
254+
}
255+
}
256+
257+
export function rreddir(dirPath: string): string[] {
258+
let result: string[] = [];
259+
_rreaddir(dirPath, '', result);
260+
return result;
261+
}
262+
263+
export function ensureDir(dirPath: string): void {
264+
if (fs.existsSync(dirPath)) {
265+
return;
266+
}
267+
ensureDir(path.dirname(dirPath));
268+
fs.mkdirSync(dirPath);
269+
}
270+
246271
export function getVersion(root: string): string | undefined {
247272
let version = process.env['BUILD_SOURCEVERSION'];
248273

0 commit comments

Comments
 (0)