-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackageJsonMonorepo.ts
More file actions
58 lines (54 loc) · 1.5 KB
/
packageJsonMonorepo.ts
File metadata and controls
58 lines (54 loc) · 1.5 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
isAbsolute,
join
} from 'path'
import { PackageJsonManifest } from '../manifest/index.js'
import { type ProjectPublishOptions } from './project.js'
import { PackageJsonProject } from './packageJson.js'
import {
type MonorepoProjectOptions,
type MonorepoMode,
type GetProjectsOptions,
MonorepoProject
} from './monorepo.js'
export interface PackageJsonMonorepoProjectOptions extends Omit<MonorepoProjectOptions, 'getProjects' | 'manifest'> {
mode: MonorepoMode
/**
* Root path of the monorepo
*/
root?: string
/**
* Get project manifests in the monorepo.
*/
getProjects(options: GetProjectsOptions): AsyncIterable<string>
}
/**
* A package.json based monorepo project.
*/
export class PackageJsonMonorepoProject extends MonorepoProject {
/**
* Creates a package.json based monorepo project.
* @param options
*/
constructor(options: PackageJsonMonorepoProjectOptions) {
const {
root = process.cwd(),
getProjects
} = options
super({
...options,
manifest: new PackageJsonManifest(join(root, PackageJsonManifest.Filename)),
async* getProjects(options) {
for await (const path of getProjects(options)) {
yield new PackageJsonProject({
path: isAbsolute(path) ? path : join(root, path),
...options
})
}
}
})
}
override publish(_options?: ProjectPublishOptions): Promise<void> {
throw new Error('Publishing a package.json monorepo project is not supported')
}
}