Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-09-08 19:51:57 +0300
committerGitHub <noreply@github.com>2022-09-08 19:51:57 +0300
commit926f0adbd71949c905932a241a245b78c85ef643 (patch)
tree3aaf0ee7a1a349d06d372f9503a3eb7fdbe17390 /lib
parent2a8c2fcd124ce7d4b23a6c26552d097c6501ac74 (diff)
feat: remove `npm set-script` (#5456)
BREAKING CHANGE: this removes `npm set-script` Folks should use `npm pkg set` to set the `scripts` field in their `package.json` Closes https://github.com/npm/statusboard/issues/449
Diffstat (limited to 'lib')
-rw-r--r--lib/commands/set-script.js96
-rw-r--r--lib/utils/cmd-list.js1
2 files changed, 0 insertions, 97 deletions
diff --git a/lib/commands/set-script.js b/lib/commands/set-script.js
deleted file mode 100644
index a085f72a3..000000000
--- a/lib/commands/set-script.js
+++ /dev/null
@@ -1,96 +0,0 @@
-const { resolve } = require('path')
-const rpj = require('read-package-json-fast')
-const PackageJson = require('@npmcli/package-json')
-const log = require('../utils/log-shim')
-
-const BaseCommand = require('../base-command.js')
-class SetScript extends BaseCommand {
- static description = 'Set tasks in the scripts section of package.json, deprecated'
- static params = ['workspace', 'workspaces', 'include-workspace-root']
- static name = 'set-script'
- static usage = ['[<script>] [<command>]']
- static ignoreImplicitWorkspace = false
-
- async completion (opts) {
- const argv = opts.conf.argv.remain
- if (argv.length === 2) {
- // find the script name
- const json = resolve(this.npm.localPrefix, 'package.json')
- const { scripts = {} } = await rpj(json).catch(er => ({}))
- return Object.keys(scripts)
- }
- }
-
- validate (args) {
- if (process.env.npm_lifecycle_event === 'postinstall') {
- throw new Error('Scripts can’t set from the postinstall script')
- }
-
- // Parse arguments
- if (args.length !== 2) {
- throw new Error(`Expected 2 arguments: got ${args.length}`)
- }
- }
-
- async exec (args) {
- this.validate(args)
- log.warn('set-script',
- 'set-script is deprecated, use `npm pkg set scripts.scriptname="cmd" instead.')
- const warn = await this.doSetScript(this.npm.localPrefix, args[0], args[1])
- if (warn) {
- log.warn('set-script', `Script "${args[0]}" was overwritten`)
- }
- }
-
- async execWorkspaces (args, filters) {
- this.validate(args)
- await this.setWorkspaces(filters)
-
- for (const [name, path] of this.workspaces) {
- try {
- const warn = await this.doSetScript(path, args[0], args[1])
- if (warn) {
- log.warn('set-script', `Script "${args[0]}" was overwritten`)
- log.warn(` in workspace: ${name}`)
- log.warn(` at location: ${path}`)
- }
- } catch (err) {
- log.error('set-script', err.message)
- log.error(` in workspace: ${name}`)
- log.error(` at location: ${path}`)
- process.exitCode = 1
- }
- }
- }
-
- // returns a Boolean that will be true if
- // the requested script was overwritten
- // and false if it was set as a new script
- async doSetScript (path, name, value) {
- let warn = false
-
- const pkgJson = await PackageJson.load(path)
- const { scripts } = pkgJson.content
-
- const overwriting =
- scripts
- && scripts[name]
- && scripts[name] !== value
-
- if (overwriting) {
- warn = true
- }
-
- pkgJson.update({
- scripts: {
- ...scripts,
- [name]: value,
- },
- })
-
- await pkgJson.save()
-
- return warn
- }
-}
-module.exports = SetScript
diff --git a/lib/utils/cmd-list.js b/lib/utils/cmd-list.js
index 4dca7df2d..d74f9878f 100644
--- a/lib/utils/cmd-list.js
+++ b/lib/utils/cmd-list.js
@@ -121,7 +121,6 @@ const cmdList = [
'run-script',
'search',
'set',
- 'set-script',
'shrinkwrap',
'star',
'stars',