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

Method execWorkspaces

deps/npm/lib/commands/init.js:53–96  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

51 }
52
53 async execWorkspaces (args) {
54 // if the root package is uninitiated, take care of it first
55 if (this.npm.flatOptions.includeWorkspaceRoot) {
56 await this.exec(args)
57 }
58
59 // reads package.json for the top-level folder first
60 // by doing this we ensure the command throw if no package.json is found before trying to create a workspace package.json file or its folders
61 const { content: pkg } = await PackageJson.normalize(this.npm.localPrefix).catch(err => {
62 if (err.code === 'ENOENT') {
63 log.warn('init', 'Missing package.json. Try with `--include-workspace-root`.')
64 }
65 throw err
66 })
67
68 // these are workspaces that are being created, so we can't use this.setWorkspaces()
69 const filters = this.npm.config.get('workspace')
70 const wPath = filterArg => resolve(this.npm.localPrefix, filterArg)
71
72 const workspacesPaths = []
73 // npm-exec style, runs in the context of each workspace filter
74 if (args.length) {
75 for (const filterArg of filters) {
76 const path = wPath(filterArg)
77 await mkdir(path, { recursive: true })
78 workspacesPaths.push(path)
79 await this.execCreate(args, path)
80 await this.setWorkspace(pkg, path)
81 }
82 return
83 }
84
85 // no args, uses classic init-package-json boilerplate
86 for (const filterArg of filters) {
87 const path = wPath(filterArg)
88 await mkdir(path, { recursive: true })
89 workspacesPaths.push(path)
90 await this.template(path)
91 await this.setWorkspace(pkg, path)
92 }
93
94 // reify packages once all workspaces have been initialized
95 await this.update(workspacesPaths)
96 }
97
98 async execCreate (args, runPath = process.cwd()) {
99 const [initerName, ...otherArgs] = args

Callers

nothing calls this directly

Calls 9

execMethod · 0.95
execCreateMethod · 0.95
setWorkspaceMethod · 0.95
templateMethod · 0.95
updateMethod · 0.95
warnMethod · 0.80
getMethod · 0.65
mkdirFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected