Skip to content

Commit

Permalink
chore: take monorepoRoot into account in getPackagesInTopologicalOrde…
Browse files Browse the repository at this point in the history
…r() (#154)

* take monorepoRoot into account in getPackagesInTopologicalOrder()

* don't call path.dirname multiple times. it is always a directory
  • Loading branch information
lerouxb authored Sep 4, 2023
1 parent aa8bbdc commit aedd3b8
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,35 @@ interface InternalPackageInfo {

export interface PackageInfo {
name: string;
location: string;
version: string;
private: boolean;
location: string;
}

export async function getPackagesInTopologicalOrder(
cwd: string
monorepoRoot: string
): Promise<PackageInfo[]> {
const patterns: string[] =
JSON.parse(await fs.readFile(path.join(cwd, `package.json`), 'utf8'))
.workspaces || [];
JSON.parse(
await fs.readFile(path.join(monorepoRoot, `package.json`), 'utf8')
).workspaces || [];

const packageJsonPaths = await glob(
patterns.map((pattern) => path.join(pattern, 'package.json'))
// NOTE: glob patterns should always use forward slashes,
// path.join here wouldn't work on win.
patterns.map((pattern) => `${pattern}/package.json`),
{ cwd: monorepoRoot }
);

const internalPackages: InternalPackageInfo[] = await Promise.all(
packageJsonPaths.map(async (packageJsonPath) => {
const packageJsonLocation = path.resolve(monorepoRoot, packageJsonPath);
const packageJson = JSON.parse(
await fs.readFile(packageJsonPath, 'utf8')
await fs.readFile(packageJsonLocation, 'utf8')
);
return {
name: packageJson.name,
location: packageJsonPath,
location: path.resolve(path.dirname(packageJsonLocation)),
packageJson,
};
})
Expand Down Expand Up @@ -70,7 +75,7 @@ export async function getPackagesInTopologicalOrder(
name: packageInfo.name,
version: packageInfo.packageJson.version,
private: !!packageInfo.packageJson.private,
location: path.resolve(path.dirname(packageInfo.location)),
location: packageInfo.location,
};
});

Expand Down

0 comments on commit aedd3b8

Please sign in to comment.