@jointhedots/gear 1.2.0 → 1.2.3

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.
Files changed (115) hide show
  1. package/esm/builder/build-app-bundle.d.ts +29 -0
  2. package/esm/builder/build-app-bundle.js +9 -6
  3. package/esm/builder/build-app-host.d.ts +28 -0
  4. package/esm/builder/build-app-host.js +20 -19
  5. package/esm/builder/build-application.d.ts +51 -0
  6. package/esm/builder/build-application.js +53 -74
  7. package/esm/builder/build-library.d.ts +21 -0
  8. package/esm/builder/build-library.js +13 -10
  9. package/esm/builder/build-target.d.ts +36 -0
  10. package/esm/builder/build-target.js +20 -12
  11. package/esm/builder/helpers/emit-artifact.d.ts +13 -0
  12. package/esm/builder/helpers/emit-artifact.js +40 -0
  13. package/esm/builder/helpers/emit-bundle-manifest.d.ts +19 -0
  14. package/esm/builder/helpers/emit-bundle-manifest.js +38 -16
  15. package/esm/builder/helpers/emit-components-dts.d.ts +9 -0
  16. package/esm/builder/helpers/emit-components-dts.js +1 -2
  17. package/esm/builder/helpers/emit-esmodules.d.ts +61 -0
  18. package/esm/builder/helpers/emit-esmodules.js +22 -23
  19. package/esm/builder/helpers/emit-package-manifest.d.ts +9 -0
  20. package/esm/builder/helpers/emit-package-manifest.js +1 -2
  21. package/esm/builder/helpers/emit-static-assets.d.ts +14 -0
  22. package/esm/builder/helpers/emit-static-assets.js +1 -2
  23. package/esm/builder/helpers/emit-typescript-definition.d.ts +35 -0
  24. package/esm/builder/helpers/emit-typescript-definition.js +7 -8
  25. package/esm/builder/helpers/path-helpers.d.ts +9 -0
  26. package/esm/builder/helpers/path-helpers.js +0 -1
  27. package/esm/builder/helpers/task.d.ts +8 -0
  28. package/esm/builder/helpers/task.js +0 -1
  29. package/esm/cli.d.ts +2 -0
  30. package/esm/cli.js +1 -4
  31. package/esm/commands/init.d.ts +2 -0
  32. package/esm/commands/init.js +0 -1
  33. package/esm/commands/install.d.ts +5 -0
  34. package/esm/commands/install.js +3 -4
  35. package/esm/commands/make.d.ts +17 -0
  36. package/esm/commands/make.js +12 -5
  37. package/esm/commands/run.d.ts +8 -0
  38. package/esm/commands/run.js +6 -7
  39. package/esm/commands/serve.d.ts +9 -0
  40. package/esm/commands/serve.js +11 -13
  41. package/esm/core/commands/interface.d.ts +26 -0
  42. package/esm/core/commands/interface.js +21 -0
  43. package/esm/core/components/components.d.ts +73 -0
  44. package/esm/core/components/components.js +2 -0
  45. package/esm/core/components/helpers.d.ts +7 -0
  46. package/esm/core/components/helpers.js +68 -0
  47. package/esm/core/components/manifold.d.ts +77 -0
  48. package/esm/core/components/manifold.js +442 -0
  49. package/esm/core/components/mod.d.ts +4 -0
  50. package/esm/core/components/mod.js +4 -0
  51. package/esm/core/components/provider.d.ts +42 -0
  52. package/esm/core/components/provider.js +127 -0
  53. package/esm/core/logging/mod.d.ts +53 -0
  54. package/esm/core/logging/mod.js +142 -0
  55. package/esm/core/logging/trace.d.ts +51 -0
  56. package/esm/core/logging/trace.js +17 -0
  57. package/esm/core/mod-browser.d.ts +1 -0
  58. package/esm/core/mod-browser.js +1 -0
  59. package/esm/core/mod-node.d.ts +1 -0
  60. package/esm/core/mod-node.js +1 -0
  61. package/esm/core/mod.d.ts +5 -0
  62. package/esm/core/mod.js +5 -0
  63. package/esm/core/schema/helpers.d.ts +36 -0
  64. package/esm/core/schema/helpers.js +163 -0
  65. package/esm/core/schema/mod.d.ts +3 -0
  66. package/esm/core/schema/mod.js +3 -0
  67. package/esm/core/schema/schema.d.ts +376 -0
  68. package/esm/core/schema/schema.js +234 -0
  69. package/esm/core/schema/zod.d.ts +44 -0
  70. package/esm/core/schema/zod.js +127 -0
  71. package/esm/core/services/mod.d.ts +5 -0
  72. package/esm/core/services/mod.js +5 -0
  73. package/esm/core/services/service-accessor.d.ts +17 -0
  74. package/esm/core/services/service-accessor.js +20 -0
  75. package/esm/core/services/service-definitions.d.ts +37 -0
  76. package/esm/core/services/service-definitions.js +44 -0
  77. package/esm/core/services/service-points.d.ts +40 -0
  78. package/esm/core/services/service-points.js +164 -0
  79. package/esm/core/services/service-specification.d.ts +52 -0
  80. package/esm/core/services/service-specification.js +59 -0
  81. package/esm/core/services/settings.d.ts +29 -0
  82. package/esm/core/services/settings.js +123 -0
  83. package/esm/utils/file.d.ts +39 -0
  84. package/esm/utils/file.js +3 -4
  85. package/esm/utils/graph-ordering.d.ts +21 -0
  86. package/esm/utils/graph-ordering.js +0 -1
  87. package/esm/utils/normalized-name.d.ts +17 -0
  88. package/esm/utils/normalized-name.js +0 -1
  89. package/esm/workspace/component.d.ts +70 -0
  90. package/esm/workspace/component.js +0 -1
  91. package/esm/workspace/helpers/config-loader.d.ts +37 -0
  92. package/esm/workspace/helpers/config-loader.js +4 -5
  93. package/esm/workspace/helpers/create-manifests.d.ts +13 -0
  94. package/esm/workspace/helpers/create-manifests.js +3 -4
  95. package/esm/workspace/helpers/discover-workspace.d.ts +4 -0
  96. package/esm/workspace/helpers/discover-workspace.js +19 -30
  97. package/esm/workspace/helpers/lockfile.d.ts +5 -0
  98. package/esm/workspace/helpers/lockfile.js +13 -14
  99. package/esm/workspace/helpers/logger.d.ts +65 -0
  100. package/esm/workspace/helpers/logger.js +1 -2
  101. package/esm/workspace/helpers/package-npm.d.ts +1 -0
  102. package/esm/workspace/helpers/package-npm.js +0 -1
  103. package/esm/workspace/mod.d.ts +1 -0
  104. package/esm/workspace/mod.js +1 -0
  105. package/esm/workspace/packager.d.ts +5 -0
  106. package/esm/workspace/packager.js +1 -2
  107. package/esm/workspace/packagers/packager-standard.d.ts +7 -0
  108. package/esm/workspace/packagers/packager-standard.js +3 -4
  109. package/esm/workspace/storage.d.ts +59 -0
  110. package/esm/workspace/storage.js +4 -5
  111. package/esm/workspace/workspace.d.ts +165 -0
  112. package/esm/workspace/workspace.js +27 -16
  113. package/package.json +74 -66
  114. package/esm/commands/publish.js +0 -36
  115. package/esm/publish/publish_aws_s3.js +0 -67
@@ -0,0 +1,123 @@
1
+ export var WriteMode;
2
+ (function (WriteMode) {
3
+ WriteMode[WriteMode["Default"] = 0] = "Default";
4
+ WriteMode[WriteMode["Reset"] = 1] = "Reset";
5
+ WriteMode[WriteMode["Temporary"] = 2] = "Temporary";
6
+ })(WriteMode || (WriteMode = {}));
7
+ export class AccountSettings {
8
+ name;
9
+ key = null;
10
+ stores = createSettingStores();
11
+ temporaries = createSettingStores();
12
+ settings = createSettingStores();
13
+ constructor(name) {
14
+ this.name = name;
15
+ this.key = `settings://${this.name}`;
16
+ try {
17
+ const bytes = localStorage.getItem(this.key);
18
+ this.restore(JSON.parse(bytes).stores);
19
+ }
20
+ catch (_) { }
21
+ try {
22
+ window.addEventListener("storage", (evt) => {
23
+ const { key, newValue } = evt;
24
+ if (key === this.key) {
25
+ try {
26
+ this.restore(JSON.parse(newValue).stores);
27
+ }
28
+ catch (_) { }
29
+ }
30
+ });
31
+ }
32
+ catch (e) {
33
+ console.error(e.message);
34
+ }
35
+ }
36
+ get(group, key) {
37
+ let data = this.settings[group][key];
38
+ if (!data) {
39
+ const bytes = this.temporaries[group][key] || this.stores[group][key];
40
+ if (bytes) {
41
+ data = JSON.parse(bytes);
42
+ this.settings[group][key] = data;
43
+ }
44
+ }
45
+ return data;
46
+ }
47
+ set(group, key, descriptor, mode = WriteMode.Default) {
48
+ const data = JSON.stringify(descriptor);
49
+ if (this.write(group, key, data, mode)) {
50
+ this.settings[group][key] = descriptor;
51
+ notifySettingsChange(this, group, key);
52
+ return true;
53
+ }
54
+ return false;
55
+ }
56
+ list(group) {
57
+ if (Object.keys(this.temporaries[group]).length > 0) {
58
+ return Object.keys(Object.assign({}, this.stores[group], this.temporaries[group]));
59
+ }
60
+ else {
61
+ return Object.keys(this.stores[group]);
62
+ }
63
+ }
64
+ read(key) {
65
+ return this.stores[key];
66
+ }
67
+ write(group, key, data, mode) {
68
+ if (mode !== WriteMode.Reset && this.temporaries[group][key] !== undefined) {
69
+ mode = WriteMode.Temporary;
70
+ }
71
+ if (mode === WriteMode.Temporary) {
72
+ if (this.temporaries[group][key] !== data) {
73
+ this.temporaries[group][key] = data;
74
+ this.settings[group][key] = null;
75
+ return true;
76
+ }
77
+ }
78
+ else if (this.stores[group][key] !== data) {
79
+ this.stores[group][key] = data;
80
+ this.settings[group][key] = null;
81
+ if (mode === WriteMode.Default) {
82
+ localStorage.setItem(this.key, JSON.stringify({ stores: this.stores }));
83
+ }
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ restore(stores) {
89
+ for (const group in stores) {
90
+ for (const key in stores[group]) {
91
+ if (this.write(group, key, stores[group][key], WriteMode.Reset)) {
92
+ notifySettingsChange(this, group, key);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ const Settings_ChangeHandlers = new Set();
99
+ const Settings = new AccountSettings("default");
100
+ export function getSettings() {
101
+ return Settings;
102
+ }
103
+ export function listenSettings(handler) {
104
+ Settings_ChangeHandlers.add(handler);
105
+ return handler;
106
+ }
107
+ export function unlistenSettings(handler) {
108
+ Settings_ChangeHandlers.delete(handler);
109
+ }
110
+ function notifySettingsChange(settings, group, key) {
111
+ if (settings === Settings && settings.settings[group][key] !== undefined) {
112
+ for (const handler of Settings_ChangeHandlers) {
113
+ handler(group, key);
114
+ }
115
+ }
116
+ }
117
+ function createSettingStores() {
118
+ return {
119
+ service_points: {},
120
+ components: {},
121
+ shareds: {},
122
+ };
123
+ }
@@ -0,0 +1,39 @@
1
+ import Fs from "node:fs";
2
+ export declare const PackageRootDir: string;
3
+ export declare const file: {
4
+ exists(path: string): boolean;
5
+ copy: {
6
+ toFile(src: string, dest: string): string;
7
+ toDir(src: string, dest: string): string;
8
+ };
9
+ move: {
10
+ toFile(src: string, dest: string): string;
11
+ toDir(src: string, dest: string): string;
12
+ };
13
+ read: {
14
+ json(path: string): any;
15
+ text(path: string): string;
16
+ };
17
+ write: {
18
+ json(path: string, data: any): void;
19
+ text(path: string, data: string): void;
20
+ };
21
+ find: {
22
+ upperDir(base: string, subpath: string): string;
23
+ };
24
+ remove(path: string): void;
25
+ };
26
+ export declare const directory: {
27
+ exists(path: string): boolean;
28
+ filenames(path: string, recursive?: Boolean): string[];
29
+ copy(src: string, dest: string, filter?: (name: string, path: string, stats: Fs.Stats) => boolean): void;
30
+ make(path: string): void;
31
+ remove(path: string, onlyInner?: boolean): void;
32
+ clean(path: string): void;
33
+ };
34
+ export declare function make_relative_path(baseDir: string, ...path: string[]): string;
35
+ export declare function make_normalized_path(baseDir: string, ...path: string[]): string;
36
+ export declare function make_normalized_dirname(baseDir: string, ...path: string[]): string;
37
+ export declare function make_canonical_path(baseDir: string, ...path: string[]): string;
38
+ /** Resolve a file path with extension probing */
39
+ export declare function resolve_normalized_suffixed_path(baseDir: string, path: string, exts?: string[]): string | null;
package/esm/utils/file.js CHANGED
@@ -1,6 +1,6 @@
1
- import Path from "path";
2
- import Fs from "fs";
3
- import { fileURLToPath } from "url";
1
+ import Path from "node:path";
2
+ import Fs from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
4
  export const PackageRootDir = Path.resolve(fileURLToPath(import.meta.url), "../../..");
5
5
  export const file = {
6
6
  exists(path) {
@@ -212,4 +212,3 @@ export function resolve_normalized_suffixed_path(baseDir, path, exts = FILE_EXTE
212
212
  }
213
213
  return null;
214
214
  }
215
- //# sourceMappingURL=file.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Topological sort using Tarjan's algorithm.
3
+ * Returns nodes in dependency order (dependencies come first).
4
+ * Throws if a cycle is detected.
5
+ *
6
+ * @param nodes - Array of node identifiers
7
+ * @param edges - Function that returns outgoing edges (dependencies) for a node
8
+ * @returns Nodes in topological order
9
+ */
10
+ export declare function topologicalSort<T>(nodes: Iterable<T>, edges: (node: T) => Iterable<T>): T[];
11
+ /**
12
+ * Get topological order with cycle detection that returns cycle info instead of throwing.
13
+ *
14
+ * @param nodes - Array of node identifiers
15
+ * @param edges - Function that returns outgoing edges for a node
16
+ * @returns Object with ordered nodes and any detected cycles
17
+ */
18
+ export declare function getGraphOrder<T>(nodes: Iterable<T>, edges: (node: T) => Iterable<T>): {
19
+ order: T[];
20
+ cycles: T[][];
21
+ };
@@ -83,4 +83,3 @@ export function getGraphOrder(nodes, edges) {
83
83
  }
84
84
  return { order, cycles };
85
85
  }
86
- //# sourceMappingURL=graph-ordering.js.map
@@ -0,0 +1,17 @@
1
+ export declare enum NameStyle {
2
+ OBJECT = "object",
3
+ WEBC = "webc",
4
+ URN = "urn",
5
+ URL = "url",
6
+ DNS = "dns"
7
+ }
8
+ export type NameStyleConfig = {
9
+ namespace: string;
10
+ key: string;
11
+ };
12
+ export declare const NormalizedNameSeparators: Record<NameStyle, NameStyleConfig>;
13
+ export declare function detectNormalizedNameStyle(name: string): NameStyle;
14
+ export declare function isNormalizedName(name: string, expectedStyle?: NameStyle): boolean;
15
+ export declare function getNormalizedKeys(name: string, fromStyle?: NameStyle): string[];
16
+ export declare function makeNormalizedName(name: string, targetStyle: NameStyle, fromStyle?: NameStyle): string;
17
+ export declare function computeNameHashID(identity: string): string;
@@ -93,4 +93,3 @@ export function computeNameHashID(identity) {
93
93
  hasher.write(identity);
94
94
  return hasher.digest().toString("base64url");
95
95
  }
96
- //# sourceMappingURL=normalized-name.js.map
@@ -0,0 +1,70 @@
1
+ export type JSONSchema = any;
2
+ export type ResourceEntry<ResourceInterface = any> = ResourceLink<ResourceInterface> | {
3
+ type: ResourceLink<ResourceFactory<ResourceInterface>>;
4
+ data?: any;
5
+ };
6
+ export type ResourceFactory<ResourceInterface = any> = (data: any) => Promise<ResourceInterface>;
7
+ export type ResourceLink<ResourceInterface = any> = string;
8
+ export type ComponentID = string;
9
+ export type BundleID = ComponentID;
10
+ export type ComponentSpec = {
11
+ "view"?: {
12
+ properties: Record<string, JSONSchema>;
13
+ };
14
+ "component"?: {
15
+ services: string[];
16
+ attributes: Record<string, JSONSchema>;
17
+ };
18
+ [customSpec: string]: any;
19
+ };
20
+ export type ComponentManifest<Data extends any = unknown> = {
21
+ $id: string;
22
+ type?: string;
23
+ name?: string;
24
+ icon?: string;
25
+ title?: string;
26
+ tags?: string[];
27
+ keywords?: string[];
28
+ description?: string;
29
+ selectors?: string[];
30
+ specs?: Record<string, ComponentSpec>;
31
+ data?: Data;
32
+ resources?: Record<string, ResourceEntry>;
33
+ apis?: Record<string, ResourceEntry>;
34
+ };
35
+ /** Configuration for a distributed package */
36
+ export interface DistributedConfig {
37
+ /** Version specifier (e.g., "*", "^18.0.0") */
38
+ version?: string;
39
+ /** Interop type: 'esm' | 'cjs-default' | 'cjs-named' */
40
+ interop?: 'esm' | 'cjs-default' | 'cjs-named';
41
+ /** List of named exports to re-export (required for cjs-named interop) */
42
+ exports?: string[];
43
+ }
44
+ export type BundleManifest = ComponentManifest<{
45
+ alias?: string;
46
+ package?: string;
47
+ baseline?: string;
48
+ namespaces?: string[];
49
+ dependencies?: string[];
50
+ distribueds?: {
51
+ [packageName: string]: string | DistributedConfig;
52
+ };
53
+ exports?: {
54
+ [id: string]: string;
55
+ };
56
+ components?: ComponentPublication[];
57
+ }>;
58
+ export interface ComponentPublication {
59
+ id: ComponentID;
60
+ ref?: string;
61
+ type?: string;
62
+ title: string;
63
+ icon?: string;
64
+ description?: string;
65
+ services?: string[];
66
+ keywords?: string[];
67
+ tags?: string[];
68
+ }
69
+ export declare function checkComponentManifest(manif: ComponentManifest, path: string): Error;
70
+ export declare function makeComponentPublication(manif: ComponentManifest): ComponentPublication;
@@ -20,4 +20,3 @@ export function makeComponentPublication(manif) {
20
20
  tags: manif.tags,
21
21
  };
22
22
  }
23
- //# sourceMappingURL=component.js.map
@@ -0,0 +1,37 @@
1
+ /** Supported config file extensions in precedence order */
2
+ export declare const config_extensions: readonly [".json", ".yaml", ".yml", ".toml"];
3
+ export type ConfigExtension = typeof config_extensions[number];
4
+ /**
5
+ * Check whether a filename matches a config base name (e.g. "component", "application")
6
+ * in any supported format (json, yaml, yml, toml).
7
+ * Matches exact names like `component.json` and dotted prefixes like `foo.component.yaml`.
8
+ */
9
+ export declare function is_config_filename(fname: string, config_base: string): boolean;
10
+ /**
11
+ * Parse a config string based on its file extension.
12
+ */
13
+ export declare function parseConfigContent(text: string, ext: ConfigExtension): any;
14
+ /**
15
+ * Read and parse a config file. The format is determined by its extension.
16
+ * Returns `undefined` if the file doesn't exist or can't be parsed.
17
+ */
18
+ export declare function readConfigFile<T = any>(path: string): Promise<T | undefined>;
19
+ /**
20
+ * Read and parse a config file synchronously.
21
+ * Returns `undefined` if the file doesn't exist or can't be parsed.
22
+ */
23
+ export declare function readConfigFileSync<T = any>(path: string): T | undefined;
24
+ /**
25
+ * Find config files matching a base name (e.g. "bundle.component") in a directory.
26
+ * Returns all matching paths across supported extensions.
27
+ */
28
+ export declare function findConfigFile(dir: string, baseName: string, fnames?: string[]): string;
29
+ /**
30
+ * Read a singleton config file (exactly one format must exist).
31
+ * Throws if multiple formats are found for the same base name.
32
+ * Returns `undefined` if no matching file exists.
33
+ */
34
+ export declare function readSingletonConfigFile<T = any>(dir: string, baseName: string, fnames?: string[]): Promise<{
35
+ data: T;
36
+ path: string;
37
+ } | undefined>;
@@ -1,8 +1,8 @@
1
- import YAML from 'yaml';
2
- import TOML from 'toml';
3
- import Path from 'node:path';
1
+ import YAML from "yaml";
2
+ import TOML from "toml";
3
+ import Path from "node:path";
4
4
  import Fsp from "node:fs/promises";
5
- import Fs from 'node:fs';
5
+ import Fs from "node:fs";
6
6
  /** Supported config file extensions in precedence order */
7
7
  export const config_extensions = [".json", ".yaml", ".yml", ".toml"];
8
8
  /**
@@ -97,4 +97,3 @@ export async function readSingletonConfigFile(dir, baseName, fnames) {
97
97
  const data = await readConfigFile(path);
98
98
  return data !== undefined ? { data, path } : undefined;
99
99
  }
100
- //# sourceMappingURL=config-loader.js.map
@@ -0,0 +1,13 @@
1
+ import { type BundleManifest } from "../component.ts";
2
+ import type { Bundle, Library, PackageDescriptor } from "../workspace.ts";
3
+ export type ExportEntry = {
4
+ id: string;
5
+ exported?: string;
6
+ basename: string;
7
+ filename: string;
8
+ source: string;
9
+ };
10
+ export type ExportEntries = Record<string, ExportEntry>;
11
+ export declare function create_export_map(lib: Library, bun: Bundle): ExportEntries;
12
+ export declare function create_bundle_manifest(lib: Library, bun: Bundle): BundleManifest;
13
+ export declare function create_package_manifest(lib: Library, bun: Bundle, build_version?: string): PackageDescriptor;
@@ -20,8 +20,8 @@ export function create_export_map(lib, bun) {
20
20
  const exports = {};
21
21
  if (bun) {
22
22
  for (const id in bun.distribueds) {
23
- const basename = lib.make_file_id("redist", id);
24
- const entry = lib.resolve_entry_path(id, lib.path);
23
+ const basename = bun.make_file_id("redist", id);
24
+ const entry = bun.resolve_entry_path(id, lib.path);
25
25
  exports[id] = {
26
26
  id,
27
27
  basename: basename,
@@ -84,7 +84,7 @@ export function create_package_manifest(lib, bun, build_version) {
84
84
  optionalDependencies: undefined,
85
85
  };
86
86
  if (pkg_manif.dependencies) {
87
- const resolved = lib.resolved_versions;
87
+ const resolved = lib.deps.resolved_versions;
88
88
  for (const dep in pkg_manif.dependencies) {
89
89
  if (pkg_manif.dependencies[dep] === "*") {
90
90
  const dep_resolved = resolved[dep];
@@ -111,4 +111,3 @@ export function create_package_manifest(lib, bun, build_version) {
111
111
  }
112
112
  return pkg_manif;
113
113
  }
114
- //# sourceMappingURL=create-manifests.js.map
@@ -0,0 +1,4 @@
1
+ import { Bundle, Library, Workspace } from "../workspace.ts";
2
+ export declare function discover_component(bundle: Bundle, fpath: string): Promise<boolean>;
3
+ export declare function discover_library_definitions(lib: Library, path: string, subdir?: boolean): Promise<void>;
4
+ export declare function discover_workspace(ws: Workspace): Promise<Workspace>;
@@ -2,8 +2,6 @@ import Fs from "node:fs";
2
2
  import Fsp from "node:fs/promises";
3
3
  import { readJsonFile } from "../storage.js";
4
4
  import { checkComponentManifest } from "../component.js";
5
- import { makeNormalizedName, NameStyle } from "../../utils/normalized-name.js";
6
- import { create_bundle_manifest } from "./create-manifests.js";
7
5
  import { Bundle, Library, Workspace } from "../workspace.js";
8
6
  import { file, make_canonical_path, make_normalized_dirname, make_normalized_path, make_relative_path } from "../../utils/file.js";
9
7
  import { findConfigFile, is_config_filename, readConfigFile, readSingletonConfigFile } from "./config-loader.js";
@@ -20,8 +18,7 @@ function is_ignored_dir(ws, path) {
20
18
  }
21
19
  return false;
22
20
  }
23
- export async function discover_component(lib, fpath) {
24
- const { bundle } = lib;
21
+ export async function discover_component(bundle, fpath) {
25
22
  if (bundle.components.has(fpath)) {
26
23
  return true;
27
24
  }
@@ -35,18 +32,18 @@ export async function discover_component(lib, fpath) {
35
32
  throw err;
36
33
  if (!desc.apis && desc["services"]) {
37
34
  desc.apis = desc["services"]; // Migrate renaming 'services' -> 'apis'
38
- lib.log.warn(`Component '${desc.$id}' manifest shall rename 'services' -> 'apis'`);
35
+ bundle.log.warn(`Component '${desc.$id}' manifest shall rename 'services' -> 'apis'`);
39
36
  }
40
37
  bundle.components.set(fpath, desc);
41
- lib.log.info(`+ 🧩 component: ${desc.$id} ${desc.type ? `(${desc.type})` : ""}`);
38
+ bundle.log.info(`+ 🧩 component: ${desc.$id} ${desc.type ? `(${desc.type})` : ""}`);
42
39
  return true;
43
40
  }
44
41
  else if (bundle.path !== make_normalized_dirname(fpath)) {
45
- lib.log.error(`invalid bundle component at ${fpath}`);
42
+ bundle.log.error(`invalid bundle component at ${fpath}`);
46
43
  }
47
44
  }
48
45
  catch (e) {
49
- lib.log.error(`invalid component at ${fpath}: ${e?.message}`);
46
+ bundle.log.error(`invalid component at ${fpath}: ${e?.message}`);
50
47
  }
51
48
  return false;
52
49
  }
@@ -86,14 +83,12 @@ export async function discover_library_definitions(lib, path, subdir = false) {
86
83
  const fstat = await Fsp.stat(fpath);
87
84
  if (fstat.isDirectory()) {
88
85
  if (!exclude_dirs.includes(fname)) {
89
- if (await discover_bundle(lib, fpath) === Discovered.None) {
90
- await discover_library_definitions(lib, fpath, true);
91
- }
86
+ await discover_library_definitions(lib, fpath, true);
92
87
  }
93
88
  }
94
89
  else if (fstat.isFile()) {
95
90
  if (is_config_filename(fname, "component")) {
96
- await discover_component(lib, fpath);
91
+ await discover_component(lib.master, fpath);
97
92
  }
98
93
  else if (is_config_filename(fname, "application")) {
99
94
  await discover_application(lib, fpath);
@@ -145,7 +140,6 @@ async function discover_library(ws, location) {
145
140
  ws.libraries.push(lib);
146
141
  ws.log.info(`+ 📚 library: ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
147
142
  // Discover library-level search_directories, lockfile, and constants (walk up to workspace root)
148
- let lockfile = null;
149
143
  lib.constants = { ...ws.constants };
150
144
  for (let path = lib.path;;) {
151
145
  const package_json = await readJsonFile(path + "/package.json");
@@ -161,24 +155,20 @@ async function discover_library(ws, location) {
161
155
  };
162
156
  }
163
157
  }
164
- if (!lockfile) {
165
- lockfile = await read_lockfile(path);
158
+ if (!lib.deps) {
159
+ lib.deps = await read_lockfile(path);
166
160
  }
167
161
  const next_path = make_normalized_dirname(path);
168
162
  if (next_path === path)
169
163
  break;
170
164
  path = next_path;
171
165
  }
172
- // Analyze lock file
173
- if (lockfile) {
174
- lib.resolved_versions = lockfile.resolved_versions;
175
- for (const dep_id in lockfile.resolved_versions) {
176
- const dep_path = lib.resolved_versions[dep_id];
177
- await discover_bundle(lib, dep_path);
178
- }
179
- }
180
- else {
181
- throw new Error(`Lock file not found for '${ws.name}'`);
166
+ if (!lib.deps)
167
+ throw new Error(`Lock file not found for '${lib.name}'`);
168
+ // Discover side bundles from lock file
169
+ for (const dep_id in lib.descriptor.dependencies) {
170
+ const dep_path = lib.deps.resolved_paths[dep_id];
171
+ await discover_bundle(lib, dep_path);
182
172
  }
183
173
  // Load library packager
184
174
  let packager = null;
@@ -217,15 +207,15 @@ async function discover_bundle(lib, location) {
217
207
  return Discovered.Ignored;
218
208
  }
219
209
  }
220
- const bun = new Bundle(bun_manif, lib.path, lib.workspace);
221
- lib.bundle = bun;
210
+ // Register bundle into library
211
+ const bun = new Bundle(bun_manif, lib.path, lib);
222
212
  lib.shelve.push(bun);
223
213
  lib.log.info(`+ 📦 bundle: ${bun.id} ⏬`);
224
214
  // Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
225
215
  if (bun_manif?.data?.components) {
226
216
  for (const pub of bun_manif.data.components) {
227
- const fpath = lib.path + "/" + (pub.ref ?? pub.id);
228
- await discover_component(lib, fpath);
217
+ const fpath = bun_path + "/" + (pub.ref ?? pub.id);
218
+ await discover_component(bun, fpath);
229
219
  }
230
220
  }
231
221
  return Discovered.Registered;
@@ -276,4 +266,3 @@ export async function discover_workspace(ws) {
276
266
  show_constants(ws);
277
267
  return ws;
278
268
  }
279
- //# sourceMappingURL=discover-workspace.js.map
@@ -0,0 +1,5 @@
1
+ export type PackageDepsInfo = {
2
+ resolved_versions: Record<string, string>;
3
+ resolved_paths: Record<string, string>;
4
+ };
5
+ export declare function read_lockfile(dir: string): Promise<PackageDepsInfo | null>;
@@ -19,27 +19,27 @@ export async function read_lockfile(dir) {
19
19
  }
20
20
  function parse_npm_lockfile(lock) {
21
21
  const resolved_versions = {};
22
- const installed_locations = [];
22
+ const resolved_paths = {};
23
23
  for (const location in lock.packages) {
24
24
  if (!location)
25
25
  continue;
26
- installed_locations.push(location);
27
26
  if (location.startsWith("node_modules/")) {
28
27
  let pkg = lock.packages[location];
29
28
  if (pkg.link) {
30
29
  pkg = lock.packages[pkg.resolved];
31
30
  }
32
31
  const name = location.replace(/^.*node_modules\//, "");
32
+ resolved_paths[name] = location;
33
33
  if (pkg?.version) {
34
34
  resolved_versions[name] = pkg.version;
35
35
  }
36
36
  }
37
37
  }
38
- return { resolved_versions, installed_locations };
38
+ return { resolved_versions, resolved_paths };
39
39
  }
40
40
  function parse_pnpm_lockfile(lock) {
41
41
  const resolved_versions = {};
42
- const locations = new Set();
42
+ const resolved_paths = {};
43
43
  if (lock.packages) {
44
44
  for (const key in lock.packages) {
45
45
  const clean = key.startsWith("/") ? key.slice(1) : key;
@@ -49,7 +49,7 @@ function parse_pnpm_lockfile(lock) {
49
49
  const version = clean.slice(atIdx + 1).split("(")[0];
50
50
  if (name && version) {
51
51
  resolved_versions[name] = version;
52
- locations.add("node_modules/" + name);
52
+ resolved_paths[name] = "node_modules/" + name;
53
53
  }
54
54
  }
55
55
  }
@@ -57,14 +57,14 @@ function parse_pnpm_lockfile(lock) {
57
57
  if (lock.importers) {
58
58
  for (const key in lock.importers) {
59
59
  if (key !== ".")
60
- locations.add(key);
60
+ resolved_paths[key] = key;
61
61
  }
62
62
  }
63
- return { resolved_versions, installed_locations: [...locations] };
63
+ return { resolved_versions, resolved_paths };
64
64
  }
65
65
  function parse_yarn_lockfile(text) {
66
66
  const resolved_versions = {};
67
- const locations = new Set();
67
+ const resolved_paths = {};
68
68
  if (text.includes("__metadata:")) {
69
69
  const lock = YAML.parse(text);
70
70
  for (const key in lock) {
@@ -74,15 +74,15 @@ function parse_yarn_lockfile(text) {
74
74
  const name = extract_package_name(key.split(",")[0].trim());
75
75
  if (name) {
76
76
  resolved_versions[name] = lock[key].version;
77
- locations.add("node_modules/" + name);
77
+ resolved_paths[name] = "node_modules/" + name;
78
78
  }
79
79
  }
80
80
  }
81
81
  }
82
82
  else {
83
- parse_yarn_classic(text, resolved_versions, locations);
83
+ parse_yarn_classic(text, resolved_versions, resolved_paths);
84
84
  }
85
- return { resolved_versions, installed_locations: [...locations] };
85
+ return { resolved_versions, resolved_paths };
86
86
  }
87
87
  function extract_package_name(entry) {
88
88
  entry = entry.replace(/^"|"$/g, "");
@@ -90,7 +90,7 @@ function extract_package_name(entry) {
90
90
  const at = entry.startsWith("@") ? entry.indexOf("@", 1) : entry.indexOf("@");
91
91
  return at > 0 ? entry.slice(0, at) : null;
92
92
  }
93
- function parse_yarn_classic(text, resolved_versions, locations) {
93
+ function parse_yarn_classic(text, resolved_versions, resolved_paths) {
94
94
  let current_name = null;
95
95
  for (const line of text.split("\n")) {
96
96
  const trimmed = line.trim();
@@ -100,9 +100,8 @@ function parse_yarn_classic(text, resolved_versions, locations) {
100
100
  else if (current_name && trimmed.startsWith("version ")) {
101
101
  const version = trimmed.slice(8).replace(/^"|"$/g, "");
102
102
  resolved_versions[current_name] = version;
103
- locations.add("node_modules/" + current_name);
103
+ resolved_paths[current_name] = "node_modules/" + current_name;
104
104
  current_name = null;
105
105
  }
106
106
  }
107
107
  }
108
- //# sourceMappingURL=lockfile.js.map