@jointhedots/gear 1.1.17 → 1.2.0

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 (30) hide show
  1. package/esm/builder/build-app-bundle.js +11 -12
  2. package/esm/builder/build-app-host.js +48 -6
  3. package/esm/builder/build-application.js +4 -5
  4. package/esm/builder/build-library.js +5 -3
  5. package/esm/builder/build-target.js +6 -6
  6. package/esm/builder/helpers/emit-bundle-manifest.js +1 -1
  7. package/esm/builder/helpers/emit-components-dts.js +66 -0
  8. package/esm/builder/helpers/emit-esmodules.js +1 -1
  9. package/esm/builder/helpers/emit-package-manifest.js +1 -1
  10. package/esm/builder/helpers/emit-static-assets.js +2 -2
  11. package/esm/builder/helpers/emit-typescript-definition.js +36 -17
  12. package/esm/cli.js +2 -0
  13. package/esm/commands/install.js +67 -0
  14. package/esm/commands/make.js +6 -5
  15. package/esm/commands/publish.js +1 -1
  16. package/esm/commands/serve.js +3 -3
  17. package/esm/publish/publish_aws_s3.js +2 -2
  18. package/esm/utils/normalized-name.js +11 -9
  19. package/esm/{model → workspace}/helpers/create-manifests.js +7 -1
  20. package/esm/{model → workspace}/helpers/discover-workspace.js +134 -154
  21. package/esm/workspace/packager.js +53 -0
  22. package/esm/workspace/packagers/packager-standard.js +64 -0
  23. package/esm/{model → workspace}/storage.js +15 -10
  24. package/esm/{model → workspace}/workspace.js +23 -14
  25. package/package.json +7 -3
  26. /package/esm/{model → workspace}/component.js +0 -0
  27. /package/esm/{model → workspace}/helpers/config-loader.js +0 -0
  28. /package/esm/{model → workspace}/helpers/lockfile.js +0 -0
  29. /package/esm/{model → workspace}/helpers/logger.js +0 -0
  30. /package/esm/{model → workspace}/helpers/package-npm.js +0 -0
@@ -50,15 +50,9 @@ export function isNormalizedName(name, expectedStyle) {
50
50
  const style = expectedStyle ?? detectNormalizedNameStyle(name);
51
51
  return check_name_regexes[style].test(name);
52
52
  }
53
- export function makeNormalizedKey(key, targetStyle) {
54
- const seps = NormalizedNameSeparators[targetStyle];
55
- const parts = key.replace(/[^a-z0-9\s\t\n:._-]/g, "").split(/[\s\t\n:._-]/g);
56
- return parts.filter(x => !!x).join(seps.key);
57
- }
58
- export function makeNormalizedName(name, targetStyle, fromStyle) {
53
+ export function getNormalizedKeys(name, fromStyle) {
59
54
  if (!name || typeof name !== "string")
60
- return name;
61
- const seps = NormalizedNameSeparators[targetStyle];
55
+ return [];
62
56
  // Split into lowercase keys
63
57
  let keys;
64
58
  name = name.toLowerCase();
@@ -81,8 +75,16 @@ export function makeNormalizedName(name, targetStyle, fromStyle) {
81
75
  }
82
76
  // Normalize keys
83
77
  for (let i = 0; i < keys.length; i++) {
84
- keys[i] = makeNormalizedKey(keys[i], targetStyle);
78
+ keys[i] = keys[i].replace(/[^a-z0-9\s\t\n:._-]/g, "");
85
79
  }
80
+ return keys;
81
+ }
82
+ export function makeNormalizedName(name, targetStyle, fromStyle) {
83
+ if (!name || typeof name !== "string")
84
+ return name;
85
+ const seps = NormalizedNameSeparators[targetStyle];
86
+ // Split into lowercase keys
87
+ const keys = getNormalizedKeys(name, fromStyle);
86
88
  // Reform name, filtering out empty keys
87
89
  return keys.filter(x => !!x).join(seps.namespace);
88
90
  }
@@ -1,6 +1,7 @@
1
1
  import Path from "node:path";
2
2
  import { makeComponentPublication } from "../component.js";
3
3
  import { resolve_normalized_suffixed_path } from "../../utils/file.js";
4
+ import { getNormalizedKeys } from "../../utils/normalized-name.js";
4
5
  function add_export_entry(exports, lib, key, value, baseDir) {
5
6
  const basename = key.startsWith("./") ? key.slice(2) : key;
6
7
  const filename = lib.make_file_id("export", basename);
@@ -49,13 +50,18 @@ export function create_bundle_manifest(lib, bun) {
49
50
  return null;
50
51
  const entries = create_export_map(lib, bun);
51
52
  const bundle_manif = bun.manifest;
53
+ const namespaces = new Set();
52
54
  const components = [];
53
55
  for (const comp of bun.components.values()) {
56
+ const ns = getNormalizedKeys(comp.$id)[0];
57
+ if (ns)
58
+ namespaces.add(ns);
54
59
  components.push(makeComponentPublication(comp));
55
60
  }
56
61
  bundle_manif.data = {
57
62
  baseline: bun.id + "-v0",
58
63
  components: components,
64
+ namespaces: Array.from(namespaces),
59
65
  exports: {},
60
66
  };
61
67
  for (const id in entries) {
@@ -78,7 +84,7 @@ export function create_package_manifest(lib, bun, build_version) {
78
84
  optionalDependencies: undefined,
79
85
  };
80
86
  if (pkg_manif.dependencies) {
81
- const resolved = lib.workspace.resolved_versions;
87
+ const resolved = lib.resolved_versions;
82
88
  for (const dep in pkg_manif.dependencies) {
83
89
  if (pkg_manif.dependencies[dep] === "*") {
84
90
  const dep_resolved = resolved[dep];
@@ -8,6 +8,8 @@ import { Bundle, Library, Workspace } from "../workspace.js";
8
8
  import { file, make_canonical_path, make_normalized_dirname, make_normalized_path, make_relative_path } from "../../utils/file.js";
9
9
  import { findConfigFile, is_config_filename, readConfigFile, readSingletonConfigFile } from "./config-loader.js";
10
10
  import { read_lockfile } from "./lockfile.js";
11
+ import { LoadLibraryPackager } from "../packager.js";
12
+ import { DefaultLibraryPackager } from "../packagers/packager-standard.js";
11
13
  const exclude_dirs = ["node_modules", ".git"];
12
14
  function is_ignored_dir(ws, path) {
13
15
  const normalized_path = make_normalized_path(path);
@@ -18,26 +20,8 @@ function is_ignored_dir(ws, path) {
18
20
  }
19
21
  return false;
20
22
  }
21
- function setup_library_bundle(lib, bundle_desc) {
22
- const ws = lib.workspace;
23
- const manif = make_library_bundle_manifest(lib, bundle_desc);
24
- let bun = ws.get_bundle(manif.$id);
25
- if (!bun) {
26
- bun = new Bundle(manif, lib.path, ws, lib);
27
- lib.bundle = bun;
28
- ws.bundles.push(bun);
29
- lib.log.info(`+ 📦 bundle: ${bun.id}`);
30
- return bun;
31
- }
32
- else {
33
- throw new Error(`Library '${lib.get_id()}' is associate to a bundle '${bun.id}' that is already associated`);
34
- }
35
- }
36
- async function discover_component(lib, fpath) {
37
- let bundle = lib.bundle;
38
- if (!bundle) {
39
- bundle = setup_library_bundle(lib);
40
- }
23
+ export async function discover_component(lib, fpath) {
24
+ const { bundle } = lib;
41
25
  if (bundle.components.has(fpath)) {
42
26
  return true;
43
27
  }
@@ -90,7 +74,7 @@ async function discover_application(lib, fpath) {
90
74
  lib.log.error(`invalid application at ${fpath}: ${e?.message}`);
91
75
  }
92
76
  }
93
- async function discover_library_components(lib, path, subdir = false) {
77
+ export async function discover_library_definitions(lib, path, subdir = false) {
94
78
  // List names from directory
95
79
  const fnames = await Fsp.readdir(path);
96
80
  if (subdir && fnames.includes("package.json")) {
@@ -102,8 +86,8 @@ async function discover_library_components(lib, path, subdir = false) {
102
86
  const fstat = await Fsp.stat(fpath);
103
87
  if (fstat.isDirectory()) {
104
88
  if (!exclude_dirs.includes(fname)) {
105
- if (await discover_library(lib.workspace, fpath, lib.installed) === Discovered.None) {
106
- await discover_library_components(lib, fpath, true);
89
+ if (await discover_bundle(lib, fpath) === Discovered.None) {
90
+ await discover_library_definitions(lib, fpath, true);
107
91
  }
108
92
  }
109
93
  }
@@ -123,152 +107,57 @@ async function discover_library_components(lib, path, subdir = false) {
123
107
  }
124
108
  }
125
109
  }
126
- export function collect_declarations_field(lib, key, value) {
127
- for (const decl of lib.declarations.values()) {
128
- if (typeof decl[key] === typeof value) {
129
- if (Array.isArray(value))
130
- value.push(...decl[key]);
131
- else if (typeof value === "object")
132
- Object.assign(value, decl[key]);
133
- else
134
- value = decl[key];
135
- }
136
- }
137
- return value;
138
- }
139
- function make_library_bundle_manifest(lib, file_desc) {
140
- let $id = file_desc?.$id;
141
- if ($id) {
142
- $id = makeNormalizedName($id, NameStyle.OBJECT);
143
- if ($id !== file_desc.$id) {
144
- lib.log.warn(`Bundle '${file_desc.$id}' is normalized into '${$id}'`);
145
- }
146
- }
147
- else {
148
- $id = makeNormalizedName(lib.name, NameStyle.OBJECT);
149
- lib.log.info(`Bundle '${$id}' named from library '${lib.name}'`);
150
- }
151
- const data = {
152
- package: lib.get_id(),
153
- alias: collect_declarations_field(lib, "alias", lib.name),
154
- namespaces: collect_declarations_field(lib, "namespaces", []),
155
- dependencies: collect_declarations_field(lib, "dependencies", []),
156
- distribueds: collect_declarations_field(lib, "distribueds", {}),
157
- };
158
- if (file_desc?.data) {
159
- data.alias = file_desc.data.alias ?? data.alias;
160
- if (file_desc.data.distribueds) {
161
- Object.assign(data.distribueds, file_desc.data.distribueds);
162
- }
163
- if (Array.isArray(file_desc.data.namespaces)) {
164
- data.namespaces.push(...file_desc.data.namespaces);
165
- }
166
- if (Array.isArray(file_desc.data.dependencies)) {
167
- data.dependencies.push(...file_desc.data.dependencies);
168
- }
169
- }
170
- const manifest = {
171
- $id,
172
- type: file_desc?.type,
173
- name: file_desc?.name ?? lib.name,
174
- icon: file_desc?.icon,
175
- title: file_desc?.title,
176
- tags: file_desc?.tags,
177
- keywords: file_desc?.keywords,
178
- description: file_desc?.description ?? lib.descriptor?.description,
179
- selectors: file_desc?.selectors,
180
- data,
181
- };
182
- return manifest;
183
- }
184
110
  var Discovered;
185
111
  (function (Discovered) {
186
112
  Discovered[Discovered["None"] = 0] = "None";
187
113
  Discovered[Discovered["Ignored"] = 1] = "Ignored";
188
114
  Discovered[Discovered["Registered"] = 2] = "Registered";
189
115
  })(Discovered || (Discovered = {}));
190
- async function discover_library(ws, location, installed) {
116
+ async function discover_library(ws, location) {
191
117
  const lib_path = make_canonical_path(ws.path, location);
192
118
  if (is_ignored_dir(ws, lib_path))
193
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
+ }
194
125
  const package_path = lib_path + "/package.json";
195
- const manifest_path = findConfigFile(lib_path, "bundle.manifest");
196
- if (!file.exists(package_path) && !file.exists(manifest_path))
126
+ const has_package_manifest = file.exists(package_path);
127
+ if (!has_package_manifest)
197
128
  return Discovered.None;
198
- const lib_not_exists = ws.libraries.reduce((r, lib) => r && lib.path !== lib_path, true);
199
- if (!lib_not_exists)
200
- return Discovered.Ignored;
201
- const lib_desc = await readJsonFile(package_path);
202
- if (!lib_desc?.name)
129
+ const lib_manifest = await readJsonFile(package_path);
130
+ if (!lib_manifest?.name)
203
131
  return Discovered.Ignored;
204
- const manifest_desc = await readConfigFile(manifest_path);
205
- if (manifest_desc || !installed) {
206
- const other = ws.get_library(lib_desc.name);
207
- if (other) {
208
- if (lib_path.includes(other.path)) {
209
- ws.log.info(`ignore library build at ${lib_path}`);
210
- return Discovered.Ignored;
211
- }
212
- else {
213
- throw new Error(`library '${lib_desc.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
214
- }
215
- }
216
- const lib = new Library(lib_desc.name, lib_path, lib_desc, ws, installed);
217
- ws.libraries.push(lib);
218
- ws.log.info(`+ 📚 library: ${installed ? "⏬" : "🐣"} ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
219
- // Setup library infos from bundle manifest
220
- setup_library_bundle(lib, manifest_desc);
221
- // Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
222
- if (manifest_desc?.data?.components) {
223
- for (const pub of manifest_desc.data.components) {
224
- const fpath = lib_path + "/" + (pub.ref ?? pub.id);
225
- await discover_component(lib, fpath);
226
- }
227
- }
228
- // Setup node search directory
229
- const lib_search_path = lib_path + "/node_modules";
230
- if (Fs.existsSync(lib_search_path)) {
231
- lib.search_directories.push(lib_search_path);
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;
232
139
  }
233
- // Collect library declaration
234
- await discover_library_components(lib, lib_path);
235
- return Discovered.Registered;
236
- }
237
- return Discovered.None;
238
- }
239
- async function discover_workspace_libraries(ws) {
240
- async function walk(dir) {
241
- if (await discover_library(ws, dir, false) === Discovered.None) {
242
- for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
243
- if (entry.name === "node_modules")
244
- continue;
245
- const fullPath = dir + "/" + entry.name;
246
- if (entry.isDirectory()) {
247
- await walk(fullPath);
248
- }
249
- }
140
+ else {
141
+ throw new Error(`library '${lib_manifest.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
250
142
  }
251
143
  }
252
- await walk(ws.path);
253
- }
254
- function show_constants(ws) {
255
- for (const name in ws.constants) {
256
- ws.log.info(`+ 🔖 ${name} = ${ws.constants[name]}`);
257
- }
258
- }
259
- 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)
260
148
  let lockfile = null;
261
- for (let path = ws.path;;) {
149
+ lib.constants = { ...ws.constants };
150
+ for (let path = lib.path;;) {
262
151
  const package_json = await readJsonFile(path + "/package.json");
263
152
  if (package_json) {
264
153
  const search_path = path + "/node_modules";
265
154
  if (Fs.existsSync(search_path)) {
266
- ws.search_directories.push(search_path);
155
+ lib.search_directories.push(search_path);
267
156
  }
268
157
  if (package_json.constants) {
269
- ws.constants = {
158
+ lib.constants = {
270
159
  ...package_json.constants,
271
- ...ws.constants,
160
+ ...lib.constants,
272
161
  };
273
162
  }
274
163
  }
@@ -280,19 +169,110 @@ export async function discover_workspace(ws) {
280
169
  break;
281
170
  path = next_path;
282
171
  }
283
- 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 {
284
181
  throw new Error(`Lock file not found for '${ws.name}'`);
285
182
  }
286
- ws.resolved_versions = lockfile.resolved_versions;
287
- await discover_workspace_libraries(ws);
288
- for (const location of lockfile.installed_locations) {
289
- 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
+ }
219
+ }
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);
229
+ }
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
+ }
290
260
  }
291
- for (const bun of ws.bundles) {
292
- if (bun.source) {
293
- bun.manifest = create_bundle_manifest(bun.source, bun);
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
+ }
294
273
  }
295
274
  }
275
+ await walk(ws.path);
296
276
  show_constants(ws);
297
277
  return ws;
298
278
  }
@@ -0,0 +1,53 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import ChildProcess from "child_process";
10
+ function parseSpecifier(specifier) {
11
+ let raw = specifier.startsWith("npm:") ? specifier.slice(4) : specifier;
12
+ let exportName;
13
+ const hashIndex = raw.indexOf("#");
14
+ if (hashIndex >= 0) {
15
+ exportName = raw.slice(hashIndex + 1);
16
+ raw = raw.slice(0, hashIndex);
17
+ }
18
+ let packageName;
19
+ if (raw.startsWith("@")) {
20
+ const parts = raw.split("/");
21
+ packageName = parts.slice(0, 2).join("/");
22
+ }
23
+ else {
24
+ packageName = raw.split("/")[0];
25
+ }
26
+ return { importPath: raw, packageName, exportName };
27
+ }
28
+ const validPackageName = /^(@[a-z0-9\-~][a-z0-9\-._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$/;
29
+ function resolveExport(mod, exportName) {
30
+ if (exportName) {
31
+ if (!(exportName in mod)) {
32
+ throw new Error(`Export '${exportName}' not found in module`);
33
+ }
34
+ return mod[exportName];
35
+ }
36
+ return mod.default ?? mod;
37
+ }
38
+ export async function LoadLibraryPackager(specifier) {
39
+ const { importPath, packageName, exportName } = parseSpecifier(specifier);
40
+ try {
41
+ const mod = await import(__rewriteRelativeImportExtension(importPath));
42
+ return resolveExport(mod, exportName);
43
+ }
44
+ catch {
45
+ if (!validPackageName.test(packageName)) {
46
+ throw new Error(`Invalid package name: ${packageName}`);
47
+ }
48
+ ChildProcess.execSync(`npm install ${packageName}`, { stdio: "inherit" });
49
+ const mod = await import(__rewriteRelativeImportExtension(importPath));
50
+ return resolveExport(mod, exportName);
51
+ }
52
+ }
53
+ //# sourceMappingURL=packager.js.map
@@ -0,0 +1,64 @@
1
+ import {} from "../component.js";
2
+ import { Bundle, Library } from "../workspace.js";
3
+ import { readSingletonConfigFile } from "../helpers/config-loader.js";
4
+ import {} from "../packager.js";
5
+ import { discover_component, discover_library_definitions } from "../helpers/discover-workspace.js";
6
+ import { makeNormalizedName, NameStyle } from "../../utils/normalized-name.js";
7
+ export class DefaultLibraryPackager {
8
+ async discover_library(lib) {
9
+ // Setup library infos from bundle manifest
10
+ setup_library_bundle(lib);
11
+ // Collect library declaration
12
+ await discover_library_definitions(lib, lib.path);
13
+ return lib.bundle;
14
+ }
15
+ }
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} 🐣`);
25
+ return bun;
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
+ };
63
+ }
64
+ //# sourceMappingURL=packager-standard.js.map
@@ -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);
@@ -23,26 +23,37 @@ export class Library extends WorkspaceItem {
23
23
  path;
24
24
  descriptor;
25
25
  workspace;
26
- installed;
27
26
  bundle = null;
28
27
  declarations = new Map();
29
28
  applications = new Map();
30
29
  externals = {};
31
- search_directories = null;
32
- constructor(name, path, descriptor, workspace, installed) {
30
+ resolved_versions = {};
31
+ search_directories = [];
32
+ constants = {};
33
+ shelve = [];
34
+ constructor(name, path, descriptor, workspace) {
33
35
  super(workspace, `lib:${name}`);
34
36
  this.name = name;
35
37
  this.path = path;
36
38
  this.descriptor = descriptor;
37
39
  this.workspace = workspace;
38
- this.installed = installed;
39
- this.search_directories = workspace.search_directories.slice();
40
40
  Object.assign(this.externals, descriptor.peerDependencies, descriptor.dependencies);
41
41
  }
42
42
  get_id() {
43
43
  const { name, version } = this.descriptor;
44
44
  return `${name}-${version}`;
45
45
  }
46
+ get_bundle(id) {
47
+ for (const bundle of this.shelve) {
48
+ if (bundle.id === id)
49
+ return bundle;
50
+ }
51
+ for (const bundle of this.shelve) {
52
+ if (bundle.alias === id)
53
+ return bundle;
54
+ }
55
+ return null;
56
+ }
46
57
  make_file_id(prefix, id) {
47
58
  const devmode = true;
48
59
  const base = devmode ? makeNormalizedName(id, NameStyle.OBJECT) : computeNameHashID(id);
@@ -104,11 +115,8 @@ export class Workspace {
104
115
  version;
105
116
  path;
106
117
  devmode;
107
- bundles = [];
108
118
  libraries = [];
109
119
  constants = {};
110
- resolved_versions = {};
111
- search_directories = [];
112
120
  ignored_directories = new Set();
113
121
  logger = new Logger();
114
122
  log;
@@ -120,13 +128,14 @@ export class Workspace {
120
128
  this.log = this.logger.get(`workspace:${name}`);
121
129
  }
122
130
  get_bundle(id) {
123
- for (const bundle of this.bundles) {
124
- if (bundle.id === id)
125
- return bundle;
131
+ for (const lib of this.libraries) {
132
+ if (lib.bundle.id === id)
133
+ return lib.bundle;
126
134
  }
127
- for (const bundle of this.bundles) {
128
- if (bundle.alias === id)
129
- return bundle;
135
+ for (const lib of this.libraries) {
136
+ const bun = lib.get_bundle(id);
137
+ if (bun)
138
+ return bun;
130
139
  }
131
140
  return null;
132
141
  }