AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
222 stars 20 forks source link

Problem with project root determination when using npm workspaces #194

Closed daedal-knickerbockers closed 1 year ago

daedal-knickerbockers commented 1 year ago

Hi!

I currently have the problem that httpyac is a bit tedious to use with npm workspaces. Here's my project setup as an example:

first-workspace/
  config/
    first-request.http
  package.json

second-workspace/
  config/
    second-request.http
  package.json

package.json
.httpyac.json

The .httpyac.json file includes all environments so that the are managed at a central place and can be shared between requests.

When trying to send first-request.http, none of the environments defined in .httpyac.json can be found. According to the docs this might be caused by the priority of the files considers the project root:

The project root directory is determined by finding closest directory depending on the current file with one of the following files:

package.json httpyac.config.js .httpyac.js .httpyac.json env directory

If no suitable folder can be determined, the default settings are used.

As a workaround, I can add a separate .httpyac.json file into each workspace and set the envDirName manually to the actual project root folder.

first-workspace/
  config/
    first-request.http
  .httpyac.json
  package.json

second-workspace/
  config/
    second-request.http
  .httpyac.json
  package.json

package.json
.httpyac.json
# first-workspace/.httpyac.json
{
  "envDirName": "../../"
}

Now when opening first-request.http shows all envs from the root .httpyac.json file.

Maybe there could be an option to exclude files based on a pattern from the project root search? In my case it would be enough to ignore package.json and everything should be set.

Is this something you would consider? Or is there an existing config option I am just missing?

Thanks a bunch for the great tool!

AnWeber commented 1 year ago

I overlooked the fact that it is stupid for monorepos. I would adjust the logic that package.json does not necessarily determine the root, but only if no other root could be determined. In addition, it is possible in package.json also specify the configuration. This I add that all found package.json are searched for a possible configuration, but only the first found is used.

AnWeber commented 1 year ago

I have adjusted the logic as described. It will go live with the next release probably on Sunday

daedal-knickerbockers commented 1 year ago

Sorry for the late answer - I just checked with my project and it works just as expected 👍🏻

Many thanks for the quick fix!

AnWeber commented 1 year ago

Not late, just in time. i released it yesterday:-)