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

Refactor and remove fakeMockNpm #6014

Merged
merged 10 commits into from
Jan 1, 2023
11 changes: 1 addition & 10 deletions .eslintrc.local.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"rules": {
"no-shadow": "off",
"no-console": "error"
},
"overrides": [{
"files": [
"test/**"
],
"rules": {
"no-console": "off"
}
}]
}
}
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-adduser.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Add a registry user account

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Create a new user in the specified registry, and save the credentials to
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manipulates packages cache

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Enables tab-completion in all npm commands.
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manage the npm configuration files

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

npm gets its config settings from the command line, environment
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-deprecate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Deprecate a version of a package

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

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: 0 additions & 2 deletions docs/lib/content/commands/npm-doctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Check your npm environment

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

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: 0 additions & 2 deletions docs/lib/content/commands/npm-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Edit an installed package

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

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: 0 additions & 2 deletions docs/lib/content/commands/npm-explore.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Browse an installed package

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

If supplied a topic, then show the appropriate documentation page.
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manage registry hooks

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Allows you to manage [npm
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-login.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Login to a registry user account

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Verify a user in the specified registry, and save the credentials to the
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-logout.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Log out of the registry

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

When logged into a registry that supports token-based authentication, tell
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-org.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manage orgs

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Example

Add a new developer to an org:
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manage package owners

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

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: 0 additions & 2 deletions docs/lib/content/commands/npm-profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Change settings on your registry profile

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Change your profile information on the registry. Note that this command
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Search for packages

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

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: 0 additions & 2 deletions docs/lib/content/commands/npm-stars.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: View packages marked as favorites

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

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: 0 additions & 2 deletions docs/lib/content/commands/npm-team.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manage organization teams and team memberships

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Used to manage teams in organizations, and change team memberships. Does not
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Manage your authentication tokens

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

This lets you list, create and revoke authentication tokens.
Expand Down
2 changes: 0 additions & 2 deletions docs/lib/content/commands/npm-unstar.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: Remove an item from your favorite packages

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

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

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Note: This command is unaware of workspaces.

### Description

Display the npm username of the currently logged-in user.
Expand Down
15 changes: 9 additions & 6 deletions docs/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ const getCommandByDoc = (docFile, docExt) => {
// `npx` is not technically a command in and of itself,
// so it just needs the usage of npm exex
const srcName = name === 'npx' ? 'exec' : name
const { params, usage = [''] } = require(`../../lib/commands/${srcName}`)
const { params, usage = [''], workspaces } = require(`../../lib/commands/${srcName}`)
const usagePrefix = name === 'npx' ? 'npx' : `npm ${name}`

return {
name,
workspaces,
params: name === 'npx' ? null : params,
usage: usage.map(u => `${usagePrefix} ${u}`.trim()).join('\n'),
}
Expand All @@ -54,7 +55,7 @@ const replaceVersion = (src) => src.replace(/@VERSION@/g, version)

const replaceUsage = (src, { path }) => {
const replacer = assertPlaceholder(src, path, TAGS.USAGE)
const { usage, name } = getCommandByDoc(path, DOC_EXT)
const { usage, name, workspaces } = getCommandByDoc(path, DOC_EXT)

const synopsis = ['```bash', usage]

Expand All @@ -66,15 +67,17 @@ const replaceUsage = (src, { path }) => {
}, [])

if (cmdAliases.length === 1) {
synopsis.push('')
synopsis.push(`alias: ${cmdAliases[0]}`)
synopsis.push('', `alias: ${cmdAliases[0]}`)
} else if (cmdAliases.length > 1) {
synopsis.push('')
synopsis.push(`aliases: ${cmdAliases.join(', ')}`)
synopsis.push('', `aliases: ${cmdAliases.join(', ')}`)
}

synopsis.push('```')

if (!workspaces) {
synopsis.push('', 'Note: This command is unaware of workspaces.')
}

return src.replace(replacer, synopsis.join('\n'))
}

Expand Down
31 changes: 22 additions & 9 deletions lib/arborist-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,35 @@ class ArboristCmd extends BaseCommand {
'install-links',
]

static workspaces = true
static ignoreImplicitWorkspace = false

constructor (npm) {
super(npm)
if (this.npm.config.isDefault('audit')
&& (this.npm.global || this.npm.config.get('location') !== 'project')
) {
this.npm.config.set('audit', false)
} else if (this.npm.global && this.npm.config.get('audit')) {
log.warn('config',
'includes both --global and --audit, which is currently unsupported.')

const { config } = this.npm

// when location isn't set and global isn't true check for a package.json at
// the localPrefix and set the location to project if found
const locationProject = config.get('location') === 'project' || (
config.isDefault('location')
// this is different then `npm.global` which falls back to checking
// location which we do not want to use here
&& !config.get('global')
&& npm.localPackage
)

// if audit is not set and we are in global mode and location is not project
// and we assume its not a project related context, then we set audit=false
if (config.isDefault('audit') && (this.npm.global || !locationProject)) {
config.set('audit', false)
} else if (this.npm.global && config.get('audit')) {
log.warn('config', 'includes both --global and --audit, which is currently unsupported.')
}
}

async execWorkspaces (args, filters) {
await this.setWorkspaces(filters)
async execWorkspaces (args) {
await this.setWorkspaces()
return this.exec(args)
}
}
Expand Down
Loading