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

v3 not reading configuration from package.json #79

Closed
ntwb opened this issue May 6, 2018 · 10 comments
Closed

v3 not reading configuration from package.json #79

ntwb opened this issue May 6, 2018 · 10 comments
Assignees
Labels
enhancement 👑 New feature or request
Milestone

Comments

@ntwb
Copy link
Contributor

ntwb commented May 6, 2018

  • A little info about your environment
    • npm-package-json-lint version - v3 via npx -p npm-package-json-lint@beta -c "npmPkgJsonLint ."
    • npm version - 6.0.0
    • node version - 8.11.1
  • The output from npm-package-json-lint
  • What you expected to happen
  • The steps to reproduce the problem

In a .npmpackagejsonlintrc.json file in the root of my repo I had:

{
	"rules": {
		"require-publishConfig": "error",
		"valid-values-author": ["error", [
			"My Name"
		]]
	}
}

The output from the above:

❯ npx -p npm-package-json-lint@beta -c "npmPkgJsonLint . -c .npmpackagejsonlintrc.json"
npx: installed 81 in 4.136s

./package.json
✖ require-publishConfig - node: publishConfig - publishConfig is required
1 error
0 warnings

./packages/package1/package.json
✖ require-publishConfig - node: publishConfig - publishConfig is required
✖ valid-values-author - node: author - Invalid value for author
2 errors
0 warnings

./packages/package2/package.json
✖ require-publishConfig - node: publishConfig - publishConfig is required
✖ valid-values-author - node: author - Invalid value for author
2 errors
0 warnings

I then copied the above (and deleted the .npmpackagejsonlintrc.json file) to my package.json:

	"npmPackageJsonLintConfig": {
		"rules": {
			"require-publishConfig": "error",
			"valid-values-author": ["error", [
				"My Name"
			]]
		}
	},

When I run npx -p npm-package-json-lint@beta -c "npmPkgJsonLint ." I get the following result:

npx: installed 81 in 4.315s
No npm-package-json-lint configuration found.
./packages/package1/package.json

I expected using the above command that npmPkgJsonLint would load the config that is now in my package.json file.

@tclindner
Copy link
Owner

Hi @ntwb - thank you for the detailed information and for helping test the beta! Can you confirm that you moved the config to your package.json at the root of your repo (./package.json)? If so, I think I made a bad assumption. Right now config in package json files don't recursively search up the directory tree. I'll work on a fix and get an update pushed.

P.S. I'm getting really close to completely the documentation for v3. v3 will release after that!

@ntwb
Copy link
Contributor Author

ntwb commented May 6, 2018

Indeed I moved it to the root repo package.json file, but I am also running npmPkgJsonLint from the root of the repo so there should be no need to "recursively search up the directory tree" for a config in the package.json file as it is the same folder where the cli is being executed

@ntwb
Copy link
Contributor Author

ntwb commented May 6, 2018

Hmmm, I just created a test repo, its a single file in a folder of its own:

{
  "name": "npj79",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
	"npmPackageJsonLintConfig": {
		"rules": {
			"require-publishConfig": "error",
			"valid-values-author": ["error", [
				"My Name"
			]]
    }
  }
}

And running npx -p npm-package-json-lint@beta -c "npmPkgJsonLint ." works as expected

@ntwb
Copy link
Contributor Author

ntwb commented May 6, 2018

Ahhh, I see what is happening, indeed it is what you suspected, in "If so, I think I made a bad assumption. Right now config in package json files don't recursively search up the directory tree."

https://www.npmjs.com/package/cosmiconfig is great at "recursively search up the directory tree" if you're interested

@tclindner
Copy link
Owner

👍 Do you know if cosmicconfig supports config extension? I would like to keep the extends property, if possible.

I think the change to fix this issue should be pretty quick. I'm currently recursively scanning up the project hierarchy, but I'm not checking the npmPackageJsonLintConfig property except in the initial directory of the actively linted package.json file 🤦‍♂️ .

@ntwb
Copy link
Contributor Author

ntwb commented May 6, 2018

I believe it does, we use cosmiconfig with stylelint and stylelint supports extends, i'll have a look around and see if I can find some docs on that

@ntwb
Copy link
Contributor Author

ntwb commented May 6, 2018

It doesn't, see cosmiconfig/cosmiconfig#40 which is a follow up to cosmiconfig/cosmiconfig#1

As noted in 1 above, https://github.com/chrisblossom/ex-config was created to handle extends with cosmiconfig

This all looks like it would involve much more refactoring on your behalf, I'll leave it with you

@tclindner tclindner added the enhancement 👑 New feature or request label May 9, 2018
@tclindner tclindner self-assigned this May 9, 2018
@tclindner tclindner added this to the v3.0.0 milestone May 9, 2018
@tclindner
Copy link
Owner

Hey @ntwb - a new beta version has been published. Please let me know if it is working for you. If it is, I'll publish v3 tomorrow!

@ntwb
Copy link
Contributor Author

ntwb commented May 13, 2018

@tclindner I've just updated to v3 and I'm still seeing this issue.

In my PR I've got a npmPackageJsonLintConfig config in the root package.json (src)

When I run any of these commands they all result in the same error:
./node_modules/.bin/npmPkgJsonLint .
./node_modules/.bin/npmPkgJsonLint packages/
npx -p npm-package-json-lint -c "npmPkgJsonLint ."
npx -p npm-package-json-lint -c "npmPkgJsonLint packages/"

Error:

No npm-package-json-lint configuration found.
./packages/a11y/package.json

I currently have a .npmpackagejsonlintrc.json file in the root of the repo (src) and if I pass that into any of the commands above using -c .npmpackagejsonlintrc.json it works as expected.

I plan on removing the .npmpackagejsonlintrc.json file from that PR and rlying on the config in the package.json file.

Any thoughts on if I may have missed something in updating to v3 maybe?

@tclindner
Copy link
Owner

Hey @ntwb I'm sorry you are still experiencing this issue. I unfortunately didn't have time to take a look at this today. I will take a look at it tomorrow and get back to you. I hope you had a nice weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 👑 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants