Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-08-02 20:53:54 +0300
committernlf <nlf@github.com>2022-08-03 00:57:32 +0300
commit3b30af25e93665f5aa21897910a65d7f26bbd066 (patch)
tree2654e4164f27175a1ff40b3fcb412e437f4b17b2 /lib
parent19f1497322411f1566885bd53e63dc39f0df27ea (diff)
fix: fix exec tests and clean up workspace-location-msg
The workspace-location-msg file was being called improperly by `npm init` and not even tested, and when digging in it probably shouldn't be used at all from there. It's not always a workspace in this context.
Diffstat (limited to 'lib')
-rw-r--r--lib/commands/exec.js34
-rw-r--r--lib/commands/init.js10
-rw-r--r--lib/exec/get-workspace-location-msg.js25
3 files changed, 5 insertions, 64 deletions
diff --git a/lib/commands/exec.js b/lib/commands/exec.js
index 0bbf7b3fa..85a71923f 100644
--- a/lib/commands/exec.js
+++ b/lib/commands/exec.js
@@ -1,31 +1,5 @@
const libexec = require('libnpmexec')
const BaseCommand = require('../base-command.js')
-const getLocationMsg = require('../exec/get-workspace-location-msg.js')
-
-// it's like this:
-//
-// npm x pkg@version <-- runs the bin named "pkg" or the only bin if only 1
-//
-// { name: 'pkg', bin: { pkg: 'pkg.js', foo: 'foo.js' }} <-- run pkg
-// { name: 'pkg', bin: { foo: 'foo.js' }} <-- run foo?
-//
-// npm x -p pkg@version -- foo
-//
-// npm x -p pkg@version -- foo --registry=/dev/null
-//
-// const pkg = npm.config.get('package') || getPackageFrom(args[0])
-// const cmd = getCommand(pkg, args[0])
-// --> npm x -c 'cmd ...args.slice(1)'
-//
-// we've resolved cmd and args, and escaped them properly, and installed the
-// relevant packages.
-//
-// Add the ${npx install prefix}/node_modules/.bin to PATH
-//
-// pkg = readPackageJson('./package.json')
-// pkg.scripts.___npx = ${the -c arg}
-// runScript({ pkg, event: 'npx', ... })
-// process.env.npm_lifecycle_event = 'npx'
class Exec extends BaseCommand {
static description = 'Run a command from a local or remote npm package'
@@ -64,7 +38,7 @@ class Exec extends BaseCommand {
localBin,
globalBin,
} = this.npm
- const output = (...outputArgs) => this.npm.output(...outputArgs)
+ const output = this.npm.output.bind(this.npm)
const scriptShell = this.npm.config.get('script-shell') || undefined
const packages = this.npm.config.get('package')
const yes = this.npm.config.get('yes')
@@ -94,10 +68,10 @@ class Exec extends BaseCommand {
async execWorkspaces (args, filters) {
await this.setWorkspaces(filters)
- const color = this.npm.color
- for (const path of this.workspacePaths) {
- const locationMsg = await getLocationMsg({ color, path })
+ for (const [name, path] of this.workspaces) {
+ const locationMsg =
+ `in workspace ${this.npm.chalk.green(name)} at location:\n${this.npm.chalk.dim(path)}`
await this.exec(args, { locationMsg, runPath: path })
}
}
diff --git a/lib/commands/init.js b/lib/commands/init.js
index cff8340dc..039f08e06 100644
--- a/lib/commands/init.js
+++ b/lib/commands/init.js
@@ -10,7 +10,6 @@ const PackageJson = require('@npmcli/package-json')
const log = require('../utils/log-shim.js')
const updateWorkspaces = require('../workspaces/update-workspaces.js')
-const getLocationMsg = require('../exec/get-workspace-location-msg.js')
const BaseCommand = require('../base-command.js')
class Init extends BaseCommand {
@@ -119,13 +118,7 @@ class Init extends BaseCommand {
localBin,
globalBin,
} = this.npm
- // this function is definitely called. But because of coverage map stuff
- // it ends up both uncovered, and the coverage report doesn't even mention.
- // the tests do assert that some output happens, so we know this line is
- // being hit.
- /* istanbul ignore next */
- const output = (...outputArgs) => this.npm.output(...outputArgs)
- const locationMsg = await getLocationMsg({ color, path })
+ const output = this.npm.output.bind(this.npm)
const runPath = path
const scriptShell = this.npm.config.get('script-shell') || undefined
const yes = this.npm.config.get('yes')
@@ -135,7 +128,6 @@ class Init extends BaseCommand {
args: newArgs,
color,
localBin,
- locationMsg,
globalBin,
output,
path,
diff --git a/lib/exec/get-workspace-location-msg.js b/lib/exec/get-workspace-location-msg.js
deleted file mode 100644
index 813b11e78..000000000
--- a/lib/exec/get-workspace-location-msg.js
+++ /dev/null
@@ -1,25 +0,0 @@
-const chalk = require('chalk')
-const readPackageJson = require('read-package-json-fast')
-
-const nocolor = {
- dim: s => s,
- green: s => s,
-}
-
-const getLocationMsg = async ({ color, path }) => {
- const colorize = color ? chalk : nocolor
- const { _id } =
- await readPackageJson(`${path}/package.json`)
- .catch(() => ({}))
-
- const workspaceMsg = _id
- ? ` in workspace ${colorize.green(_id)}`
- : ` in a ${colorize.green('new')} workspace`
- const locationMsg = ` at location:\n${
- colorize.dim(path)
- }`
-
- return `${workspaceMsg}${locationMsg}`
-}
-
-module.exports = getLocationMsg