Skip to content

Commit ec9f675

Browse files
committed
feat: add run-script workspaces
- Add workspaces-related configs: - workspace: list of workspaces names/dir to filter for - workspaces: boolean value to enable/disable workspaces awareness - adds the proposed note in the docs of each of the commands that are not affected by these configs. - Add workspaces support to `npm run-script` - add ability to serially run lifecycle scripts in workspaces - add ability to list scripts for all workspaces - add colors to `npm run` (no args) output Relates to: npm/rfcs#117 Fixes: npm/statusboard#276 Fixes: npm/statusboard#283 Fixes: npm/statusboard#284 Fixes: npm/statusboard#285 Fixes: npm/statusboard#286
1 parent 08673c3 commit ec9f675

35 files changed

+781
-24
lines changed

docs/content/commands/npm-adduser.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ npm adduser [--registry=url] [--scope=@orgname] [--always-auth] [--auth-type=leg
1212
aliases: login, add-user
1313
```
1414

15+
Note: This command is unaware of workspaces.
16+
1517
### Description
1618

1719
Create or verify a user named `<username>` in the specified registry, and

docs/content/commands/npm-bin.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Display npm bin folder
1010
npm bin [-g|--global]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Print the folder where npm will install executables.

docs/content/commands/npm-cache.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ aliases: npm cache clear, npm cache rm
1818
npm cache verify
1919
```
2020

21+
Note: This command is unaware of workspaces.
22+
2123
### Description
2224

2325
Used to add, list, or clean the npm cache folder.

docs/content/commands/npm-completion.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Tab Completion for npm
1010
source <(npm completion)
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Enables tab-completion in all npm commands.

docs/content/commands/npm-config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ npm get [<key> [<key> ...]]
1818
alias: c
1919
```
2020
21+
Note: This command is unaware of workspaces.
22+
2123
### Description
2224
2325
npm gets its config settings from the command line, environment

docs/content/commands/npm-deprecate.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Deprecate a version of a package
1010
npm deprecate <pkg>[@<version range>] <message>
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
This command will update the npm registry entry for a package, providing a

docs/content/commands/npm-doctor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Check your npm environment
1010
npm doctor
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
`npm doctor` runs a set of checks to ensure that your npm installation has

docs/content/commands/npm-edit.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Edit an installed package
1010
npm edit <pkg>
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Selects a dependency in the current project and opens the package folder in

docs/content/commands/npm-explore.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Browse an installed package
1010
npm explore <pkg> [ -- <command>]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Spawn a subshell in the directory of the installed package specified.

docs/content/commands/npm-help-search.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Search npm help documentation
1010
npm help-search <text>
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
This command will search the npm markdown documentation files for the terms

docs/content/commands/npm-help.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Get help on npm
1010
npm help <term> [<terms..>]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
If supplied a topic, then show the appropriate documentation page.

docs/content/commands/npm-hook.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ npm hook update <id> <url> [secret]
1313
npm hook rm <id>
1414
```
1515

16+
Note: This command is unaware of workspaces.
17+
1618
### Description
1719

1820
Allows you to manage [npm

docs/content/commands/npm-logout.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Log out of the registry
1010
npm logout [--registry=<url>] [--scope=<@scope>]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
When logged into a registry that supports token-based authentication, tell

docs/content/commands/npm-org.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ npm org rm <orgname> <username>
1212
npm org ls <orgname> [<username>]
1313
```
1414

15+
Note: This command is unaware of workspaces.
16+
1517
### Example
1618

1719
Add a new developer to an org:

docs/content/commands/npm-owner.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ npm owner ls [<@scope>/]<pkg>
1414
aliases: author
1515
```
1616

17+
Note: This command is unaware of workspaces.
18+
1719
### Description
1820

1921
Manage ownership of published packages.

docs/content/commands/npm-ping.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Ping npm registry
1010
npm ping [--registry <registry>]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Ping the configured or given npm registry and verify authentication.

docs/content/commands/npm-prefix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Display prefix
1010
npm prefix [-g]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Print the local prefix to standard output. This is the closest parent directory

docs/content/commands/npm-profile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ npm profile enable-2fa [auth-and-writes|auth-only]
1414
npm profile disable-2fa
1515
```
1616

17+
Note: This command is unaware of workspaces.
18+
1719
### Description
1820

1921
Change your profile information on the registry. Note that this command

docs/content/commands/npm-search.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms .
1212
aliases: s, se, find
1313
```
1414

15+
Note: This command is unaware of workspaces.
16+
1517
### Description
1618

1719
Search the registry for packages matching the search terms. `npm search`

docs/content/commands/npm-shrinkwrap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Lock down dependency versions for publication
1010
npm shrinkwrap
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
This command repurposes `package-lock.json` into a publishable

docs/content/commands/npm-star.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Mark your favorite packages
1010
npm star [<pkg>...]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
"Starring" a package means that you have some interest in it. It's

docs/content/commands/npm-stars.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ description: View packages marked as favorites
99
npm stars [<user>]
1010
```
1111

12+
Note: This command is unaware of workspaces.
13+
1214
### Description
1315

1416
If you have starred a lot of neat things and want to find them again

docs/content/commands/npm-team.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ npm team rm <scope:team> <user>
1616
npm team ls <scope>|<scope:team>
1717
```
1818

19+
Note: This command is unaware of workspaces.
20+
1921
### Description
2022

2123
Used to manage teams in organizations, and change team memberships. Does not

docs/content/commands/npm-token.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ description: Manage your authentication tokens
99
npm token list [--json|--parseable]
1010
npm token create [--read-only] [--cidr=1.1.1.1/24,2.2.2.2/16]
1111
npm token revoke <id|token>
12-
```
12+
```
13+
14+
Note: This command is unaware of workspaces.
1315

1416
### Description
1517

docs/content/commands/npm-unstar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Remove an item from your favorite packages
1010
npm unstar [<pkg>...]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
"Unstarring" a package is the opposite of [`npm star`](/commands/npm-star),

docs/content/commands/npm-whoami.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: Display npm username
1010
npm whoami [--registry <registry>]
1111
```
1212

13+
Note: This command is unaware of workspaces.
14+
1315
### Description
1416

1517
Print the `username` config to standard output.

lib/base-command.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Base class for npm.commands[cmd]
2+
const npmlog = require('npmlog')
23
const usageUtil = require('./utils/usage.js')
34

45
class BaseCommand {
@@ -34,5 +35,10 @@ class BaseCommand {
3435
code: 'EUSAGE',
3536
})
3637
}
38+
39+
execWorkspaces (args, filters, cb) {
40+
npmlog.warn('This command does not support workspaces.')
41+
cb()
42+
}
3743
}
3844
module.exports = BaseCommand

lib/npm.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,18 @@ const npm = module.exports = new class extends EventEmitter {
105105
})
106106
}
107107

108+
const workspacesEnabled = this.config.get('workspaces')
109+
const workspacesFilters = this.config.get('workspace')
110+
const filterByWorkspaces = workspacesEnabled || workspacesFilters.length > 0
111+
108112
if (this.config.get('usage')) {
109113
console.log(impl.usage)
110114
cb()
115+
} else if (filterByWorkspaces) {
116+
impl.execWorkspaces(args, this.config.get('workspace'), er => {
117+
process.emit('timeEnd', `command:${cmd}`)
118+
cb(er)
119+
})
111120
} else {
112121
impl.exec(args, er => {
113122
process.emit('timeEnd', `command:${cmd}`)

0 commit comments

Comments
 (0)