MCPcopy Index your code
hub / github.com/nodejs/node / callExec

Method callExec

deps/npm/lib/commands/exec.js:45–116  ·  view source on GitHub ↗
(args, { name, locationMsg, runPath } = {})

Source from the content-addressed store, hash-verified

43 }
44
45 async callExec (args, { name, locationMsg, runPath } = {}) {
46 let localBin = this.npm.localBin
47 let pkgPath = this.npm.localPrefix
48
49 // This is where libnpmexec will actually run the scripts from
50 if (!runPath) {
51 runPath = process.cwd()
52 } else {
53 // We have to consider if the workspace has its own separate versions libnpmexec will walk up to localDir after looking here
54 localBin = resolve(this.npm.localDir, name, 'node_modules', '.bin')
55 // We also need to look for `bin` entries in the workspace package.json
56 // libnpmexec will NOT look in the project root for the bin entry
57 pkgPath = runPath
58 }
59
60 const call = this.npm.config.get('call')
61 let globalPath
62 const {
63 flatOptions,
64 globalBin,
65 globalDir,
66 chalk,
67 } = this.npm
68 const scriptShell = this.npm.config.get('script-shell') || undefined
69 const packages = this.npm.config.get('package')
70 const yes = this.npm.config.get('yes')
71 // --prefix sets both of these to the same thing, meaning the global prefix is invalid (i.e. no lib/node_modules).
72 // This is not a trivial thing to untangle and fix so we work around it here.
73 if (this.npm.localPrefix !== this.npm.globalPrefix) {
74 globalPath = resolve(globalDir, '..')
75 }
76
77 if (call && args.length) {
78 throw this.usageError()
79 }
80
81 // Resolve the install-script policy from the user/global .npmrc layer
82 // only. The RFC requires exec/npx to ignore any project
83 // package.json#allowScripts; CLI flags still apply.
84 const { policy: allowScriptsPolicy } = await resolveAllowScripts(this.npm, {
85 skipProjectConfig: true,
86 })
87
88 return libexec({
89 ...flatOptions,
90 allowScripts: allowScriptsPolicy,
91 // we explicitly set packageLockOnly to false because if it's true when we try to install a missing package, we won't actually install it
92 packageLockOnly: false,
93 // what the user asked to run args[0] is run by default
94 args: [...args], // copy args so they don't get mutated
95 // specify a custom command to be run instead of args[0]
96 call,
97 chalk,
98 // where to look for bins globally, if a file matches call or args[0] it is called
99 globalBin,
100 // where to look for packages globally, if a package matches call or args[0] it is called
101 globalPath,
102 // where to look for bins locally, if a file matches call or args[0] it is called

Callers 2

execMethod · 0.95
execWorkspacesMethod · 0.95

Calls 4

resolveAllowScriptsFunction · 0.85
usageErrorMethod · 0.80
getMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected