forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetClerkPackages.js
More file actions
29 lines (25 loc) · 930 Bytes
/
Copy pathgetClerkPackages.js
File metadata and controls
29 lines (25 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { readFile } from 'node:fs/promises';
import { dirname, posix } from 'node:path';
import { globby } from 'globby';
import { NULL_ROOT_ERROR } from './errors.js';
import { getMonorepoRoot } from './getMonorepoRoot.js';
/**
* Generates an object with keys of package names and values of absolute paths to the package folder.
* @returns {Promise<Record<string, string>>}
*/
export async function getClerkPackages() {
const monorepoRoot = await getMonorepoRoot();
if (!monorepoRoot) {
throw new Error(NULL_ROOT_ERROR);
}
/** @type {Record<string, string>} */
const packages = {};
const clerkPackages = await globby([posix.join(monorepoRoot, 'packages', '*', 'package.json'), '!*node_modules*']);
for (const packageJSON of clerkPackages) {
const { name } = JSON.parse(await readFile(packageJSON, 'utf-8'));
if (name) {
packages[name] = dirname(packageJSON);
}
}
return packages;
}