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

chore: set repository.directory to all sub package.json files #830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ybiquitous
Copy link

Hi there,

I've created this PR to make npm commands such as npm repo more useful.
For example, all packages in the Babel repository have that field (babel/babel#11625).

This change sets the repository.directory field to all package.json files except for package.json at the repository root.

See also https://docs.npmjs.com/cli/v7/configuring-npm/package-json#repository

How to create this change

I've created the following Bash script for this PR:

#!/usr/bin/env bash
set -eu -o pipefail

files=$(git ls-files | grep package.json)
for file in $files; do
  echo "Setting repository.directory to ${file} ..."
  dir=$(dirname $file)
  if [[ $dir != "." ]]; then
    (cd "$dir" && npm pkg set repository.directory="$dir")
  fi
done

In addition, I've used the command npm-package-json-lint to verify this change as below:

.npmpackagejsonlintrc.json:

{
  "rules": {
    "require-repository-directory": "error"
  }
}

Run:

$ npx npm-package-json-lint .

./package.json
✖ require-repository-directory - node: repository - repository object missing directory property
1 error
0 warnings

Totals
1 error
0 warnings
0 files ignored

Note: package.json at the top should not have directory, so the error above is expected.


I would appreciate it if you could check this PR.
If this PR is undesirable, please feel free to close it. Thank you. 😃

This change sets the `repository.directory` field to all `package.json` files
except for `package.json` at the repository root.

See also <https://docs.npmjs.com/cli/v7/configuring-npm/package-json#repository>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant