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

enable running individual npm scripts in the containing folder #79960

Merged
merged 7 commits into from Oct 14, 2019

Conversation

@helen3141
Copy link
Contributor

helen3141 commented Aug 28, 2019

No description provided.

@msftclas

This comment has been minimized.

Copy link

msftclas commented Aug 28, 2019

CLA assistant check
All CLA requirements met.

helen3141 and others added 3 commits Aug 29, 2019
@egamma

This comment has been minimized.

Copy link
Member

egamma commented Oct 8, 2019

@helen3141 thank you for the PR (sorry for the delayed review, but there was no corresponding issue with a feature request filed).

The PR currently includes no description. Can you please provide more background what the feature does, why is it needed, and how it can be tested?

@helen3141

This comment has been minimized.

Copy link
Contributor Author

helen3141 commented Oct 9, 2019

Hi @egamma!

The feature request originates from our team's need to easily view and run custom scripts written in the package.json file of a particular folder of interest.

The idea is that users can select any folder in the Explorer pane to view the custom scripts within the folder's package.json file(s) by right-clicking the folder and selecting the option 'Select npm Scripts to Run...'

Run npm from root

Then a command palette will pop up with all of the custom scripts within that folder:

npm command palette

You can run this branch in Debug mode with the option 'Launch VS Code' selected.

The default setting is that this feature is enabled.

You can toggle the feature on/off. Go to File>Preferences>Settings> click the 'Extensions' drop down, click 'Npm' and untick the box 'Enable Run From Folder Context Menu':

npmoptions

When the feature is enabled you can test it.

Open any folder/project. The extension will check for custom scripts in the package.json file of the folder that is being right-clicked or the root folder (detected by ExplorerFolderContext and ExplorerRootContext mechanisms, I'm guessing).

This check leverages the code already in the extension, and is executed every time a folder is right-clicked in the Explorer pane. This could potentially be computationally expensive if the project is very large with many nested package.json files and I haven't stress tested/optimized for an extreme use case like that.

When the 'Select npm Scripts to Run...' option from the context menu is selected, all the custom scripts available in the folder will be listed in the command palette that pops up.

Scripts available from the package.json file of the parent folder are prefaced with >. If the scripts are from a package.json file that is nested in a subfolder, the script will be prefaced with its relative directory + >

When the user selects an option from the command palette, that particular script will run. If you have a terminal visible, you should be able to see the console output of that script.

Thank you for your feedback and please feel free to comment with any more questions/thoughts you may have!

Copy link
Member

egamma left a comment

@helen3141 thank you for the additional background. I've reviewed the PR.

In general the default value of the setting to enable the context menu should be false. The NPM extension is bundled with VS Code and it has to be defensive with regard to contributing to the context menu, given that not all workspaces are node based, e.g., think of a Python workspace.

extensions/npm/package.json Outdated Show resolved Hide resolved
extensions/npm/package.json Outdated Show resolved Hide resolved
extensions/npm/package.json Show resolved Hide resolved
extensions/npm/package.nls.json Outdated Show resolved Hide resolved
extensions/npm/src/commands.ts Outdated Show resolved Hide resolved
});
let result = await vscode.window.showQuickPick(Object.keys(taskMap).sort(), {
placeHolder: `Run scripts on folder ${folderInfo.fsPath}...`,

This comment has been minimized.

Copy link
@egamma

egamma Oct 9, 2019

Member

The quick pick should have a title 'Run npm Script in Folder' and the place holder should be 'Select script'

This comment has been minimized.

Copy link
@helen3141

helen3141 Oct 11, 2019

Author Contributor

Thanks for your helpful feedback! I was able to implement all except the title for the quick pick as I don't think there is a property for showQuickPick

extensions/npm/src/commands.ts Outdated Show resolved Hide resolved
extensions/npm/src/main.ts Outdated Show resolved Hide resolved
extensions/npm/src/tasks.ts Outdated Show resolved Hide resolved
helen3141 added 3 commits Oct 11, 2019
…che if available instead of creating new tasks
@egamma egamma merged commit 34648a0 into microsoft:master Oct 14, 2019
2 checks passed
2 checks passed
VS Code #20191011.73 succeeded
Details
license/cla All CLA requirements met.
Details
@egamma

This comment has been minimized.

Copy link
Member

egamma commented Oct 14, 2019

@helen3141 thanks again 🌷 for the PR it is now merged in.

I've removed the code that leverages the tasks cache, it still requires to do a search on the file system and it is more tricky to get it right in all the cases.

I was able to implement all except the title for the quick pick as I don't think there is a property for showQuickPick

Correct this option is not available for the simple showQuickPick API, you have to create a QuickPick by yourself to get at this option, pls see this commit 7485ffd for how it can be done. This commit also includes some wording tweaks.

One tweaks I made was to simplify the setting from npm.enableRunFromFolderContextMenu to npm.runScriptFromFolder

@egamma egamma referenced this pull request Oct 15, 2019
@egamma

This comment has been minimized.

Copy link
Member

egamma commented Oct 16, 2019

@helen3141 the feature is now available in the insiders build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.