Skip to content
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

Gar/test mocks #4645

Merged
merged 6 commits into from
Apr 4, 2022
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: 2 additions & 0 deletions docs/content/commands/npm-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
26 changes: 5 additions & 21 deletions docs/content/commands/npm-dedupe.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ result in new modules being installed.

Using `npm find-dupes` will run the command in `--dry-run` mode.

Note that by default `npm dedupe` will not update the semver values of direct
dependencies in your project `package.json`, if you want to also update
values in `package.json` you can run: `npm dedupe --save` (or add the
`save=true` option to a [configuration file](/configuring-npm/npmrc)
to make that the default behavior).
Note: `npm dedupe` will never update the semver values of direct
dependencies in your project `package.json`, if you want to update
values in `package.json` you can run: `npm update --save` instead.

### Configuration

Expand Down Expand Up @@ -158,22 +156,6 @@ This configuration does not affect `npm ci`.
<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.

When used with the `npm rm` command, removes the dependency from
`package.json`.

Will also prevent writing to `package-lock.json` if set to `false`.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### `omit`

* Default: 'dev' if the `NODE_ENV` environment variable is set to
Expand Down Expand Up @@ -323,6 +305,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-dist-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-find-dupes.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
5 changes: 3 additions & 2 deletions docs/content/commands/npm-install-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ takes exactly the same arguments as `npm install`.
<!-- see lib/utils/config/definitions.js -->
#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Default: `true` unless when using `npm update` where it defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.
Expand Down Expand Up @@ -315,6 +314,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
5 changes: 3 additions & 2 deletions docs/content/commands/npm-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ These are some of the most common options related to installation.
<!-- see lib/utils/config/definitions.js -->
#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Default: `true` unless when using `npm update` where it defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.
Expand Down Expand Up @@ -705,6 +704,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
5 changes: 3 additions & 2 deletions docs/content/commands/npm-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ workspace(s).
<!-- see lib/utils/config/definitions.js -->
#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Default: `true` unless when using `npm update` where it defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.
Expand Down Expand Up @@ -383,6 +382,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-prune.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-rebuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-run-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-set-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
5 changes: 3 additions & 2 deletions docs/content/commands/npm-uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ npm uninstall lodash --no-save
<!-- see lib/utils/config/definitions.js -->
#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Default: `true` unless when using `npm update` where it defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.
Expand Down Expand Up @@ -141,6 +140,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
5 changes: 3 additions & 2 deletions docs/content/commands/npm-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ be _downgraded_.
<!-- see lib/utils/config/definitions.js -->
#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Default: `true` unless when using `npm update` where it defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.
Expand Down Expand Up @@ -433,6 +432,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
2 changes: 2 additions & 0 deletions docs/content/commands/npm-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
5 changes: 3 additions & 2 deletions docs/content/using-npm/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ When false, specifying individual workspaces via the `workspace` config, or
all workspaces via the `workspaces` flag, will cause npm to operate only on
the specified workspaces, and not on the root project.

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down Expand Up @@ -1343,8 +1345,7 @@ The base URL of the npm registry.

#### `save`

* Default: `true` unless when using `npm update` or `npm dedupe` where it
defaults to `false`
* Default: `true` unless when using `npm update` where it defaults to `false`
* Type: Boolean

Save installed packages to a `package.json` file as dependencies.
Expand Down
13 changes: 5 additions & 8 deletions lib/commands/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Dedupe extends ArboristWorkspaceCmd {
'legacy-bundling',
'strict-peer-deps',
'package-lock',
'save',
'omit',
'ignore-scripts',
'audit',
Expand All @@ -29,19 +28,17 @@ class Dedupe extends ArboristWorkspaceCmd {
throw er
}

// In the context of `npm dedupe` the save
// config value should default to `false`
const save = this.npm.config.isDefault('save')
? false
: this.npm.config.get('save')

const dryRun = this.npm.config.get('dry-run')
const where = this.npm.prefix
const opts = {
...this.npm.flatOptions,
path: where,
dryRun,
save,
// Saving during dedupe would only update if one of your direct
// dependencies was also duplicated somewhere in your tree. It would be
// confusing if running this were to also update your package.json. In
// order to reduce potential confusion we set this to false.
save: false,
workspaces: this.workspaceNames,
}
const arb = new Arborist(opts)
Expand Down
3 changes: 3 additions & 0 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ class Npm extends EventEmitter {

const isGlobal = this.config.get('global')
const workspacesEnabled = this.config.get('workspaces')
// if cwd is a workspace, the default is set to [that workspace]
const implicitWorkspace = this.config.get('workspace', 'default').length > 0
const workspacesFilters = this.config.get('workspace')
const includeWorkspaceRoot = this.config.get('include-workspace-root')
// only call execWorkspaces when we have workspaces explicitly set
// or when it is implicit and not in our ignore list
const hasWorkspaceFilters = workspacesFilters.length > 0
const invalidWorkspaceConfig = workspacesEnabled === false && hasWorkspaceFilters

// (-ws || -w foo) && (cwd is not a workspace || command is not ignoring implicit workspaces)
const filterByWorkspaces = (workspacesEnabled || hasWorkspaceFilters) &&
(!implicitWorkspace || !command.ignoreImplicitWorkspace)
// normally this would go in the constructor, but our tests don't
Expand Down
5 changes: 3 additions & 2 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ define('include-staged', {
define('include-workspace-root', {
default: false,
type: Boolean,
envExport: false,
description: `
Include the workspace root when workspaces are enabled for a command.

Expand Down Expand Up @@ -1605,8 +1606,8 @@ define('registry', {

define('save', {
default: true,
defaultDescription: `\`true\` unless when using \`npm update\` or
\`npm dedupe\` where it defaults to \`false\``,
defaultDescription: `\`true\` unless when using \`npm update\` where it
defaults to \`false\``,
usage: '-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle',
type: Boolean,
short: 'S',
Expand Down
Loading