Skip to content

Add node as npm script runner#236967

Merged
connor4312 merged 10 commits intomicrosoft:mainfrom
xymopen:main
Feb 7, 2025
Merged

Add node as npm script runner#236967
connor4312 merged 10 commits intomicrosoft:mainfrom
xymopen:main

Conversation

@xymopen
Copy link
Contributor

@xymopen xymopen commented Dec 26, 2024

Fixes #234468

  • Add standalone npm.scriptRunner setting for running scripts
  • Add node as a script runner
  • Some code clean up

Copy link
Member

@connor4312 connor4312 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall, some comments

const scriptRunner = await getScriptRunner(folder, context, showWarning);
const result = [scriptRunner, scriptRunner === 'node' ? '--run' : 'run'];
if (workspace.getConfiguration('npm', folder).get<boolean>('runSilent')) {
result.push('--silent');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--silent will cause an error if the scriptRunner is node, we should ignore that setting in this case

return false;
}
const preScripts: Set<string> = new Set([
'est', /* test typo? */ 'install', 'pack', 'pack', 'publish', 'restart',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a typo, you can fix it :)

Comment on lines +124 to +125
export async function getScriptRunner(folder: Uri, context?: ExtensionContext, showWarning?: boolean): Promise<string> {
let scriptRunner = workspace.getConfiguration('npm', folder).get<string>('scriptRunner', 'npm');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default in get here should be auto, and if it's auto then we return getPackageManager(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPackageManager also defaults to auto and call detectPackageManager. They basically do the same thing, just get different configuration.

}
}
return allTasks;
} catch (error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it was added initially, but this catch is a no-op, you can remove the try/catch if you want

const { name, multipleLockFilesDetected: multiplePMDetected } = await findPreferredPM(folder.fsPath);
const neverShowWarning = 'npm.multiplePMWarning.neverShow';
if (showWarning && multiplePMDetected && extensionContext && !extensionContext.globalState.get<boolean>(neverShowWarning)) {
// todo: add text for npm.scriptRunner?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're okay with this text

@xymopen
Copy link
Contributor Author

xymopen commented Jan 9, 2025

Thank you for your review. I've made some adjustment to the code and I believe it is ready for merge.

@xymopen xymopen marked this pull request as ready for review January 9, 2025 12:37
@xymopen
Copy link
Contributor Author

xymopen commented Jan 9, 2025

Also I note that js-debug is using npm.packageManager setting to create debug terminal. Do we need to make some change there, or instead make another command and return the full run command line to other extensions?

@xymopen
Copy link
Contributor Author

xymopen commented Feb 7, 2025

@connor4312 It's been a while since your last comment. Is there any more adjustment I need to make for this PR?

@connor4312 connor4312 enabled auto-merge (squash) February 7, 2025 16:30
@vs-code-engineering vs-code-engineering bot added this to the February 2025 milestone Feb 7, 2025
@connor4312 connor4312 merged commit 6a5991c into microsoft:main Feb 7, 2025
7 checks passed
roblourens added a commit that referenced this pull request Feb 11, 2025
@roblourens
Copy link
Member

Reverting this #240413 since I couldn't run npm tasks in one of my private repos. I see this thrown repeatedly

throw new Error('Unexpected: The resolved task definition must be the same object as the original task definition. The task definition cannot be changed.');

roblourens added a commit that referenced this pull request Feb 11, 2025
@xymopen
Copy link
Contributor Author

xymopen commented Feb 12, 2025

Sorry to hear that. Could you please isolate a minimal reproduction so I can look into it?

@xymopen
Copy link
Contributor Author

xymopen commented Feb 12, 2025

@roblourens I found the potential cause and open another PR #240527. Please check and let me know if the bug persists. Thanks in advanced.

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Mar 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add node as npm script runner

3 participants