Skip to content

Commit 262ab80

Browse files
committed
launch: check prerequisites in a pre-launch task
Fixes microsoft#103708
1 parent 98dd195 commit 262ab80

File tree

9 files changed

+158
-60
lines changed

9 files changed

+158
-60
lines changed

.vscode/launch.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@
216216
"port": 9222,
217217
"timeout": 20000,
218218
"env": {
219-
"VSCODE_EXTHOST_WILL_SEND_SOCKET": null
219+
"VSCODE_EXTHOST_WILL_SEND_SOCKET": null,
220+
"VSCODE_SKIP_PRELAUNCH": "1"
220221
},
221222
"cleanUp": "wholeBrowser",
222-
"breakOnLoad": false,
223223
"urlFilter": "*workbench.html*",
224224
"runtimeArgs": [
225225
"--inspect=5875",
@@ -232,7 +232,8 @@
232232
"outFiles": [
233233
"${workspaceFolder}/out/**/*.js"
234234
],
235-
"browserLaunchLocation": "workspace"
235+
"browserLaunchLocation": "workspace",
236+
"preLaunchTask": "Ensure Prelaunch Dependencies",
236237
},
237238
{
238239
"type": "node",

.vscode/tasks.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@
186186
"source": "eslint",
187187
"base": "$eslint-stylish"
188188
}
189-
}
189+
},
190+
{
191+
"type": "shell",
192+
"command": "node build/lib/prelaunch.js",
193+
"label": "Ensure Prelaunch Dependencies",
194+
"presentation": {
195+
"reveal": "silent"
196+
}
197+
},
190198
]
191199
}

build/lib/builtInExtensions.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function writeControlFile(control) {
100100
fs.writeFileSync(controlFilePath, JSON.stringify(control, null, 2));
101101
}
102102

103-
function main() {
103+
exports.getBuiltInExtensions = function getBuiltInExtensions() {
104104
log('Syncronizing built-in extensions...');
105105
log(`You can manage built-in extensions with the ${ansiColors.cyan('--builtin')} flag`);
106106

@@ -116,14 +116,16 @@ function main() {
116116

117117
writeControlFile(control);
118118

119-
es.merge(streams)
120-
.on('error', err => {
121-
console.error(err);
122-
process.exit(1);
123-
})
124-
.on('end', () => {
125-
process.exit(0);
126-
});
119+
return new Promise((resolve, reject) => {
120+
es.merge(streams)
121+
.on('error', reject)
122+
.on('end', resolve);
123+
});
124+
};
125+
126+
if (require.main === module) {
127+
main().then(() => process.exit(0)).catch(err => {
128+
console.error(err);
129+
process.exit(1);
130+
});
127131
}
128-
129-
main();

build/lib/preLaunch.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
Object.defineProperty(exports, "__esModule", { value: true });
7+
// @ts-check
8+
const path = require("path");
9+
const child_process_1 = require("child_process");
10+
const fs_1 = require("fs");
11+
const yarn = process.platform === 'win32' ? 'yarn.cmd' : 'yarn';
12+
const rootDir = path.resolve(__dirname, '..', '..');
13+
function runProcess(command, args = []) {
14+
return new Promise((resolve, reject) => {
15+
const child = child_process_1.spawn(command, args, { cwd: rootDir, stdio: 'inherit', env: process.env });
16+
child.on('exit', err => !err ? resolve() : process.exit(err !== null && err !== void 0 ? err : 1));
17+
child.on('error', reject);
18+
});
19+
}
20+
async function exists(subdir) {
21+
try {
22+
await fs_1.promises.stat(path.join(rootDir, subdir));
23+
return true;
24+
}
25+
catch (_a) {
26+
return false;
27+
}
28+
}
29+
async function ensureNodeModules() {
30+
if (!(await exists('node_modules'))) {
31+
await runProcess(yarn);
32+
}
33+
}
34+
async function getElectron() {
35+
await runProcess(yarn, ['electron']);
36+
}
37+
async function ensureCompiled() {
38+
if (!(await exists('out'))) {
39+
await runProcess(yarn, ['compile']);
40+
}
41+
}
42+
async function main() {
43+
await ensureNodeModules();
44+
await getElectron();
45+
await ensureCompiled();
46+
// Can't require this until after dependencies are installed
47+
const { getBuiltInExtensions } = require('./builtInExtensions');
48+
await getBuiltInExtensions();
49+
}
50+
if (require.main === module) {
51+
main().catch(err => {
52+
console.error(err);
53+
process.exit(1);
54+
});
55+
}

build/lib/preLaunch.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
// @ts-check
9+
10+
import * as path from 'path';
11+
import { spawn } from 'child_process';
12+
import { promises as fs } from 'fs';
13+
14+
const yarn = process.platform === 'win32' ? 'yarn.cmd' : 'yarn';
15+
const rootDir = path.resolve(__dirname, '..', '..');
16+
17+
function runProcess(command: string, args: ReadonlyArray<string> = []) {
18+
return new Promise((resolve, reject) => {
19+
const child = spawn(command, args, { cwd: rootDir, stdio: 'inherit', env: process.env });
20+
child.on('exit', err => !err ? resolve() : process.exit(err ?? 1));
21+
child.on('error', reject);
22+
});
23+
}
24+
25+
async function exists(subdir: string) {
26+
try {
27+
await fs.stat(path.join(rootDir, subdir));
28+
return true;
29+
} catch {
30+
return false;
31+
}
32+
}
33+
34+
async function ensureNodeModules() {
35+
if (!(await exists('node_modules'))) {
36+
await runProcess(yarn);
37+
}
38+
}
39+
40+
async function getElectron() {
41+
await runProcess(yarn, ['electron']);
42+
}
43+
44+
async function ensureCompiled() {
45+
if (!(await exists('out'))) {
46+
await runProcess(yarn, ['compile']);
47+
}
48+
}
49+
50+
async function main() {
51+
await ensureNodeModules();
52+
await getElectron();
53+
await ensureCompiled();
54+
55+
// Can't require this until after dependencies are installed
56+
const { getBuiltInExtensions } = require('./builtInExtensions');
57+
await getBuiltInExtensions();
58+
}
59+
60+
if (require.main === module) {
61+
main().catch(err => {
62+
console.error(err);
63+
process.exit(1);
64+
});
65+
}

scripts/code-cli.bat

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,17 @@ title VSCode Dev
55

66
pushd %~dp0\..
77

8-
:: Node modules
9-
if not exist node_modules call yarn
8+
:: Get electron, compile, built-in extensions
9+
if "%VSCODE_SKIP_PRELAUNCH%"=="" node build/lib/preLaunch.js
1010

1111
for /f "tokens=2 delims=:," %%a in ('findstr /R /C:"\"nameShort\":.*" product.json') do set NAMESHORT=%%~a
1212
set NAMESHORT=%NAMESHORT: "=%
1313
set NAMESHORT=%NAMESHORT:"=%.exe
1414
set CODE=".build\electron\%NAMESHORT%"
1515

16-
:: Download Electron if needed
17-
node build\lib\electron.js
18-
if %errorlevel% neq 0 node .\node_modules\gulp\bin\gulp.js electron
19-
2016
:: Manage built-in extensions
2117
if "%1"=="--builtin" goto builtin
2218

23-
:: Sync built-in extensions
24-
node build\lib\builtInExtensions.js
25-
26-
:: Build
27-
if not exist out yarn compile
28-
2919
:: Configuration
3020
set ELECTRON_RUN_AS_NODE=1
3121
set NODE_ENV=development

scripts/code-cli.sh

+4-11
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,17 @@ function code() {
1818
CODE=".build/electron/$NAME"
1919
fi
2020

21-
# Node modules
22-
test -d node_modules || yarn
23-
24-
# Get electron
25-
yarn electron
21+
# Get electron, compile, built-in extensions
22+
if [[ -z "${VSCODE_SKIP_PRELAUNCH}" ]]; then
23+
node build/lib/preLaunch.js
24+
fi
2625

2726
# Manage built-in extensions
2827
if [[ "$1" == "--builtin" ]]; then
2928
exec "$CODE" build/builtin
3029
return
3130
fi
3231

33-
# Sync built-in extensions
34-
node build/lib/builtInExtensions.js
35-
36-
# Build
37-
test -d out || yarn compile
38-
3932
ELECTRON_RUN_AS_NODE=1 \
4033
NODE_ENV=development \
4134
VSCODE_DEV=1 \

scripts/code.bat

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@ title VSCode Dev
55

66
pushd %~dp0\..
77

8-
:: Node modules
9-
if not exist node_modules call yarn
8+
:: Get electron, compile, built-in extensions
9+
if "%VSCODE_SKIP_PRELAUNCH%"=="" node build/lib/preLaunch.js
1010

1111
for /f "tokens=2 delims=:," %%a in ('findstr /R /C:"\"nameShort\":.*" product.json') do set NAMESHORT=%%~a
1212
set NAMESHORT=%NAMESHORT: "=%
1313
set NAMESHORT=%NAMESHORT:"=%.exe
1414
set CODE=".build\electron\%NAMESHORT%"
1515

16-
:: Get electron
17-
call yarn electron
18-
1916
:: Manage built-in extensions
2017
if "%1"=="--builtin" goto builtin
2118

22-
:: Sync built-in extensions
23-
node build\lib\builtInExtensions.js
24-
25-
:: Build
26-
if not exist out yarn compile
27-
2819
:: Configuration
2920
set NODE_ENV=development
3021
set VSCODE_DEV=1

scripts/code.sh

+4-11
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,17 @@ function code() {
2424
CODE=".build/electron/$NAME"
2525
fi
2626

27-
# Node modules
28-
test -d node_modules || yarn
29-
30-
# Get electron
31-
yarn electron
27+
# Get electron, compile, built-in extensions
28+
if [[ -z "${VSCODE_SKIP_PRELAUNCH}" ]]; then
29+
node build/lib/preLaunch.js
30+
fi
3231

3332
# Manage built-in extensions
3433
if [[ "$1" == "--builtin" ]]; then
3534
exec "$CODE" build/builtin
3635
return
3736
fi
3837

39-
# Sync built-in extensions
40-
node build/lib/builtInExtensions.js
41-
42-
# Build
43-
test -d out || yarn compile
44-
4538
# Configuration
4639
export NODE_ENV=development
4740
export VSCODE_DEV=1

0 commit comments

Comments
 (0)