near-cli icon indicating copy to clipboard operation
near-cli copied to clipboard

Near CLI looks at CWD for a src/config.js file which can cause interference

Open taylorjdawson opened this issue 4 years ago • 4 comments

Describe the bug Essentially in the near cli on [this line](https://github.com/near/near-cli/blob/509846163695ba227f4ad5dc070b56040fcd9bab/get-config.js#L3) it tries an look for a config.js file within the users current working directory. To me this shouldn’t be the case, it should use a default unless a user explicitly specifies otherwise like --config <your config.js file>

 ...
 const configPath = process.cwd() + '/src/config';
 const nearEnv = process.env.NEAR_ENV || process.env.NODE_ENV || 'development';
 try 

 { const config = require(configPath)(nearEnv); return config; } 

 catch (e) 

 { ... } 

...

To Reproduce Reproduction for this issue is tricky as you will see different results depending on what is in the config.js file.

Steps to reproduce the behavior: 1. Run near within a project directory that has a src/config.js file 2. See error

 ❯ near
 /Some/project/directory/src/config.js:L99
 export default function someMethod() {
 ^^^^^^

SyntaxError: Unexpected token 'export'

Expected behavior I expect that when I run the near command that I will get determintic behaviour regardless of which directory I am in. I expect the the near cli would not be effected by external files within my current directory.

Desktop (please complete the following information):

  • OS: MacOS
  • Version: 2.0.1

Let me know what needs to be done and I can open a PR to address this, thanks!

taylorjdawson avatar May 24 '21 23:05 taylorjdawson

I agree. This has bugged me quite a bit.

near dev-deploy

For example also fails (sometimes silently depending on your setup) if this config file specifies an object that contains additional fields it doesn't recognize...

Odd.

mattlockyer avatar May 25 '21 00:05 mattlockyer

Yep, one of my least favorite "features" of near-cli

chadoh avatar May 25 '21 13:05 chadoh

@chadoh Would it be safe to remove as @MaximusHaximus suggested?

Screenshot_20210525-084647.jpg

cc @vgrichina

taylorjdawson avatar May 25 '21 15:05 taylorjdawson

@vgrichina @MaximusHaximus @mattlockyer

Any update?

taylorjdawson avatar Jul 23 '21 15:07 taylorjdawson