mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 02:48:30 -05:00
Merge vscode source through 1.62 release (#19981)
* Build breaks 1 * Build breaks * Build breaks * Build breaks * More build breaks * Build breaks (#2512) * Runtime breaks * Build breaks * Fix dialog location break * Update typescript * Fix ASAR break issue * Unit test breaks * Update distro * Fix breaks in ADO builds (#2513) * Bump to node 16 * Fix hygiene errors * Bump distro * Remove reference to node type * Delete vscode specific extension * Bump to node 16 in CI yaml * Skip integration tests in CI builds (while fixing) * yarn.lock update * Bump moment dependency in remote yarn * Fix drop-down chevron style * Bump to node 16 * Remove playwrite from ci.yaml * Skip building build scripts in hygine check
This commit is contained in:
@@ -5,20 +5,23 @@
|
||||
|
||||
import { ChildProcess, spawn, SpawnOptions } from 'child_process';
|
||||
import { chmodSync, existsSync, readFileSync, statSync, truncateSync, unlinkSync } from 'fs';
|
||||
import { homedir } from 'os';
|
||||
import { homedir, release, tmpdir } from 'os';
|
||||
import type { ProfilingSession, Target } from 'v8-inspect-profiler';
|
||||
import { isAbsolute, join } from 'vs/base/common/path';
|
||||
import { IProcessEnvironment, isWindows } from 'vs/base/common/platform';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { isAbsolute, join, resolve } from 'vs/base/common/path';
|
||||
import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform';
|
||||
import { randomPort } from 'vs/base/common/ports';
|
||||
import { isString } from 'vs/base/common/types';
|
||||
import { whenDeleted, writeFileSync } from 'vs/base/node/pfs';
|
||||
import { findFreePort } from 'vs/base/node/ports';
|
||||
import { watchFileContents } from 'vs/base/node/watcher';
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
import { buildHelpMessage, buildVersionMessage, OPTIONS } from 'vs/platform/environment/node/argv';
|
||||
import { addArg, parseCLIProcessArgv } from 'vs/platform/environment/node/argvHelper';
|
||||
import { getStdinFilePath, hasStdinWithoutTty, readFromStdin, stdinDataListener } from 'vs/platform/environment/node/stdin';
|
||||
import { createWaitMarkerFile } from 'vs/platform/environment/node/wait';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
|
||||
function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean {
|
||||
return !!argv['install-source']
|
||||
@@ -29,6 +32,10 @@ function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean {
|
||||
|| !!argv['telemetry'];
|
||||
}
|
||||
|
||||
function createFileName(dir: string, prefix: string): string {
|
||||
return join(dir, `${prefix}-${Math.random().toString(16).slice(-4)}`);
|
||||
}
|
||||
|
||||
interface IMainCli {
|
||||
main: (argv: NativeParsedArgs) => Promise<void>;
|
||||
}
|
||||
@@ -134,7 +141,7 @@ export async function main(argv: string[]): Promise<any> {
|
||||
child.stdout!.on('data', (data: Buffer) => console.log(data.toString('utf8').trim()));
|
||||
child.stderr!.on('data', (data: Buffer) => console.log(data.toString('utf8').trim()));
|
||||
|
||||
await new Promise<void>(resolve => child.once('exit', () => resolve()));
|
||||
await Event.toPromise(Event.fromNodeEventEmitter(child, 'exit'));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,6 +195,8 @@ export async function main(argv: string[]): Promise<any> {
|
||||
}
|
||||
}
|
||||
|
||||
const isMacOSBigSurOrNewer = isMacintosh && release() > '20.0.0';
|
||||
|
||||
// If we are started with --wait create a random temporary file
|
||||
// and pass it over to the starting instance. We can use this file
|
||||
// to wait for it to be deleted to monitor that the edited file
|
||||
@@ -198,6 +207,42 @@ export async function main(argv: string[]): Promise<any> {
|
||||
if (waitMarkerFilePath) {
|
||||
addArg(argv, '--waitMarkerFilePath', waitMarkerFilePath);
|
||||
}
|
||||
|
||||
// When running with --wait, we want to continue running CLI process
|
||||
// until either:
|
||||
// - the wait marker file has been deleted (e.g. when closing the editor)
|
||||
// - the launched process terminates (e.g. due to a crash)
|
||||
processCallbacks.push(async child => {
|
||||
let childExitPromise;
|
||||
if (isMacOSBigSurOrNewer) {
|
||||
// On Big Sur, we resolve the following promise only when the child,
|
||||
// i.e. the open command, exited with a signal or error. Otherwise, we
|
||||
// wait for the marker file to be deleted or for the child to error.
|
||||
childExitPromise = new Promise<void>(resolve => {
|
||||
// Only resolve this promise if the child (i.e. open) exited with an error
|
||||
child.on('exit', (code, signal) => {
|
||||
if (code !== 0 || signal) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// On other platforms, we listen for exit in case the child exits before the
|
||||
// marker file is deleted.
|
||||
childExitPromise = Event.toPromise(Event.fromNodeEventEmitter(child, 'exit'));
|
||||
}
|
||||
try {
|
||||
await Promise.race([
|
||||
whenDeleted(waitMarkerFilePath!),
|
||||
Event.toPromise(Event.fromNodeEventEmitter(child, 'error')),
|
||||
childExitPromise
|
||||
]);
|
||||
} finally {
|
||||
if (stdinFilePath) {
|
||||
unlinkSync(stdinFilePath); // Make sure to delete the tmp stdin file if we have any
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If we have been started with `--prof-startup` we need to find free ports to profile
|
||||
@@ -214,7 +259,7 @@ export async function main(argv: string[]): Promise<any> {
|
||||
throw new Error('Failed to find free ports for profiler. Make sure to shutdown all instances of the editor first.');
|
||||
}
|
||||
|
||||
const filenamePrefix = join(homedir(), 'prof-' + Math.random().toString(16).slice(-4));
|
||||
const filenamePrefix = createFileName(homedir(), 'prof');
|
||||
|
||||
addArg(argv, `--inspect-brk=${portMain}`);
|
||||
addArg(argv, `--remote-debugging-port=${portRenderer}`);
|
||||
@@ -319,23 +364,82 @@ export async function main(argv: string[]): Promise<any> {
|
||||
options['stdio'] = 'ignore';
|
||||
}
|
||||
|
||||
const child = spawn(process.execPath, argv.slice(2), options);
|
||||
let child: ChildProcess;
|
||||
if (!isMacOSBigSurOrNewer) {
|
||||
// We spawn process.execPath directly
|
||||
child = spawn(process.execPath, argv.slice(2), options);
|
||||
} else {
|
||||
// On Big Sur, we spawn using the open command to obtain behavior
|
||||
// similar to if the app was launched from the dock
|
||||
// https://github.com/microsoft/vscode/issues/102975
|
||||
|
||||
if (args.wait && waitMarkerFilePath) {
|
||||
return new Promise<void>(resolve => {
|
||||
// The following args are for the open command itself, rather than for VS Code:
|
||||
// -n creates a new instance.
|
||||
// Without -n, the open command re-opens the existing instance as-is.
|
||||
// -g starts the new instance in the background.
|
||||
// Later, Electron brings the instance to the foreground.
|
||||
// This way, Mac does not automatically try to foreground the new instance, which causes
|
||||
// focusing issues when the new instance only sends data to a previous instance and then closes.
|
||||
const spawnArgs = ['-n', '-g'];
|
||||
// -a opens the given application.
|
||||
spawnArgs.push('-a', process.execPath); // -a: opens a specific application
|
||||
|
||||
// Complete when process exits
|
||||
child.once('exit', () => resolve(undefined));
|
||||
if (verbose) {
|
||||
spawnArgs.push('--wait-apps'); // `open --wait-apps`: blocks until the launched app is closed (even if they were already running)
|
||||
|
||||
// Complete when wait marker file is deleted
|
||||
whenDeleted(waitMarkerFilePath!).then(resolve, resolve);
|
||||
}).then(() => {
|
||||
// The open command only allows for redirecting stderr and stdout to files,
|
||||
// so we make it redirect those to temp files, and then use a logger to
|
||||
// redirect the file output to the console
|
||||
for (const outputType of ['stdout', 'stderr']) {
|
||||
|
||||
// Make sure to delete the tmp stdin file if we have any
|
||||
if (stdinFilePath) {
|
||||
unlinkSync(stdinFilePath);
|
||||
// Tmp file to target output to
|
||||
const tmpName = createFileName(tmpdir(), `code-${outputType}`);
|
||||
writeFileSync(tmpName, '');
|
||||
spawnArgs.push(`--${outputType}`, tmpName);
|
||||
|
||||
// Listener to redirect content to stdout/stderr
|
||||
processCallbacks.push(async child => {
|
||||
try {
|
||||
const stream = outputType === 'stdout' ? process.stdout : process.stderr;
|
||||
|
||||
const cts = new CancellationTokenSource();
|
||||
child.on('close', () => cts.dispose(true));
|
||||
await watchFileContents(tmpName, chunk => stream.write(chunk), cts.token);
|
||||
} finally {
|
||||
unlinkSync(tmpName);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (const e in env) {
|
||||
// Ignore the _ env var, because the open command
|
||||
// ignores it anyway.
|
||||
// Pass the rest of the env vars in to fix
|
||||
// https://github.com/microsoft/vscode/issues/134696.
|
||||
if (e !== '_') {
|
||||
spawnArgs.push('--env');
|
||||
spawnArgs.push(`${e}=${env[e]}`);
|
||||
}
|
||||
}
|
||||
|
||||
spawnArgs.push('--args', ...argv.slice(2)); // pass on our arguments
|
||||
|
||||
if (env['VSCODE_DEV']) {
|
||||
// If we're in development mode, replace the . arg with the
|
||||
// vscode source arg. Because the OSS app isn't bundled,
|
||||
// it needs the full vscode source arg to launch properly.
|
||||
const curdir = '.';
|
||||
const launchDirIndex = spawnArgs.indexOf(curdir);
|
||||
if (launchDirIndex !== -1) {
|
||||
spawnArgs[launchDirIndex] = resolve(curdir);
|
||||
}
|
||||
}
|
||||
|
||||
// We already passed over the env variables
|
||||
// using the --env flags, so we can leave them out here.
|
||||
// Also, we don't need to pass env._, which is different from argv._
|
||||
child = spawn('open', spawnArgs, { ...options, env: {} });
|
||||
}
|
||||
|
||||
return Promise.all(processCallbacks.map(callback => callback(child)));
|
||||
|
||||
Reference in New Issue
Block a user