code-web forward to @vscode/test-web

This commit is contained in:
Martin Aeschlimann
2022-02-02 17:48:36 +01:00
parent aacef0b137
commit 47dbe8bbf6
4 changed files with 140 additions and 111 deletions

View File

@@ -124,7 +124,7 @@
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"@vscode/telemetry-extractor": "^1.9.5",
"@vscode/test-web": "^0.0.19",
"@vscode/test-web": "^0.0.21",
"ansi-colors": "^3.2.3",
"asar": "^3.0.3",
"chromium-pickle-js": "^0.2.0",

View File

@@ -7,11 +7,12 @@
const cp = require('child_process');
const path = require('path');
const os = require('os');
const opn = require('opn');
const crypto = require('crypto');
const minimist = require('minimist');
function main() {
const args = minimist(process.argv.slice(2), {
boolean: [
'help',
@@ -31,7 +32,8 @@ if (args.help) {
'./scripts/code-server.sh|bat [options]\n' +
' --launch Opens a browser'
);
// more help options will be printed by startServer
startServer(['--help']);
return
}
const serverArgs = process.argv.slice(2).filter(v => v !== '--launch');
@@ -50,14 +52,19 @@ if (args['port'] === undefined) {
serverArgs.push('--port', PORT);
}
startServer(serverArgs);
if (args['launch']) {
opn(`http://${HOST}:${PORT}/?tkn=${TOKEN}`);
}
}
function startServer(programArgs) {
const env = { ...process.env };
const entryPoint = path.join(__dirname, '..', 'out', 'server-main.js');
startServer();
function startServer() {
console.log(`Starting server: ${entryPoint} ${serverArgs.join(' ')}`);
const proc = cp.spawn(process.execPath, [entryPoint, ...serverArgs], { env, stdio: 'inherit' });
console.log(`Starting server: ${entryPoint} ${programArgs.join(' ')}`);
const proc = cp.spawn(process.execPath, [entryPoint, ...programArgs], { env, stdio: 'inherit' });
proc.on('exit', (code) => process.exit(code));
@@ -73,6 +80,5 @@ function startServer() {
}
if (args['launch']) {
opn(`http://${HOST}:${PORT}/?tkn=${TOKEN}`);
}
main();

View File

@@ -5,10 +5,11 @@
// @ts-check
const testWeb = require('@vscode/test-web');
const testWebLocation = require.resolve('@vscode/test-web');
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const minimist = require('minimist');
const fancyLog = require('fancy-log');
@@ -22,16 +23,17 @@ const WEB_DEV_EXTENSIONS_ROOT = path.join(APP_ROOT, '.build', 'builtInWebDevExte
const WEB_PLAYGROUND_VERSION = '0.0.13';
async function main() {
const args = minimist(process.argv.slice(2), {
boolean: [
'help',
'verbose',
'open-devtools'
'playground'
],
string: [
'host',
'port',
'extension',
'extensionPath',
'browserType'
],
});
@@ -39,50 +41,68 @@ const args = minimist(process.argv.slice(2), {
if (args.help) {
console.log(
'./scripts/code-web.sh|bat [options]\n' +
' --host Server host address\n' +
' --port Server port\n' +
' --browserType The browser type to launch: `chromium`, `firefox`, `webkit` or `none`. If not specified the OS default browser will be used.' +
' --extension Path of an extension to include\n' +
' --open-devtools Open the dev tools' +
' --verbose Print out more information\n' +
' --help\n' +
'[Example]\n' +
' ./scripts/code-web.sh|bat --port 8080'
' --playground Include the vscode-web-playground extension\n'
);
startServer(['--help']);
process.exit(0);
}
openTestWeb();
const serverArgs = [];
const HOST = args['host'] ?? 'localhost';
const PORT = args['port'] ?? '8080';
async function openTestWeb() {
await ensureWebDevExtensions();
const extensionPaths = [WEB_DEV_EXTENSIONS_ROOT];
const extensions = args['extension'];
if (Array.isArray(extensions)) {
extensionPaths.push(...extensions);
} else if (extensions) {
extensionPaths.push(extensions);
if (args['host'] === undefined) {
serverArgs.push('--host', HOST);
}
if (args['port'] === undefined) {
serverArgs.push('--port', PORT);
}
const host = args.host || 'localhost';
const port = args.port || 8080;
await testWeb.open({
browserType: args['browserType'] ?? 'none',
host,
port,
folderUri: 'memfs:///sample-folder',
vsCodeDevPath: APP_ROOT,
extensionPaths,
devTools: !!args['open-devtools'],
hideServerLog: !args['verbose'],
verbose: !!args['verbose']
});
if (args['playground'] || args['_'].length === 0) {
serverArgs.push('--extensionPath', WEB_DEV_EXTENSIONS_ROOT);
serverArgs.push('--folder-uri', 'memfs:///sample-folder');
await ensureWebDevExtensions(args['verbose'])
}
let openSystemBrowser = false;
if (!args['browserType']) {
opn(`http://${host}:${port}/`);
serverArgs.push('--browserType', 'none');
openSystemBrowser = true;
}
if (!args['verbose'] && args['hideServerLog'] === undefined) {
serverArgs.push('--hideServerLog');
}
serverArgs.push('--sourcesPath', APP_ROOT);
serverArgs.push(...process.argv.slice(2).filter(v => v !== '--playground'))
startServer(serverArgs);
if (openSystemBrowser) {
opn(`http://${HOST}:${PORT}/`);
}
}
function startServer(runnerArguments) {
const env = { ...process.env };
console.log(`Starting @vscode/test-web: ${testWebLocation} ${runnerArguments.join(' ')}`);
const proc = cp.spawn(process.execPath, [testWebLocation, ...runnerArguments], { env, stdio: 'inherit' });
proc.on('exit', (code) => process.exit(code));
process.on('exit', () => proc.kill());
process.on('SIGINT', () => {
proc.kill();
process.exit(128 + 2); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
});
process.on('SIGTERM', () => {
proc.kill();
process.exit(128 + 15); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
});
}
async function directoryExists(path) {
@@ -93,7 +113,7 @@ async function directoryExists(path) {
}
}
async function ensureWebDevExtensions() {
async function ensureWebDevExtensions(verbose) {
// Playground (https://github.com/microsoft/vscode-web-playground)
const webDevPlaygroundRoot = path.join(WEB_DEV_EXTENSIONS_ROOT, 'vscode-web-playground');
@@ -114,7 +134,7 @@ async function ensureWebDevExtensions() {
}
if (downloadPlayground) {
if (args.verbose) {
if (verbose) {
fancyLog(`${ansiColors.magenta('Web Development extensions')}: Downloading vscode-web-playground to ${webDevPlaygroundRoot}`);
}
await new Promise((resolve, reject) => {
@@ -123,8 +143,11 @@ async function ensureWebDevExtensions() {
}).pipe(vfs.dest(webDevPlaygroundRoot)).on('end', resolve).on('error', reject);
});
} else {
if (args.verbose) {
if (verbose) {
fancyLog(`${ansiColors.magenta('Web Development extensions')}: Using existing vscode-web-playground in ${webDevPlaygroundRoot}`);
}
}
}
main();

View File

@@ -1585,10 +1585,10 @@
ts-morph "^12.2.0"
vscode-ripgrep "^1.12.1"
"@vscode/test-web@^0.0.19":
version "0.0.19"
resolved "https://registry.yarnpkg.com/@vscode/test-web/-/test-web-0.0.19.tgz#2e2b030bca049c31f56bb73709b15c03b04bcaa1"
integrity sha512-7Idk5qmShFCG65OMg7zB5028L38CVk5StKONgnzJNDjKXMj4BOch5CMAK6ad1P+oah94EYVSzGrX/AF1EgpxWA==
"@vscode/test-web@^0.0.21":
version "0.0.21"
resolved "https://registry.yarnpkg.com/@vscode/test-web/-/test-web-0.0.21.tgz#b1dd359c6d9903c81df9e9d95464b36aeec39bd2"
integrity sha512-4JYWCYrG8pb76MgI2W0vkN1a3numZDLH6tpz6OPmfx6YsI8Z+CHyiWqAGhIQOlXqsquvsyR9mhPe15yGAEupMw==
dependencies:
"@koa/router" "^10.1.1"
decompress "^4.2.1"