Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[RRFC] Top-level command to manage package.json #398

Closed
ruyadorno opened this issue Jun 11, 2021 · 4 comments
Closed

[RRFC] Top-level command to manage package.json #398

ruyadorno opened this issue Jun 11, 2021 · 4 comments

Comments

@ruyadorno
Copy link
Contributor

Motivation ("The Why")

Some users prefer managing their package.json using npm cli comands rather than manually editing a JSON file.

As of today, some of the npm cli commands already handle the automated management of the package.json file, such as npm install adding / updating dependency declarations, npm version bumping the version value, or in the case of npm set-script a top-level command that serves specifically the purpose of managing "scripts" data in the package.json file.

Example

$ cat package.json
{
  "name": "a",
  "version": "1.0.0"
}

$ npm install abbrev

added 1 package, and audited 2 packages in 493ms

found 0 vulnerabilities

$ cat package.json
{
  "name": "a",
  "version": "1.0.0",
  "dependencies": {
    "abbrev": "^1.1.1"
  }
}

$ npm set-script test echo
{
  "name": "a",
  "version": "1.0.0",
  "dependencies": {
    "abbrev": "^1.1.1"
  },
  "scripts": {
    "test": "echo"
  }
}

How

Introduce a new top-level command npm pkg that would help managing the remaining package.json fields and centralize this management under a single command.

Current Behaviour

Taking the current npm set-script type of behavior:

$ npm set-script lint eslint

Desired Behaviour

Migrate set-script under a single pkg top-level command and expand it to make it possible to manage the reminder of package.json fields.

$ npm pkg set script --key=lint --value=eslint

References

@ruyadorno ruyadorno added the Agenda will be discussed at the Open RFC call label Jun 11, 2021
@isaacs
Copy link
Contributor

isaacs commented Jun 16, 2021

Suggestion:

npm pkg set [key]=[value] (key=value ...)
npm pkg get [key] (key ...)
npm pkg delete [key]

Examples:

$ npm pkg set scripts.lint=eslint
$ npm pkg get scripts
{
  "lint": "eslint"
}
$ npm pkg get scripts.lint
"eslint"
$ npm pkg set scripts.lint.eslint.foo=bar
error: "scripts.lint" exists and is not an object
$ npm pkg delete scripts
$ npm pkg set scripts.lint.eslint.foo=bar
$ npm pkg get scripts
{
  "lint": {
    "eslint": {
      "foo": "bar"
    }
  }
}

@isaacs
Copy link
Contributor

isaacs commented Jun 23, 2021

Other thoughts:

# replace "tap" object with {"timeout":60}
npm pkg delete tap
npm pkg set tap.timeout=60 # <-- how do we know this is `60` and not `"60"`?

Look into userland jq editing syntax.

How do add to an array, or remove an entry from an array?

@ljharb
Copy link
Contributor

ljharb commented Jun 23, 2021

[] to add to the end, [n] to target the nth

@ruyadorno
Copy link
Contributor Author

#402

@darcyclarke darcyclarke removed the Agenda will be discussed at the Open RFC call label Jul 21, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants