Skip to content

feat: use run by default and run-script as the alias #8265

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

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/lib/content/commands/npm-exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ project.

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [npm test](/commands/npm-test)
* [npm start](/commands/npm-start)
Expand Down
4 changes: 2 additions & 2 deletions docs/lib/content/commands/npm-restart.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: Restart a package

### Description

This restarts a project. It is equivalent to running `npm run-script
This restarts a project. It is equivalent to running `npm run
restart`.

If the current project has a `"restart"` script specified in
Expand Down Expand Up @@ -38,7 +38,7 @@ If it does _not_ have a `"restart"` script specified, but it does have

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [npm test](/commands/npm-test)
* [npm start](/commands/npm-start)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: npm-run-script
title: npm-run
section: 1
description: Run arbitrary package scripts
---
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/content/commands/npm-shrinkwrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ design and purpose of package locks in npm, see
### See Also

* [npm install](/commands/npm-install)
* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [package.json](/configuring-npm/package-json)
* [package-lock.json](/configuring-npm/package-lock-json)
Expand Down
4 changes: 2 additions & 2 deletions docs/lib/content/commands/npm-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ the file specified in a package's `"main"` attribute when evoking with
`node .`

As of [`[email protected]`](https://blog.npmjs.org/post/98131109725/npm-2-0-0), you can
use custom arguments when executing scripts. Refer to [`npm run-script`](/commands/npm-run-script) for more details.
use custom arguments when executing scripts. Refer to [`npm run`](/commands/npm-run) for more details.

### Example

Expand Down Expand Up @@ -49,7 +49,7 @@ npm start

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [npm test](/commands/npm-test)
* [npm restart](/commands/npm-restart)
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/content/commands/npm-stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ npm stop

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [npm test](/commands/npm-test)
* [npm start](/commands/npm-start)
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/content/commands/npm-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ npm test

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [npm start](/commands/npm-start)
* [npm restart](/commands/npm-restart)
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/content/commands/npm-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ deletes the `build/temp` directory.
### See Also

* [npm init](/commands/npm-init)
* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [package.json](/configuring-npm/package-json)
* [config](/using-npm/config)
2 changes: 1 addition & 1 deletion docs/lib/content/commands/npx.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ This resulted in some shifts in its functionality:

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [npm scripts](/using-npm/scripts)
* [npm test](/commands/npm-test)
* [npm start](/commands/npm-start)
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/content/configuring-npm/package-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ file in the `bin` field, so it is available to run by `name` or `name.cmd` (on
Windows PowerShell). When this package is installed as a dependency in another
package, the file will be linked where it will be available to that package
either directly by `npm exec` or by name in other scripts when invoking them
via `npm run-script`.
via `npm run`.


For example, myapp could have this:
Expand Down
4 changes: 2 additions & 2 deletions docs/lib/content/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
- title: npm root
url: /commands/npm-root
description: Display npm root
- title: npm run-script
url: /commands/npm-run-script
- title: npm run
url: /commands/npm-run
description: Run arbitrary package scripts
- title: npm sbom
url: /commands/npm-sbom
Expand Down
6 changes: 3 additions & 3 deletions docs/lib/content/using-npm/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: How npm handles the "scripts" field
The `"scripts"` property of your `package.json` file supports a number
of built-in scripts and their preset life cycle events as well as
arbitrary scripts. These all can be executed by running
`npm run-script <stage>` or `npm run <stage>` for short. *Pre* and *post*
`npm run <stage>` or `npm run <stage>` for short. *Pre* and *post*
commands with matching names will be run for those as well (e.g. `premyscript`,
`myscript`, `postmyscript`). Scripts from dependencies can be run with
`npm explore <pkg> -- npm run <stage>`.
Expand Down Expand Up @@ -180,7 +180,7 @@ If there is a `restart` script defined, these events are run, otherwise
* `restart`
* `postrestart`

#### [`npm run <user defined>`](/commands/npm-run-script)
#### [`npm run <user defined>`](/commands/npm-run)

* `pre<user-defined>`
* `<user-defined>`
Expand Down Expand Up @@ -358,7 +358,7 @@ file.

### See Also

* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [package.json](/configuring-npm/package-json)
* [npm developers](/using-npm/developers)
* [npm install](/commands/npm-install)
2 changes: 1 addition & 1 deletion docs/lib/content/using-npm/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ npm run test --workspaces --if-present

* [npm install](/commands/npm-install)
* [npm publish](/commands/npm-publish)
* [npm run-script](/commands/npm-run-script)
* [npm run](/commands/npm-run)
* [config](/using-npm/config)

2 changes: 1 addition & 1 deletion lib/commands/restart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LifecycleCmd = require('../lifecycle-cmd.js')

// This ends up calling run-script(['restart', ...args])
// This ends up calling run(['restart', ...args])
class Restart extends LifecycleCmd {
static description = 'Restart a package'
static name = 'restart'
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/run-script.js → lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RunScript extends BaseCommand {
'script-shell',
]

static name = 'run-script'
static name = 'run'
static usage = ['<command> [-- <args>]']
static workspaces = true
static ignoreImplicitWorkspace = false
Expand Down Expand Up @@ -201,7 +201,7 @@ class RunScript extends BaseCommand {
}

if (runScripts.length) {
const via = `via \`${blue('npm run-script')}\`:`
const via = `via \`${blue('npm run')}\`:`
if (!cmds.length) {
output.standard(`${title('Scripts')} available ${pkgId} ${via}`)
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LifecycleCmd = require('../lifecycle-cmd.js')

// This ends up calling run-script(['start', ...args])
// This ends up calling run(['start', ...args])
class Start extends LifecycleCmd {
static description = 'Start a package'
static name = 'start'
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/stop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LifecycleCmd = require('../lifecycle-cmd.js')

// This ends up calling run-script(['stop', ...args])
// This ends up calling run(['stop', ...args])
class Stop extends LifecycleCmd {
static description = 'Stop a package'
static name = 'stop'
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LifecycleCmd = require('../lifecycle-cmd.js')

// This ends up calling run-script(['test', ...args])
// This ends up calling run(['test', ...args])
class Test extends LifecycleCmd {
static description = 'Test a package'
static name = 'test'
Expand Down
4 changes: 2 additions & 2 deletions lib/lifecycle-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class LifecycleCmd extends BaseCommand {
static ignoreImplicitWorkspace = false

async exec (args) {
return this.npm.exec('run-script', [this.constructor.name, ...args])
return this.npm.exec('run', [this.constructor.name, ...args])
}

async execWorkspaces (args) {
return this.npm.exec('run-script', [this.constructor.name, ...args])
return this.npm.exec('run', [this.constructor.name, ...args])
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Npm {
const command = new Command(this)

// since 'test', 'start', 'stop', etc. commands re-enter this function
// to call the run-script command, we need to only set it one time.
// to call the run command, we need to only set it one time.
if (!this.#command) {
this.#command = command
process.env.npm_command = this.command
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/cmd-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const commands = [
'repo',
'restart',
'root',
'run-script',
'run',
'sbom',
'search',
'set',
Expand Down Expand Up @@ -105,7 +105,7 @@ const aliases = {
t: 'test',
ddp: 'dedupe',
v: 'view',
run: 'run-script',
'run-script': 'run',
'clean-install': 'ci',
'clean-install-test': 'install-ci-test',
x: 'exec',
Expand All @@ -132,9 +132,9 @@ const aliases = {
'dist-tags': 'dist-tag',
upgrade: 'update',
udpate: 'update',
rum: 'run-script',
rum: 'run',
sit: 'install-ci-test',
urn: 'run-script',
urn: 'run',
ogr: 'org',
'add-user': 'adduser',
}
Expand Down
9 changes: 4 additions & 5 deletions smoke-tests/tap-snapshots/test/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ All commands:
help-search, init, install, install-ci-test, install-test,
link, ll, login, logout, ls, org, outdated, owner, pack,
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
repo, restart, root, run, sbom, search, set, shrinkwrap,
star, stars, start, stop, team, test, token, undeprecate,
uninstall, unpublish, unstar, update, version, view, whoami

Specify configs in the ini-formatted file:
{NPM}/{TESTDIR}/home/.npmrc
Expand Down Expand Up @@ -355,7 +354,7 @@ exports[`test/index.js TAP basic npm prefix > should have expected prefix output
{NPM}/{TESTDIR}/project
`

exports[`test/index.js TAP basic npm run-script > should have expected run-script output 1`] = `
exports[`test/index.js TAP basic npm run > should have expected run output 1`] = `
> [email protected] hello
> echo Hello

Expand Down
6 changes: 3 additions & 3 deletions smoke-tests/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ t.test('basic', async t => {
)
})

await t.test('npm run-script', async t => {
const cmdRes = await npm('run', 'hello')
await t.test('npm run', async t => {
const cmdRes = await npm('run-script', 'hello')

t.matchSnapshot(cmdRes.stdout, 'should have expected run-script output')
t.matchSnapshot(cmdRes.stdout, 'should have expected run output')
})

await t.test('npm prefix', async t => {
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test/lib/commands/completion.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Array [
repo
restart
root
run-script
run
sbom
search
set
Expand Down Expand Up @@ -135,7 +135,7 @@ Array [
t
ddp
v
run
run-script
clean-install
clean-install-test
x
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/lib/commands/publish.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Object {
"man/man1/npm-repo.1",
"man/man1/npm-restart.1",
"man/man1/npm-root.1",
"man/man1/npm-run-script.1",
"man/man1/npm-run.1",
"man/man1/npm-sbom.1",
"man/man1/npm-search.1",
"man/man1/npm-shrinkwrap.1",
Expand Down
Loading
Loading