@travetto/manifest 4.0.0-rc.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/manifest",
3
- "version": "4.0.0-rc.4",
3
+ "version": "4.0.0-rc.5",
4
4
  "description": "Support for project indexing, manifesting, along with file watching",
5
5
  "keywords": [
6
6
  "path",
@@ -23,23 +23,56 @@ type Req = {
23
23
  */
24
24
  export class PackageModuleVisitor {
25
25
 
26
- constructor(public ctx: ManifestContext) {
27
- this.#mainSourcePath = path.resolve(this.ctx.workspace.path, this.ctx.main.folder);
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: Map<string, string>;
33
+ #workspaceModules: Record<string, string>;
34
+ #ctx: ManifestContext;
35
+
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;
40
+ }
41
+
42
+ /**
43
+ * Build a package module
44
+ */
45
+ #create(sourcePath: string, { main, workspace, prod = false, roleRoot = false, parent }: CreateOpts = {}): Req {
46
+ const pkg = PackageUtil.readPackage(sourcePath);
47
+ const value = this.#cache[sourcePath] ??= {
48
+ main,
49
+ prod,
50
+ name: pkg.name,
51
+ version: pkg.version,
52
+ workspace: workspace ?? (pkg.name in this.#workspaceModules),
53
+ internal: pkg.private === true,
54
+ sourceFolder: sourcePath === this.#ctx.workspace.path ? '' : sourcePath.replace(`${this.#ctx.workspace.path}/`, ''),
55
+ outputFolder: `node_modules/${pkg.name}`,
56
+ state: {
57
+ childSet: new Set(), parentSet: new Set(), roleSet: new Set(), roleRoot,
58
+ travetto: pkg.travetto, prodDeps: new Set(Object.keys(pkg.dependencies ?? {}))
59
+ }
60
+ };
61
+
62
+ const deps: PackageDepType[] = ['dependencies', ...(value.main ? ['devDependencies'] as const : [])];
63
+ const children = Object.fromEntries(deps.flatMap(x => Object.entries(pkg[x] ?? {})));
64
+ return { pkg, value, children, parent };
65
+ }
33
66
 
34
67
  /**
35
68
  * Get monorepo root includes
36
69
  */
37
70
  #getMonoRootIncludes(parent: Req): Req[] {
38
- if (!(this.ctx.workspace.mono && !this.ctx.main.folder)) { // If not mono root, bail
71
+ if (!(this.#ctx.workspace.mono && !this.#ctx.main.folder)) { // If not mono root, bail
39
72
  return [];
40
73
  }
41
74
 
42
- return [...this.#workspaceModules.values()]
75
+ return Object.values(this.#workspaceModules)
43
76
  .map(loc => this.#create(loc, { main: true, workspace: true, roleRoot: true, parent: parent.value }));
44
77
  }
45
78
 
@@ -47,63 +80,22 @@ export class PackageModuleVisitor {
47
80
  * Determine default includes
48
81
  */
49
82
  #getIncludes(parent: Req): Req[] {
50
- if (this.ctx.workspace.mono && !this.ctx.main.folder) { // If mono and not at mono root, bail
83
+ if (this.#ctx.workspace.mono && !this.#ctx.main.folder) { // If mono and not at mono root, bail
51
84
  return [];
52
85
  }
53
86
 
54
- const root = PackageUtil.readPackage(this.ctx.workspace.path);
87
+ const root = PackageUtil.readPackage(this.#ctx.workspace.path);
55
88
  if (root.travetto?.build?.includes) {
56
89
  return Object.entries(root.travetto.build.includes).map(([name, type]) =>
57
90
  this.#create(PackageUtil.resolvePackagePath(name), { main: type === 'main', workspace: true, parent: parent.value })
58
91
  );
59
92
  } else {
60
- return [...this.#workspaceModules.values()]
93
+ return Object.values(this.#workspaceModules)
61
94
  .filter((loc) => PackageUtil.readPackage(loc).travetto?.workspaceInclude)
62
95
  .map(loc => this.#create(loc, { workspace: true, parent: parent.value }));
63
96
  }
64
97
  }
65
98
 
66
- /**
67
- * Initialize visitor, and provide global dependencies
68
- */
69
- async init(): Promise<Iterable<Req>> {
70
- const mainReq = this.#create(this.#mainSourcePath, { main: true, workspace: true, roleRoot: true, prod: true });
71
- this.#workspaceModules = new Map(
72
- (await PackageUtil.resolveWorkspaces(this.ctx)).map(x => [x.name, x.path])
73
- );
74
-
75
- return [
76
- mainReq,
77
- ...this.#getMonoRootIncludes(mainReq),
78
- ...this.#getIncludes(mainReq)
79
- ];
80
- }
81
-
82
- /**
83
- * Build a package module
84
- */
85
- #create(sourcePath: string, { main, workspace, prod = false, roleRoot = false, parent }: CreateOpts = {}): Req {
86
- const pkg = PackageUtil.readPackage(sourcePath);
87
- const value = this.#cache[sourcePath] ??= {
88
- main,
89
- prod,
90
- name: pkg.name,
91
- version: pkg.version,
92
- workspace: workspace ?? this.#workspaceModules.has(pkg.name),
93
- internal: pkg.private === true,
94
- sourceFolder: sourcePath === this.ctx.workspace.path ? '' : sourcePath.replace(`${this.ctx.workspace.path}/`, ''),
95
- outputFolder: `node_modules/${pkg.name}`,
96
- state: {
97
- childSet: new Set(), parentSet: new Set(), roleSet: new Set(), roleRoot,
98
- travetto: pkg.travetto, prodDeps: new Set(Object.keys(pkg.dependencies ?? {}))
99
- }
100
- };
101
-
102
- const deps: PackageDepType[] = ['dependencies', ...(value.main ? ['devDependencies'] as const : [])];
103
- const children = Object.fromEntries(deps.flatMap(x => Object.entries(pkg[x] ?? {})));
104
- return { pkg, value, children, parent };
105
- }
106
-
107
99
  /**
108
100
  * Propagate prod, role information through graph
109
101
  */
@@ -163,7 +155,13 @@ export class PackageModuleVisitor {
163
155
  */
164
156
  async visit(): Promise<Iterable<PackageModule>> {
165
157
  const seen = new Set<PackageModule>();
166
- const queue = [...await this.init()];
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
+ ];
167
165
 
168
166
  while (queue.length) {
169
167
  const { value: node, parent, children, pkg } = queue.shift()!; // Visit initial set first
@@ -172,7 +170,7 @@ export class PackageModuleVisitor {
172
170
  }
173
171
 
174
172
  // Track parentage
175
- if (node.name !== this.ctx.main.name && parent) {
173
+ if (node.name !== this.#ctx.main.name && parent) {
176
174
  node.state.parentSet.add(parent.name);
177
175
  parent.state.childSet.add(node.name);
178
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 new PackageModuleVisitor(ctx).visit();
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/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,