Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node as npm script runner #236967

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Add node as npm script runner #236967

wants to merge 9 commits into from

Conversation

xymopen
Copy link

@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

@@ -104,49 +103,61 @@ function isTestTask(name: string): boolean {
}
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
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
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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add node as npm script runner
2 participants