Skip to content

Commit 47dbe8b

Browse files
committed
code-web forward to @vscode/test-web
1 parent aacef0b commit 47dbe8b

File tree

4 files changed

+134
-105
lines changed

4 files changed

+134
-105
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"@typescript-eslint/eslint-plugin": "^5.10.0",
125125
"@typescript-eslint/parser": "^5.10.0",
126126
"@vscode/telemetry-extractor": "^1.9.5",
127-
"@vscode/test-web": "^0.0.19",
127+
"@vscode/test-web": "^0.0.21",
128128
"ansi-colors": "^3.2.3",
129129
"asar": "^3.0.3",
130130
"chromium-pickle-js": "^0.2.0",

Diff for: scripts/code-server.js

+49-43
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,64 @@
77

88
const cp = require('child_process');
99
const path = require('path');
10-
const os = require('os');
1110
const opn = require('opn');
1211
const crypto = require('crypto');
1312
const minimist = require('minimist');
1413

15-
const args = minimist(process.argv.slice(2), {
16-
boolean: [
17-
'help',
18-
'launch'
19-
],
20-
string: [
21-
'host',
22-
'port',
23-
'driver',
24-
'connection-token',
25-
'server-data-dir'
26-
],
27-
});
28-
29-
if (args.help) {
30-
console.log(
31-
'./scripts/code-server.sh|bat [options]\n' +
32-
' --launch Opens a browser'
33-
);
34-
// more help options will be printed by startServer
35-
}
14+
function main() {
3615

37-
const serverArgs = process.argv.slice(2).filter(v => v !== '--launch');
16+
const args = minimist(process.argv.slice(2), {
17+
boolean: [
18+
'help',
19+
'launch'
20+
],
21+
string: [
22+
'host',
23+
'port',
24+
'driver',
25+
'connection-token',
26+
'server-data-dir'
27+
],
28+
});
3829

39-
const HOST = args['host'] ?? 'localhost';
40-
const PORT = args['port'] ?? '9888';
41-
const TOKEN = args['connection-token'] ?? String(crypto.randomInt(0xffffffff));
30+
if (args.help) {
31+
console.log(
32+
'./scripts/code-server.sh|bat [options]\n' +
33+
' --launch Opens a browser'
34+
);
35+
startServer(['--help']);
36+
return
37+
}
4238

43-
if (args['connection-token'] === undefined && args['connection-token-file'] === undefined && !args['without-connection-token']) {
44-
serverArgs.push('--connection-token', TOKEN);
45-
}
46-
if (args['host'] === undefined) {
47-
serverArgs.push('--host', HOST);
48-
}
49-
if (args['port'] === undefined) {
50-
serverArgs.push('--port', PORT);
39+
const serverArgs = process.argv.slice(2).filter(v => v !== '--launch');
40+
41+
const HOST = args['host'] ?? 'localhost';
42+
const PORT = args['port'] ?? '9888';
43+
const TOKEN = args['connection-token'] ?? String(crypto.randomInt(0xffffffff));
44+
45+
if (args['connection-token'] === undefined && args['connection-token-file'] === undefined && !args['without-connection-token']) {
46+
serverArgs.push('--connection-token', TOKEN);
47+
}
48+
if (args['host'] === undefined) {
49+
serverArgs.push('--host', HOST);
50+
}
51+
if (args['port'] === undefined) {
52+
serverArgs.push('--port', PORT);
53+
}
54+
55+
startServer(serverArgs);
56+
if (args['launch']) {
57+
opn(`http://${HOST}:${PORT}/?tkn=${TOKEN}`);
58+
}
5159
}
5260

53-
const env = { ...process.env };
61+
function startServer(programArgs) {
62+
const env = { ...process.env };
5463

55-
const entryPoint = path.join(__dirname, '..', 'out', 'server-main.js');
56-
startServer();
64+
const entryPoint = path.join(__dirname, '..', 'out', 'server-main.js');
5765

58-
function startServer() {
59-
console.log(`Starting server: ${entryPoint} ${serverArgs.join(' ')}`);
60-
const proc = cp.spawn(process.execPath, [entryPoint, ...serverArgs], { env, stdio: 'inherit' });
66+
console.log(`Starting server: ${entryPoint} ${programArgs.join(' ')}`);
67+
const proc = cp.spawn(process.execPath, [entryPoint, ...programArgs], { env, stdio: 'inherit' });
6168

6269
proc.on('exit', (code) => process.exit(code));
6370

@@ -73,6 +80,5 @@ function startServer() {
7380

7481
}
7582

76-
if (args['launch']) {
77-
opn(`http://${HOST}:${PORT}/?tkn=${TOKEN}`);
78-
}
83+
main();
84+

Diff for: scripts/code-web.js

+80-57
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
// @ts-check
77

8-
const testWeb = require('@vscode/test-web');
8+
const testWebLocation = require.resolve('@vscode/test-web');
99

1010
const fs = require('fs');
1111
const path = require('path');
12+
const cp = require('child_process');
1213

1314
const minimist = require('minimist');
1415
const fancyLog = require('fancy-log');
@@ -22,69 +23,88 @@ const WEB_DEV_EXTENSIONS_ROOT = path.join(APP_ROOT, '.build', 'builtInWebDevExte
2223

2324
const WEB_PLAYGROUND_VERSION = '0.0.13';
2425

25-
const args = minimist(process.argv.slice(2), {
26-
boolean: [
27-
'help',
28-
'verbose',
29-
'open-devtools'
30-
],
31-
string: [
32-
'host',
33-
'port',
34-
'extension',
35-
'browserType'
36-
],
37-
});
38-
39-
if (args.help) {
40-
console.log(
41-
'./scripts/code-web.sh|bat [options]\n' +
42-
' --host Server host address\n' +
43-
' --port Server port\n' +
44-
' --browserType The browser type to launch: `chromium`, `firefox`, `webkit` or `none`. If not specified the OS default browser will be used.' +
45-
' --extension Path of an extension to include\n' +
46-
' --open-devtools Open the dev tools' +
47-
' --verbose Print out more information\n' +
48-
' --help\n' +
49-
'[Example]\n' +
50-
' ./scripts/code-web.sh|bat --port 8080'
51-
);
52-
process.exit(0);
53-
}
26+
async function main() {
27+
28+
const args = minimist(process.argv.slice(2), {
29+
boolean: [
30+
'help',
31+
'playground'
32+
],
33+
string: [
34+
'host',
35+
'port',
36+
'extensionPath',
37+
'browserType'
38+
],
39+
});
40+
41+
if (args.help) {
42+
console.log(
43+
'./scripts/code-web.sh|bat [options]\n' +
44+
' --playground Include the vscode-web-playground extension\n'
45+
);
46+
startServer(['--help']);
47+
process.exit(0);
48+
}
5449

55-
openTestWeb();
50+
const serverArgs = [];
5651

52+
const HOST = args['host'] ?? 'localhost';
53+
const PORT = args['port'] ?? '8080';
5754

58-
async function openTestWeb() {
59-
await ensureWebDevExtensions();
60-
const extensionPaths = [WEB_DEV_EXTENSIONS_ROOT];
61-
const extensions = args['extension'];
62-
if (Array.isArray(extensions)) {
63-
extensionPaths.push(...extensions);
64-
} else if (extensions) {
65-
extensionPaths.push(extensions);
55+
if (args['host'] === undefined) {
56+
serverArgs.push('--host', HOST);
57+
}
58+
if (args['port'] === undefined) {
59+
serverArgs.push('--port', PORT);
6660
}
67-
const host = args.host || 'localhost';
68-
const port = args.port || 8080;
69-
70-
await testWeb.open({
71-
browserType: args['browserType'] ?? 'none',
72-
host,
73-
port,
74-
folderUri: 'memfs:///sample-folder',
75-
vsCodeDevPath: APP_ROOT,
76-
extensionPaths,
77-
devTools: !!args['open-devtools'],
78-
hideServerLog: !args['verbose'],
79-
verbose: !!args['verbose']
80-
});
8161

62+
if (args['playground'] || args['_'].length === 0) {
63+
serverArgs.push('--extensionPath', WEB_DEV_EXTENSIONS_ROOT);
64+
serverArgs.push('--folder-uri', 'memfs:///sample-folder');
65+
await ensureWebDevExtensions(args['verbose'])
66+
}
8267

68+
let openSystemBrowser = false;
8369
if (!args['browserType']) {
84-
opn(`http://${host}:${port}/`);
70+
serverArgs.push('--browserType', 'none');
71+
openSystemBrowser = true;
72+
}
73+
74+
if (!args['verbose'] && args['hideServerLog'] === undefined) {
75+
serverArgs.push('--hideServerLog');
76+
}
77+
78+
serverArgs.push('--sourcesPath', APP_ROOT);
79+
80+
serverArgs.push(...process.argv.slice(2).filter(v => v !== '--playground'))
81+
82+
83+
startServer(serverArgs);
84+
if (openSystemBrowser) {
85+
opn(`http://${HOST}:${PORT}/`);
8586
}
8687
}
8788

89+
function startServer(runnerArguments) {
90+
const env = { ...process.env };
91+
92+
console.log(`Starting @vscode/test-web: ${testWebLocation} ${runnerArguments.join(' ')}`);
93+
const proc = cp.spawn(process.execPath, [testWebLocation, ...runnerArguments], { env, stdio: 'inherit' });
94+
95+
proc.on('exit', (code) => process.exit(code));
96+
97+
process.on('exit', () => proc.kill());
98+
process.on('SIGINT', () => {
99+
proc.kill();
100+
process.exit(128 + 2); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
101+
});
102+
process.on('SIGTERM', () => {
103+
proc.kill();
104+
process.exit(128 + 15); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
105+
});
106+
}
107+
88108
async function directoryExists(path) {
89109
try {
90110
return (await fs.promises.stat(path)).isDirectory();
@@ -93,7 +113,7 @@ async function directoryExists(path) {
93113
}
94114
}
95115

96-
async function ensureWebDevExtensions() {
116+
async function ensureWebDevExtensions(verbose) {
97117

98118
// Playground (https://github.com/microsoft/vscode-web-playground)
99119
const webDevPlaygroundRoot = path.join(WEB_DEV_EXTENSIONS_ROOT, 'vscode-web-playground');
@@ -114,7 +134,7 @@ async function ensureWebDevExtensions() {
114134
}
115135

116136
if (downloadPlayground) {
117-
if (args.verbose) {
137+
if (verbose) {
118138
fancyLog(`${ansiColors.magenta('Web Development extensions')}: Downloading vscode-web-playground to ${webDevPlaygroundRoot}`);
119139
}
120140
await new Promise((resolve, reject) => {
@@ -123,8 +143,11 @@ async function ensureWebDevExtensions() {
123143
}).pipe(vfs.dest(webDevPlaygroundRoot)).on('end', resolve).on('error', reject);
124144
});
125145
} else {
126-
if (args.verbose) {
146+
if (verbose) {
127147
fancyLog(`${ansiColors.magenta('Web Development extensions')}: Using existing vscode-web-playground in ${webDevPlaygroundRoot}`);
128148
}
129149
}
130150
}
151+
152+
153+
main();

Diff for: yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1585,10 +1585,10 @@
15851585
ts-morph "^12.2.0"
15861586
vscode-ripgrep "^1.12.1"
15871587

1588-
"@vscode/test-web@^0.0.19":
1589-
version "0.0.19"
1590-
resolved "https://registry.yarnpkg.com/@vscode/test-web/-/test-web-0.0.19.tgz#2e2b030bca049c31f56bb73709b15c03b04bcaa1"
1591-
integrity sha512-7Idk5qmShFCG65OMg7zB5028L38CVk5StKONgnzJNDjKXMj4BOch5CMAK6ad1P+oah94EYVSzGrX/AF1EgpxWA==
1588+
"@vscode/test-web@^0.0.21":
1589+
version "0.0.21"
1590+
resolved "https://registry.yarnpkg.com/@vscode/test-web/-/test-web-0.0.21.tgz#b1dd359c6d9903c81df9e9d95464b36aeec39bd2"
1591+
integrity sha512-4JYWCYrG8pb76MgI2W0vkN1a3numZDLH6tpz6OPmfx6YsI8Z+CHyiWqAGhIQOlXqsquvsyR9mhPe15yGAEupMw==
15921592
dependencies:
15931593
"@koa/router" "^10.1.1"
15941594
decompress "^4.2.1"

0 commit comments

Comments
 (0)