Add node as npm script runner (#236967)

* refactor: Separate `createScriptRunnerTask` and `createInstallationTask` from `createTask`

* feat: Add `npm.scriptRunner`

* feat: Add Node.js as script runner

* refactor: Refactor `isPrePostScript`

* refactor: Extract `get*Command`

* fix: Typo

* style: Remove no-op `catch`es

* fix: `node --run` doesn't support `--silent`

* refactor: Use `.map` in `escapeCommandLine`

* chore: Remove TODO

Upstream reviewer is ok with current state
This commit is contained in:
xymopen_Official
2025-02-08 01:26:29 +08:00
committed by GitHub
parent 5a42ab46c9
commit 6a5991cfb6
8 changed files with 223 additions and 152 deletions

View File

@@ -15,8 +15,8 @@ import {
workspace,
l10n
} from 'vscode';
import { findPreferredPM } from './preferred-pm';
import { readScripts } from './readScripts';
import { getRunScriptCommand } from './tasks';
const enum Constants {
@@ -87,18 +87,20 @@ export class NpmScriptLensProvider implements CodeLensProvider, Disposable {
}
if (this.lensLocation === 'all') {
const packageManager = await findPreferredPM(Uri.joinPath(document.uri, '..').fsPath);
return tokens.scripts.map(
({ name, nameRange }) =>
new CodeLens(
const folder = Uri.joinPath(document.uri, '..');
return Promise.all(tokens.scripts.map(
async ({ name, nameRange }) => {
const runScriptCommand = await getRunScriptCommand(name, folder);
return new CodeLens(
nameRange,
{
title,
command: 'extension.js-debug.createDebuggerTerminal',
arguments: [`${packageManager.name} run ${name}`, workspace.getWorkspaceFolder(document.uri), { cwd }],
arguments: [runScriptCommand.join(' '), workspace.getWorkspaceFolder(document.uri), { cwd }],
},
),
);
);
},
));
}
return [];