Skip to content

Commit

Permalink
feat: add run-script workspaces
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ruyadorno committed Mar 15, 2021
1 parent 08673c3 commit dfbdbb9
Show file tree
Hide file tree
Showing 35 changed files with 782 additions and 24 deletions.
2 changes: 2 additions & 0 deletions docs/content/commands/npm-adduser.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ npm adduser [--registry=url] [--scope=@orgname] [--always-auth] [--auth-type=leg
aliases: login, add-user
```

Note: This command is unaware of workspaces.

### Description

Create or verify a user named `<username>` in the specified registry, and
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Display npm bin folder
npm bin [-g|--global]
```

Note: This command is unaware of workspaces.

### Description

Print the folder where npm will install executables.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ aliases: npm cache clear, npm cache rm
npm cache verify
```

Note: This command is unaware of workspaces.

### Description

Used to add, list, or clean the npm cache folder.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Tab Completion for npm
source <(npm completion)
```

Note: This command is unaware of workspaces.

### Description

Enables tab-completion in all npm commands.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ npm get [<key> [<key> ...]]
alias: c
```
Note: This command is unaware of workspaces.
### Description
npm gets its config settings from the command line, environment
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-deprecate.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Deprecate a version of a package
npm deprecate <pkg>[@<version range>] <message>
```

Note: This command is unaware of workspaces.

### Description

This command will update the npm registry entry for a package, providing a
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-doctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Check your npm environment
npm doctor
```

Note: This command is unaware of workspaces.

### Description

`npm doctor` runs a set of checks to ensure that your npm installation has
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Edit an installed package
npm edit <pkg>
```

Note: This command is unaware of workspaces.

### Description

Selects a dependency in the current project and opens the package folder in
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-explore.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Browse an installed package
npm explore <pkg> [ -- <command>]
```

Note: This command is unaware of workspaces.

### Description

Spawn a subshell in the directory of the installed package specified.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-help-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Search npm help documentation
npm help-search <text>
```

Note: This command is unaware of workspaces.

### Description

This command will search the npm markdown documentation files for the terms
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Get help on npm
npm help <term> [<terms..>]
```

Note: This command is unaware of workspaces.

### Description

If supplied a topic, then show the appropriate documentation page.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ npm hook update <id> <url> [secret]
npm hook rm <id>
```

Note: This command is unaware of workspaces.

### Description

Allows you to manage [npm
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-logout.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Log out of the registry
npm logout [--registry=<url>] [--scope=<@scope>]
```

Note: This command is unaware of workspaces.

### Description

When logged into a registry that supports token-based authentication, tell
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-org.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ npm org rm <orgname> <username>
npm org ls <orgname> [<username>]
```

Note: This command is unaware of workspaces.

### Example

Add a new developer to an org:
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ npm owner ls [<@scope>/]<pkg>
aliases: author
```

Note: This command is unaware of workspaces.

### Description

Manage ownership of published packages.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-ping.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Ping npm registry
npm ping [--registry <registry>]
```

Note: This command is unaware of workspaces.

### Description

Ping the configured or given npm registry and verify authentication.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-prefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Display prefix
npm prefix [-g]
```

Note: This command is unaware of workspaces.

### Description

Print the local prefix to standard output. This is the closest parent directory
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ npm profile enable-2fa [auth-and-writes|auth-only]
npm profile disable-2fa
```

Note: This command is unaware of workspaces.

### Description

Change your profile information on the registry. Note that this command
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms .
aliases: s, se, find
```

Note: This command is unaware of workspaces.

### Description

Search the registry for packages matching the search terms. `npm search`
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-shrinkwrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Lock down dependency versions for publication
npm shrinkwrap
```

Note: This command is unaware of workspaces.

### Description

This command repurposes `package-lock.json` into a publishable
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-star.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Mark your favorite packages
npm star [<pkg>...]
```

Note: This command is unaware of workspaces.

### Description

"Starring" a package means that you have some interest in it. It's
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-stars.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ description: View packages marked as favorites
npm stars [<user>]
```

Note: This command is unaware of workspaces.

### Description

If you have starred a lot of neat things and want to find them again
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-team.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ npm team rm <scope:team> <user>
npm team ls <scope>|<scope:team>
```

Note: This command is unaware of workspaces.

### Description

Used to manage teams in organizations, and change team memberships. Does not
Expand Down
4 changes: 3 additions & 1 deletion docs/content/commands/npm-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ description: Manage your authentication tokens
npm token list [--json|--parseable]
npm token create [--read-only] [--cidr=1.1.1.1/24,2.2.2.2/16]
npm token revoke <id|token>
```
```

Note: This command is unaware of workspaces.

### Description

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-unstar.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Remove an item from your favorite packages
npm unstar [<pkg>...]
```

Note: This command is unaware of workspaces.

### Description

"Unstarring" a package is the opposite of [`npm star`](/commands/npm-star),
Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-whoami.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description: Display npm username
npm whoami [--registry <registry>]
```

Note: This command is unaware of workspaces.

### Description

Print the `username` config to standard output.
Expand Down
6 changes: 6 additions & 0 deletions lib/base-command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Base class for npm.commands[cmd]
const npmlog = require('npmlog')
const usageUtil = require('./utils/usage.js')

class BaseCommand {
Expand Down Expand Up @@ -34,5 +35,10 @@ class BaseCommand {
code: 'EUSAGE',
})
}

execWorkspaces (args, filters, cb) {
npmlog.warn('This command does not support workspaces.')
cb()
}
}
module.exports = BaseCommand
9 changes: 9 additions & 0 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,18 @@ const npm = module.exports = new class extends EventEmitter {
})
}

const workspacesEnabled = this.config.get('workspaces')
const workspacesFilters = this.config.get('workspace')
const filterByWorkspaces = workspacesEnabled || workspacesFilters.length > 0

if (this.config.get('usage')) {
console.log(impl.usage)
cb()
} else if (filterByWorkspaces) {
impl.execWorkspaces(args, this.config.get('workspace'), er => {
process.emit('timeEnd', `command:${cmd}`)
cb(er)
})
} else {
impl.exec(args, er => {
process.emit('timeEnd', `command:${cmd}`)
Expand Down
Loading

0 comments on commit dfbdbb9

Please sign in to comment.