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

env files and variables are not correctly resolved #51

Closed
amkisko opened this issue Jul 13, 2021 · 9 comments
Closed

env files and variables are not correctly resolved #51

amkisko opened this issue Jul 13, 2021 · 9 comments

Comments

@amkisko
Copy link

amkisko commented Jul 13, 2021

Hello!

Here's the list of few found issues related to dotenv feature:

  1. For some reason env files with names like .env.local, .env.production are not properly handled, it is possible to select .local from the list, but variables are not available within script. In the same time local.env works fine.

first_case_screenshot

# cat .env.local
TEST=this_is_a_test_value

Additional question: how to log all available variables?

  1. Files within env directory is not visible in the list of available environments. Structure is:
|__specs
  |__env
    |__.env.local
    |__local.env
  |__requests.http
  1. The editor shows variables from env as missing ones (red underline).

third_case_screenshot

Probably it will be good to have environment name to be set as a global variable, at least it gives an option to use dotenv-like packages.

Also at the moment it almost impossible to create Postman-like directory structure (or I could not figure out how):

|__specs
  |__env
    |__local.env
    |__staging.env
    |__production.env
  |__api
    |__user
      |__auth.http
      |__profile.http
    |__messages
      |__index.http
      |__create.http
      |__update.http
      |__destroy.http 

Configuration:

VSCodium
Version: 1.58.0
Commit: 2d23c42a936db1c7b3b06f918cde29561cc47cd6
Date: 2021-07-11T00:18:10.593Z (2 days ago)
Electron: 12.0.13
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Darwin x64 20.5.0

httpYac - Rest Client
anweber.vscode-httpyac
anweber
v2.16.1

Httpyac: Dotenv Dirname = env
Httpyac: Dotenv Enabled = true
Httpyac: Dotenv Variable Provider Enabled = true
Httpyac: Environment Pick Many = true
@AnWeber
Copy link
Owner

AnWeber commented Jul 13, 2021

  1. Will have to look into it, I use the exact other spelling and it works for me. But for Linux the .env.local would be better.
  2. Currently I only search the root folder of the workspace for the env folder. The change request with the folder structure is already addressed in root folder determination #50. This can be corrected in the meantime with the setting httpyac.dotenvDirname.
  3. The red underlining is your installed rest-client extension. It only resolves dotenv variable in the same root like the http file. I would recommend to use only httpyac or rest-client, not both, because we solve the same purpose differently. My extension unfortunately can't validate the variables. rest-client solves this by automatically checking the logic for the variables on the fly (eating CPU), I deliberately didn't want this and the dynamic NodeJS scripts make it too complex.

@amkisko
Copy link
Author

amkisko commented Jul 13, 2021

Thanks for the reply.

  1. Tuning httpyac.dotenvDirname does not affect anything, I could not make it work, tried ./env and ../env and env.
  2. Correct, I completely forgot about this extension (rest-client), disabling it helped.

@AnWeber
Copy link
Owner

AnWeber commented Jul 13, 2021

What is your folder structure in vscode

|__specs
  |__env
    |__...
  |__api
    |__...

or

|__env
  |__...
|__src
  |__...

The second option is my own way to use the extension.
If httpyac.logLevel is set to trace, all search paths are written to output console httpyac - Log. You just need to reopen vscode or execute comman httpyac.reset.

@amkisko
Copy link
Author

amkisko commented Jul 13, 2021

Current folder structure is described in initial post under the second point, api specs are stored somewhere in deep structure of the project, no env directory in root.

|__specs
  |__env
    |__.env.local
    |__local.env
  |__requests.http

@AnWeber
Copy link
Owner

AnWeber commented Jul 13, 2021

then you need to configure ./specs/env

@amkisko
Copy link
Author

amkisko commented Jul 13, 2021

then you need to configure ./specs/env

Yeah, and probably this should be stored inside .vscode/settings.json per project.

@amkisko
Copy link
Author

amkisko commented Jul 13, 2021

Changing httpyac.dotenvDirname to ./specs/env does not affect the list, still no entries from the directory.

Can extension also fire an exception if directory is not found?

@AnWeber
Copy link
Owner

AnWeber commented Jul 13, 2021

I have now recreated your project. I could understand the error with .env.local, but not the problem with the env folder.
env

my project as zip #51.zip

@AnWeber
Copy link
Owner

AnWeber commented Jul 18, 2021

I have provided an update to vscode-httpyac (v2.20.0) that fixes the bug. I will continue to work on the problems with recognizing the env files using #50.

@AnWeber AnWeber closed this as completed Jul 18, 2021
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

No branches or pull requests

2 participants