@jointhedots/gear 1.1.11 → 1.1.12

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.
@@ -67,7 +67,7 @@ export function readConfigFileSync(path) {
67
67
  * Find config files matching a base name (e.g. "bundle.component") in a directory.
68
68
  * Returns all matching paths across supported extensions.
69
69
  */
70
- export function findConfigFiles(dir, baseName, fnames) {
70
+ export function findConfigFile(dir, baseName, fnames) {
71
71
  const results = [];
72
72
  for (const ext of config_extensions) {
73
73
  const fname = baseName + ext;
@@ -80,7 +80,12 @@ export function findConfigFiles(dir, baseName, fnames) {
80
80
  results.push(`${dir}/${fname}`);
81
81
  }
82
82
  }
83
- return results;
83
+ if (results.length === 0)
84
+ return undefined;
85
+ if (results.length > 1) {
86
+ throw new Error(`Multiple config files found for '${baseName}': ${results.join(", ")}. Only one format is allowed.`);
87
+ }
88
+ return results[0];
84
89
  }
85
90
  /**
86
91
  * Read a singleton config file (exactly one format must exist).
@@ -88,13 +93,8 @@ export function findConfigFiles(dir, baseName, fnames) {
88
93
  * Returns `undefined` if no matching file exists.
89
94
  */
90
95
  export async function readSingletonConfigFile(dir, baseName, fnames) {
91
- const paths = findConfigFiles(dir, baseName, fnames);
92
- if (paths.length === 0)
93
- return undefined;
94
- if (paths.length > 1) {
95
- throw new Error(`Multiple config files found for '${baseName}': ${paths.join(", ")}. Only one format is allowed.`);
96
- }
97
- const data = await readConfigFile(paths[0]);
98
- return data !== undefined ? { data, path: paths[0] } : undefined;
96
+ const path = findConfigFile(dir, baseName, fnames);
97
+ const data = await readConfigFile(path);
98
+ return data !== undefined ? { data, path } : undefined;
99
99
  }
100
100
  //# sourceMappingURL=config-loader.js.map
@@ -5,9 +5,9 @@ import { checkComponentManifest } from "../component.js";
5
5
  import { makeNormalizedName, NameStyle } from "../../utils/normalized-name.js";
6
6
  import { create_manifests } from "./create-manifests.js";
7
7
  import { Bundle, Library, Workspace } from "../workspace.js";
8
- import { make_canonical_path, make_normalized_dirname, make_normalized_path, make_relative_path } from "../../utils/file.js";
9
- import { is_config_filename, readConfigFile, readSingletonConfigFile } from "./config-loader.js";
10
- const exclude_dirs = ["node_modules"];
8
+ import { file, make_canonical_path, make_normalized_dirname, make_normalized_path, make_relative_path } from "../../utils/file.js";
9
+ import { findConfigFile, is_config_filename, readConfigFile, readSingletonConfigFile } from "./config-loader.js";
10
+ const exclude_dirs = ["node_modules", ".git"];
11
11
  function is_ignored_dir(ws, path) {
12
12
  const normalized_path = make_normalized_path(path);
13
13
  for (const ignored of ws.ignored_directories) {
@@ -97,7 +97,9 @@ async function discover_library_components(lib, path, subdir = false) {
97
97
  const fstat = await Fsp.stat(fpath);
98
98
  if (fstat.isDirectory()) {
99
99
  if (!exclude_dirs.includes(fname)) {
100
- await discover_library_components(lib, fpath, true);
100
+ if (await discover_library(lib.workspace, fpath, lib.installed) === Discovered.None) {
101
+ await discover_library_components(lib, fpath, true);
102
+ }
101
103
  }
102
104
  }
103
105
  else if (fstat.isFile()) {
@@ -115,15 +117,6 @@ async function discover_library_components(lib, path, subdir = false) {
115
117
  }
116
118
  }
117
119
  }
118
- // Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
119
- const manifest_result = await readSingletonConfigFile(path, "bundle.manifest", fnames);
120
- if (manifest_result) {
121
- const manifest = manifest_result.data;
122
- for (const pub of manifest.data.components) {
123
- const fpath = path + "/" + (pub.ref ?? pub.id);
124
- await discover_component(lib, fpath);
125
- }
126
- }
127
120
  }
128
121
  function make_library_bundle_manifest(lib, file_desc) {
129
122
  let $id = file_desc?.$id;
@@ -174,53 +167,71 @@ function make_library_bundle_manifest(lib, file_desc) {
174
167
  };
175
168
  return manifest;
176
169
  }
170
+ var Discovered;
171
+ (function (Discovered) {
172
+ Discovered[Discovered["None"] = 0] = "None";
173
+ Discovered[Discovered["Ignored"] = 1] = "Ignored";
174
+ Discovered[Discovered["Registered"] = 2] = "Registered";
175
+ })(Discovered || (Discovered = {}));
177
176
  async function discover_library(ws, location, installed) {
178
177
  const lib_path = make_canonical_path(ws.path, location);
179
178
  if (is_ignored_dir(ws, lib_path))
180
- return false;
179
+ return Discovered.Ignored;
180
+ const package_path = lib_path + "/package.json";
181
+ const manifest_path = findConfigFile(lib_path, "bundle.manifest");
182
+ if (!file.exists(package_path) && !file.exists(manifest_path))
183
+ return Discovered.None;
181
184
  const lib_not_exists = ws.libraries.reduce((r, lib) => r && lib.path !== lib_path, true);
182
- if (lib_not_exists) {
183
- const lib_desc = await readJsonFile(lib_path + "/package.json");
184
- if (!lib_desc?.name)
185
- return false;
186
- const bundle_result = await readSingletonConfigFile(lib_path, "bundle.component");
187
- const bundle_desc = bundle_result?.data;
188
- if (bundle_desc || !installed) {
189
- const other = ws.get_library(lib_desc.name);
190
- if (other) {
191
- if (lib_path.includes(other.path)) {
192
- ws.log.info(`ignore library build at ${lib_path}`);
193
- return false;
194
- }
195
- else {
196
- throw new Error(`library '${lib_desc.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
197
- }
185
+ if (!lib_not_exists)
186
+ return Discovered.Ignored;
187
+ const lib_desc = await readJsonFile(package_path);
188
+ if (!lib_desc?.name)
189
+ return Discovered.Ignored;
190
+ const manifest_desc = await readConfigFile(manifest_path);
191
+ if (manifest_desc || !installed) {
192
+ const other = ws.get_library(lib_desc.name);
193
+ if (other) {
194
+ if (lib_path.includes(other.path)) {
195
+ ws.log.info(`ignore library build at ${lib_path}`);
196
+ return Discovered.Ignored;
198
197
  }
199
- const lib = new Library(lib_desc.name, lib_path, lib_desc, ws);
200
- ws.libraries.push(lib);
201
- ws.log.info(`+ 📚 library: ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
202
- if (bundle_desc) {
203
- setup_library_bundle(lib, bundle_desc);
198
+ else {
199
+ throw new Error(`library '${lib_desc.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
204
200
  }
205
- const lib_search_path = lib_path + "/node_modules";
206
- if (Fs.existsSync(lib_search_path)) {
207
- lib.search_directories.push(lib_search_path);
201
+ }
202
+ const lib = new Library(lib_desc.name, lib_path, lib_desc, ws, installed);
203
+ ws.libraries.push(lib);
204
+ ws.log.info(`+ 📚 library: ${installed ? "⏬" : "🐣"} ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
205
+ // Setup library infos from bundle manifest
206
+ if (manifest_desc) {
207
+ setup_library_bundle(lib, manifest_desc);
208
+ // Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
209
+ for (const pub of manifest_desc.data.components) {
210
+ const fpath = lib_path + "/" + (pub.ref ?? pub.id);
211
+ await discover_component(lib, fpath);
208
212
  }
209
- await discover_library_components(lib, lib_path);
210
- return true;
211
213
  }
214
+ // Setup node search directory
215
+ const lib_search_path = lib_path + "/node_modules";
216
+ if (Fs.existsSync(lib_search_path)) {
217
+ lib.search_directories.push(lib_search_path);
218
+ }
219
+ // Collect library declaration
220
+ await discover_library_components(lib, lib_path);
221
+ return Discovered.Registered;
212
222
  }
213
- return false;
223
+ return Discovered.None;
214
224
  }
215
225
  async function discover_workspace_libraries(ws) {
216
226
  async function walk(dir) {
217
- await discover_library(ws, dir, false);
218
- for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
219
- if (entry.name === "node_modules")
220
- continue;
221
- const fullPath = dir + "/" + entry.name;
222
- if (entry.isDirectory()) {
223
- await walk(fullPath);
227
+ if (await discover_library(ws, dir, false) === Discovered.None) {
228
+ for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
229
+ if (entry.name === "node_modules")
230
+ continue;
231
+ const fullPath = dir + "/" + entry.name;
232
+ if (entry.isDirectory()) {
233
+ await walk(fullPath);
234
+ }
224
235
  }
225
236
  }
226
237
  }
@@ -25,17 +25,19 @@ export class Library extends WorkspaceItem {
25
25
  path;
26
26
  descriptor;
27
27
  workspace;
28
+ installed;
28
29
  bundle = null;
29
30
  declarations = new Map();
30
31
  applications = new Map();
31
32
  externals = {};
32
33
  search_directories = null;
33
- constructor(name, path, descriptor, workspace) {
34
+ constructor(name, path, descriptor, workspace, installed) {
34
35
  super(workspace, `lib:${name}`);
35
36
  this.name = name;
36
37
  this.path = path;
37
38
  this.descriptor = descriptor;
38
39
  this.workspace = workspace;
40
+ this.installed = installed;
39
41
  this.search_directories = workspace.search_directories.slice();
40
42
  Object.assign(this.externals, descriptor.peerDependencies, descriptor.dependencies);
41
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jointhedots/gear",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "jointhedots-gear": "esm/cli.js"
@@ -23,6 +23,7 @@
23
23
  "serve:mono": "node --enable-source-maps --watch-path=esm esm/cli serve --app playground:ui --devmode --port 3002 --ws ../jointhedots-core",
24
24
  "serve:host": "node --enable-source-maps --watch-path=esm esm/cli serve --app playground:ui:host --port 3002 --ws ../jointhedots-core",
25
25
  "serve:sfe": "node --enable-source-maps --watch-path=esm esm/cli serve --app sfe-demo --devmode --ws ../sf-explorer-app",
26
+ "serve:demo": "node --enable-source-maps --watch-path=esm esm/cli serve --app sfe-demo --devmode --ws ../sf-explorer-demo",
26
27
  "make:sfe": "node --enable-source-maps --watch-path=esm esm/cli make --libs @sf-explorer/app --devmode --ws ../sf-explorer-app",
27
28
  "prepublishOnly": "node scripts/prepublish.mjs"
28
29
  },