@jointhedots/gear 1.1.18 → 1.2.2

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 (113) hide show
  1. package/esm/builder/build-app-bundle.d.ts +28 -0
  2. package/esm/builder/build-app-bundle.js +4 -7
  3. package/esm/builder/build-app-host.d.ts +28 -0
  4. package/esm/builder/build-app-host.js +0 -1
  5. package/esm/builder/build-application.d.ts +47 -0
  6. package/esm/builder/build-application.js +3 -5
  7. package/esm/builder/build-library.d.ts +20 -0
  8. package/esm/builder/build-library.js +1 -2
  9. package/esm/builder/build-target.d.ts +27 -0
  10. package/esm/builder/build-target.js +3 -4
  11. package/esm/builder/helpers/emit-bundle-manifest.d.ts +9 -0
  12. package/esm/builder/helpers/emit-bundle-manifest.js +1 -2
  13. package/esm/builder/helpers/emit-components-dts.d.ts +9 -0
  14. package/esm/builder/helpers/emit-components-dts.js +1 -2
  15. package/esm/builder/helpers/emit-esmodules.d.ts +61 -0
  16. package/esm/builder/helpers/emit-esmodules.js +5 -6
  17. package/esm/builder/helpers/emit-package-manifest.d.ts +9 -0
  18. package/esm/builder/helpers/emit-package-manifest.js +0 -1
  19. package/esm/builder/helpers/emit-static-assets.d.ts +14 -0
  20. package/esm/builder/helpers/emit-static-assets.js +1 -2
  21. package/esm/builder/helpers/emit-typescript-definition.d.ts +35 -0
  22. package/esm/builder/helpers/emit-typescript-definition.js +6 -7
  23. package/esm/builder/helpers/path-helpers.d.ts +9 -0
  24. package/esm/builder/helpers/path-helpers.js +0 -1
  25. package/esm/builder/helpers/task.d.ts +8 -0
  26. package/esm/builder/helpers/task.js +0 -1
  27. package/esm/cli.d.ts +2 -0
  28. package/esm/cli.js +1 -4
  29. package/esm/commands/init.d.ts +2 -0
  30. package/esm/commands/init.js +0 -1
  31. package/esm/commands/install.d.ts +5 -0
  32. package/esm/commands/install.js +4 -5
  33. package/esm/commands/make.d.ts +16 -0
  34. package/esm/commands/make.js +5 -5
  35. package/esm/commands/run.d.ts +8 -0
  36. package/esm/commands/run.js +6 -7
  37. package/esm/commands/serve.d.ts +9 -0
  38. package/esm/commands/serve.js +3 -4
  39. package/esm/core/commands/interface.d.ts +26 -0
  40. package/esm/core/commands/interface.js +21 -0
  41. package/esm/core/components/components.d.ts +73 -0
  42. package/esm/core/components/components.js +2 -0
  43. package/esm/core/components/helpers.d.ts +7 -0
  44. package/esm/core/components/helpers.js +68 -0
  45. package/esm/core/components/manifold.d.ts +77 -0
  46. package/esm/core/components/manifold.js +442 -0
  47. package/esm/core/components/mod.d.ts +4 -0
  48. package/esm/core/components/mod.js +4 -0
  49. package/esm/core/components/provider.d.ts +42 -0
  50. package/esm/core/components/provider.js +127 -0
  51. package/esm/core/logging/mod.d.ts +53 -0
  52. package/esm/core/logging/mod.js +142 -0
  53. package/esm/core/logging/trace.d.ts +51 -0
  54. package/esm/core/logging/trace.js +17 -0
  55. package/esm/core/mod-browser.d.ts +1 -0
  56. package/esm/core/mod-browser.js +1 -0
  57. package/esm/core/mod-node.d.ts +1 -0
  58. package/esm/core/mod-node.js +1 -0
  59. package/esm/core/mod.d.ts +5 -0
  60. package/esm/core/mod.js +5 -0
  61. package/esm/core/schema/helpers.d.ts +36 -0
  62. package/esm/core/schema/helpers.js +163 -0
  63. package/esm/core/schema/mod.d.ts +3 -0
  64. package/esm/core/schema/mod.js +3 -0
  65. package/esm/core/schema/schema.d.ts +376 -0
  66. package/esm/core/schema/schema.js +234 -0
  67. package/esm/core/schema/zod.d.ts +44 -0
  68. package/esm/core/schema/zod.js +127 -0
  69. package/esm/core/services/mod.d.ts +5 -0
  70. package/esm/core/services/mod.js +5 -0
  71. package/esm/core/services/service-accessor.d.ts +17 -0
  72. package/esm/core/services/service-accessor.js +20 -0
  73. package/esm/core/services/service-definitions.d.ts +37 -0
  74. package/esm/core/services/service-definitions.js +44 -0
  75. package/esm/core/services/service-points.d.ts +40 -0
  76. package/esm/core/services/service-points.js +164 -0
  77. package/esm/core/services/service-specification.d.ts +52 -0
  78. package/esm/core/services/service-specification.js +59 -0
  79. package/esm/core/services/settings.d.ts +29 -0
  80. package/esm/core/services/settings.js +123 -0
  81. package/esm/utils/file.d.ts +39 -0
  82. package/esm/utils/file.js +3 -4
  83. package/esm/utils/graph-ordering.d.ts +21 -0
  84. package/esm/utils/graph-ordering.js +0 -1
  85. package/esm/utils/normalized-name.d.ts +17 -0
  86. package/esm/utils/normalized-name.js +0 -1
  87. package/esm/workspace/component.d.ts +70 -0
  88. package/esm/workspace/component.js +0 -1
  89. package/esm/workspace/helpers/config-loader.d.ts +37 -0
  90. package/esm/workspace/helpers/config-loader.js +4 -5
  91. package/esm/workspace/helpers/create-manifests.d.ts +13 -0
  92. package/esm/workspace/helpers/create-manifests.js +1 -2
  93. package/esm/workspace/helpers/discover-workspace.d.ts +4 -0
  94. package/esm/workspace/helpers/discover-workspace.js +130 -134
  95. package/esm/workspace/helpers/lockfile.d.ts +5 -0
  96. package/esm/workspace/helpers/lockfile.js +0 -1
  97. package/esm/workspace/helpers/logger.d.ts +65 -0
  98. package/esm/workspace/helpers/logger.js +0 -1
  99. package/esm/workspace/helpers/package-npm.d.ts +1 -0
  100. package/esm/workspace/helpers/package-npm.js +0 -1
  101. package/esm/workspace/mod.d.ts +1 -0
  102. package/esm/workspace/mod.js +1 -0
  103. package/esm/workspace/packager.d.ts +5 -0
  104. package/esm/workspace/packager.js +1 -2
  105. package/esm/workspace/packagers/packager-standard.d.ts +7 -0
  106. package/esm/workspace/packagers/packager-standard.js +48 -24
  107. package/esm/workspace/storage.d.ts +59 -0
  108. package/esm/workspace/storage.js +19 -15
  109. package/esm/workspace/workspace.d.ts +161 -0
  110. package/esm/workspace/workspace.js +25 -17
  111. package/package.json +25 -18
  112. package/esm/commands/publish.js +0 -36
  113. package/esm/publish/publish_aws_s3.js +0 -67
@@ -9,7 +9,7 @@ import { file, make_canonical_path, make_normalized_dirname, make_normalized_pat
9
9
  import { findConfigFile, is_config_filename, readConfigFile, readSingletonConfigFile } from "./config-loader.js";
10
10
  import { read_lockfile } from "./lockfile.js";
11
11
  import { LoadLibraryPackager } from "../packager.js";
12
- import { BundledLibraryPackager, DefaultLibraryPackager } from "../packagers/packager-standard.js";
12
+ import { DefaultLibraryPackager } from "../packagers/packager-standard.js";
13
13
  const exclude_dirs = ["node_modules", ".git"];
14
14
  function is_ignored_dir(ws, path) {
15
15
  const normalized_path = make_normalized_path(path);
@@ -20,26 +20,8 @@ function is_ignored_dir(ws, path) {
20
20
  }
21
21
  return false;
22
22
  }
23
- export function setup_library_bundle(lib) {
24
- const ws = lib.workspace;
25
- const manif = make_library_bundle_manifest(lib);
26
- let bun = ws.get_bundle(manif.$id);
27
- if (!bun) {
28
- bun = new Bundle(manif, lib.path, ws, lib);
29
- lib.bundle = bun;
30
- ws.bundles.push(bun);
31
- lib.log.info(`+ 📦 bundle: ${bun.id}`);
32
- return bun;
33
- }
34
- else {
35
- throw new Error(`Library '${lib.get_id()}' is associate to a bundle '${bun.id}' that is already associated`);
36
- }
37
- }
38
23
  export async function discover_component(lib, fpath) {
39
- let bundle = lib.bundle;
40
- if (!bundle) {
41
- bundle = setup_library_bundle(lib);
42
- }
24
+ const { bundle } = lib;
43
25
  if (bundle.components.has(fpath)) {
44
26
  return true;
45
27
  }
@@ -92,7 +74,7 @@ async function discover_application(lib, fpath) {
92
74
  lib.log.error(`invalid application at ${fpath}: ${e?.message}`);
93
75
  }
94
76
  }
95
- export async function discover_library_components(lib, path, subdir = false) {
77
+ export async function discover_library_definitions(lib, path, subdir = false) {
96
78
  // List names from directory
97
79
  const fnames = await Fsp.readdir(path);
98
80
  if (subdir && fnames.includes("package.json")) {
@@ -104,8 +86,8 @@ export async function discover_library_components(lib, path, subdir = false) {
104
86
  const fstat = await Fsp.stat(fpath);
105
87
  if (fstat.isDirectory()) {
106
88
  if (!exclude_dirs.includes(fname)) {
107
- if (await discover_library(lib.workspace, fpath, lib.installed) === Discovered.None) {
108
- await discover_library_components(lib, fpath, true);
89
+ if (await discover_bundle(lib, fpath) === Discovered.None) {
90
+ await discover_library_definitions(lib, fpath, true);
109
91
  }
110
92
  }
111
93
  }
@@ -125,133 +107,57 @@ export async function discover_library_components(lib, path, subdir = false) {
125
107
  }
126
108
  }
127
109
  }
128
- export function collect_declarations_field(lib, key, value) {
129
- for (const decl of lib.declarations.values()) {
130
- if (typeof decl[key] === typeof value) {
131
- if (Array.isArray(value))
132
- value.push(...decl[key]);
133
- else if (typeof value === "object")
134
- Object.assign(value, decl[key]);
135
- else
136
- value = decl[key];
137
- }
138
- }
139
- return value;
140
- }
141
- function make_library_bundle_manifest(lib) {
142
- return {
143
- $id: makeNormalizedName(collect_declarations_field(lib, "$id", lib.name), NameStyle.OBJECT),
144
- type: "bundle",
145
- name: lib.name,
146
- icon: collect_declarations_field(lib, "icon", ""),
147
- title: collect_declarations_field(lib, "title", lib.name),
148
- tags: collect_declarations_field(lib, "tags", lib.descriptor?.tags),
149
- keywords: collect_declarations_field(lib, "keywords", lib.descriptor?.keywords),
150
- description: collect_declarations_field(lib, "description", lib.descriptor?.description),
151
- selectors: collect_declarations_field(lib, "selectors", undefined),
152
- data: {
153
- package: lib.get_id(),
154
- alias: collect_declarations_field(lib, "alias", lib.name),
155
- namespaces: collect_declarations_field(lib, "namespaces", []),
156
- dependencies: collect_declarations_field(lib, "dependencies", []),
157
- distribueds: collect_declarations_field(lib, "distribueds", {}),
158
- }
159
- };
160
- }
161
110
  var Discovered;
162
111
  (function (Discovered) {
163
112
  Discovered[Discovered["None"] = 0] = "None";
164
113
  Discovered[Discovered["Ignored"] = 1] = "Ignored";
165
114
  Discovered[Discovered["Registered"] = 2] = "Registered";
166
115
  })(Discovered || (Discovered = {}));
167
- async function discover_library(ws, location, installed) {
116
+ async function discover_library(ws, location) {
168
117
  const lib_path = make_canonical_path(ws.path, location);
169
118
  if (is_ignored_dir(ws, lib_path))
170
119
  return Discovered.Ignored;
120
+ const has_bundle_manifest = file.exists(findConfigFile(lib_path, "bundle.manifest"));
121
+ if (has_bundle_manifest) {
122
+ // discover_bundle
123
+ return Discovered.Ignored;
124
+ }
171
125
  const package_path = lib_path + "/package.json";
172
126
  const has_package_manifest = file.exists(package_path);
173
- const has_bundle_manifest = file.exists(findConfigFile(lib_path, "bundle.manifest"));
174
- if (!has_package_manifest && !has_bundle_manifest)
127
+ if (!has_package_manifest)
175
128
  return Discovered.None;
176
- const lib_not_exists = ws.libraries.reduce((r, lib) => r && lib.path !== lib_path, true);
177
- if (!lib_not_exists)
178
- return Discovered.Ignored;
179
- const lib_desc = await readJsonFile(package_path);
180
- if (!lib_desc?.name)
129
+ const lib_manifest = await readJsonFile(package_path);
130
+ if (!lib_manifest?.name)
181
131
  return Discovered.Ignored;
182
- if (has_bundle_manifest || !installed) {
183
- const other = ws.get_library(lib_desc.name);
184
- if (other) {
185
- if (lib_path.includes(other.path)) {
186
- ws.log.info(`ignore library build at ${lib_path}`);
187
- return Discovered.Ignored;
188
- }
189
- else {
190
- throw new Error(`library '${lib_desc.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
191
- }
192
- }
193
- const lib = new Library(lib_desc.name, lib_path, lib_desc, ws, installed);
194
- ws.libraries.push(lib);
195
- ws.log.info(`+ 📚 library: ${installed ? "⏬" : "🐣"} ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
196
- // Setup node search directory
197
- const lib_search_path = lib_path + "/node_modules";
198
- if (Fs.existsSync(lib_search_path)) {
199
- lib.search_directories.push(lib_search_path);
200
- }
201
- // Load library packager
202
- let packager = null;
203
- if (has_bundle_manifest) {
204
- packager = new BundledLibraryPackager();
132
+ if (!lib_manifest?.dots)
133
+ return Discovered.None;
134
+ const other = ws.get_library(lib_manifest.name);
135
+ if (other) {
136
+ if (lib_path.includes(other.path)) {
137
+ ws.log.info(`ignore library build at ${lib_path}`);
138
+ return Discovered.Ignored;
205
139
  }
206
140
  else {
207
- const declaration_config = await readSingletonConfigFile(lib_path, "declaration");
208
- const packager_ref = declaration_config && declaration_config.data?.packager;
209
- if (packager_ref) {
210
- packager = await LoadLibraryPackager(packager_ref);
211
- }
212
- else {
213
- packager = new DefaultLibraryPackager();
214
- }
141
+ throw new Error(`library '${lib_manifest.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
215
142
  }
216
- // Discover library with packager
217
- await packager.discover_library(lib);
218
- return Discovered.Registered;
219
143
  }
220
- return Discovered.None;
221
- }
222
- async function discover_workspace_libraries(ws) {
223
- async function walk(dir) {
224
- if (await discover_library(ws, dir, false) === Discovered.None) {
225
- for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
226
- if (entry.name === "node_modules")
227
- continue;
228
- const fullPath = dir + "/" + entry.name;
229
- if (entry.isDirectory()) {
230
- await walk(fullPath);
231
- }
232
- }
233
- }
234
- }
235
- await walk(ws.path);
236
- }
237
- function show_constants(ws) {
238
- for (const name in ws.constants) {
239
- ws.log.info(`+ 🔖 ${name} = ${ws.constants[name]}`);
240
- }
241
- }
242
- export async function discover_workspace(ws) {
144
+ const lib = new Library(lib_manifest.name, lib_path, lib_manifest, ws);
145
+ ws.libraries.push(lib);
146
+ ws.log.info(`+ 📚 library: ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
147
+ // Discover library-level search_directories, lockfile, and constants (walk up to workspace root)
243
148
  let lockfile = null;
244
- for (let path = ws.path;;) {
149
+ lib.constants = { ...ws.constants };
150
+ for (let path = lib.path;;) {
245
151
  const package_json = await readJsonFile(path + "/package.json");
246
152
  if (package_json) {
247
153
  const search_path = path + "/node_modules";
248
154
  if (Fs.existsSync(search_path)) {
249
- ws.search_directories.push(search_path);
155
+ lib.search_directories.push(search_path);
250
156
  }
251
157
  if (package_json.constants) {
252
- ws.constants = {
158
+ lib.constants = {
253
159
  ...package_json.constants,
254
- ...ws.constants,
160
+ ...lib.constants,
255
161
  };
256
162
  }
257
163
  }
@@ -263,20 +169,110 @@ export async function discover_workspace(ws) {
263
169
  break;
264
170
  path = next_path;
265
171
  }
266
- if (!lockfile) {
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 {
267
181
  throw new Error(`Lock file not found for '${ws.name}'`);
268
182
  }
269
- ws.resolved_versions = lockfile.resolved_versions;
270
- await discover_workspace_libraries(ws);
271
- for (const location of lockfile.installed_locations) {
272
- await discover_library(ws, location, true);
183
+ // Load library packager
184
+ let packager = null;
185
+ const declaration_config = await readSingletonConfigFile(lib_path, "declaration");
186
+ const packager_ref = declaration_config && declaration_config.data?.packager;
187
+ if (packager_ref) {
188
+ packager = await LoadLibraryPackager(packager_ref);
189
+ }
190
+ else {
191
+ packager = new DefaultLibraryPackager();
192
+ }
193
+ // Discover library with packager
194
+ await packager.discover_library(lib);
195
+ return Discovered.Registered;
196
+ }
197
+ async function discover_bundle(lib, location) {
198
+ const bun_path = make_canonical_path(lib.path, location);
199
+ if (is_ignored_dir(lib.workspace, bun_path))
200
+ return Discovered.Ignored;
201
+ const bun_manif_path = findConfigFile(bun_path, "bundle.manifest");
202
+ if (!bun_manif_path)
203
+ return Discovered.None;
204
+ const bun_manif = await readConfigFile(bun_manif_path);
205
+ if (!bun_manif) {
206
+ lib.log.error(`bundle manifest invalid at: ${bun_manif_path}`);
207
+ return Discovered.Ignored;
208
+ }
209
+ const other = lib.get_bundle(bun_manif.$id);
210
+ if (other) {
211
+ if (bun_path.includes(other.path)) {
212
+ lib.log.info(`ignore bundle at ${bun_path}`);
213
+ return Discovered.Ignored;
214
+ }
215
+ else {
216
+ lib.log.error(`bundle '${bun_manif.$id}' declared multiple times\n - ${other.path}\n - ${bun_path}`);
217
+ return Discovered.Ignored;
218
+ }
273
219
  }
274
- for (const bun of ws.bundles) {
275
- if (bun.source) {
276
- bun.manifest = create_bundle_manifest(bun.source, bun);
220
+ const bun = new Bundle(bun_manif, lib.path, lib.workspace);
221
+ lib.bundle = bun;
222
+ lib.shelve.push(bun);
223
+ lib.log.info(`+ 📦 bundle: ${bun.id} ⏬`);
224
+ // Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
225
+ if (bun_manif?.data?.components) {
226
+ for (const pub of bun_manif.data.components) {
227
+ const fpath = lib.path + "/" + (pub.ref ?? pub.id);
228
+ await discover_component(lib, fpath);
277
229
  }
278
230
  }
231
+ return Discovered.Registered;
232
+ }
233
+ function show_constants(ws) {
234
+ // Collect all constant keys across libraries
235
+ const all_keys = new Set();
236
+ for (const lib of ws.libraries) {
237
+ for (const key in lib.constants)
238
+ all_keys.add(key);
239
+ }
240
+ for (const name of all_keys) {
241
+ const lib_values = new Map();
242
+ for (const lib of ws.libraries) {
243
+ if (name in lib.constants) {
244
+ const val = lib.constants[name];
245
+ const key = String(val);
246
+ if (!lib_values.has(val))
247
+ lib_values.set(val, []);
248
+ lib_values.get(val).push(lib.name);
249
+ }
250
+ }
251
+ if (lib_values.size === 1) {
252
+ const [value] = lib_values.keys();
253
+ ws.log.info(`+ 🔖 ${name} = ${value}`);
254
+ }
255
+ else {
256
+ for (const [value, libs] of lib_values) {
257
+ ws.log.info(`+ 🔖 ${name} = ${value} (${libs.join(", ")})`);
258
+ }
259
+ }
260
+ }
261
+ }
262
+ export async function discover_workspace(ws) {
263
+ async function walk(dir) {
264
+ if (await discover_library(ws, dir) === Discovered.None) {
265
+ for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
266
+ if (entry.name === "node_modules")
267
+ continue;
268
+ const fullPath = dir + "/" + entry.name;
269
+ if (entry.isDirectory()) {
270
+ await walk(fullPath);
271
+ }
272
+ }
273
+ }
274
+ }
275
+ await walk(ws.path);
279
276
  show_constants(ws);
280
277
  return ws;
281
278
  }
282
- //# sourceMappingURL=discover-workspace.js.map
@@ -0,0 +1,5 @@
1
+ export type LockFileInfo = {
2
+ resolved_versions: Record<string, string>;
3
+ installed_locations: string[];
4
+ };
5
+ export declare function read_lockfile(dir: string): Promise<LockFileInfo | null>;
@@ -105,4 +105,3 @@ function parse_yarn_classic(text, resolved_versions, locations) {
105
105
  }
106
106
  }
107
107
  }
108
- //# sourceMappingURL=lockfile.js.map
@@ -0,0 +1,65 @@
1
+ export interface Message {
2
+ id: string;
3
+ text: string;
4
+ location?: Location | string;
5
+ notes?: Note[];
6
+ /**
7
+ * Optional user-specified data that is passed through unmodified. You can
8
+ * use this to stash the original error, for example.
9
+ */
10
+ detail?: any;
11
+ }
12
+ export interface Note {
13
+ title?: string;
14
+ text: string;
15
+ location?: Location | string;
16
+ }
17
+ export interface Location {
18
+ file: string;
19
+ namespace?: string;
20
+ /** 1-based */
21
+ line?: number;
22
+ /** 0-based, in bytes */
23
+ column?: number;
24
+ /** in bytes */
25
+ length?: number;
26
+ lineText?: string;
27
+ suggestion?: string;
28
+ }
29
+ export type LogKind = "error" | "warn" | "info" | "success" | "debug" | "trace";
30
+ export type LogMode = "normal" | "debug" | "verbose";
31
+ export interface LogEntry {
32
+ kind: LogKind;
33
+ message: Message;
34
+ timestamp: number;
35
+ }
36
+ export declare class Log {
37
+ readonly id: string;
38
+ private entries;
39
+ private logger;
40
+ constructor(id: string, logger: Logger);
41
+ put(kind: LogKind, message: string | Error | Message): void;
42
+ error(message: string | Error | Message): void;
43
+ warn(message: string | Error | Message): void;
44
+ info(message: string | Error | Message): void;
45
+ success(message: string | Error | Message): void;
46
+ debug(message: string | Error | Message): void;
47
+ trace(message: string | Error | Message): void;
48
+ private normalizeMessage;
49
+ getEntries(): readonly LogEntry[];
50
+ clear(): void;
51
+ }
52
+ export declare class Logger {
53
+ private loggers;
54
+ readonly mode: LogMode;
55
+ readonly silentKinds: Set<LogKind>;
56
+ constructor(mode?: LogMode);
57
+ get(id: string): Log;
58
+ has(id: string): boolean;
59
+ remove(id: string): boolean;
60
+ all(): IterableIterator<Log>;
61
+ clear(): void;
62
+ }
63
+ export declare function stringifyLocation(loc: Location | string | null | undefined): string;
64
+ export declare function stringifyLogEntry(loggerId: string, entry: LogEntry): string;
65
+ export declare function stringifyLogEntryPretty(loggerId: string, entry: LogEntry): string;
@@ -145,4 +145,3 @@ export function stringifyLogEntryPretty(loggerId, entry) {
145
145
  }
146
146
  return lines.join("\n");
147
147
  }
148
- //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ export declare function resolvePackageVersion(startDir: string): string | undefined;
@@ -18,4 +18,3 @@ export function resolvePackageVersion(startDir) {
18
18
  }
19
19
  return undefined;
20
20
  }
21
- //# sourceMappingURL=package-npm.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Bundle, Library } from "./workspace.ts";
2
+ export interface LibraryPackager {
3
+ discover_library(lib: Library): Promise<Bundle>;
4
+ }
5
+ export declare function LoadLibraryPackager(specifier: string): Promise<LibraryPackager>;
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import ChildProcess from "child_process";
9
+ import ChildProcess from "node:child_process";
10
10
  function parseSpecifier(specifier) {
11
11
  let raw = specifier.startsWith("npm:") ? specifier.slice(4) : specifier;
12
12
  let exportName;
@@ -50,4 +50,3 @@ export async function LoadLibraryPackager(specifier) {
50
50
  return resolveExport(mod, exportName);
51
51
  }
52
52
  }
53
- //# sourceMappingURL=packager.js.map
@@ -0,0 +1,7 @@
1
+ import { Bundle, Library } from "../workspace.ts";
2
+ import { type LibraryPackager } from "../packager.ts";
3
+ export declare class DefaultLibraryPackager implements LibraryPackager {
4
+ discover_library(lib: Library): Promise<Bundle>;
5
+ }
6
+ export declare function setup_library_bundle(lib: Library): Bundle;
7
+ export declare function collect_declarations_field(lib: Library, key: string, value: any): any;
@@ -2,38 +2,62 @@ import {} from "../component.js";
2
2
  import { Bundle, Library } from "../workspace.js";
3
3
  import { readSingletonConfigFile } from "../helpers/config-loader.js";
4
4
  import {} from "../packager.js";
5
- import { discover_component, discover_library_components, setup_library_bundle } from "../helpers/discover-workspace.js";
5
+ import { discover_component, discover_library_definitions } from "../helpers/discover-workspace.js";
6
+ import { makeNormalizedName, NameStyle } from "../../utils/normalized-name.js";
6
7
  export class DefaultLibraryPackager {
7
8
  async discover_library(lib) {
8
9
  // Setup library infos from bundle manifest
9
10
  setup_library_bundle(lib);
10
11
  // Collect library declaration
11
- await discover_library_components(lib, lib.path);
12
+ await discover_library_definitions(lib, lib.path);
12
13
  return lib.bundle;
13
14
  }
14
15
  }
15
- export class BundledLibraryPackager {
16
- async discover_library(lib) {
17
- const { data: manif } = await readSingletonConfigFile(lib.path, "bundle.manifest");
18
- const ws = lib.workspace;
19
- let bun = ws.get_bundle(manif.$id);
20
- if (!bun) {
21
- bun = new Bundle(manif, lib.path, lib.workspace, lib);
22
- lib.bundle = bun;
23
- ws.bundles.push(bun);
24
- lib.log.info(`+ 📦 bundle: ${bun.id}`);
25
- }
26
- else if (bun.source != lib) {
27
- lib.log.warn(`Conflict between two prebuild library bundle`);
28
- }
29
- // Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
30
- if (manif?.data?.components) {
31
- for (const pub of manif.data.components) {
32
- const fpath = lib.path + "/" + (pub.ref ?? pub.id);
33
- await discover_component(lib, fpath);
34
- }
35
- }
16
+ export function setup_library_bundle(lib) {
17
+ const ws = lib.workspace;
18
+ const manif = make_library_bundle_manifest(lib);
19
+ let bun = lib.get_bundle(manif.$id);
20
+ if (!bun) {
21
+ bun = new Bundle(manif, lib.path, ws, lib);
22
+ lib.bundle = bun;
23
+ lib.shelve.push(bun);
24
+ lib.log.info(`+ 📦 bundle: ${bun.id} 🐣`);
36
25
  return bun;
37
26
  }
27
+ else {
28
+ throw new Error(`Library '${lib.get_id()}' is associate to a bundle '${bun.id}' that is already associated`);
29
+ }
30
+ }
31
+ export function collect_declarations_field(lib, key, value) {
32
+ for (const decl of lib.declarations.values()) {
33
+ if (typeof decl[key] === typeof value) {
34
+ if (Array.isArray(value))
35
+ value.push(...decl[key]);
36
+ else if (typeof value === "object")
37
+ Object.assign(value, decl[key]);
38
+ else
39
+ value = decl[key];
40
+ }
41
+ }
42
+ return value;
43
+ }
44
+ function make_library_bundle_manifest(lib) {
45
+ return {
46
+ $id: makeNormalizedName(collect_declarations_field(lib, "$id", lib.name), NameStyle.OBJECT),
47
+ type: "bundle",
48
+ name: lib.name,
49
+ icon: collect_declarations_field(lib, "icon", ""),
50
+ title: collect_declarations_field(lib, "title", lib.name),
51
+ tags: collect_declarations_field(lib, "tags", lib.descriptor?.tags),
52
+ keywords: collect_declarations_field(lib, "keywords", lib.descriptor?.keywords),
53
+ description: collect_declarations_field(lib, "description", lib.descriptor?.description),
54
+ selectors: collect_declarations_field(lib, "selectors", undefined),
55
+ data: {
56
+ package: lib.get_id(),
57
+ alias: collect_declarations_field(lib, "alias", lib.name),
58
+ namespaces: collect_declarations_field(lib, "namespaces", []),
59
+ dependencies: collect_declarations_field(lib, "dependencies", []),
60
+ distribueds: collect_declarations_field(lib, "distribueds", {}),
61
+ }
62
+ };
38
63
  }
39
- //# sourceMappingURL=packager-standard.js.map
@@ -0,0 +1,59 @@
1
+ export type StorageChanges = {
2
+ added: string[];
3
+ updated: string[];
4
+ changed: boolean;
5
+ };
6
+ export interface IStorageTransaction {
7
+ commitContent(contentData: Uint8Array | string, contentType?: string): string;
8
+ commitFile(key: string, contentData: Uint8Array | string, contentType?: string): any;
9
+ accept(): Promise<StorageChanges>;
10
+ }
11
+ export interface IStorageZone {
12
+ clean(): any;
13
+ edit(scratch?: boolean): IStorageTransaction;
14
+ branch(path: string): IStorageZone;
15
+ getBaseDirFS(): string;
16
+ }
17
+ export declare class SourceEventEmitter {
18
+ clients: any[];
19
+ sendEventsToAll(type: string, data: any): void;
20
+ route(): (req: any, res: any) => void;
21
+ }
22
+ export declare function createContentCID(data: Uint8Array | string): string;
23
+ export declare function createContentKey(contentData: Uint8Array | string, contentType?: string): string;
24
+ export type FileCache = Map<string, string>;
25
+ export declare class StorageTransaction implements IStorageTransaction {
26
+ private baseDir;
27
+ private scratch;
28
+ private root;
29
+ private pending;
30
+ constructor(baseDir: string, scratch: boolean, root: StorageFiles);
31
+ commitContent(contentData: Uint8Array | string, contentType?: string): string;
32
+ commitFile(key: string, contentData: Uint8Array | string, contentType?: string): void;
33
+ accept(): Promise<StorageChanges>;
34
+ }
35
+ export declare class SubStorageFiles implements IStorageZone {
36
+ readonly root: StorageFiles;
37
+ readonly baseDir: string;
38
+ constructor(root: StorageFiles, baseDir: string);
39
+ getBaseDirFS(): string;
40
+ clean(): void;
41
+ edit(scratch?: boolean): IStorageTransaction;
42
+ branch(path: string): IStorageZone;
43
+ }
44
+ export declare class StorageFiles implements IStorageZone {
45
+ name: string;
46
+ readonly baseDir: string;
47
+ cache: FileCache;
48
+ on_changes: SourceEventEmitter;
49
+ constructor(name: string, baseDir: string);
50
+ getBaseDirFS(): string;
51
+ clean(): void;
52
+ edit(scratch?: boolean): IStorageTransaction;
53
+ branch(path: string): IStorageZone;
54
+ route(): (req: any, res: any) => void;
55
+ }
56
+ export declare function copyToStorageStream(storage: IStorageTransaction, key: string, path: string, contentType?: string): void;
57
+ export declare function removeFile(path: string): void;
58
+ export declare function removeDirectory(path: string): void;
59
+ export declare function readJsonFile<T = any>(path: string): Promise<T>;
@@ -1,8 +1,8 @@
1
1
  import Fsp from "node:fs/promises";
2
- import Fs from 'node:fs';
3
- import Crypto from 'node:crypto';
4
- import Path from 'node:path';
5
- import MIME from 'mime';
2
+ import Fs from "node:fs";
3
+ import Crypto from "node:crypto";
4
+ import Path from "node:path";
5
+ import MIME from "mime";
6
6
  import { directory } from "../utils/file.js";
7
7
  export class SourceEventEmitter {
8
8
  clients = [];
@@ -54,17 +54,22 @@ export class StorageTransaction {
54
54
  const { root, scratch, baseDir } = this;
55
55
  await Fsp.mkdir(baseDir, { recursive: true });
56
56
  const changes = { added: [], updated: [], changed: false };
57
- const writes = [];
58
- for (const [fpath, { data, hash }] of this.pending) {
59
- const prev = root.cache.get(fpath);
60
- if (prev !== hash) {
61
- ;
62
- (prev ? changes.updated : changes.added).push(Path.basename(fpath));
63
- writes.push(Fsp.mkdir(Path.dirname(fpath), { recursive: true }).then(() => Fsp.writeFile(fpath, data)));
64
- }
57
+ const pending_writes = [...this.pending].filter(([fpath, { hash }]) => root.cache.get(fpath) !== hash);
58
+ const write_channel = async () => {
59
+ const item = pending_writes.pop();
60
+ if (!item)
61
+ return;
62
+ const [fpath, { data, hash }] = item;
63
+ const changelist = root.cache.has(fpath) ? changes.updated : changes.added;
64
+ changelist.push(Path.basename(fpath));
65
65
  root.cache.set(fpath, hash);
66
- }
67
- await Promise.all(writes);
66
+ await Fsp.mkdir(Path.dirname(fpath), { recursive: true });
67
+ await Fsp.writeFile(fpath, data);
68
+ if (pending_writes.length > 0) {
69
+ return write_channel();
70
+ }
71
+ };
72
+ await Promise.all(Array.from({ length: Math.min(100, pending_writes.length) }, () => write_channel()));
68
73
  this.pending.clear();
69
74
  if (changes.updated.length > 0 || changes.added.length > 0) {
70
75
  root.on_changes.sendEventsToAll("change", changes);
@@ -169,4 +174,3 @@ export async function readJsonFile(path) {
169
174
  return undefined;
170
175
  }
171
176
  }
172
- //# sourceMappingURL=storage.js.map