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

npm script not detected if the package.json is not in root folder #31217

Closed
lski opened this issue Jul 21, 2017 · 9 comments
Closed

npm script not detected if the package.json is not in root folder #31217

lski opened this issue Jul 21, 2017 · 9 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues verified Verification succeeded
Milestone

Comments

@lski
Copy link

lski commented Jul 21, 2017

  • VSCode Version: 1.14.2
  • OS Version: Win 10 (14393)

When the package.json file is in a sub folder of the one opened in VSCode (therefore not in the root), the tasks in the scripts section are not auto detected. I did test opening VSCode with the folder that contains the package.json file directly and the tasks were autodetected correctly, it just seems to be if its in a parent folder that the issue is caused.

This might be expected behaviour, although in the same project I had a tsconfig.json file in the same folder as package.json and it was detected in a subfolder when the package.json tasks were not detected. Ideally it would be better to autodetect in a sub folder like the tsconfig.json file does.

Steps to Reproduce:

  1. Open VSCode with parent folder above the folder containing package.json (so its not in the root)
  2. Click task in menu bar
  3. Click Run Task to get the list of auto detected scripts. List should not show the tasks from the scripts section of package.json

Reproduces without extensions: Yes

Thank you, apologies if I missed something

@vscodebot vscodebot bot added new release tasks Task system issues labels Jul 21, 2017
@egamma egamma self-assigned this Jul 23, 2017
@egamma egamma added the feature-request Request for new features or functionality label Jul 24, 2017
@craigbrett17
Copy link

craigbrett17 commented Nov 15, 2017

Might it not be better to specify the rootDir of the package.json you're looking for in the task? Akin to the options object in other types of task.

NVM: Just seen the path property. And this as about auto-detection. Ignore me

@craigbrett17
Copy link

Actualy, trying this out, the path property doesn't seem to work even on specified tasks. May or may not be related. If not related, I'll add a separate issue.

@lski
Copy link
Author

lski commented Nov 16, 2017

Sorry for not replying or adding information to this issue, I am in the middle of moving home and have very limited PC access for a couple of weeks.

@satoyan
Copy link

satoyan commented Feb 26, 2018

I have same problem.
My folder structure looks like below.

.
├── client
│   ├── package.json
│   ├── src
│   └── tsconfig.json
├── host
│   ├── package.json
│   ├── src
│   └── tsconfig.json
├── README.md
└── workspace.code-workspace

I have two TypeScript project each client and host directories.

I defined npm task each package.json(client and host).
Tasks I defined are very simple like this.

# host/package.json
"build": "parcel watch --no-hmr --no-source-maps src/main.ts",
# client/package.json
"build": "parcel watch --no-hmr src/main.ts"

I opend these projects with VSCode as multi-workspace-projects and I tried to show task list with ">Tasks: Run Task".
Unfortunately I could see only defaut tasks provided by VSCode not tasks I defined. This looks like this.

tsc:build - client/tsconfig.json
tsc:build - host/tsconfig.json

So I switched to open each one project with VSCode in the terminal.

cd host # or client
code .

And did the same thing as above.

Then I could see a npm task (npm:build) which I defined in package.json

I guess VSCode does not auto-detect npm tasks when it is opend as multi-workspace-projects.

Thank you.

@egamma egamma changed the title Auto-detected Tasks not showing NPM script tasks if a parent folder Auto-detected Tasks not showing NPM script tasks if not in root folder Feb 28, 2018
@egamma egamma changed the title Auto-detected Tasks not showing NPM script tasks if not in root folder npm script not detected if the package.json is not in root folder Feb 28, 2018
@egamma egamma added this to the February 2018 milestone Feb 28, 2018
@egamma
Copy link
Member

egamma commented Feb 28, 2018

The task provider is now searching for package.json file inside the workspace with the exception of node_modules. Additional exclusions can be defined using the npm.exclude setting.

@egamma egamma closed this as completed Feb 28, 2018
@egamma egamma added bug Issue identified by VS Code Team member as probable bug and removed feature-request Request for new features or functionality labels Mar 2, 2018
@egamma
Copy link
Member

egamma commented Mar 2, 2018

To verify:

@tsalinger tsalinger added the verified Verification succeeded label Mar 2, 2018
@DanTup
Copy link
Contributor

DanTup commented Mar 9, 2018

I think the problem of people having projects in sub-folders is much wider than just here. I've proposed that sub-folders should be able to be full-fledged WorkspaceFolders so they can have their own settings, debug configs, etc. here -> #45399

I think it'd solve a bunch of issues!

@jtokoph
Copy link

jtokoph commented Mar 14, 2018

I think this has caused a regression in performance and usability in large repositories.

The change here a6dde81#diff-3b21ed98f2447f0d29ed636bdcf00c98R103 is calling vscode.workspace.findFiles before checking if the main workspace settings have npm.autoDetect set to on/off.

In my large workspaces I have disabled all *.autoDetect configuration options so that my default build task (cmd+shift+b) doesn't have to wait for vscode to look for all build tasks.

Before this change, my default build task started running immediately.
After this change, my default build task spends 20 seconds Fetching build tasks... before finally running my build script.

@jtokoph
Copy link

jtokoph commented Mar 14, 2018

Github doesn't seem to link to diff lines properly, this is the line that I believe is causing the slowdown with a call to vscode.workspace.findFiles: https://github.com/Microsoft/vscode/blob/a6dde81592febe579a24ada7b0e6d63b15a37cfd/extensions/npm/src/main.ts#L103

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

8 participants