MCPcopy Create free account
hub / github.com/SBoudrias/Inquirer.js / readWorkspaceProject

Function readWorkspaceProject

tools/package/src/workspaces.ts:81–121  ·  view source on GitHub ↗
(
  cwd = process.cwd(),
)

Source from the content-addressed store, hash-verified

79}
80
81export async function readWorkspaceProject(
82 cwd = process.cwd(),
83): Promise<WorkspaceProject> {
84 const rootPackagePath = path.join(cwd, 'package.json');
85 const rootPackageJson = readPackageJsonFile(rootPackagePath);
86 const workspacePatterns = [
87 ...packageJsonWorkspacePatterns(rootPackageJson),
88 ...(await readPnpmWorkspacePatterns(cwd)),
89 ];
90
91 if (workspacePatterns.length === 0) {
92 return {
93 rootPackageJson,
94 rootPackagePath,
95 packages: [
96 {
97 packageJson: rootPackageJson,
98 packagePath: 'package.json',
99 packageDir: cwd,
100 },
101 ],
102 };
103 }
104
105 const packagePaths = await globby(
106 [...new Set(workspacePatterns.map(workspacePackagePattern)), '!**/node_modules'],
107 { cwd },
108 );
109
110 const packages = packagePaths.toSorted().map((packagePath) => {
111 const absolutePackagePath = path.join(cwd, packagePath);
112
113 return {
114 packageJson: readPackageJsonFile(absolutePackagePath),
115 packagePath,
116 packageDir: path.dirname(absolutePackagePath),
117 };
118 });
119
120 return { rootPackageJson, rootPackagePath, packages };
121}

Callers 2

lintPackagesFunction · 0.90
workspaces.test.tsFile · 0.90

Calls 3

readPackageJsonFileFunction · 0.90

Tested by

no test coverage detected