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

Propose that n auto skip over empty files or package.json with no engines property #692

Closed
ericbf opened this issue Sep 30, 2021 · 6 comments

Comments

@ericbf
Copy link

ericbf commented Sep 30, 2021

Problem

n auto in a directory with an empty .n-node-version, .node-version, or .nvmrc, or a package.json with no engines will default to current, overriding any system default.

Short Version

I would expect that the presence of a file lacking configuration in it (empty . file, or package.json without the respective config) would be treated the same as not having that file in the first place (continue search or error out, as applicable).

Long Version

n auto's behavior was a little unexpected for me—I expected an error message like Error: no auto version found (.n-node-version, .node-version, .nvmrc, or engine in package.json) if no preferred version setting is found, not invisibly selecting the current version. I prefer to stay on lts, but this behavior makes it hard to use auto as I don't want to necessarily check whether a repo is configured with a preferred version.

The lack of a configuration should not be treated as configuration to use current. That's weird.

Configuration Details

$ n --version
7.3.1

$ command -v node
/usr/local/bin/node

$ node -p process.platform
darwin
@shadowspawn
Copy link
Collaborator

In practice, is it a package.json with no engine property that causes the problem?

I was not entirely happy with going for current when there are no restrictions. I'll have another think about this.

@shadowspawn
Copy link
Collaborator

If there is no node property on engines field, how about:

% n auto
       found : /Users/john/Documents/Sandpits/n/issues/692/package.json

  Error: did not find supported versions of node in 'engines' field of package.json

For interest you can check what version is found with n lsr auto.

@ericbf
Copy link
Author

ericbf commented Oct 1, 2021

In practice, is it a package.json with no engine property that causes the problem?

I was not entirely happy with going for current when there are no restrictions. I'll have another think about this.

Exactly right. When running auto in a directory where I expected auto to error out (since I hadn't configured any preference), I found it switched to current instead. Debugging my situation a little showed it was the existence of the package.json. Further debugging showed that even an empty .npmrc or etc behaves the same way–just selects current.

@ericbf
Copy link
Author

ericbf commented Oct 1, 2021

If there is no node property on engines field, how about:

% n auto
       found : /Users/john/Documents/Sandpits/n/issues/692/package.json

  Error: did not find supported versions of node in 'engines' field of package.json

For interest you can check what version is found with n lsr auto.

Something like this would make sense.

It wouldn't really make sense for there to exist an empty .n-node-version or etc, so that can probably be safely ignored (though technically it could be an issue for someone else). This would solve for the package.json with no engines though.

@ericbf
Copy link
Author

ericbf commented Oct 1, 2021

If there is no node property on engines field, how about:

% n auto
       found : /Users/john/Documents/Sandpits/n/issues/692/package.json

  Error: did not find supported versions of node in 'engines' field of package.json

For interest you can check what version is found with n lsr auto.

Something like this would make sense.

It wouldn't really make sense for there to exist an empty .n-node-version or etc, so that can probably be safely ignored (though technically it could be an issue for someone else). This would solve for the package.json with no engines though.

Though it should keep searching (as in monorepos). Ideally it would search the current directory for a valid preference. If none is found, it would search the parent directory and so on.

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Oct 16, 2021
@shadowspawn
Copy link
Collaborator

Released in v8.0.0

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants