@antelopejs/dms 0.20.0 → 0.20.1

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 (144) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +19 -12
  3. package/bin/control/backend-mode.test.mjs +41 -1
  4. package/bin/control/backend-records.test.mjs +154 -100
  5. package/bin/control/backend.mjs +1 -1
  6. package/bin/control/backend.test.mjs +4 -1
  7. package/bin/control/base.mjs +6 -1
  8. package/bin/control/build-key-refusals.test.mjs +8 -8
  9. package/bin/control/build-key.mjs +8 -6
  10. package/bin/control/build-key.test.mjs +3 -2
  11. package/bin/control/build-layout.test.mjs +5 -4
  12. package/bin/control/forwarder.test.mjs +19 -11
  13. package/bin/control/helpers/fake-run.mjs +59 -60
  14. package/bin/control/helpers/key-fixture.mjs +1 -1
  15. package/bin/control/helpers/pids.mjs +10 -0
  16. package/bin/control/helpers/tree.mjs +4 -4
  17. package/bin/control/journey.test.mjs +32 -32
  18. package/bin/control/mongo-server.test.mjs +64 -19
  19. package/bin/control/mongo.mjs +12 -3
  20. package/bin/control/namespaces.test.mjs +50 -31
  21. package/bin/control/processes.mjs +13 -1
  22. package/bin/control/processes.test.mjs +98 -64
  23. package/bin/control/renderer.test.mjs +2 -2
  24. package/bin/control/run-ports.test.mjs +24 -9
  25. package/bin/control/stack.mjs +16 -3
  26. package/bin/control/tab.test.mjs +1 -1
  27. package/bin/control/verify/formal.test.mjs +2 -2
  28. package/checks/dms-components.d.mts +38 -0
  29. package/data/mockup-spec.schema.json +4 -2
  30. package/data/module-store/catalog.json +1 -7
  31. package/dist/builder.js +2 -1
  32. package/dist/builder.js.map +1 -1
  33. package/dist/crons/cleanup-user-invites.js +7 -1
  34. package/dist/crons/cleanup-user-invites.js.map +1 -1
  35. package/dist/dev/module-update-notifications.js +2 -4
  36. package/dist/dev/module-update-notifications.js.map +1 -1
  37. package/dist/implementations/dms/dev-handshake.js +2 -5
  38. package/dist/implementations/dms/dev-handshake.js.map +1 -1
  39. package/dist/implementations/dms-auth/index.d.ts +3 -4
  40. package/dist/implementations/dms-auth/index.js +20 -4
  41. package/dist/implementations/dms-auth/index.js.map +1 -1
  42. package/dist/implementations/dms-auth/token-session.d.ts +2 -2
  43. package/dist/implementations/dms-auth/token-session.js +1 -4
  44. package/dist/implementations/dms-auth/token-session.js.map +1 -1
  45. package/dist/implementations/dms-builder/engine/connection-access-config.js +2 -7
  46. package/dist/implementations/dms-builder/engine/connection-access-config.js.map +1 -1
  47. package/dist/implementations/dms-builder/engine/driver-packages.js +4 -1
  48. package/dist/implementations/dms-builder/engine/driver-packages.js.map +1 -1
  49. package/dist/implementations/dms-builder/engine/file-paths.d.ts +3 -0
  50. package/dist/implementations/dms-builder/engine/file-paths.js +18 -0
  51. package/dist/implementations/dms-builder/engine/file-paths.js.map +1 -0
  52. package/dist/implementations/dms-builder/engine/index.d.ts +2 -0
  53. package/dist/implementations/dms-builder/engine/index.js +2 -0
  54. package/dist/implementations/dms-builder/engine/index.js.map +1 -1
  55. package/dist/implementations/dms-builder/engine/inherited-variables.d.ts +2 -0
  56. package/dist/implementations/dms-builder/engine/inherited-variables.js +19 -0
  57. package/dist/implementations/dms-builder/engine/inherited-variables.js.map +1 -0
  58. package/dist/implementations/dms-builder/engine/map-resources.js +1 -1
  59. package/dist/implementations/dms-builder/engine/map-resources.js.map +1 -1
  60. package/dist/implementations/dms-builder/engine/modules.js +3 -5
  61. package/dist/implementations/dms-builder/engine/modules.js.map +1 -1
  62. package/dist/implementations/dms-builder/engine/placement.js +2 -1
  63. package/dist/implementations/dms-builder/engine/placement.js.map +1 -1
  64. package/dist/implementations/dms-builder/engine/project-config-ops.js +2 -1
  65. package/dist/implementations/dms-builder/engine/project-config-ops.js.map +1 -1
  66. package/dist/implementations/dms-builder/engine/project-env.js +5 -0
  67. package/dist/implementations/dms-builder/engine/project-env.js.map +1 -1
  68. package/dist/implementations/dms-builder/engine/project-scaffold.js +18 -8
  69. package/dist/implementations/dms-builder/engine/project-scaffold.js.map +1 -1
  70. package/dist/implementations/dms-builder/engine/theme-app-config.d.ts +1 -1
  71. package/dist/implementations/dms-builder/engine/theme-app-config.js +96 -22
  72. package/dist/implementations/dms-builder/engine/theme-app-config.js.map +1 -1
  73. package/dist/mcp/project-files.js +2 -8
  74. package/dist/mcp/project-files.js.map +1 -1
  75. package/dist/mcp/tools/preview-blocks.js +8 -24
  76. package/dist/mcp/tools/preview-blocks.js.map +1 -1
  77. package/dist/mcp/tools/typecheck.js +2 -5
  78. package/dist/mcp/tools/typecheck.js.map +1 -1
  79. package/dist/mockup/json-schema.js +2 -2
  80. package/dist/mockup/json-schema.js.map +1 -1
  81. package/dist/mockup/sketch-allowlist.d.ts +11 -0
  82. package/dist/mockup/sketch-allowlist.js +368 -0
  83. package/dist/mockup/sketch-allowlist.js.map +1 -0
  84. package/dist/mockup/sketch-css.d.ts +3 -0
  85. package/dist/mockup/sketch-css.js +306 -0
  86. package/dist/mockup/sketch-css.js.map +1 -0
  87. package/dist/mockup/sketch-html.d.ts +7 -0
  88. package/dist/mockup/sketch-html.js +243 -0
  89. package/dist/mockup/sketch-html.js.map +1 -0
  90. package/dist/mockup/sketch-limits.d.ts +1 -0
  91. package/dist/mockup/sketch-limits.js +5 -0
  92. package/dist/mockup/sketch-limits.js.map +1 -0
  93. package/dist/mockup/sketch-scan.d.ts +1 -0
  94. package/dist/mockup/sketch-scan.js +136 -0
  95. package/dist/mockup/sketch-scan.js.map +1 -0
  96. package/dist/mockup/sketch-tokens.d.ts +22 -0
  97. package/dist/mockup/sketch-tokens.js +42 -0
  98. package/dist/mockup/sketch-tokens.js.map +1 -0
  99. package/dist/mockup/sketch.d.ts +19 -1
  100. package/dist/mockup/sketch.js +78 -94
  101. package/dist/mockup/sketch.js.map +1 -1
  102. package/dist/routes/auth/logout.d.ts +2 -2
  103. package/dist/routes/auth/logout.js +3 -9
  104. package/dist/routes/auth/logout.js.map +1 -1
  105. package/dist/routes/auth/refresh.js +6 -8
  106. package/dist/routes/auth/refresh.js.map +1 -1
  107. package/dist/routes/auth/switch-tenant.js +8 -11
  108. package/dist/routes/auth/switch-tenant.js.map +1 -1
  109. package/dist/routes/auth.js +1 -1
  110. package/dist/routes/auth.js.map +1 -1
  111. package/dist/store/registry.js +2 -4
  112. package/dist/store/registry.js.map +1 -1
  113. package/dist/store/tarball.js +12 -6
  114. package/dist/store/tarball.js.map +1 -1
  115. package/dist/utils/index.d.ts +1 -0
  116. package/dist/utils/index.js +1 -0
  117. package/dist/utils/index.js.map +1 -1
  118. package/dist/utils/owner-only-file.d.ts +1 -0
  119. package/dist/utils/owner-only-file.js +60 -0
  120. package/dist/utils/owner-only-file.js.map +1 -0
  121. package/dist/utils/package-manager/index.d.ts +1 -0
  122. package/dist/utils/package-manager/index.js +18 -0
  123. package/dist/utils/package-manager/index.js.map +1 -0
  124. package/dist/utils/package-manager.d.ts +12 -0
  125. package/dist/utils/package-manager.js +28 -0
  126. package/dist/utils/package-manager.js.map +1 -0
  127. package/frontend-vue/layers/dms-auth/app/middleware/auth.ts +11 -7
  128. package/frontend-vue/layers/dms-layout/app/composables/useHeaderActions.ts +4 -4
  129. package/frontend-vue/layers/dms-layout/i18n/locales/layout-en-GB.json +0 -4
  130. package/frontend-vue/layers/dms-layout/i18n/locales/layout-fr-FR.json +0 -4
  131. package/frontend-vue/layers/dms-ui/app/build/utils/sketch.ts +9 -0
  132. package/frontend-vue/package.json +1 -1
  133. package/frontend-vue/scripts/check-autoimport-boundaries.mjs +12 -7
  134. package/frontend-vue/scripts/check-dms-components.mjs +519 -0
  135. package/frontend-vue/scripts/check-invariants.mjs +7 -1
  136. package/frontend-vue/scripts/dms-components-dependencies.mjs +89 -0
  137. package/frontend-vue/scripts/test-dms-components.mjs +255 -0
  138. package/package.json +29 -16
  139. package/skills/dms/REFERENCE.md +1 -1
  140. package/skills/dms/SKILL.md +1 -1
  141. package/skills/dms-module/SKILL.md +1 -1
  142. package/skills/dms-module/cases.json +3 -3
  143. package/skills/dms-project/SKILL.md +1 -1
  144. package/skills/dms-project/scripts/dms-dev.sh +1 -1
@@ -0,0 +1,519 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { join, relative, resolve, sep } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import {
5
+ addCommand,
6
+ dependencies,
7
+ RENDERER,
8
+ rendererComponentNames,
9
+ } from "./dms-components-dependencies.mjs";
10
+
11
+ const DMS_PREFIX = "Dms";
12
+ const DMS_LAYERS = fileURLToPath(new URL("../layers", import.meta.url));
13
+ const DMS_NAME = /^(?:Dms[A-Z]|dms-[a-z])/;
14
+ const SKIP = new Set(["node_modules", "dist", "tests", "test", "fixtures"]);
15
+ const SKIPPED_FILE = /\.(?:test|spec|d)\.[cm]?ts$/;
16
+ const ELEMENT = 1;
17
+ const COMPONENT_TAG = 1;
18
+ const ATTRIBUTE = 6;
19
+
20
+ const COMPONENT_FILE = /\/app\/(?:build\/)?components\/(?:.*\/)?([^/]+)\.vue$/;
21
+ const PAGE_FILE = /\/app\/custom-pages\/(.+?)(?:\/index)?\.vue$/;
22
+ const LAYOUT_FILE = /\/app\/custom-layouts\/(.+)\.vue$/;
23
+
24
+ /** Layer files dms.frontend.ts leaves out of its component globs. */
25
+ const UNREGISTERED_DMS_FILES = new Set([
26
+ "dms-ui/app/components/form/components/ImagePresentation.vue",
27
+ "dms-ui/app/build/components/table/TableBody.vue",
28
+ ]);
29
+
30
+ /** The second names dms.frontend.ts registers some components under. */
31
+ const DMS_ALIASES = {
32
+ ActivityFeed: "ActivityFeedBlock",
33
+ SectionPanel: "SectionBlock",
34
+ FieldRow: "FieldRowBlock",
35
+ };
36
+
37
+ /** A file path as dms.frontend.ts names its component: `notice-banner.vue` is `NoticeBanner`. */
38
+ function pascalCase(name) {
39
+ return name
40
+ .replace(/\.vue$/, "")
41
+ .split(/[./_-]+/)
42
+ .filter(Boolean)
43
+ .map((part) => `${part[0].toUpperCase()}${part.slice(1)}`)
44
+ .join("");
45
+ }
46
+
47
+ /** The last name Vue's `resolveComponent` tries for a tag: `dms-card-panel` is `DmsCardPanel`. */
48
+ function vueName(name) {
49
+ const camel = name.replace(/-(\w)/g, (_, letter) => letter.toUpperCase());
50
+ return `${camel.charAt(0).toUpperCase()}${camel.slice(1)}`;
51
+ }
52
+
53
+ /** A component name as the renderer's `resolveDmsComponent` compares it. */
54
+ function componentKey(name) {
55
+ return name
56
+ .replace(/^lazy/i, "")
57
+ .replace(/[^a-z0-9]/gi, "")
58
+ .toLowerCase();
59
+ }
60
+
61
+ /** A layout name as the renderer's `registerLayout` compares it. */
62
+ function layoutKey(name) {
63
+ return name
64
+ .replace(/^lazy/i, "")
65
+ .replace(/^dms[-_]?/i, "")
66
+ .replace(/[^a-z0-9]/gi, "")
67
+ .toLowerCase();
68
+ }
69
+
70
+ function files(root, keep) {
71
+ if (!existsSync(root)) return [];
72
+ return readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
73
+ if (entry.name.startsWith(".") || SKIP.has(entry.name)) return [];
74
+ const path = join(root, entry.name);
75
+ if (entry.isDirectory()) return files(path, keep);
76
+ return keep(path) ? [path] : [];
77
+ });
78
+ }
79
+
80
+ /**
81
+ * The components and layouts a `dms.frontend.ts` registers from the `.vue`
82
+ * files under `root`, before its prefix: the file name of a component under
83
+ * `app/components/` or `app/build/components/`, the path below
84
+ * `app/custom-pages/` of a custom page, the path below `app/custom-layouts/`
85
+ * of a layout.
86
+ */
87
+ function registeredFiles(root, skip = new Set()) {
88
+ const components = [];
89
+ const layouts = [];
90
+ for (const path of files(root, (file) => file.endsWith(".vue"))) {
91
+ const file = relative(root, path).split(sep).join("/");
92
+ if (skip.has(file)) continue;
93
+ const component = (COMPONENT_FILE.exec(`/${file}`) ??
94
+ PAGE_FILE.exec(`/${file}`))?.[1];
95
+ if (component) components.push(pascalCase(component));
96
+ const layout = LAYOUT_FILE.exec(`/${file}`)?.[1];
97
+ if (layout) layouts.push(layout);
98
+ }
99
+ return { components, layouts };
100
+ }
101
+
102
+ /**
103
+ * The names the installed `@antelopejs/dms` registers, as its
104
+ * `dms.frontend.ts` does: each component with its `Dms` prefix and aliases,
105
+ * and each layout.
106
+ */
107
+ export function dmsRegistrations() {
108
+ const { components, layouts } = registeredFiles(
109
+ DMS_LAYERS,
110
+ UNREGISTERED_DMS_FILES,
111
+ );
112
+ return {
113
+ components: new Set(
114
+ components.flatMap((name) =>
115
+ [name, DMS_ALIASES[name]]
116
+ .filter(Boolean)
117
+ .map((registered) => DMS_PREFIX + registered),
118
+ ),
119
+ ),
120
+ layouts: new Set(layouts),
121
+ };
122
+ }
123
+
124
+ function parseScript(file, source, ts) {
125
+ return ts.createSourceFile(
126
+ file,
127
+ source,
128
+ ts.ScriptTarget.Latest,
129
+ true,
130
+ ts.ScriptKind.TS,
131
+ );
132
+ }
133
+
134
+ function unwrap(node, ts) {
135
+ let inner = node;
136
+ while (
137
+ ts.isParenthesizedExpression(inner) ||
138
+ ts.isAsExpression(inner) ||
139
+ ts.isSatisfiesExpression(inner) ||
140
+ ts.isNonNullExpression(inner) ||
141
+ ts.isTypeAssertionExpression(inner)
142
+ )
143
+ inner = inner.expression;
144
+ return inner;
145
+ }
146
+
147
+ function literalText(node, ts) {
148
+ return ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)
149
+ ? node.text
150
+ : undefined;
151
+ }
152
+
153
+ function bindingNames(name, ts) {
154
+ if (ts.isIdentifier(name)) return [name.text];
155
+ return name.elements.flatMap((element) =>
156
+ ts.isOmittedExpression(element) ? [] : bindingNames(element.name, ts),
157
+ );
158
+ }
159
+
160
+ /**
161
+ * What the statements of one scope declare under `name`: the text of a
162
+ * `const` holding a string, `{}` for any other declaration, or nothing.
163
+ */
164
+ function declaredIn(statements, name, ts) {
165
+ for (const statement of statements) {
166
+ if (ts.isVariableStatement(statement))
167
+ for (const declaration of statement.declarationList.declarations) {
168
+ if (!bindingNames(declaration.name, ts).includes(name)) continue;
169
+ const constant =
170
+ statement.declarationList.flags & ts.NodeFlags.Const &&
171
+ ts.isIdentifier(declaration.name) &&
172
+ declaration.initializer;
173
+ return {
174
+ text: constant
175
+ ? literalText(unwrap(declaration.initializer, ts), ts)
176
+ : undefined,
177
+ };
178
+ }
179
+ const imported = ts.isImportDeclaration(statement)
180
+ ? [
181
+ statement.importClause?.name,
182
+ ...(statement.importClause?.namedBindings?.elements ?? []),
183
+ ]
184
+ : [statement.name];
185
+ if (
186
+ imported.some((binding) => nameOf(binding?.name ?? binding, ts) === name)
187
+ )
188
+ return {};
189
+ }
190
+ return undefined;
191
+ }
192
+
193
+ function shadows(scope, name, ts) {
194
+ const loop =
195
+ (ts.isForStatement(scope) ||
196
+ ts.isForOfStatement(scope) ||
197
+ ts.isForInStatement(scope)) &&
198
+ scope.initializer &&
199
+ ts.isVariableDeclarationList(scope.initializer);
200
+ const declarations = [
201
+ ...(ts.isFunctionLike(scope) ? scope.parameters : []),
202
+ ...(loop ? scope.initializer.declarations : []),
203
+ ...(ts.isCatchClause(scope) && scope.variableDeclaration
204
+ ? [scope.variableDeclaration]
205
+ : []),
206
+ ];
207
+ return declarations.some((declaration) =>
208
+ bindingNames(declaration.name, ts).includes(name),
209
+ );
210
+ }
211
+
212
+ /** The string the `const` that `identifier` refers to holds, when the nearest declaration of its name is one. */
213
+ function constantFor(identifier, ts) {
214
+ for (let scope = identifier.parent; scope; scope = scope.parent) {
215
+ if (shadows(scope, identifier.text, ts)) return undefined;
216
+ if (
217
+ ts.isBlock(scope) ||
218
+ ts.isSourceFile(scope) ||
219
+ ts.isModuleBlock(scope)
220
+ ) {
221
+ const declared = declaredIn(scope.statements, identifier.text, ts);
222
+ if (declared) return declared.text;
223
+ }
224
+ }
225
+ return undefined;
226
+ }
227
+
228
+ /** A string literal, or a `const` of the same file in scope holding one. */
229
+ function stringOf(node, ts) {
230
+ if (!node) return undefined;
231
+ const value = unwrap(node, ts);
232
+ return ts.isIdentifier(value)
233
+ ? constantFor(value, ts)
234
+ : literalText(value, ts);
235
+ }
236
+
237
+ function nameOf(node, ts) {
238
+ if (!node) return undefined;
239
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node)) return node.text;
240
+ if (ts.isPropertyAccessExpression(node)) return node.name.text;
241
+ return undefined;
242
+ }
243
+
244
+ function isBanner(object, ts) {
245
+ const keys = new Set(object.properties.map((p) => nameOf(p.name, ts)));
246
+ return keys.has("key") && keys.has("variant");
247
+ }
248
+
249
+ /**
250
+ * What a node names by string: a component Vue resolves (`resolveComponent`),
251
+ * one an interface-dms builder takes (`CustomComponent`, `new
252
+ * ComponentBuilder`, a `componentName` property, a layout banner's
253
+ * `component`), or one the layer registers.
254
+ */
255
+ function namedString(node, ts) {
256
+ const callee =
257
+ (ts.isCallExpression(node) || ts.isNewExpression(node)) &&
258
+ nameOf(node.expression, ts);
259
+ const argument = callee && node.arguments?.[0];
260
+ if (callee === "resolveComponent") return { kind: "vue", node: argument };
261
+ if (
262
+ callee === "CustomComponent" ||
263
+ (callee === "ComponentBuilder" && ts.isNewExpression(node))
264
+ )
265
+ return { kind: "builder", node: argument };
266
+ if (callee === "registerComponent" || callee === "registerLayout")
267
+ return { kind: callee, node: argument, unprefixed: unprefixed(node, ts) };
268
+ if (ts.isShorthandPropertyAssignment(node))
269
+ return nameOf(node.name, ts) === "componentName"
270
+ ? { kind: "componentName", node: node.name }
271
+ : undefined;
272
+ if (!ts.isPropertyAssignment(node)) return undefined;
273
+ const property = nameOf(node.name, ts);
274
+ if (property === "componentName")
275
+ return { kind: "componentName", node: node.initializer };
276
+ return property === "component" && isBanner(node.parent, ts)
277
+ ? { kind: "builder", node: node.initializer }
278
+ : undefined;
279
+ }
280
+
281
+ /** Whether a `registerComponent` call passes `{ prefix: false }`. */
282
+ function unprefixed(call, ts) {
283
+ const options = call.arguments?.[2];
284
+ return Boolean(
285
+ options &&
286
+ ts.isObjectLiteralExpression(options) &&
287
+ options.properties.some(
288
+ (property) =>
289
+ ts.isPropertyAssignment(property) &&
290
+ nameOf(property.name, ts) === "prefix" &&
291
+ property.initializer.kind === ts.SyntaxKind.FalseKeyword,
292
+ ),
293
+ );
294
+ }
295
+
296
+ /** The component names a script names by string, with the offset of each. */
297
+ function scriptStrings(tree, ts) {
298
+ const found = [];
299
+ const visit = (node) => {
300
+ const named = namedString(node, ts);
301
+ const name = named && stringOf(named.node, ts);
302
+ if (name)
303
+ found.push({
304
+ kind: named.kind,
305
+ name,
306
+ unprefixed: named.unprefixed,
307
+ offset: named.node.getStart(tree),
308
+ });
309
+ ts.forEachChild(node, visit);
310
+ };
311
+ visit(tree);
312
+ return found;
313
+ }
314
+
315
+ function lineAt(source, offset) {
316
+ return source.slice(0, offset).split("\n").length;
317
+ }
318
+
319
+ /** The names a script declares at its top level, which its template may use as tags. */
320
+ function scriptBindings(tree, ts) {
321
+ return tree.statements.flatMap((statement) => {
322
+ if (ts.isImportDeclaration(statement)) {
323
+ const clause = statement.importClause;
324
+ if (!clause || clause.isTypeOnly) return [];
325
+ const named = clause.namedBindings;
326
+ return [
327
+ ...(clause.name ? [clause.name.text] : []),
328
+ ...(named && ts.isNamedImports(named)
329
+ ? named.elements
330
+ .filter((element) => !element.isTypeOnly)
331
+ .map((element) => element.name.text)
332
+ : []),
333
+ ];
334
+ }
335
+ if (ts.isVariableStatement(statement))
336
+ return statement.declarationList.declarations.flatMap((declaration) =>
337
+ bindingNames(declaration.name, ts),
338
+ );
339
+ return (ts.isFunctionDeclaration(statement) ||
340
+ ts.isClassDeclaration(statement)) &&
341
+ statement.name
342
+ ? [statement.name.text]
343
+ : [];
344
+ });
345
+ }
346
+
347
+ function templateUses(node) {
348
+ const children = (node.children ?? []).flatMap(templateUses);
349
+ if (node.type !== ELEMENT) return children;
350
+ const is = node.props.find(
351
+ (prop) => prop.type === ATTRIBUTE && prop.name === "is" && prop.value,
352
+ );
353
+ const tag = node.tagType === COMPONENT_TAG ? node.tag : undefined;
354
+ const name = node.tag === "component" ? is?.value.content : tag;
355
+ return name
356
+ ? [{ kind: "vue", name, line: node.loc.start.line }, ...children]
357
+ : children;
358
+ }
359
+
360
+ /** What one source file names by string or tag, with the line of each. */
361
+ function fileStrings({ file, source }, tools) {
362
+ if (!file.endsWith(".vue"))
363
+ return scriptStrings(parseScript(file, source, tools.ts), tools.ts).map(
364
+ ({ offset, ...use }) => ({ ...use, file, line: lineAt(source, offset) }),
365
+ );
366
+ const { descriptor, errors } = tools.parse(source, { filename: file });
367
+ if (errors.length)
368
+ throw new Error(`Cannot parse ${file}: ${errors.join(", ")}`);
369
+ const scripts = [descriptor.script, descriptor.scriptSetup]
370
+ .filter(Boolean)
371
+ .map((block) => ({
372
+ block,
373
+ tree: parseScript(file, block.content, tools.ts),
374
+ }));
375
+ const bound = new Set(
376
+ scripts.flatMap(({ tree }) => scriptBindings(tree, tools.ts)).map(vueName),
377
+ );
378
+ const tags = descriptor.template?.ast
379
+ ? templateUses(descriptor.template.ast).filter(
380
+ ({ name }) => !bound.has(vueName(name)),
381
+ )
382
+ : [];
383
+ return [
384
+ ...tags.map((use) => ({ ...use, file })),
385
+ ...scripts.flatMap(({ block, tree }) =>
386
+ scriptStrings(tree, tools.ts).map(({ offset, ...use }) => ({
387
+ ...use,
388
+ file,
389
+ line: lineAt(source, block.loc.start.offset + offset),
390
+ })),
391
+ ),
392
+ ];
393
+ }
394
+
395
+ /**
396
+ * The `componentPrefix` of the layer's `dms.frontend.ts`: the first one
397
+ * written as a string, or as a `const` of that file holding one.
398
+ */
399
+ function layerPrefix(layer, ts) {
400
+ const entry = join(layer, "dms.frontend.ts");
401
+ if (!existsSync(entry)) return "";
402
+ const tree = parseScript(entry, readFileSync(entry, "utf8"), ts);
403
+ const declared = [];
404
+ const visit = (node) => {
405
+ if (
406
+ (ts.isPropertyAssignment(node) ||
407
+ ts.isShorthandPropertyAssignment(node)) &&
408
+ nameOf(node.name, ts) === "componentPrefix"
409
+ )
410
+ declared.push(stringOf(node.initializer ?? node.name, ts));
411
+ ts.forEachChild(node, visit);
412
+ };
413
+ visit(tree);
414
+ const prefix = declared.find((value) => value !== undefined);
415
+ if (declared.length && prefix === undefined)
416
+ throw new Error(
417
+ `${entry}: write componentPrefix as a string, or a const of that file holding one, so that the DMS component check reads it`,
418
+ );
419
+ return prefix ?? "";
420
+ }
421
+
422
+ function readSources(roots, pattern) {
423
+ return roots
424
+ .flatMap((root) => {
425
+ if (!existsSync(root)) throw new Error(`No such source: ${root}`);
426
+ return statSync(root).isDirectory()
427
+ ? files(root, (path) => pattern.test(path) && !SKIPPED_FILE.test(path))
428
+ : [root];
429
+ })
430
+ .map((file) => ({ file, source: readFileSync(file, "utf8") }));
431
+ }
432
+
433
+ /** The names Vue and the renderer resolve, from dms, the renderer and the layer. */
434
+ async function knownNames(root, layerStrings, tools) {
435
+ const dms = dmsRegistrations();
436
+ const prefix = layerPrefix(root, tools.ts);
437
+ const own = registeredFiles(root);
438
+ const registered = (kind) => layerStrings.filter((use) => use.kind === kind);
439
+ const tags = new Set([
440
+ ...dms.components,
441
+ ...(await rendererComponentNames(tools.rendererGlobals)),
442
+ ...own.components.map((name) => prefix + name),
443
+ ...registered("registerComponent").map((use) =>
444
+ use.unprefixed || !prefix ? use.name : prefix + vueName(use.name),
445
+ ),
446
+ ]);
447
+ return {
448
+ tags,
449
+ components: new Set([...tags].map(componentKey)),
450
+ layouts: new Set(
451
+ [
452
+ ...dms.layouts,
453
+ ...own.layouts,
454
+ ...registered("registerLayout").map(({ name }) => name),
455
+ ].map(layoutKey),
456
+ ),
457
+ };
458
+ }
459
+
460
+ function isKnown({ kind, name }, known) {
461
+ if (kind === "vue")
462
+ return known.tags.has(name) || known.tags.has(vueName(name));
463
+ return (
464
+ known.components.has(componentKey(name)) ||
465
+ (kind === "componentName" && known.layouts.has(layoutKey(name)))
466
+ );
467
+ }
468
+
469
+ /**
470
+ * Every place the layer names a `Dms` component that neither the installed
471
+ * `@antelopejs/dms`, the installed `@antelopejs/dms-frontend` nor the layer
472
+ * registers: a tag, static `is` or `resolveComponent` string in one of its
473
+ * files, or a string an interface-dms builder takes as a component name in
474
+ * the layer or in `sources` (the module's backend directories). Vue renders
475
+ * an unknown tag as an empty element, with no error. Each diagnostic names
476
+ * the file, the line and the name.
477
+ */
478
+ export async function checkDmsComponents(options) {
479
+ return (await inspect(options)).diagnostics;
480
+ }
481
+
482
+ async function inspect({ layer, sources = [] }) {
483
+ const root = resolve(layer);
484
+ const tools = dependencies(root);
485
+ const layerFiles = readSources([root], /\.(?:vue|[cm]?ts)$/);
486
+ const layerStrings = layerFiles.flatMap((file) => fileStrings(file, tools));
487
+ const known = await knownNames(root, layerStrings, tools);
488
+ const read = new Set(layerFiles.map(({ file }) => file));
489
+ const sourceStrings = readSources(
490
+ sources.map((source) => resolve(source)),
491
+ /\.[cm]?ts$/,
492
+ )
493
+ .filter(({ file }) => !read.has(file))
494
+ .flatMap((file) => fileStrings(file, tools));
495
+ const diagnostics = [...layerStrings, ...sourceStrings]
496
+ .filter(({ kind }) => ["vue", "builder", "componentName"].includes(kind))
497
+ .filter((use) => DMS_NAME.test(use.name) && !isKnown(use, known))
498
+ .map(
499
+ ({ file, line, name }) =>
500
+ `${relative(process.cwd(), file)}:${line}: \`${name}\` is no component the installed @antelopejs/dms, @antelopejs/dms-frontend or this layer registers`,
501
+ );
502
+ return { diagnostics, root, rendererMissing: !tools.rendererGlobals };
503
+ }
504
+
505
+ /**
506
+ * Rejects with every diagnostic of {@link checkDmsComponents}, one per line.
507
+ * When `@antelopejs/dms-frontend` is not installed, the last line says that
508
+ * the components its renderer registers count as unknown, and how to add it.
509
+ */
510
+ export async function assertDmsComponents(options) {
511
+ const { diagnostics, root, rendererMissing } = await inspect(options);
512
+ if (!diagnostics.length) return;
513
+ const note = rendererMissing
514
+ ? [
515
+ `${RENDERER} is not installed in ${root}, so the components its renderer registers, such as DmsLink, count as unknown. If the layer uses one, run in ${root}: ${addCommand([RENDERER])}`,
516
+ ]
517
+ : [];
518
+ throw new Error([...diagnostics, ...note].join("\n"));
519
+ }
@@ -6,6 +6,8 @@ import { brotliDecompressSync } from "node:zlib";
6
6
  import { z } from "zod";
7
7
  import { assertApiErrorPresentation } from "./check-api-error-presentation.mjs";
8
8
  import "./test-api-error-presentation.mjs";
9
+ import { assertDmsComponents } from "./check-dms-components.mjs";
10
+ import "./test-dms-components.mjs";
9
11
  import "./check-autoimport-boundaries.mjs";
10
12
  import "./test-autoimport-boundaries.mjs";
11
13
  import "./check-page-invariants.mjs";
@@ -356,6 +358,10 @@ function checkGeistNarrowSpace() {
356
358
 
357
359
  for (const [name, check] of [
358
360
  ["API error presentation", () => assertApiErrorPresentation([LAYERS_DIR])],
361
+ [
362
+ "DMS components",
363
+ () => assertDmsComponents({ layer: ROOT, sources: [join(ROOT, "../src")] }),
364
+ ],
359
365
  ["core error fallback", checkCoreErrorFallback],
360
366
  ["translated accessible names", checkAccessibleNames],
361
367
  ["layer plugin registration", checkPluginRegistration],
@@ -369,7 +375,7 @@ for (const [name, check] of [
369
375
  ["onboarding page meta", checkOnboardingPageMeta],
370
376
  ]) {
371
377
  try {
372
- check();
378
+ await check();
373
379
  console.log(`PASS ${name}`);
374
380
  } catch (error) {
375
381
  console.error(`FAIL ${name}`);
@@ -0,0 +1,89 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { join } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+
6
+ export const RENDERER = "@antelopejs/dms-frontend";
7
+
8
+ function manifest(path) {
9
+ return JSON.parse(readFileSync(new URL(path, import.meta.url), "utf8"));
10
+ }
11
+
12
+ const FRONTEND = manifest("../package.json");
13
+
14
+ /**
15
+ * The development dependencies the check resolves, at the range the
16
+ * installed `@antelopejs/dms` declares for each. `typescript` and `vue` parse
17
+ * the layer's files; the renderer only lists the components it registers
18
+ * itself, such as `DmsLink`.
19
+ */
20
+ const DMS_COMPONENTS_DEPENDENCIES = Object.freeze({
21
+ typescript: manifest("../../package.json").peerDependencies.typescript,
22
+ vue: FRONTEND.peerDependencies.vue,
23
+ [RENDERER]: FRONTEND.engines[RENDERER],
24
+ });
25
+
26
+ /** How the package manager running the check adds a development dependency. */
27
+ const ADD_DEV_DEPENDENCY = {
28
+ pnpm: "pnpm add -D",
29
+ npm: "npm install -D",
30
+ yarn: "yarn add -D",
31
+ bun: "bun add -d",
32
+ };
33
+
34
+ /** The command that adds `packages` at their range, for the package manager running the check. */
35
+ export function addCommand(packages) {
36
+ const manager = (process.env.npm_config_user_agent ?? "").split("/")[0];
37
+ const add = Object.hasOwn(ADD_DEV_DEPENDENCY, manager)
38
+ ? ADD_DEV_DEPENDENCY[manager]
39
+ : ADD_DEV_DEPENDENCY.pnpm;
40
+ const specs = packages.map(
41
+ (name) => `"${name}@${DMS_COMPONENTS_DEPENDENCIES[name]}"`,
42
+ );
43
+ return `${add} ${specs.join(" ")}`;
44
+ }
45
+
46
+ function resolveFirst(requires, specifier) {
47
+ for (const require of requires) {
48
+ try {
49
+ return require.resolve(specifier);
50
+ } catch {
51
+ continue;
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+
57
+ /**
58
+ * Resolves `typescript` and `vue` from the layer, then from the installed
59
+ * `@antelopejs/dms`, and the renderer from the layer alone.
60
+ */
61
+ export function dependencies(layer) {
62
+ const manifest = join(layer, "package.json");
63
+ if (!existsSync(manifest)) throw new Error(`No package.json in ${layer}`);
64
+ const fromLayer = createRequire(manifest);
65
+ const parsers = [fromLayer, createRequire(import.meta.url)];
66
+ const typescript = resolveFirst(parsers, "typescript");
67
+ const sfc = resolveFirst(parsers, "vue/compiler-sfc");
68
+ const missing = [
69
+ ...(typescript ? [] : ["typescript"]),
70
+ ...(sfc ? [] : ["vue"]),
71
+ ];
72
+ if (missing.length)
73
+ throw new Error(
74
+ `The DMS component check parses the layer with typescript and vue, and ${missing.join(" and ")} cannot be resolved from ${layer}. In ${layer}, run: ${addCommand(missing)}`,
75
+ );
76
+ const require = createRequire(import.meta.url);
77
+ return {
78
+ ts: require(typescript),
79
+ parse: require(sfc).parse,
80
+ rendererGlobals: resolveFirst([fromLayer], `${RENDERER}/eslint-globals`),
81
+ };
82
+ }
83
+
84
+ /** The `Dms` components the `@antelopejs/dms-frontend` renderer registers itself, or none when it is not installed. */
85
+ export async function rendererComponentNames(globalsPath) {
86
+ if (!globalsPath) return [];
87
+ const { default: globals } = await import(pathToFileURL(globalsPath).href);
88
+ return Object.keys(globals).filter((name) => /^Dms[A-Z]/.test(name));
89
+ }