@travetto/manifest 4.0.0-rc.3 → 4.0.0-rc.5
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 +1 -1
- package/src/dependencies.ts +51 -33
- package/src/module.ts +1 -1
- package/src/types/package.ts +2 -1
- package/src/util.ts +2 -2
package/package.json
CHANGED
package/src/dependencies.ts
CHANGED
|
@@ -23,40 +23,20 @@ type Req = {
|
|
|
23
23
|
*/
|
|
24
24
|
export class PackageModuleVisitor {
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
static async visit(ctx: ManifestContext): Promise<Iterable<PackageModule>> {
|
|
27
|
+
const visitor = new PackageModuleVisitor(ctx, Object.fromEntries((await PackageUtil.resolveWorkspaces(ctx)).map(x => [x.name, x.path])));
|
|
28
|
+
return visitor.visit();
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
#mainSourcePath: string;
|
|
31
32
|
#cache: Record<string, PackageModule> = {};
|
|
32
|
-
#workspaceModules:
|
|
33
|
+
#workspaceModules: Record<string, string>;
|
|
34
|
+
#ctx: ManifestContext;
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const mainReq = this.#create(this.#mainSourcePath, { main: true, workspace: true, roleRoot: true, prod: true });
|
|
39
|
-
const globals = [mainReq];
|
|
40
|
-
this.#workspaceModules = new Map(
|
|
41
|
-
(await PackageUtil.resolveWorkspaces(this.ctx)).map(x => [x.name, x.path])
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Treat all workspace modules as main modules
|
|
45
|
-
if (this.ctx.workspace.mono && !this.ctx.main.folder) {
|
|
46
|
-
for (const [, loc] of this.#workspaceModules) {
|
|
47
|
-
globals.push(this.#create(loc, { main: true, workspace: true, roleRoot: true, parent: mainReq.value }));
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
// If we have 'withModules' at workspace root
|
|
51
|
-
const root = PackageUtil.readPackage(this.ctx.workspace.path);
|
|
52
|
-
for (const [name, type] of Object.entries(root.travetto?.build?.withModules ?? {})) {
|
|
53
|
-
globals.push(this.#create(PackageUtil.resolvePackagePath(name),
|
|
54
|
-
{ main: type === 'main', workspace: true, parent: mainReq.value }
|
|
55
|
-
));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return globals;
|
|
36
|
+
constructor(ctx: ManifestContext, workspaceModules: Record<string, string>) {
|
|
37
|
+
this.#mainSourcePath = path.resolve(ctx.workspace.path, ctx.main.folder);
|
|
38
|
+
this.#ctx = ctx;
|
|
39
|
+
this.#workspaceModules = workspaceModules;
|
|
60
40
|
}
|
|
61
41
|
|
|
62
42
|
/**
|
|
@@ -69,9 +49,9 @@ export class PackageModuleVisitor {
|
|
|
69
49
|
prod,
|
|
70
50
|
name: pkg.name,
|
|
71
51
|
version: pkg.version,
|
|
72
|
-
workspace: workspace ??
|
|
52
|
+
workspace: workspace ?? (pkg.name in this.#workspaceModules),
|
|
73
53
|
internal: pkg.private === true,
|
|
74
|
-
sourceFolder: sourcePath === this
|
|
54
|
+
sourceFolder: sourcePath === this.#ctx.workspace.path ? '' : sourcePath.replace(`${this.#ctx.workspace.path}/`, ''),
|
|
75
55
|
outputFolder: `node_modules/${pkg.name}`,
|
|
76
56
|
state: {
|
|
77
57
|
childSet: new Set(), parentSet: new Set(), roleSet: new Set(), roleRoot,
|
|
@@ -84,6 +64,38 @@ export class PackageModuleVisitor {
|
|
|
84
64
|
return { pkg, value, children, parent };
|
|
85
65
|
}
|
|
86
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Get monorepo root includes
|
|
69
|
+
*/
|
|
70
|
+
#getMonoRootIncludes(parent: Req): Req[] {
|
|
71
|
+
if (!(this.#ctx.workspace.mono && !this.#ctx.main.folder)) { // If not mono root, bail
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return Object.values(this.#workspaceModules)
|
|
76
|
+
.map(loc => this.#create(loc, { main: true, workspace: true, roleRoot: true, parent: parent.value }));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Determine default includes
|
|
81
|
+
*/
|
|
82
|
+
#getIncludes(parent: Req): Req[] {
|
|
83
|
+
if (this.#ctx.workspace.mono && !this.#ctx.main.folder) { // If mono and not at mono root, bail
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const root = PackageUtil.readPackage(this.#ctx.workspace.path);
|
|
88
|
+
if (root.travetto?.build?.includes) {
|
|
89
|
+
return Object.entries(root.travetto.build.includes).map(([name, type]) =>
|
|
90
|
+
this.#create(PackageUtil.resolvePackagePath(name), { main: type === 'main', workspace: true, parent: parent.value })
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
return Object.values(this.#workspaceModules)
|
|
94
|
+
.filter((loc) => PackageUtil.readPackage(loc).travetto?.workspaceInclude)
|
|
95
|
+
.map(loc => this.#create(loc, { workspace: true, parent: parent.value }));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
/**
|
|
88
100
|
* Propagate prod, role information through graph
|
|
89
101
|
*/
|
|
@@ -143,7 +155,13 @@ export class PackageModuleVisitor {
|
|
|
143
155
|
*/
|
|
144
156
|
async visit(): Promise<Iterable<PackageModule>> {
|
|
145
157
|
const seen = new Set<PackageModule>();
|
|
146
|
-
const
|
|
158
|
+
const mainReq = this.#create(this.#mainSourcePath, { main: true, workspace: true, roleRoot: true, prod: true });
|
|
159
|
+
|
|
160
|
+
const queue = [
|
|
161
|
+
mainReq,
|
|
162
|
+
...this.#getMonoRootIncludes(mainReq),
|
|
163
|
+
...this.#getIncludes(mainReq)
|
|
164
|
+
];
|
|
147
165
|
|
|
148
166
|
while (queue.length) {
|
|
149
167
|
const { value: node, parent, children, pkg } = queue.shift()!; // Visit initial set first
|
|
@@ -152,7 +170,7 @@ export class PackageModuleVisitor {
|
|
|
152
170
|
}
|
|
153
171
|
|
|
154
172
|
// Track parentage
|
|
155
|
-
if (node.name !== this
|
|
173
|
+
if (node.name !== this.#ctx.main.name && parent) {
|
|
156
174
|
node.state.parentSet.add(parent.name);
|
|
157
175
|
parent.state.childSet.add(node.name);
|
|
158
176
|
}
|
package/src/module.ts
CHANGED
|
@@ -197,7 +197,7 @@ export class ManifestModuleUtil {
|
|
|
197
197
|
* Produce all modules for a given manifest folder, adding in some given modules when developing framework
|
|
198
198
|
*/
|
|
199
199
|
static async produceModules(ctx: ManifestContext): Promise<Record<string, ManifestModule>> {
|
|
200
|
-
const pkgs = await
|
|
200
|
+
const pkgs = await PackageModuleVisitor.visit(ctx);
|
|
201
201
|
const modules = await Promise.all([...pkgs].map(x => this.describeModule(ctx, x)));
|
|
202
202
|
return Object.fromEntries(modules.map(m => [m.name, m]));
|
|
203
203
|
}
|
package/src/types/package.ts
CHANGED
|
@@ -41,9 +41,10 @@ export type Package = {
|
|
|
41
41
|
outputs?: string[];
|
|
42
42
|
};
|
|
43
43
|
defaultEnv?: string;
|
|
44
|
+
workspaceInclude?: boolean;
|
|
44
45
|
build?: Partial<ManifestContext['build']> & {
|
|
45
46
|
isolated?: boolean;
|
|
46
|
-
|
|
47
|
+
includes?: Record<string, 'main' | true>;
|
|
47
48
|
watchIgnores?: string[];
|
|
48
49
|
};
|
|
49
50
|
};
|
package/src/util.ts
CHANGED
|
@@ -116,9 +116,9 @@ export class ManifestUtil {
|
|
|
116
116
|
/**
|
|
117
117
|
* Produce the manifest context for a given module module
|
|
118
118
|
*/
|
|
119
|
-
static getModuleContext(ctx: ManifestContext, folder: string): ManifestContext {
|
|
119
|
+
static getModuleContext(ctx: ManifestContext, folder: string, ensureLatest = false): ManifestContext {
|
|
120
120
|
const modPath = path.resolve(ctx.workspace.path, folder);
|
|
121
|
-
const pkg = PackageUtil.readPackage(modPath);
|
|
121
|
+
const pkg = PackageUtil.readPackage(modPath, ensureLatest);
|
|
122
122
|
|
|
123
123
|
return {
|
|
124
124
|
workspace: ctx.workspace,
|