@vltpkg/workspaces 1.0.0-rc.2 → 1.0.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +35 -45
- package/dist/esm/index.d.ts +0 -221
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -512
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/package.json +0 -3
package/package.json
CHANGED
|
@@ -1,77 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/workspaces",
|
|
3
3
|
"description": "Utility for working with vlt workspaces",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.23",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
8
|
"directory": "src/workspaces"
|
|
9
9
|
},
|
|
10
|
-
"author":
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"liveDev": true,
|
|
14
|
-
"dialects": [
|
|
15
|
-
"esm"
|
|
16
|
-
],
|
|
17
|
-
"exports": {
|
|
18
|
-
"./package.json": "./package.json",
|
|
19
|
-
".": "./src/index.ts"
|
|
20
|
-
}
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "vlt technology inc.",
|
|
12
|
+
"email": "support@vlt.sh"
|
|
21
13
|
},
|
|
22
14
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"@vltpkg/
|
|
28
|
-
"@vltpkg/
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
15
|
+
"@vltpkg/dep-id": "1.0.0-rc.23",
|
|
16
|
+
"@vltpkg/error-cause": "1.0.0-rc.23",
|
|
17
|
+
"@vltpkg/graph-run": "1.0.0-rc.23",
|
|
18
|
+
"@vltpkg/package-json": "1.0.0-rc.23",
|
|
19
|
+
"@vltpkg/types": "1.0.0-rc.23",
|
|
20
|
+
"@vltpkg/vlt-json": "1.0.0-rc.23",
|
|
21
|
+
"glob": "^13.0.0",
|
|
22
|
+
"minimatch": "^10.1.1",
|
|
23
|
+
"path-scurry": "^2.0.1"
|
|
32
24
|
},
|
|
33
25
|
"devDependencies": {
|
|
34
|
-
"@eslint/js": "^9.
|
|
35
|
-
"@types/node": "^22.
|
|
36
|
-
"eslint": "^9.
|
|
37
|
-
"prettier": "^3.
|
|
38
|
-
"tap": "^21.
|
|
39
|
-
"tshy": "^3.0.2",
|
|
26
|
+
"@eslint/js": "^9.39.1",
|
|
27
|
+
"@types/node": "^22.19.2",
|
|
28
|
+
"eslint": "^9.39.1",
|
|
29
|
+
"prettier": "^3.7.4",
|
|
30
|
+
"tap": "^21.5.0",
|
|
40
31
|
"typedoc": "~0.27.9",
|
|
41
32
|
"typescript": "5.7.3",
|
|
42
|
-
"typescript-eslint": "^8.
|
|
33
|
+
"typescript-eslint": "^8.49.0"
|
|
43
34
|
},
|
|
44
35
|
"license": "BSD-2-Clause-Patent",
|
|
45
36
|
"engines": {
|
|
46
|
-
"node": ">=22"
|
|
37
|
+
"node": ">=22.22.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
41
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
42
|
+
"lint": "eslint . --fix",
|
|
43
|
+
"lint:check": "eslint .",
|
|
44
|
+
"prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
|
|
45
|
+
"snap": "tap",
|
|
46
|
+
"test": "tap",
|
|
47
|
+
"posttest": "tsc --noEmit",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
47
49
|
},
|
|
48
50
|
"tap": {
|
|
49
51
|
"extends": "../../tap-config.yaml"
|
|
50
52
|
},
|
|
51
53
|
"prettier": "../../.prettierrc.js",
|
|
52
|
-
"module": "./dist/
|
|
54
|
+
"module": "./dist/index.js",
|
|
53
55
|
"type": "module",
|
|
54
56
|
"exports": {
|
|
55
57
|
"./package.json": "./package.json",
|
|
56
58
|
".": {
|
|
57
59
|
"import": {
|
|
58
|
-
"
|
|
59
|
-
"default": "./dist/esm/index.js"
|
|
60
|
+
"default": "./dist/index.js"
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
"files": [
|
|
64
65
|
"dist"
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
68
|
-
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
69
|
-
"lint": "eslint . --fix",
|
|
70
|
-
"lint:check": "eslint .",
|
|
71
|
-
"snap": "tap",
|
|
72
|
-
"test": "tap",
|
|
73
|
-
"posttest": "tsc --noEmit",
|
|
74
|
-
"tshy": "tshy",
|
|
75
|
-
"typecheck": "tsc --noEmit"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
66
|
+
]
|
|
67
|
+
}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import type { DepID } from '@vltpkg/dep-id';
|
|
2
|
-
import { PackageJson } from '@vltpkg/package-json';
|
|
3
|
-
import type { NormalizedManifest } from '@vltpkg/types';
|
|
4
|
-
import type { DepResults } from 'graph-run';
|
|
5
|
-
import { PathScurry } from 'path-scurry';
|
|
6
|
-
export type WorkspacesLoadedConfig = {
|
|
7
|
-
workspace?: string[];
|
|
8
|
-
'workspace-group'?: string[];
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* The object passed to the constructor or {@link Monorepo#load} to limit which
|
|
12
|
-
* {@link Workspace Workspaces} get loaded.
|
|
13
|
-
*/
|
|
14
|
-
export type LoadQuery = {
|
|
15
|
-
/**
|
|
16
|
-
* A glob pattern string, or an array of them. Only workspaces found
|
|
17
|
-
* in paths matched will be loaded.
|
|
18
|
-
*/
|
|
19
|
-
paths?: string[] | string;
|
|
20
|
-
/**
|
|
21
|
-
* A string, or an array of strings. If set, only workspaces in the
|
|
22
|
-
* specified groups named will be included, if set.
|
|
23
|
-
*/
|
|
24
|
-
groups?: string[] | string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Canonical form of the {@link WorkspaceConfig}, used
|
|
28
|
-
* internally for consistency.
|
|
29
|
-
*/
|
|
30
|
-
export type WorkspaceConfigObject = Record<string, string[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Allowed datatype in the `workspaces` field of the `vlt.json` file.
|
|
33
|
-
*/
|
|
34
|
-
export type WorkspaceConfig = string[] | WorkspaceConfigObject | string;
|
|
35
|
-
/**
|
|
36
|
-
* Turn a {@link WorkspaceConfig} into a
|
|
37
|
-
* {@link WorkspaceConfigObject}, or throw if it's not valid.
|
|
38
|
-
*/
|
|
39
|
-
export declare const asWSConfig: (conf: unknown, path?: string) => WorkspaceConfigObject;
|
|
40
|
-
/**
|
|
41
|
-
* Throw if the provided value is not a valid {@link WorkspaceConfig}
|
|
42
|
-
*/
|
|
43
|
-
export declare const assertWSConfig: (conf: unknown, path?: string) => asserts conf is WorkspaceConfig;
|
|
44
|
-
export type MonorepoOptions = {
|
|
45
|
-
/**
|
|
46
|
-
* A {@link PackageJson} object, for sharing manifest caches
|
|
47
|
-
*/
|
|
48
|
-
packageJson?: PackageJson;
|
|
49
|
-
/**
|
|
50
|
-
* A {@link PathScurry} object, for use in globs
|
|
51
|
-
*/
|
|
52
|
-
scurry?: PathScurry;
|
|
53
|
-
/**
|
|
54
|
-
* Parsed normalized contents of the workspaces from a `vlt.json`
|
|
55
|
-
* file
|
|
56
|
-
*/
|
|
57
|
-
config?: WorkspaceConfigObject;
|
|
58
|
-
/**
|
|
59
|
-
* If set, then {@link Monorepo#load} will be called immediately with
|
|
60
|
-
* this argument.
|
|
61
|
-
*/
|
|
62
|
-
load?: LoadQuery;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Class representing a Monorepo containing multiple workspaces.
|
|
66
|
-
*
|
|
67
|
-
* Does not automatically look up the root, but that can be provided by
|
|
68
|
-
* running `Config.load()`, since it stops seeking the route when a
|
|
69
|
-
* `vlt.json` file is encountered.
|
|
70
|
-
*/
|
|
71
|
-
export declare class Monorepo {
|
|
72
|
-
#private;
|
|
73
|
-
/** The project root where vlt.json is found */
|
|
74
|
-
projectRoot: string;
|
|
75
|
-
/** Scurry object to cache all filesystem calls (mostly globs) */
|
|
76
|
-
scurry: PathScurry;
|
|
77
|
-
packageJson: PackageJson;
|
|
78
|
-
/**
|
|
79
|
-
* Number of {@link Workspace} objects loaded in this Monorepo
|
|
80
|
-
*/
|
|
81
|
-
get size(): number;
|
|
82
|
-
constructor(projectRoot: string, options?: MonorepoOptions);
|
|
83
|
-
/**
|
|
84
|
-
* Load the workspace definitions from vlt.json,
|
|
85
|
-
* canonicalizing the result into the effective `{[group:string]:string[]}`
|
|
86
|
-
* form.
|
|
87
|
-
*
|
|
88
|
-
* Eg:
|
|
89
|
-
* - `"src/*"` => `{packages:["src/*"]}`
|
|
90
|
-
* - `{"apps": "src/*"}` => `{apps: ["src/*"]}`
|
|
91
|
-
*/
|
|
92
|
-
get config(): WorkspaceConfigObject;
|
|
93
|
-
/**
|
|
94
|
-
* Iterating the Monorepo object yields the workspace objects, in as close to
|
|
95
|
-
* topological dependency order as possible.
|
|
96
|
-
*/
|
|
97
|
-
[Symbol.iterator](): Generator<Workspace, void, void>;
|
|
98
|
-
/**
|
|
99
|
-
* Iterating the Monorepo object yields the workspace objects, in as close to
|
|
100
|
-
* topological dependency order as possible.
|
|
101
|
-
*/
|
|
102
|
-
[Symbol.asyncIterator](): AsyncGenerator<Workspace, void, void>;
|
|
103
|
-
/**
|
|
104
|
-
* By default, loads all workspaces reachable in the Monorepo.
|
|
105
|
-
*
|
|
106
|
-
* If provided with one (`string`)or more (`string[]`) group names in
|
|
107
|
-
* the {@link LoadQuery#groups} field, then only Workspaces in the named
|
|
108
|
-
* group(s) will be considered. Note that group names are unique string
|
|
109
|
-
* matches, not globs.
|
|
110
|
-
*
|
|
111
|
-
* If provided with a set of arbitrary path arguments, then only paths
|
|
112
|
-
* patching the provided pattern(s) will be included.
|
|
113
|
-
*
|
|
114
|
-
* These two options intersect, so
|
|
115
|
-
* `load({groups:'foo', paths:'./foo/[xy]*'})` will only load the workspaces
|
|
116
|
-
* in the group `foo` that match the paths glob.
|
|
117
|
-
*/
|
|
118
|
-
load(query?: LoadQuery): this;
|
|
119
|
-
/**
|
|
120
|
-
* Return the array of workspace dependencies that are found in
|
|
121
|
-
* the loaded set, for use in calculating dependency graph order for
|
|
122
|
-
* build operations.
|
|
123
|
-
*
|
|
124
|
-
* This does *not* get the full set of dependencies, or expand any
|
|
125
|
-
* `workspace:` dependencies that are not loaded.
|
|
126
|
-
*
|
|
127
|
-
* Call with the `forceLoad` param set to `true` to attempt a full
|
|
128
|
-
* load if any deps are not currently loaded.
|
|
129
|
-
*/
|
|
130
|
-
getDeps(ws: Workspace, forceLoad?: boolean): Workspace[];
|
|
131
|
-
onCycle(_ws: Workspace, _cycle: Workspace[], _depPath: Workspace[]): void;
|
|
132
|
-
/**
|
|
133
|
-
* Return the set of workspaces in the named group.
|
|
134
|
-
* If the group is not one we know about, then undefined is returned.
|
|
135
|
-
*/
|
|
136
|
-
group(group: string): Set<Workspace> | undefined;
|
|
137
|
-
/**
|
|
138
|
-
* Get a loaded workspace by path or name.
|
|
139
|
-
*
|
|
140
|
-
* Note that this can only return workspaces that were ingested via a
|
|
141
|
-
* previous call to {@link Monorepo#load}.
|
|
142
|
-
*/
|
|
143
|
-
get(nameOrPath: string): Workspace | undefined;
|
|
144
|
-
/**
|
|
145
|
-
* get the list of all loaded workspace names used as keys
|
|
146
|
-
*/
|
|
147
|
-
names(): Generator<string, void, unknown>;
|
|
148
|
-
/**
|
|
149
|
-
* get the list of all loaded workspace paths used as keys
|
|
150
|
-
*/
|
|
151
|
-
paths(): Generator<string, void, unknown>;
|
|
152
|
-
/**
|
|
153
|
-
* get the workspace objects in no particular order.
|
|
154
|
-
* this is ever so slightly faster than iterating, because it doesn't
|
|
155
|
-
* explore the graph to yield results in topological dependency order,
|
|
156
|
-
* and should be used instead when order doesn't matter.
|
|
157
|
-
*/
|
|
158
|
-
values(): Generator<Workspace, void, unknown>;
|
|
159
|
-
/**
|
|
160
|
-
* Get all the keys (package names and paths) for loaded workspaces.
|
|
161
|
-
* Union of {@link Monorepo#names} and {@link Monorepo#paths}
|
|
162
|
-
*/
|
|
163
|
-
keys(): Generator<string, void, unknown>;
|
|
164
|
-
/**
|
|
165
|
-
* Filter the monorepo object yielding the workspace objects that matches
|
|
166
|
-
* either of the {@link WorkspacesLoadedConfig} options provided, in as close
|
|
167
|
-
* to topological dependency order as possible.
|
|
168
|
-
*/
|
|
169
|
-
filter({ workspace: namesOrPaths, 'workspace-group': groupName, }: WorkspacesLoadedConfig): Generator<Workspace, void, unknown>;
|
|
170
|
-
/**
|
|
171
|
-
* Run an operation asynchronously over all loaded workspaces
|
|
172
|
-
*
|
|
173
|
-
* If the `forceLoad` param is true, then it will attempt to do a full load
|
|
174
|
-
* when encountering a `workspace:` dependency that isn't loaded.
|
|
175
|
-
*
|
|
176
|
-
* Note that because the return type appears in the parameters of the
|
|
177
|
-
* operation function, it must be set explicitly either in the operation
|
|
178
|
-
* function signature or by calling `run<MyType>` or it'll fall back to
|
|
179
|
-
* `unknown`, similar to `Array.reduce()`, and for the same reason.
|
|
180
|
-
*/
|
|
181
|
-
run<R>(operation: (s: Workspace, signal: AbortSignal, depResults: DepResults<Workspace, R>) => Promise<R> | R, forceLoad?: boolean): Promise<Map<Workspace, R>>;
|
|
182
|
-
/**
|
|
183
|
-
* Run an operation synchronously over all loaded workspaces
|
|
184
|
-
*
|
|
185
|
-
* If the `forceLoad` param is true, then it will attempt to do a full load
|
|
186
|
-
* when encountering a `workspace:` dependency that isn't loaded.
|
|
187
|
-
*
|
|
188
|
-
* Note that because the return type appears in the parameters of the
|
|
189
|
-
* operation function, it must be set explicitly either in the operation
|
|
190
|
-
* function signature or by calling `runSync<MyType>` or it'll fall back to
|
|
191
|
-
* `unknown`, similar to `Array.reduce()`, and for the same reason.
|
|
192
|
-
*/
|
|
193
|
-
runSync<R>(operation: (s: Workspace, signal: AbortSignal, depResults: DepResults<Workspace, R>) => R, forceLoad?: boolean): Map<Workspace, R>;
|
|
194
|
-
/**
|
|
195
|
-
* Convenience method to instantiate and load in one call.
|
|
196
|
-
* Returns undefined if the project is not a monorepo workspaces
|
|
197
|
-
* root, otherwise returns the loaded Monorepo.
|
|
198
|
-
*/
|
|
199
|
-
static maybeLoad(projectRoot: string, options?: MonorepoOptions): Monorepo | undefined;
|
|
200
|
-
/**
|
|
201
|
-
* Convenience method to instantiate and load in one call.
|
|
202
|
-
* Throws if called on a directory that is not a workspaces root.
|
|
203
|
-
*/
|
|
204
|
-
static load(projectRoot: string, options?: MonorepoOptions): Monorepo;
|
|
205
|
-
}
|
|
206
|
-
export declare const workspaceCache: Map<string, Workspace>;
|
|
207
|
-
/**
|
|
208
|
-
* Class representing a single Workspace in a {@link Monorepo}
|
|
209
|
-
*/
|
|
210
|
-
export declare class Workspace {
|
|
211
|
-
#private;
|
|
212
|
-
id: DepID;
|
|
213
|
-
path: string;
|
|
214
|
-
fullpath: string;
|
|
215
|
-
manifest: NormalizedManifest;
|
|
216
|
-
groups: string[];
|
|
217
|
-
name: string;
|
|
218
|
-
constructor(path: string, manifest: NormalizedManifest, fullpath: string);
|
|
219
|
-
get keys(): string[];
|
|
220
|
-
}
|
|
221
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB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;;;;;;;;;;OAUG;IACH,OAAO,CAAC,CAAC,EACP,SAAS,EAAE,CACT,CAAC,EAAE,SAAS,EACZ,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC,KACjC,CAAC,EACN,SAAS,UAAQ;IAgBnB;;;;OAIG;IACH,MAAM,CAAC,SAAS,CACd,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,eAA8B;IAOzC;;;OAGG;IACH,MAAM,CAAC,IAAI,CACT,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,eAA8B;CAK1C;AAED,eAAO,MAAM,cAAc,wBAA+B,CAAA;AAE1D;;GAEG;AACH,qBAAa,SAAS;;IACpB,EAAE,EAAE,KAAK,CAAA;IACT,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAK;IACrB,IAAI,EAAE,MAAM,CAAA;gBAIV,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,MAAM;IAUlB,IAAI,IAAI,IAAI,MAAM,EAAE,CAMnB;CACF"}
|
package/dist/esm/index.js
DELETED
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
import { joinDepIDTuple } from '@vltpkg/dep-id';
|
|
2
|
-
import { error } from '@vltpkg/error-cause';
|
|
3
|
-
import { PackageJson } from '@vltpkg/package-json';
|
|
4
|
-
import { load } from '@vltpkg/vlt-json';
|
|
5
|
-
import { globSync } from 'glob';
|
|
6
|
-
import { graphRun, graphRunSync } from 'graph-run';
|
|
7
|
-
import { minimatch } from 'minimatch';
|
|
8
|
-
import { basename, posix, resolve } from 'node:path';
|
|
9
|
-
import { PathScurry } from 'path-scurry';
|
|
10
|
-
/**
|
|
11
|
-
* Turn a {@link WorkspaceConfig} into a
|
|
12
|
-
* {@link WorkspaceConfigObject}, or throw if it's not valid.
|
|
13
|
-
*/
|
|
14
|
-
export const asWSConfig = (conf, path) => {
|
|
15
|
-
assertWSConfig(conf, path);
|
|
16
|
-
return (typeof conf === 'string' ? { packages: [conf] }
|
|
17
|
-
: Array.isArray(conf) ? { packages: conf }
|
|
18
|
-
: Object.fromEntries(Object.entries(conf).map(([k, v]) => [
|
|
19
|
-
k,
|
|
20
|
-
typeof v === 'string' ? [v] : v,
|
|
21
|
-
])));
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Throw if the provided value is not a valid {@link WorkspaceConfig}
|
|
25
|
-
*/
|
|
26
|
-
export const assertWSConfig = (conf, path) => {
|
|
27
|
-
if (typeof conf === 'string')
|
|
28
|
-
return;
|
|
29
|
-
if (Array.isArray(conf)) {
|
|
30
|
-
for (const c of conf) {
|
|
31
|
-
if (typeof c !== 'string') {
|
|
32
|
-
throw error('Invalid workspace definition', {
|
|
33
|
-
path,
|
|
34
|
-
found: c,
|
|
35
|
-
wanted: 'string',
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (conf && typeof conf === 'object') {
|
|
42
|
-
for (const [group, value] of Object.entries(conf)) {
|
|
43
|
-
if (typeof value === 'string')
|
|
44
|
-
continue;
|
|
45
|
-
if (Array.isArray(value)) {
|
|
46
|
-
for (const c of value) {
|
|
47
|
-
if (typeof c !== 'string') {
|
|
48
|
-
throw error('Invalid workspace definition', {
|
|
49
|
-
path,
|
|
50
|
-
name: group,
|
|
51
|
-
found: c,
|
|
52
|
-
wanted: 'string',
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
throw error('Invalid workspace definition', {
|
|
59
|
-
path,
|
|
60
|
-
name: group,
|
|
61
|
-
found: value,
|
|
62
|
-
wanted: 'string | string[]',
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
throw error('Invalid workspace definition', {
|
|
68
|
-
path,
|
|
69
|
-
found: conf,
|
|
70
|
-
wanted: 'string | string[] | { [group: string]: string | string[] }',
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Class representing a Monorepo containing multiple workspaces.
|
|
75
|
-
*
|
|
76
|
-
* Does not automatically look up the root, but that can be provided by
|
|
77
|
-
* running `Config.load()`, since it stops seeking the route when a
|
|
78
|
-
* `vlt.json` file is encountered.
|
|
79
|
-
*/
|
|
80
|
-
export class Monorepo {
|
|
81
|
-
/** The project root where vlt.json is found */
|
|
82
|
-
projectRoot;
|
|
83
|
-
/** Scurry object to cache all filesystem calls (mostly globs) */
|
|
84
|
-
scurry;
|
|
85
|
-
// maps both name and path to the workspace objects
|
|
86
|
-
#workspaces = new Map();
|
|
87
|
-
#groups = new Map();
|
|
88
|
-
#config;
|
|
89
|
-
packageJson;
|
|
90
|
-
/**
|
|
91
|
-
* Number of {@link Workspace} objects loaded in this Monorepo
|
|
92
|
-
*/
|
|
93
|
-
get size() {
|
|
94
|
-
return [...this.values()].length;
|
|
95
|
-
}
|
|
96
|
-
constructor(projectRoot, options = {}) {
|
|
97
|
-
this.projectRoot = resolve(projectRoot);
|
|
98
|
-
this.scurry = options.scurry ?? new PathScurry(projectRoot);
|
|
99
|
-
this.packageJson = options.packageJson ?? new PackageJson();
|
|
100
|
-
this.#config = options.config;
|
|
101
|
-
if (options.load)
|
|
102
|
-
this.load(options.load);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Load the workspace definitions from vlt.json,
|
|
106
|
-
* canonicalizing the result into the effective `{[group:string]:string[]}`
|
|
107
|
-
* form.
|
|
108
|
-
*
|
|
109
|
-
* Eg:
|
|
110
|
-
* - `"src/*"` => `{packages:["src/*"]}`
|
|
111
|
-
* - `{"apps": "src/*"}` => `{apps: ["src/*"]}`
|
|
112
|
-
*/
|
|
113
|
-
get config() {
|
|
114
|
-
if (this.#config)
|
|
115
|
-
return this.#config;
|
|
116
|
-
this.#config = asWSConfig(load('workspaces', assertWSConfig) ?? {});
|
|
117
|
-
return this.#config;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Iterating the Monorepo object yields the workspace objects, in as close to
|
|
121
|
-
* topological dependency order as possible.
|
|
122
|
-
*/
|
|
123
|
-
*[Symbol.iterator]() {
|
|
124
|
-
const [ws] = [...this.values()];
|
|
125
|
-
if (!ws)
|
|
126
|
-
return;
|
|
127
|
-
// leverage the fact that graphRun returns results in
|
|
128
|
-
// as close to topological order as possible.
|
|
129
|
-
for (const workspace of this.runSync(() => { }).keys()) {
|
|
130
|
-
yield workspace;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Iterating the Monorepo object yields the workspace objects, in as close to
|
|
135
|
-
* topological dependency order as possible.
|
|
136
|
-
*/
|
|
137
|
-
async *[Symbol.asyncIterator]() {
|
|
138
|
-
const [ws] = [...this.values()];
|
|
139
|
-
if (!ws)
|
|
140
|
-
return;
|
|
141
|
-
for (const workspace of (await this.run(() => { })).keys()) {
|
|
142
|
-
yield workspace;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* By default, loads all workspaces reachable in the Monorepo.
|
|
147
|
-
*
|
|
148
|
-
* If provided with one (`string`)or more (`string[]`) group names in
|
|
149
|
-
* the {@link LoadQuery#groups} field, then only Workspaces in the named
|
|
150
|
-
* group(s) will be considered. Note that group names are unique string
|
|
151
|
-
* matches, not globs.
|
|
152
|
-
*
|
|
153
|
-
* If provided with a set of arbitrary path arguments, then only paths
|
|
154
|
-
* patching the provided pattern(s) will be included.
|
|
155
|
-
*
|
|
156
|
-
* These two options intersect, so
|
|
157
|
-
* `load({groups:'foo', paths:'./foo/[xy]*'})` will only load the workspaces
|
|
158
|
-
* in the group `foo` that match the paths glob.
|
|
159
|
-
*/
|
|
160
|
-
load(query = {}) {
|
|
161
|
-
const paths = new Set(typeof query.paths === 'string' ?
|
|
162
|
-
[query.paths]
|
|
163
|
-
: (query.paths ?? []));
|
|
164
|
-
const groups = new Set(typeof query.groups === 'string' ?
|
|
165
|
-
[query.groups]
|
|
166
|
-
: (query.groups ?? []));
|
|
167
|
-
const groupsExpanded = {};
|
|
168
|
-
for (const [group, pattern] of Object.entries(this.config)) {
|
|
169
|
-
if (groups.size && !groups.has(group))
|
|
170
|
-
continue;
|
|
171
|
-
groupsExpanded[group] = this.#glob(pattern);
|
|
172
|
-
}
|
|
173
|
-
const filter = paths.size ? this.#glob([...paths]) : paths;
|
|
174
|
-
// if we specified paths, but none matched, nothing to do
|
|
175
|
-
if (paths.size && !filter.size)
|
|
176
|
-
return this;
|
|
177
|
-
for (const [group, matches] of Object.entries(groupsExpanded)) {
|
|
178
|
-
for (const path of matches) {
|
|
179
|
-
if (filter.size && !filter.has(path))
|
|
180
|
-
continue;
|
|
181
|
-
this.#loadWS(path, group);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return this;
|
|
185
|
-
}
|
|
186
|
-
// Either load a workspace from disk, or from our internal set,
|
|
187
|
-
// and assign it to the named group
|
|
188
|
-
#loadWS(path, group) {
|
|
189
|
-
const fullpath = resolve(this.projectRoot, path);
|
|
190
|
-
const loaded = this.#workspaces.get(fullpath);
|
|
191
|
-
if (loaded)
|
|
192
|
-
return loaded;
|
|
193
|
-
const fromCache = workspaceCache.get(fullpath);
|
|
194
|
-
const manifest = fromCache?.manifest ?? this.packageJson.read(fullpath);
|
|
195
|
-
const ws = fromCache ?? new Workspace(path, manifest, fullpath);
|
|
196
|
-
if (group)
|
|
197
|
-
ws.groups.push(group);
|
|
198
|
-
// Check for duplicate workspace names
|
|
199
|
-
const existingWS = this.#workspaces.get(ws.name);
|
|
200
|
-
if (existingWS && existingWS.fullpath !== ws.fullpath) {
|
|
201
|
-
throw error('Duplicate workspace name found', {
|
|
202
|
-
name: ws.name,
|
|
203
|
-
path: this.projectRoot,
|
|
204
|
-
wanted: ws.fullpath,
|
|
205
|
-
found: existingWS.fullpath,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
this.#workspaces.set(ws.fullpath, ws);
|
|
209
|
-
this.#workspaces.set(ws.path, ws);
|
|
210
|
-
this.#workspaces.set(ws.name, ws);
|
|
211
|
-
for (const name of ws.groups) {
|
|
212
|
-
const group = this.#groups.get(name) ?? new Set();
|
|
213
|
-
group.add(ws);
|
|
214
|
-
this.#groups.set(name, group);
|
|
215
|
-
}
|
|
216
|
-
return ws;
|
|
217
|
-
}
|
|
218
|
-
// can't be cached, because it's dependent on the matches set
|
|
219
|
-
// but still worthwhile to have it defined in one place
|
|
220
|
-
#globOptions(matches) {
|
|
221
|
-
// if the entry or any of its parent dirs are already matched,
|
|
222
|
-
// then we should not explore further down that directory tree.
|
|
223
|
-
// if we hit the projectRoot then stop searching.
|
|
224
|
-
const inMatches = (p) => {
|
|
225
|
-
return (!!p?.relativePosix() &&
|
|
226
|
-
(matches.has(p.relativePosix()) || inMatches(p.parent)));
|
|
227
|
-
};
|
|
228
|
-
return {
|
|
229
|
-
root: this.projectRoot,
|
|
230
|
-
cwd: this.projectRoot,
|
|
231
|
-
posix: true,
|
|
232
|
-
scurry: this.scurry,
|
|
233
|
-
withFileTypes: false,
|
|
234
|
-
ignore: {
|
|
235
|
-
childrenIgnored: p => basename(p.relativePosix()) === 'node_modules' ||
|
|
236
|
-
inMatches(p),
|
|
237
|
-
// ignore if fails to load package.json
|
|
238
|
-
ignored: p => {
|
|
239
|
-
p.lstatSync();
|
|
240
|
-
const rel = p.relativePosix();
|
|
241
|
-
if (!rel)
|
|
242
|
-
return true;
|
|
243
|
-
const maybeDelete = [];
|
|
244
|
-
for (const m of matches) {
|
|
245
|
-
if (rel.startsWith(m + '/'))
|
|
246
|
-
return true;
|
|
247
|
-
if (m.startsWith(rel + '/')) {
|
|
248
|
-
maybeDelete.push(m);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (!p.isDirectory())
|
|
252
|
-
return true;
|
|
253
|
-
const pj = p.resolve('package.json').lstatSync();
|
|
254
|
-
if (!pj?.isFile())
|
|
255
|
-
return true;
|
|
256
|
-
try {
|
|
257
|
-
this.packageJson.read(p.fullpath());
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
for (const m of maybeDelete) {
|
|
263
|
-
matches.delete(m);
|
|
264
|
-
}
|
|
265
|
-
matches.add(rel);
|
|
266
|
-
return false;
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
#glob(pattern) {
|
|
272
|
-
const matches = new Set();
|
|
273
|
-
globSync(pattern, this.#globOptions(matches));
|
|
274
|
-
return matches;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Return the array of workspace dependencies that are found in
|
|
278
|
-
* the loaded set, for use in calculating dependency graph order for
|
|
279
|
-
* build operations.
|
|
280
|
-
*
|
|
281
|
-
* This does *not* get the full set of dependencies, or expand any
|
|
282
|
-
* `workspace:` dependencies that are not loaded.
|
|
283
|
-
*
|
|
284
|
-
* Call with the `forceLoad` param set to `true` to attempt a full
|
|
285
|
-
* load if any deps are not currently loaded.
|
|
286
|
-
*/
|
|
287
|
-
getDeps(ws, forceLoad = false) {
|
|
288
|
-
// load manifest and find workspace: deps
|
|
289
|
-
// filter by those loaded
|
|
290
|
-
const { manifest } = ws;
|
|
291
|
-
const depWorkspaces = [];
|
|
292
|
-
let didForceLoad = false;
|
|
293
|
-
for (const depType of [
|
|
294
|
-
'dependencies',
|
|
295
|
-
'devDependencies',
|
|
296
|
-
'optionalDependencies',
|
|
297
|
-
'peerDependencies',
|
|
298
|
-
]) {
|
|
299
|
-
const deps = manifest[depType];
|
|
300
|
-
if (!deps)
|
|
301
|
-
continue;
|
|
302
|
-
for (const [dep, spec] of Object.entries(deps)) {
|
|
303
|
-
if (spec.startsWith('workspace:')) {
|
|
304
|
-
let depWS = this.#workspaces.get(dep);
|
|
305
|
-
if (!depWS) {
|
|
306
|
-
if (!forceLoad)
|
|
307
|
-
continue;
|
|
308
|
-
if (didForceLoad)
|
|
309
|
-
continue;
|
|
310
|
-
didForceLoad = true;
|
|
311
|
-
this.load();
|
|
312
|
-
depWS = this.#workspaces.get(dep);
|
|
313
|
-
if (!depWS)
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
depWorkspaces.push(depWS);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return depWorkspaces;
|
|
321
|
-
}
|
|
322
|
-
onCycle(_ws, _cycle, _depPath) {
|
|
323
|
-
// XXX - process logging? Need to say something like:
|
|
324
|
-
// Cyclical workspace dependency warning!
|
|
325
|
-
// When evaluating dependency ${ws.name} via ${
|
|
326
|
-
// path.map(ws => ws.name).join(' -> ')
|
|
327
|
-
// }, a dependency cycle was detected: ${
|
|
328
|
-
// cycle.map(ws => ws.name).join(' -> ')
|
|
329
|
-
// }. Operation will continue, but dependency order not guaranteed.`
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Return the set of workspaces in the named group.
|
|
333
|
-
* If the group is not one we know about, then undefined is returned.
|
|
334
|
-
*/
|
|
335
|
-
group(group) {
|
|
336
|
-
return this.#groups.get(group);
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Get a loaded workspace by path or name.
|
|
340
|
-
*
|
|
341
|
-
* Note that this can only return workspaces that were ingested via a
|
|
342
|
-
* previous call to {@link Monorepo#load}.
|
|
343
|
-
*/
|
|
344
|
-
get(nameOrPath) {
|
|
345
|
-
return this.#workspaces.get(nameOrPath);
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* get the list of all loaded workspace names used as keys
|
|
349
|
-
*/
|
|
350
|
-
*names() {
|
|
351
|
-
for (const [key, ws] of this.#workspaces) {
|
|
352
|
-
if (key === ws.name)
|
|
353
|
-
yield key;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* get the list of all loaded workspace paths used as keys
|
|
358
|
-
*/
|
|
359
|
-
*paths() {
|
|
360
|
-
for (const [key, ws] of this.#workspaces) {
|
|
361
|
-
if (key === ws.path)
|
|
362
|
-
yield key;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* get the workspace objects in no particular order.
|
|
367
|
-
* this is ever so slightly faster than iterating, because it doesn't
|
|
368
|
-
* explore the graph to yield results in topological dependency order,
|
|
369
|
-
* and should be used instead when order doesn't matter.
|
|
370
|
-
*/
|
|
371
|
-
*values() {
|
|
372
|
-
const seen = new Set();
|
|
373
|
-
for (const ws of this.#workspaces.values()) {
|
|
374
|
-
if (seen.has(ws.fullpath))
|
|
375
|
-
continue;
|
|
376
|
-
seen.add(ws.fullpath);
|
|
377
|
-
yield ws;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Get all the keys (package names and paths) for loaded workspaces.
|
|
382
|
-
* Union of {@link Monorepo#names} and {@link Monorepo#paths}
|
|
383
|
-
*/
|
|
384
|
-
*keys() {
|
|
385
|
-
for (const ws of this.values()) {
|
|
386
|
-
yield ws.path;
|
|
387
|
-
if (ws.name !== ws.path)
|
|
388
|
-
yield ws.name;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Filter the monorepo object yielding the workspace objects that matches
|
|
393
|
-
* either of the {@link WorkspacesLoadedConfig} options provided, in as close
|
|
394
|
-
* to topological dependency order as possible.
|
|
395
|
-
*/
|
|
396
|
-
*filter({ workspace: namesOrPaths, 'workspace-group': groupName, }) {
|
|
397
|
-
const globPatternChecks = namesOrPaths?.map(glob => minimatch.filter(posix.join(glob)));
|
|
398
|
-
for (const ws of this) {
|
|
399
|
-
// check if any group has any of the provided group names
|
|
400
|
-
if (groupName?.some(i => ws.groups.includes(i))) {
|
|
401
|
-
yield ws;
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
// check if any workspace-provided name directly matches any of the
|
|
405
|
-
// configured workspaces by either name or file path
|
|
406
|
-
if (namesOrPaths
|
|
407
|
-
?.map(i => posix.join(i))
|
|
408
|
-
.some(i => ws.keys.includes(i))) {
|
|
409
|
-
yield ws;
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
// check if one of the workspace values are matching glob patterns
|
|
413
|
-
if (ws.keys.some(key => globPatternChecks?.some(fn => fn(key)))) {
|
|
414
|
-
yield ws;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Run an operation asynchronously over all loaded workspaces
|
|
420
|
-
*
|
|
421
|
-
* If the `forceLoad` param is true, then it will attempt to do a full load
|
|
422
|
-
* when encountering a `workspace:` dependency that isn't loaded.
|
|
423
|
-
*
|
|
424
|
-
* Note that because the return type appears in the parameters of the
|
|
425
|
-
* operation function, it must be set explicitly either in the operation
|
|
426
|
-
* function signature or by calling `run<MyType>` or it'll fall back to
|
|
427
|
-
* `unknown`, similar to `Array.reduce()`, and for the same reason.
|
|
428
|
-
*/
|
|
429
|
-
async run(operation, forceLoad = false) {
|
|
430
|
-
const [ws, ...rest] = [...this.#workspaces.values()];
|
|
431
|
-
if (!ws) {
|
|
432
|
-
throw error('No workspaces loaded', undefined, this.run);
|
|
433
|
-
}
|
|
434
|
-
return graphRun({
|
|
435
|
-
graph: [ws, ...rest],
|
|
436
|
-
getDeps: ws => this.getDeps(ws, forceLoad),
|
|
437
|
-
visit: async (ws, signal, _, depResults) => await operation(ws, signal, depResults),
|
|
438
|
-
onCycle: (ws, cycle, path) => this.onCycle(ws, cycle, path),
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Run an operation synchronously over all loaded workspaces
|
|
443
|
-
*
|
|
444
|
-
* If the `forceLoad` param is true, then it will attempt to do a full load
|
|
445
|
-
* when encountering a `workspace:` dependency that isn't loaded.
|
|
446
|
-
*
|
|
447
|
-
* Note that because the return type appears in the parameters of the
|
|
448
|
-
* operation function, it must be set explicitly either in the operation
|
|
449
|
-
* function signature or by calling `runSync<MyType>` or it'll fall back to
|
|
450
|
-
* `unknown`, similar to `Array.reduce()`, and for the same reason.
|
|
451
|
-
*/
|
|
452
|
-
runSync(operation, forceLoad = false) {
|
|
453
|
-
const [ws, ...rest] = [...this.#workspaces.values()];
|
|
454
|
-
if (!ws) {
|
|
455
|
-
throw error('No workspaces loaded', undefined, this.run);
|
|
456
|
-
}
|
|
457
|
-
return graphRunSync({
|
|
458
|
-
graph: [ws, ...rest],
|
|
459
|
-
getDeps: ws => this.getDeps(ws, forceLoad),
|
|
460
|
-
visit: (ws, signal, _, depResults) => operation(ws, signal, depResults),
|
|
461
|
-
onCycle: (ws, cycle, path) => this.onCycle(ws, cycle, path),
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Convenience method to instantiate and load in one call.
|
|
466
|
-
* Returns undefined if the project is not a monorepo workspaces
|
|
467
|
-
* root, otherwise returns the loaded Monorepo.
|
|
468
|
-
*/
|
|
469
|
-
static maybeLoad(projectRoot, options = { load: {} }) {
|
|
470
|
-
const config = load('workspaces', assertWSConfig);
|
|
471
|
-
if (!config)
|
|
472
|
-
return;
|
|
473
|
-
return new Monorepo(projectRoot, { load: {}, ...options });
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Convenience method to instantiate and load in one call.
|
|
477
|
-
* Throws if called on a directory that is not a workspaces root.
|
|
478
|
-
*/
|
|
479
|
-
static load(projectRoot, options = { load: {} }) {
|
|
480
|
-
const { load = {} } = options;
|
|
481
|
-
return new Monorepo(projectRoot, { ...options, load });
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
export const workspaceCache = new Map();
|
|
485
|
-
/**
|
|
486
|
-
* Class representing a single Workspace in a {@link Monorepo}
|
|
487
|
-
*/
|
|
488
|
-
export class Workspace {
|
|
489
|
-
id;
|
|
490
|
-
path;
|
|
491
|
-
fullpath;
|
|
492
|
-
manifest;
|
|
493
|
-
groups = [];
|
|
494
|
-
name;
|
|
495
|
-
#keys;
|
|
496
|
-
constructor(path, manifest, fullpath) {
|
|
497
|
-
this.id = joinDepIDTuple(['workspace', path]);
|
|
498
|
-
workspaceCache.set(fullpath, this);
|
|
499
|
-
this.path = path;
|
|
500
|
-
this.fullpath = fullpath;
|
|
501
|
-
this.manifest = manifest;
|
|
502
|
-
this.name = manifest.name ?? path;
|
|
503
|
-
}
|
|
504
|
-
get keys() {
|
|
505
|
-
if (this.#keys) {
|
|
506
|
-
return this.#keys;
|
|
507
|
-
}
|
|
508
|
-
this.#keys = [this.name, this.path, this.fullpath];
|
|
509
|
-
return this.#keys;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAE/B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAsCxC;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAa,EACb,IAAa,EACU,EAAE;IACzB,cAAc,CAAC,IAAI,EAAE,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I,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAA;IACnC,CAAC;IAED,IAAI,IAAI;QACN,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,KAAK,CAAA;QACnB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAClD,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;CACF","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { joinDepIDTuple } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { PackageJson } from '@vltpkg/package-json'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport { load } from '@vltpkg/vlt-json'\nimport type { GlobOptionsWithFileTypesFalse } from 'glob'\nimport { globSync } from 'glob'\nimport type { DepResults } from 'graph-run'\nimport { graphRun, graphRunSync } from 'graph-run'\nimport { minimatch } from 'minimatch'\nimport { basename, posix, resolve } from 'node:path'\nimport type { Path } from 'path-scurry'\nimport { PathScurry } from 'path-scurry'\n\nexport type WorkspacesLoadedConfig = {\n workspace?: string[]\n 'workspace-group'?: string[]\n}\n\n/**\n * The object passed to the constructor or {@link Monorepo#load} to limit which\n * {@link Workspace Workspaces} get loaded.\n */\nexport type LoadQuery = {\n /**\n * A glob pattern string, or an array of them. Only workspaces found\n * in paths matched will be loaded.\n */\n paths?: string[] | string\n /**\n * A string, or an array of strings. If set, only workspaces in the\n * specified groups named will be included, if set.\n */\n groups?: string[] | string\n}\n\n/**\n * Canonical form of the {@link WorkspaceConfig}, used\n * internally for consistency.\n */\nexport type WorkspaceConfigObject = Record<string, string[]>\n\n/**\n * Allowed datatype in the `workspaces` field of the `vlt.json` file.\n */\nexport type WorkspaceConfig =\n | string[]\n | WorkspaceConfigObject\n | string\n\n/**\n * Turn a {@link WorkspaceConfig} into a\n * {@link WorkspaceConfigObject}, or throw if it's not valid.\n */\nexport const asWSConfig = (\n conf: unknown,\n path?: string,\n): WorkspaceConfigObject => {\n assertWSConfig(conf, path)\n return (\n typeof conf === 'string' ? { packages: [conf] }\n : Array.isArray(conf) ? { packages: conf }\n : Object.fromEntries(\n Object.entries(conf).map(([k, v]) => [\n k,\n typeof v === 'string' ? [v] : v,\n ]),\n )\n )\n}\n\n/**\n * Throw if the provided value is not a valid {@link WorkspaceConfig}\n */\nexport const assertWSConfig: (\n conf: unknown,\n path?: string,\n) => asserts conf is WorkspaceConfig = (\n conf: unknown,\n path?: string,\n) => {\n if (typeof conf === 'string') return\n\n if (Array.isArray(conf)) {\n for (const c of conf) {\n if (typeof c !== 'string') {\n throw error('Invalid workspace definition', {\n path,\n found: c as unknown,\n wanted: 'string',\n })\n }\n }\n return\n }\n\n if (conf && typeof conf === 'object') {\n for (const [group, value] of Object.entries(conf)) {\n if (typeof value === 'string') continue\n if (Array.isArray(value)) {\n for (const c of value) {\n if (typeof c !== 'string') {\n throw error('Invalid workspace definition', {\n path,\n name: group,\n found: c as unknown,\n wanted: 'string',\n })\n }\n }\n continue\n }\n throw error('Invalid workspace definition', {\n path,\n name: group,\n found: value as unknown,\n wanted: 'string | string[]',\n })\n }\n return\n }\n\n throw error('Invalid workspace definition', {\n path,\n found: conf,\n wanted:\n 'string | string[] | { [group: string]: string | string[] }',\n })\n}\n\nexport type MonorepoOptions = {\n /**\n * A {@link PackageJson} object, for sharing manifest caches\n */\n packageJson?: PackageJson\n /**\n * A {@link PathScurry} object, for use in globs\n */\n scurry?: PathScurry\n /**\n * Parsed normalized contents of the workspaces from a `vlt.json`\n * file\n */\n config?: WorkspaceConfigObject\n /**\n * If set, then {@link Monorepo#load} will be called immediately with\n * this argument.\n */\n load?: LoadQuery\n}\n\n/**\n * Class representing a Monorepo containing multiple workspaces.\n *\n * Does not automatically look up the root, but that can be provided by\n * running `Config.load()`, since it stops seeking the route when a\n * `vlt.json` file is encountered.\n */\nexport class Monorepo {\n /** The project root where vlt.json is found */\n projectRoot: string\n /** Scurry object to cache all filesystem calls (mostly globs) */\n scurry: PathScurry\n\n // maps both name and path to the workspace objects\n #workspaces = new Map<string, Workspace>()\n #groups = new Map<string, Set<Workspace>>()\n #config?: WorkspaceConfigObject\n packageJson: PackageJson\n\n /**\n * Number of {@link Workspace} objects loaded in this Monorepo\n */\n get size(): number {\n return [...this.values()].length\n }\n\n constructor(projectRoot: string, options: MonorepoOptions = {}) {\n this.projectRoot = resolve(projectRoot)\n this.scurry = options.scurry ?? new PathScurry(projectRoot)\n this.packageJson = options.packageJson ?? new PackageJson()\n this.#config = options.config\n if (options.load) this.load(options.load)\n }\n\n /**\n * Load the workspace definitions from vlt.json,\n * canonicalizing the result into the effective `{[group:string]:string[]}`\n * form.\n *\n * Eg:\n * - `\"src/*\"` => `{packages:[\"src/*\"]}`\n * - `{\"apps\": \"src/*\"}` => `{apps: [\"src/*\"]}`\n */\n get config(): WorkspaceConfigObject {\n if (this.#config) return this.#config\n this.#config = asWSConfig(\n load('workspaces', assertWSConfig) ?? {},\n )\n return this.#config\n }\n\n /**\n * Iterating the Monorepo object yields the workspace objects, in as close to\n * topological dependency order as possible.\n */\n *[Symbol.iterator](): Generator<Workspace, void, void> {\n const [ws] = [...this.values()]\n if (!ws) return\n // leverage the fact that graphRun returns results in\n // as close to topological order as possible.\n for (const workspace of this.runSync(() => {}).keys()) {\n yield workspace\n }\n }\n\n /**\n * Iterating the Monorepo object yields the workspace objects, in as close to\n * topological dependency order as possible.\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<\n Workspace,\n void,\n void\n > {\n const [ws] = [...this.values()]\n if (!ws) return\n for (const workspace of (await this.run(() => {})).keys()) {\n yield workspace\n }\n }\n\n /**\n * By default, loads all workspaces reachable in the Monorepo.\n *\n * If provided with one (`string`)or more (`string[]`) group names in\n * the {@link LoadQuery#groups} field, then only Workspaces in the named\n * group(s) will be considered. Note that group names are unique string\n * matches, not globs.\n *\n * If provided with a set of arbitrary path arguments, then only paths\n * patching the provided pattern(s) will be included.\n *\n * These two options intersect, so\n * `load({groups:'foo', paths:'./foo/[xy]*'})` will only load the workspaces\n * in the group `foo` that match the paths glob.\n */\n load(query: LoadQuery = {}): this {\n const paths = new Set(\n typeof query.paths === 'string' ?\n [query.paths]\n : (query.paths ?? []),\n )\n const groups = new Set(\n typeof query.groups === 'string' ?\n [query.groups]\n : (query.groups ?? []),\n )\n\n const groupsExpanded: Record<string, Set<string>> = {}\n for (const [group, pattern] of Object.entries(this.config)) {\n if (groups.size && !groups.has(group)) continue\n groupsExpanded[group] = this.#glob(pattern)\n }\n const filter = paths.size ? this.#glob([...paths]) : paths\n\n // if we specified paths, but none matched, nothing to do\n if (paths.size && !filter.size) return this\n\n for (const [group, matches] of Object.entries(groupsExpanded)) {\n for (const path of matches) {\n if (filter.size && !filter.has(path)) continue\n this.#loadWS(path, group)\n }\n }\n\n return this\n }\n\n // Either load a workspace from disk, or from our internal set,\n // and assign it to the named group\n #loadWS(path: string, group?: string): Workspace {\n const fullpath = resolve(this.projectRoot, path)\n const loaded = this.#workspaces.get(fullpath)\n if (loaded) return loaded\n const fromCache = workspaceCache.get(fullpath)\n const manifest =\n fromCache?.manifest ?? this.packageJson.read(fullpath)\n const ws = fromCache ?? new Workspace(path, manifest, fullpath)\n if (group) ws.groups.push(group)\n\n // Check for duplicate workspace names\n const existingWS = this.#workspaces.get(ws.name)\n if (existingWS && existingWS.fullpath !== ws.fullpath) {\n throw error('Duplicate workspace name found', {\n name: ws.name,\n path: this.projectRoot,\n wanted: ws.fullpath,\n found: existingWS.fullpath,\n })\n }\n\n this.#workspaces.set(ws.fullpath, ws)\n this.#workspaces.set(ws.path, ws)\n this.#workspaces.set(ws.name, ws)\n for (const name of ws.groups) {\n const group = this.#groups.get(name) ?? new Set()\n group.add(ws)\n this.#groups.set(name, group)\n }\n return ws\n }\n\n // can't be cached, because it's dependent on the matches set\n // but still worthwhile to have it defined in one place\n #globOptions(matches: Set<string>): GlobOptionsWithFileTypesFalse {\n // if the entry or any of its parent dirs are already matched,\n // then we should not explore further down that directory tree.\n // if we hit the projectRoot then stop searching.\n const inMatches = (p?: Path): boolean => {\n return (\n !!p?.relativePosix() &&\n (matches.has(p.relativePosix()) || inMatches(p.parent))\n )\n }\n\n return {\n root: this.projectRoot,\n cwd: this.projectRoot,\n posix: true,\n scurry: this.scurry,\n withFileTypes: false,\n ignore: {\n childrenIgnored: p =>\n basename(p.relativePosix()) === 'node_modules' ||\n inMatches(p),\n // ignore if fails to load package.json\n ignored: p => {\n p.lstatSync()\n const rel = p.relativePosix()\n if (!rel) return true\n const maybeDelete: string[] = []\n for (const m of matches) {\n if (rel.startsWith(m + '/')) return true\n if (m.startsWith(rel + '/')) {\n maybeDelete.push(m)\n }\n }\n if (!p.isDirectory()) return true\n const pj = p.resolve('package.json').lstatSync()\n if (!pj?.isFile()) return true\n try {\n this.packageJson.read(p.fullpath())\n } catch {\n return true\n }\n for (const m of maybeDelete) {\n matches.delete(m)\n }\n matches.add(rel)\n return false\n },\n },\n }\n }\n\n #glob(pattern: string[] | string) {\n const matches = new Set<string>()\n globSync(pattern, this.#globOptions(matches))\n return matches\n }\n\n /**\n * Return the array of workspace dependencies that are found in\n * the loaded set, for use in calculating dependency graph order for\n * build operations.\n *\n * This does *not* get the full set of dependencies, or expand any\n * `workspace:` dependencies that are not loaded.\n *\n * Call with the `forceLoad` param set to `true` to attempt a full\n * load if any deps are not currently loaded.\n */\n getDeps(ws: Workspace, forceLoad = false): Workspace[] {\n // load manifest and find workspace: deps\n // filter by those loaded\n const { manifest } = ws\n const depWorkspaces: Workspace[] = []\n let didForceLoad = false\n for (const depType of [\n 'dependencies',\n 'devDependencies',\n 'optionalDependencies',\n 'peerDependencies',\n ] as const) {\n const deps = manifest[depType]\n if (!deps) continue\n for (const [dep, spec] of Object.entries(deps)) {\n if (spec.startsWith('workspace:')) {\n let depWS = this.#workspaces.get(dep)\n if (!depWS) {\n if (!forceLoad) continue\n if (didForceLoad) continue\n didForceLoad = true\n this.load()\n depWS = this.#workspaces.get(dep)\n if (!depWS) continue\n }\n depWorkspaces.push(depWS)\n }\n }\n }\n return depWorkspaces\n }\n\n onCycle(\n _ws: Workspace,\n _cycle: Workspace[],\n _depPath: Workspace[],\n ) {\n // XXX - process logging? Need to say something like:\n // Cyclical workspace dependency warning!\n // When evaluating dependency ${ws.name} via ${\n // path.map(ws => ws.name).join(' -> ')\n // }, a dependency cycle was detected: ${\n // cycle.map(ws => ws.name).join(' -> ')\n // }. Operation will continue, but dependency order not guaranteed.`\n }\n\n /**\n * Return the set of workspaces in the named group.\n * If the group is not one we know about, then undefined is returned.\n */\n group(group: string) {\n return this.#groups.get(group)\n }\n\n /**\n * Get a loaded workspace by path or name.\n *\n * Note that this can only return workspaces that were ingested via a\n * previous call to {@link Monorepo#load}.\n */\n get(nameOrPath: string) {\n return this.#workspaces.get(nameOrPath)\n }\n\n /**\n * get the list of all loaded workspace names used as keys\n */\n *names() {\n for (const [key, ws] of this.#workspaces) {\n if (key === ws.name) yield key\n }\n }\n\n /**\n * get the list of all loaded workspace paths used as keys\n */\n *paths() {\n for (const [key, ws] of this.#workspaces) {\n if (key === ws.path) yield key\n }\n }\n\n /**\n * get the workspace objects in no particular order.\n * this is ever so slightly faster than iterating, because it doesn't\n * explore the graph to yield results in topological dependency order,\n * and should be used instead when order doesn't matter.\n */\n *values() {\n const seen = new Set<string>()\n for (const ws of this.#workspaces.values()) {\n if (seen.has(ws.fullpath)) continue\n seen.add(ws.fullpath)\n yield ws\n }\n }\n\n /**\n * Get all the keys (package names and paths) for loaded workspaces.\n * Union of {@link Monorepo#names} and {@link Monorepo#paths}\n */\n *keys() {\n for (const ws of this.values()) {\n yield ws.path\n if (ws.name !== ws.path) yield ws.name\n }\n }\n\n /**\n * Filter the monorepo object yielding the workspace objects that matches\n * either of the {@link WorkspacesLoadedConfig} options provided, in as close\n * to topological dependency order as possible.\n */\n *filter({\n workspace: namesOrPaths,\n 'workspace-group': groupName,\n }: WorkspacesLoadedConfig) {\n const globPatternChecks = namesOrPaths?.map(glob =>\n minimatch.filter(posix.join(glob)),\n )\n for (const ws of this) {\n // check if any group has any of the provided group names\n if (groupName?.some(i => ws.groups.includes(i))) {\n yield ws\n continue\n }\n // check if any workspace-provided name directly matches any of the\n // configured workspaces by either name or file path\n if (\n namesOrPaths\n ?.map(i => posix.join(i))\n .some(i => ws.keys.includes(i))\n ) {\n yield ws\n continue\n }\n // check if one of the workspace values are matching glob patterns\n if (\n ws.keys.some(key => globPatternChecks?.some(fn => fn(key)))\n ) {\n yield ws\n }\n }\n }\n\n /**\n * Run an operation asynchronously over all loaded workspaces\n *\n * If the `forceLoad` param is true, then it will attempt to do a full load\n * when encountering a `workspace:` dependency that isn't loaded.\n *\n * Note that because the return type appears in the parameters of the\n * operation function, it must be set explicitly either in the operation\n * function signature or by calling `run<MyType>` or it'll fall back to\n * `unknown`, similar to `Array.reduce()`, and for the same reason.\n */\n async run<R>(\n operation: (\n s: Workspace,\n signal: AbortSignal,\n depResults: DepResults<Workspace, R>,\n ) => Promise<R> | R,\n forceLoad = false,\n ) {\n const [ws, ...rest] = [...this.#workspaces.values()]\n if (!ws) {\n throw error('No workspaces loaded', undefined, this.run)\n }\n\n return graphRun<Workspace, R>({\n graph: [ws, ...rest],\n getDeps: ws => this.getDeps(ws, forceLoad),\n visit: async (ws, signal, _, depResults) =>\n await operation(ws, signal, depResults),\n onCycle: (ws, cycle, path) => this.onCycle(ws, cycle, path),\n })\n }\n\n /**\n * Run an operation synchronously over all loaded workspaces\n *\n * If the `forceLoad` param is true, then it will attempt to do a full load\n * when encountering a `workspace:` dependency that isn't loaded.\n *\n * Note that because the return type appears in the parameters of the\n * operation function, it must be set explicitly either in the operation\n * function signature or by calling `runSync<MyType>` or it'll fall back to\n * `unknown`, similar to `Array.reduce()`, and for the same reason.\n */\n runSync<R>(\n operation: (\n s: Workspace,\n signal: AbortSignal,\n depResults: DepResults<Workspace, R>,\n ) => R,\n forceLoad = false,\n ) {\n const [ws, ...rest] = [...this.#workspaces.values()]\n if (!ws) {\n throw error('No workspaces loaded', undefined, this.run)\n }\n\n return graphRunSync<Workspace, R>({\n graph: [ws, ...rest],\n getDeps: ws => this.getDeps(ws, forceLoad),\n visit: (ws, signal, _, depResults) =>\n operation(ws, signal, depResults),\n onCycle: (ws, cycle, path) => this.onCycle(ws, cycle, path),\n })\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Returns undefined if the project is not a monorepo workspaces\n * root, otherwise returns the loaded Monorepo.\n */\n static maybeLoad(\n projectRoot: string,\n options: MonorepoOptions = { load: {} },\n ) {\n const config = load('workspaces', assertWSConfig)\n if (!config) return\n return new Monorepo(projectRoot, { load: {}, ...options })\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Throws if called on a directory that is not a workspaces root.\n */\n static load(\n projectRoot: string,\n options: MonorepoOptions = { load: {} },\n ) {\n const { load = {} } = options\n return new Monorepo(projectRoot, { ...options, load })\n }\n}\n\nexport const workspaceCache = new Map<string, Workspace>()\n\n/**\n * Class representing a single Workspace in a {@link Monorepo}\n */\nexport class Workspace {\n id: DepID\n path: string\n fullpath: string\n manifest: NormalizedManifest\n groups: string[] = []\n name: string\n #keys?: string[]\n\n constructor(\n path: string,\n manifest: NormalizedManifest,\n fullpath: string,\n ) {\n this.id = joinDepIDTuple(['workspace', path])\n workspaceCache.set(fullpath, this)\n this.path = path\n this.fullpath = fullpath\n this.manifest = manifest\n this.name = manifest.name ?? path\n }\n\n get keys(): string[] {\n if (this.#keys) {\n return this.#keys\n }\n this.#keys = [this.name, this.path, this.fullpath]\n return this.#keys\n }\n}\n"]}
|
package/dist/esm/package.json
DELETED