Files
vscode/extensions/gulp/src/main.ts
T
RoboandGitHub 8748be1f1a feat: update to Electron v42 (#316661)
* feat: update to Electron v42

* chore: drop support for arm 32-bit server

* chore: update types/node to v24.x

* chore: temporarily lock the target version for build/

* chore: update v8-source-location.patch

* chore: fix clippy

* chore: cleanup armhf server ci config

* fix: broken lock file

* fix: c++ version requirement for sysroot builds

* fix: msvc compilation of native modules

* fix: handle rejections for fire-and-forget loadurl

* fix: windows build

* ci: fix teardown of daemon process on windows

```
2026-05-15T20:55:09.7717127Z Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76
```

* chore: update deb and rpm dependencies

* chore: update version info

* spec: improve reliablity of offscreencanvas tests

* spec: retry EPERM failures on teardown

* chore: update x86_64 rpm deps

* ci: exclude server binskim for armhf

* temp: bump distro

* test: ignore deprecation warnings treated as errors

* chore: update lockfile

* fix: externalize electron from auth extension bundles

 Error: Cannot find module 'c:\Users\cloudtest\AppData\Local\Temp\vscode-sanityQvCaze\vscode-server-win32-x64-web\extensions\github-authentication\dist\install.js'
     at Module._resolveFilename (node:internal/modules/cjs/loader:1476:15)
     at wrapResolveFilename (node:internal/modules/cjs/loader:1049:27)
     at defaultResolveImplForCJSLoading (node:internal/modules/cjs/loader:1073:10)
     at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1094:12)
     at Module._load (node:internal/modules/cjs/loader:1262:25)
     at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
     at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
     at node:internal/main/run_main_module:33:47 {
   code: 'MODULE_NOT_FOUND',
   requireStack: []
 }

 Node.js v24.15.0

* test: make wsl sanity tests reliable

* chore: bump electron@42.1.0

* temp: bump distro

* chore: bump electron@42.2.0

* chore: bump distro

* chore: update debian dependencies

* Revert "test: make wsl sanity tests reliable"

This reverts commit b3f2b63e83.

* test: do not fail for deprecation warnings

* chore: patch node24 server binary for wsl1

* chore: address review feedback

* chore: revert global navigation error handler in browserview

* chore: bump distro
2026-05-27 14:57:41 +02:00

407 lines
11 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as fs from 'fs';
import * as cp from 'child_process';
import * as vscode from 'vscode';
type AutoDetect = 'on' | 'off';
/**
* Check if the given filename is a file.
*
* If returns false in case the file does not exist or
* the file stats cannot be accessed/queried or it
* is no file at all.
*
* @param filename
* the filename to the checked
* @returns
* true in case the file exists, in any other case false.
*/
async function exists(filename: string): Promise<boolean> {
try {
if ((await fs.promises.stat(filename)).isFile()) {
return true;
}
} catch (ex) {
// In case requesting the file statistics fail.
// we assume it does not exist.
return false;
}
return false;
}
function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: string; stderr: string }> {
return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => {
cp.exec(command, options, (error, stdout, stderr) => {
if (error) {
reject({ error, stdout, stderr });
}
resolve({ stdout: stdout.toString(), stderr: stderr.toString() });
});
});
}
const buildNames: string[] = ['build', 'compile', 'watch'];
function isBuildTask(name: string): boolean {
for (const buildName of buildNames) {
if (name.indexOf(buildName) !== -1) {
return true;
}
}
return false;
}
const testNames: string[] = ['test'];
function isTestTask(name: string): boolean {
for (const testName of testNames) {
if (name.indexOf(testName) !== -1) {
return true;
}
}
return false;
}
let _channel: vscode.OutputChannel;
function getOutputChannel(): vscode.OutputChannel {
if (!_channel) {
_channel = vscode.window.createOutputChannel('Gulp Auto Detection');
}
return _channel;
}
function showError() {
vscode.window.showWarningMessage(vscode.l10n.t("Problem finding gulp tasks. See the output for more information."),
vscode.l10n.t("Go to output")).then((choice) => {
if (choice !== undefined) {
_channel.show(true);
}
});
}
async function findGulpCommand(rootPath: string): Promise<string> {
const platform = process.platform;
if (platform === 'win32' && await exists(path.join(rootPath, 'node_modules', '.bin', 'gulp.cmd'))) {
const globalGulp = path.join(process.env.APPDATA ? process.env.APPDATA : '', 'npm', 'gulp.cmd');
if (await exists(globalGulp)) {
return `"${globalGulp}"`;
}
return path.join('.', 'node_modules', '.bin', 'gulp.cmd');
}
if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(rootPath, 'node_modules', '.bin', 'gulp'))) {
return path.join('.', 'node_modules', '.bin', 'gulp');
}
return 'gulp';
}
interface GulpTaskDefinition extends vscode.TaskDefinition {
task: string;
file?: string;
}
class FolderDetector {
private fileWatcher: vscode.FileSystemWatcher | undefined;
private promise: Thenable<vscode.Task[]> | undefined;
constructor(
private _workspaceFolder: vscode.WorkspaceFolder,
private _gulpCommand: Promise<string>) {
}
public get workspaceFolder(): vscode.WorkspaceFolder {
return this._workspaceFolder;
}
public isEnabled(): boolean {
return vscode.workspace.getConfiguration('gulp', this._workspaceFolder.uri).get<AutoDetect>('autoDetect') === 'on';
}
public start(): void {
const pattern = path.join(this._workspaceFolder.uri.fsPath, '{node_modules,gulpfile{.babel.js,.esm.js,.js,.mjs,.cjs,.ts}}');
this.fileWatcher = vscode.workspace.createFileSystemWatcher(pattern);
this.fileWatcher.onDidChange(() => this.promise = undefined);
this.fileWatcher.onDidCreate(() => this.promise = undefined);
this.fileWatcher.onDidDelete(() => this.promise = undefined);
}
public async getTasks(): Promise<vscode.Task[]> {
if (!this.isEnabled()) {
return [];
}
if (!this.promise) {
this.promise = this.computeTasks();
}
return this.promise;
}
public async getTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
const gulpTask = _task.definition.task;
if (gulpTask) {
const kind = _task.definition as GulpTaskDefinition;
const options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
const task = new vscode.Task(kind, this.workspaceFolder, gulpTask, 'gulp', new vscode.ShellExecution(await this._gulpCommand, [gulpTask], options));
return task;
}
return undefined;
}
/**
* Searches for a gulp entry point inside the given folder.
*
* Typically the entry point is a file named "gulpfile.js"
*
* It can also be a transposed gulp entry points, like gulp.babel.js or gulp.esm.js
*
* Additionally recent node version prefer the .mjs or .cjs extension over the .js.
*
* @param root
* the folder which should be checked.
*/
private async hasGulpfile(root: string): Promise<boolean | undefined> {
for (const filename of await fs.promises.readdir(root)) {
const ext = path.extname(filename);
if (ext !== '.js' && ext !== '.mjs' && ext !== '.cjs' && ext !== '.ts') {
continue;
}
if (!exists(filename)) {
continue;
}
const basename = path.basename(filename, ext).toLowerCase();
if (basename === 'gulpfile') {
return true;
}
if (basename === 'gulpfile.esm') {
return true;
}
if (basename === 'gulpfile.babel') {
return true;
}
}
return false;
}
private async computeTasks(): Promise<vscode.Task[]> {
const rootPath = this._workspaceFolder.uri.scheme === 'file' ? this._workspaceFolder.uri.fsPath : undefined;
const emptyTasks: vscode.Task[] = [];
if (!rootPath) {
return emptyTasks;
}
if (!await this.hasGulpfile(rootPath)) {
return emptyTasks;
}
const commandLine = `${await this._gulpCommand} --tasks-simple --no-color`;
try {
const { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
if (stderr && stderr.length > 0) {
// Filter out "No license field"
const errors = stderr.split('\n');
errors.pop(); // The last line is empty.
if (!errors.every(value => value.indexOf('No license field') >= 0)) {
getOutputChannel().appendLine(stderr);
showError();
}
}
const result: vscode.Task[] = [];
if (stdout) {
const lines = stdout.split(/\r{0,1}\n/);
for (const line of lines) {
if (line.length === 0) {
continue;
}
const kind: GulpTaskDefinition = {
type: 'gulp',
task: line
};
const options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
const task = new vscode.Task(kind, this.workspaceFolder, line, 'gulp', new vscode.ShellExecution(await this._gulpCommand, [line], options));
result.push(task);
const lowerCaseLine = line.toLowerCase();
if (isBuildTask(lowerCaseLine)) {
task.group = vscode.TaskGroup.Build;
} else if (isTestTask(lowerCaseLine)) {
task.group = vscode.TaskGroup.Test;
}
}
}
return result;
} catch (err) {
const channel = getOutputChannel();
if (err.stderr) {
channel.appendLine(err.stderr);
}
if (err.stdout) {
channel.appendLine(err.stdout);
}
channel.appendLine(vscode.l10n.t("Auto detecting gulp for folder {0} failed with error: {1}', this.workspaceFolder.name, err.error ? err.error.toString() : 'unknown"));
showError();
return emptyTasks;
}
}
public dispose() {
this.promise = undefined;
if (this.fileWatcher) {
this.fileWatcher.dispose();
}
}
}
class TaskDetector {
private taskProvider: vscode.Disposable | undefined;
private detectors: Map<string, FolderDetector> = new Map();
constructor() {
}
public start(): void {
const folders = vscode.workspace.workspaceFolders;
if (folders) {
this.updateWorkspaceFolders(folders, []);
}
vscode.workspace.onDidChangeWorkspaceFolders((event) => this.updateWorkspaceFolders(event.added, event.removed));
vscode.workspace.onDidChangeConfiguration(this.updateConfiguration, this);
}
public dispose(): void {
if (this.taskProvider) {
this.taskProvider.dispose();
this.taskProvider = undefined;
}
this.detectors.clear();
}
private updateWorkspaceFolders(added: readonly vscode.WorkspaceFolder[], removed: readonly vscode.WorkspaceFolder[]): void {
for (const remove of removed) {
const detector = this.detectors.get(remove.uri.toString());
if (detector) {
detector.dispose();
this.detectors.delete(remove.uri.toString());
}
}
for (const add of added) {
const detector = new FolderDetector(add, findGulpCommand(add.uri.fsPath));
this.detectors.set(add.uri.toString(), detector);
if (detector.isEnabled()) {
detector.start();
}
}
this.updateProvider();
}
private updateConfiguration(): void {
for (const detector of this.detectors.values()) {
detector.dispose();
this.detectors.delete(detector.workspaceFolder.uri.toString());
}
const folders = vscode.workspace.workspaceFolders;
if (folders) {
for (const folder of folders) {
if (!this.detectors.has(folder.uri.toString())) {
const detector = new FolderDetector(folder, findGulpCommand(folder.uri.fsPath));
this.detectors.set(folder.uri.toString(), detector);
if (detector.isEnabled()) {
detector.start();
}
}
}
}
this.updateProvider();
}
private updateProvider(): void {
if (!this.taskProvider && this.detectors.size > 0) {
const thisCapture = this;
this.taskProvider = vscode.tasks.registerTaskProvider('gulp', {
provideTasks(): Promise<vscode.Task[]> {
return thisCapture.getTasks();
},
resolveTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
return thisCapture.getTask(_task);
}
});
}
else if (this.taskProvider && this.detectors.size === 0) {
this.taskProvider.dispose();
this.taskProvider = undefined;
}
}
public getTasks(): Promise<vscode.Task[]> {
return this.computeTasks();
}
private computeTasks(): Promise<vscode.Task[]> {
if (this.detectors.size === 0) {
return Promise.resolve([]);
} else if (this.detectors.size === 1) {
return this.detectors.values().next().value!.getTasks();
} else {
const promises: Promise<vscode.Task[]>[] = [];
for (const detector of this.detectors.values()) {
promises.push(detector.getTasks().then((value) => value, () => []));
}
return Promise.all(promises).then((values) => {
const result: vscode.Task[] = [];
for (const tasks of values) {
if (tasks && tasks.length > 0) {
result.push(...tasks);
}
}
return result;
});
}
}
public async getTask(task: vscode.Task): Promise<vscode.Task | undefined> {
if (this.detectors.size === 0) {
return undefined;
} else if (this.detectors.size === 1) {
return this.detectors.values().next().value!.getTask(task);
} else {
if ((task.scope === vscode.TaskScope.Workspace) || (task.scope === vscode.TaskScope.Global)) {
// Not supported, we don't have enough info to create the task.
return undefined;
} else if (task.scope) {
const detector = this.detectors.get(task.scope.uri.toString());
if (detector) {
return detector.getTask(task);
}
}
return undefined;
}
}
}
let detector: TaskDetector;
export function activate(_context: vscode.ExtensionContext): void {
detector = new TaskDetector();
detector.start();
}
export function deactivate(): void {
detector.dispose();
}