MCPcopy
hub / github.com/vercel/next.js / findWorkspaceRoot

Function findWorkspaceRoot

scripts/patch-preview-tarball.mjs:126–158  ·  view source on GitHub ↗
(projectPath)

Source from the content-addressed store, hash-verified

124}
125
126async function findWorkspaceRoot(projectPath) {
127 for (const ev of ['NPM_CONFIG_WORKSPACE_DIR', 'npm_config_workspace_dir']) {
128 if (process.env[ev]) {
129 return process.env[ev]
130 }
131 }
132
133 try {
134 const canonicalPath = await fs.realpath(projectPath)
135 let currentDir = canonicalPath
136
137 while (currentDir !== path.parse(currentDir).root) {
138 if (await fileExists(path.join(currentDir, 'pnpm-workspace.yaml'))) {
139 return currentDir
140 }
141
142 const packageJsonPath = path.join(currentDir, 'package.json')
143 if (await fileExists(packageJsonPath)) {
144 const content = await fs.readFile(packageJsonPath, 'utf8')
145 const pkg = JSON.parse(content)
146 if (pkg.workspaces) {
147 return currentDir
148 }
149 }
150
151 currentDir = path.dirname(currentDir)
152 }
153
154 return null
155 } catch {
156 return null
157 }
158}
159
160// --- Patch package.json ---
161

Callers 1

patchPackageJsonFunction · 0.70

Calls 5

realpathMethod · 0.80
fileExistsFunction · 0.70
parseMethod · 0.45
joinMethod · 0.45
readFileMethod · 0.45

Tested by

no test coverage detected