Skip to content

Commit 58bdc8a

Browse files
committed
Improve troubleshooting treeshaking failures
1 parent 6835108 commit 58bdc8a

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

build/gulpfile.editor.js

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () =>
126126
});
127127

128128
const compileEditorESMTask = task.define('compile-editor-esm', () => {
129+
const KEEP_PREV_ANALYSIS = false;
129130
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-editor-esm')}...`);
130131
let result;
131132
if (process.platform === 'win32') {
@@ -144,37 +145,41 @@ const compileEditorESMTask = task.define('compile-editor-esm', () => {
144145
if (result.status !== 0) {
145146
console.log(`The TS Compilation failed, preparing analysis folder...`);
146147
const destPath = path.join(__dirname, '../../vscode-monaco-editor-esm-analysis');
147-
return util.rimraf(destPath)().then(() => {
148-
fs.mkdirSync(destPath);
149-
150-
// initialize a new repository
151-
cp.spawnSync(`git`, [`init`], {
152-
cwd: destPath
153-
});
154-
148+
const keepPrevAnalysis = (KEEP_PREV_ANALYSIS && fs.existsSync(destPath));
149+
const cleanDestPath = (keepPrevAnalysis ? Promise.resolve() : util.rimraf(destPath)());
150+
return cleanDestPath.then(() => {
155151
// build a list of files to copy
156152
const files = util.rreddir(path.join(__dirname, '../out-editor-esm'));
157153

158-
// copy files from src
159-
for (const file of files) {
160-
const srcFilePath = path.join(__dirname, '../src', file);
161-
const dstFilePath = path.join(destPath, file);
162-
if (fs.existsSync(srcFilePath)) {
163-
util.ensureDir(path.dirname(dstFilePath));
164-
const contents = fs.readFileSync(srcFilePath).toString().replace(/\r\n|\r|\n/g, '\n');
165-
fs.writeFileSync(dstFilePath, contents);
154+
if (!keepPrevAnalysis) {
155+
fs.mkdirSync(destPath);
156+
157+
// initialize a new repository
158+
cp.spawnSync(`git`, [`init`], {
159+
cwd: destPath
160+
});
161+
162+
// copy files from src
163+
for (const file of files) {
164+
const srcFilePath = path.join(__dirname, '../src', file);
165+
const dstFilePath = path.join(destPath, file);
166+
if (fs.existsSync(srcFilePath)) {
167+
util.ensureDir(path.dirname(dstFilePath));
168+
const contents = fs.readFileSync(srcFilePath).toString().replace(/\r\n|\r|\n/g, '\n');
169+
fs.writeFileSync(dstFilePath, contents);
170+
}
166171
}
167-
}
168172

169-
// create an initial commit to diff against
170-
cp.spawnSync(`git`, [`add`, `.`], {
171-
cwd: destPath
172-
});
173+
// create an initial commit to diff against
174+
cp.spawnSync(`git`, [`add`, `.`], {
175+
cwd: destPath
176+
});
173177

174-
// create the commit
175-
cp.spawnSync(`git`, [`commit`, `-m`, `"original sources"`, `--no-gpg-sign`], {
176-
cwd: destPath
177-
});
178+
// create the commit
179+
cp.spawnSync(`git`, [`commit`, `-m`, `"original sources"`, `--no-gpg-sign`], {
180+
cwd: destPath
181+
});
182+
}
178183

179184
// copy files from esm
180185
for (const file of files) {
@@ -329,6 +334,13 @@ const finalEditorResourcesTask = task.define('final-editor-resources', () => {
329334
);
330335
});
331336

337+
gulp.task('extract-editor-src',
338+
task.series(
339+
util.rimraf('out-editor-src'),
340+
extractEditorSrcTask
341+
)
342+
);
343+
332344
gulp.task('editor-distro',
333345
task.series(
334346
task.parallel(

0 commit comments

Comments
 (0)