@xeonr/console-shell 0.5.11 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeonr/console-shell",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "description": "The Xeonr Cloud Console chrome: product rail, team switcher, section sidebar, top bar, ⌘K and the All-products launcher, plus the console context hooks every product console mounts.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -160,10 +160,43 @@ function ancestorObjects(src, open) {
160
160
  }
161
161
  }
162
162
 
163
+ /**
164
+ * The string values of an object literal `name = { key: "…" }` defined in
165
+ * `file`, or imported into it from a relative module: Lantern declares its
166
+ * routes as `path: routePatterns.trace` against one such table (CON-62).
167
+ */
168
+ function pathTable(file, name, seen = new Set()) {
169
+ const key = `${file}#${name}`;
170
+ if (seen.has(key)) return null;
171
+ seen.add(key);
172
+ const src = read(file);
173
+ const def = src.match(new RegExp(`(?:^|\\n)(?:export\\s+)?(?:const|let)\\s+${name}\\b[^=\\n]*=\\s*\\{`));
174
+ if (def) {
175
+ const open = def.index + def[0].length - 1;
176
+ const body = src.slice(open, matchClose(src, open));
177
+ const table = {};
178
+ for (const m of body.matchAll(/(?:^|[\s,{])(["']?)([A-Za-z_$][\w$]*)\1\s*:\s*(["'`])([^"'`]*)\3/g)) table[m[2]] = m[4];
179
+ return table;
180
+ }
181
+ const imp = importOf(file, name);
182
+ return imp?.file ? pathTable(imp.file, imp.name, seen) : null;
183
+ }
184
+
163
185
  /** Every route declaration in a file: { path, elements, parents, layout, at }. */
164
- function routesIn(src) {
186
+ function routesIn(src, file) {
165
187
  const out = [];
166
- for (const m of src.matchAll(/\bpath\s*:\s*(["'`])([^"'`]*)\1/g)) {
188
+ const tables = new Map();
189
+ const lookup = (obj, key) => {
190
+ if (!tables.has(obj)) tables.set(obj, file ? pathTable(file, obj) : null);
191
+ return tables.get(obj)?.[key];
192
+ };
193
+ const literal = /\bpath\s*:\s*(["'`])([^"'`]*)\1/g;
194
+ const member = /\bpath\s*:\s*()([A-Za-z_$][\w$]*)\.([A-Za-z_$][\w$]*)\b/g;
195
+ const hits = [
196
+ ...[...src.matchAll(literal)].map((m) => ({ index: m.index, path: m[2] })),
197
+ ...[...src.matchAll(member)].map((m) => ({ index: m.index, path: lookup(m[2], m[3]) })).filter((h) => typeof h.path === "string"),
198
+ ];
199
+ for (const m of hits) {
167
200
  const open = enclosingBrace(src, m.index);
168
201
  if (open < 0) continue;
169
202
  const obj = topLevel(src.slice(open, matchClose(src, open)));
@@ -173,7 +206,7 @@ function routesIn(src) {
173
206
  const pe = o.match(/\belement\s*:\s*(<[\s\S]*)/);
174
207
  return pe ? componentsIn(pe[1]) : [];
175
208
  });
176
- out.push({ path: m[2], elements: el ? componentsIn(el[1]) : [], parents, layout: /\bchildren\s*:/.test(obj), at: m.index });
209
+ out.push({ path: m.path, elements: el ? componentsIn(el[1]) : [], parents, layout: /\bchildren\s*:/.test(obj), at: m.index });
177
210
  }
178
211
  for (const m of src.matchAll(/<Route\b/g)) {
179
212
  // the opening tag ends at the first `>` outside braces
@@ -185,10 +218,12 @@ function routesIn(src) {
185
218
  else if (src[i] === ">" && depth === 0) break;
186
219
  }
187
220
  const tag = src.slice(m.index, i + 1);
188
- const path = tag.match(/\bpath\s*=\s*(?:\{\s*)?(["'`])([^"'`]*)\1/);
189
- if (!path) continue;
221
+ const lit = tag.match(/\bpath\s*=\s*(?:\{\s*)?(["'`])([^"'`]*)\1/);
222
+ const mem = lit ? null : tag.match(/\bpath\s*=\s*\{\s*([A-Za-z_$][\w$]*)\.([A-Za-z_$][\w$]*)\s*\}/);
223
+ const p = lit ? lit[2] : mem ? lookup(mem[1], mem[2]) : undefined;
224
+ if (typeof p !== "string") continue;
190
225
  const el = tag.match(/\belement\s*=\s*\{\s*(<[\s\S]*)/);
191
- out.push({ path: path[2], elements: el ? componentsIn(el[1]) : [], parents: [], layout: !tag.endsWith("/>"), at: m.index });
226
+ out.push({ path: p, elements: el ? componentsIn(el[1]) : [], parents: [], layout: !tag.endsWith("/>"), at: m.index });
192
227
  }
193
228
  return out;
194
229
  }
@@ -295,7 +330,7 @@ for (const dir of dirs) {
295
330
  }
296
331
  for (const file of collect(abs)) {
297
332
  const src = read(file);
298
- for (const r of routesIn(src)) {
333
+ for (const r of routesIn(src, file)) {
299
334
  if (r.layout || r.elements.length === 0) continue;
300
335
  const params = entityParams(r.path, ignore);
301
336
  if (params.length === 0) continue;