@astryxdesign/cli 0.7.2-canary.6a3ff0f → 0.7.2-canary.6c792d8
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/README.md +62 -62
- package/api/component/_adapter.d.mts +31 -0
- package/api/component/_adapter.mjs +116 -0
- package/api/component/component.mjs +60 -10
- package/api/component/doc-links.test.mjs +386 -0
- package/api/discover/_adapter.d.mts +119 -12
- package/api/discover/_adapter.mjs +449 -10
- package/api/discover/_adapter.test.mjs +599 -17
- package/api/discover/_catalog-view.d.mts +16 -5
- package/api/discover/_catalog-view.mjs +32 -8
- package/api/discover/detail/doc/doc.mjs +9 -1
- package/api/discover/discover.d.mts +11 -0
- package/api/discover/discover.doc.mjs +7 -6
- package/api/discover/discover.mjs +107 -19
- package/api/discover/discover.type.d.mts +18 -7
- package/api/discover/discover.type.mjs +15 -7
- package/api/discover/list/list.d.mts +4 -3
- package/api/discover/list/list.mjs +17 -10
- package/api/docs/_adapter.d.mts +63 -0
- package/api/docs/_adapter.mjs +309 -16
- package/api/docs/integration-tree.test.mjs +22 -0
- package/api/docs/list/list.mjs +12 -2
- package/api/doctor/theme-checks.test.mjs +136 -0
- package/api/integration/_adapter.d.mts +33 -0
- package/api/integration/_adapter.mjs +58 -0
- package/api/integration/authoring-checks.mjs +98 -3
- package/api/integration/authoring-checks.test.mjs +769 -0
- package/api/integration/authoring-checks.type.d.mts +134 -0
- package/api/integration/authoring-checks.type.mjs +60 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +3 -1
- package/api/integration/integrationDocConflicts.doc.mjs +22 -5
- package/api/integration/pack-check.mjs +296 -7
- package/api/integration/pack-check.test.mjs +367 -0
- package/api/integration/validate-integration-fixes.test.mjs +67 -0
- package/api/integration/validate-integration.mjs +28 -3
- package/api/integration/validate-integration.test.mjs +77 -8
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/search.mjs +2 -1
- package/assets/discover/official-packages.json +367 -0
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/browser-support.doc.mjs +1 -1
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +3 -3
- package/assets/docs/tree/check-the-props.doc.mjs +7 -2
- package/assets/docs/tree/check-your-docs.doc.mjs +15 -3
- package/assets/docs/tree/checks.doc.mjs +5 -5
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -7
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/migration-setup.doc.mjs +2 -2
- package/assets/docs/tree/publishing.doc.mjs +3 -3
- package/assets/docs/tree/quick-start.doc.mjs +2 -2
- package/assets/docs/tree/sections-and-placement.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +5 -5
- package/assets/docs/tree/upgrading.doc.mjs +1 -1
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/component/type.ts +8 -0
- package/authoring/doctypes/hook/type.ts +4 -0
- package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/discover.mjs +144 -93
- package/clients/cli/commands/discover.no-source.test.mjs +447 -33
- package/clients/cli/commands/discover.sources.test.mjs +20 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -2
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
- package/clients/cli/commands/doctor-integration.test.mjs +48 -1
- package/clients/cli/commands/doctor.mjs +91 -5
- package/clients/cli/commands/integration-authoring.test.mjs +46 -0
- package/clients/cli/commands/integration-check.test.mjs +127 -0
- package/clients/cli/commands/integration.mjs +10 -4
- package/clients/cli/commands/json-contract.test.mjs +5 -1
- package/foundation/discovery/copied-passages.d.mts +216 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -0
- package/foundation/discovery/doc-consistency.d.mts +34 -0
- package/foundation/discovery/doc-consistency.mjs +513 -0
- package/foundation/discovery/doc-consistency.test.mjs +347 -0
- package/foundation/discovery/doc-fluff.d.mts +112 -0
- package/foundation/discovery/doc-fluff.mjs +328 -0
- package/foundation/discovery/doc-fluff.test.mjs +142 -0
- package/foundation/discovery/doc-types.mjs +12 -5
- package/foundation/discovery/doc-types.test.mjs +46 -2
- package/foundation/discovery/docs-discovery.d.mts +7 -0
- package/foundation/discovery/docs-discovery.mjs +26 -2
- package/foundation/discovery/prop-drift.d.mts +25 -6
- package/foundation/discovery/prop-drift.mjs +171 -6
- package/foundation/discovery/prop-drift.test.mjs +65 -0
- package/foundation/discovery/stray-pointers.d.mts +52 -0
- package/foundation/discovery/stray-pointers.mjs +293 -0
- package/foundation/discovery/stray-pointers.test.mjs +86 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +16 -0
- package/foundation/doc-compiler/links.d.mts +32 -0
- package/foundation/doc-compiler/links.mjs +163 -26
- package/foundation/doc-compiler/links.test.mjs +97 -4
- package/foundation/doc-compiler/tree.mjs +30 -1
- package/foundation/doc-compiler/tree.test.mjs +7 -0
- package/foundation/fs/module-loader.d.mts +2 -1
- package/foundation/fs/module-loader.mjs +60 -4
- package/foundation/fs/module-loader.test.mjs +194 -0
- package/foundation/integrations/contribution-inventory.d.mts +11 -0
- package/foundation/integrations/contribution-inventory.mjs +50 -2
- package/foundation/integrations/issue.ts +6 -0
- package/foundation/integrations/validate-contributions.mjs +30 -1
- package/foundation/response/response-types.doc.mjs +5 -5
- package/package.json +11 -11
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
import {describe, expect, it} from 'vitest';
|
|
9
9
|
import {
|
|
10
10
|
linkBlocks,
|
|
11
|
+
linkFields,
|
|
11
12
|
linkSections,
|
|
12
13
|
parseLinkTarget,
|
|
14
|
+
textFields,
|
|
13
15
|
unlinkText,
|
|
14
16
|
} from './links.mjs';
|
|
15
17
|
|
|
@@ -58,14 +60,20 @@ describe('linkBlocks', () => {
|
|
|
58
60
|
const {content, problems} = await linkBlocks(
|
|
59
61
|
[
|
|
60
62
|
{type: 'prose', text: 'Check it with {@link command:doctor}.'},
|
|
61
|
-
{
|
|
63
|
+
{
|
|
64
|
+
type: 'list',
|
|
65
|
+
style: 'unordered',
|
|
66
|
+
items: ['See {@link @acme/kit:generic:setup}'],
|
|
67
|
+
},
|
|
62
68
|
{type: 'table', headers: ['Doc'], rows: [['{@link command:doctor}']]},
|
|
63
69
|
{type: 'code', lang: 'js', code: '{@link command:doctor}'},
|
|
64
70
|
],
|
|
65
71
|
resolve,
|
|
66
72
|
);
|
|
67
73
|
expect(problems).toEqual([]);
|
|
68
|
-
expect(content[0].text).toBe(
|
|
74
|
+
expect(content[0].text).toBe(
|
|
75
|
+
'Check it with `astryx docs cli/commands/doctor`.',
|
|
76
|
+
);
|
|
69
77
|
expect(content[1].items).toEqual(['See `astryx docs acme/setup`']);
|
|
70
78
|
expect(content[2].rows).toEqual([['`astryx docs cli/commands/doctor`']]);
|
|
71
79
|
// Code is an example: it is shown as written.
|
|
@@ -74,7 +82,12 @@ describe('linkBlocks', () => {
|
|
|
74
82
|
|
|
75
83
|
it('shows a link written in code ticks as written', async () => {
|
|
76
84
|
const {content, problems} = await linkBlocks(
|
|
77
|
-
[
|
|
85
|
+
[
|
|
86
|
+
{
|
|
87
|
+
type: 'prose',
|
|
88
|
+
text: 'Write `{@link <target>}` to link; {@link command:doctor} checks it.',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
78
91
|
resolve,
|
|
79
92
|
);
|
|
80
93
|
expect(problems).toEqual([]);
|
|
@@ -172,7 +185,10 @@ describe('linkBlocks', () => {
|
|
|
172
185
|
},
|
|
173
186
|
],
|
|
174
187
|
resolve,
|
|
175
|
-
).then(({sections, problems}) => ({
|
|
188
|
+
).then(({sections, problems}) => ({
|
|
189
|
+
content: sections[0].content,
|
|
190
|
+
problems,
|
|
191
|
+
}));
|
|
176
192
|
expect(content[0].text).toBe('See {@link command:nope}.');
|
|
177
193
|
expect(content[1].link).toBeNull();
|
|
178
194
|
expect(problems.map(p => [p.section, p.target])).toEqual([
|
|
@@ -190,3 +206,80 @@ describe('unlinkText', () => {
|
|
|
190
206
|
);
|
|
191
207
|
});
|
|
192
208
|
});
|
|
209
|
+
|
|
210
|
+
describe('linkFields', () => {
|
|
211
|
+
/** A component doc with a link in every kind of text field, and in code. */
|
|
212
|
+
const DOC = {
|
|
213
|
+
name: 'AcmeButton',
|
|
214
|
+
description: 'Run {@link command:doctor} first.',
|
|
215
|
+
usage: {
|
|
216
|
+
description: 'Set it up: {@link @acme/kit:generic:setup}.',
|
|
217
|
+
bestPractices: [
|
|
218
|
+
{guidance: true, description: 'Check with {@link command:doctor}.'},
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
props: [
|
|
222
|
+
{
|
|
223
|
+
name: 'tone',
|
|
224
|
+
type: '{@link command:doctor}',
|
|
225
|
+
default: "'{@link command:doctor}'",
|
|
226
|
+
description: 'Like `{@link command:doctor}`, or {@link generic:nope}.',
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
propDescriptions: {tone: 'See {@link command:doctor}.'},
|
|
230
|
+
examples: [
|
|
231
|
+
{label: 'From {@link command:doctor}', code: '{@link command:doctor}'},
|
|
232
|
+
],
|
|
233
|
+
playground: {defaults: {label: '{@link command:doctor}'}},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
it('resolves each text field and leaves names, types, defaults, and code as written', async () => {
|
|
237
|
+
const {doc, problems} = await linkFields(DOC, resolve);
|
|
238
|
+
expect(doc).toEqual({
|
|
239
|
+
...DOC,
|
|
240
|
+
description: 'Run `astryx docs cli/commands/doctor` first.',
|
|
241
|
+
usage: {
|
|
242
|
+
description: 'Set it up: `astryx docs acme/setup`.',
|
|
243
|
+
bestPractices: [
|
|
244
|
+
{
|
|
245
|
+
guidance: true,
|
|
246
|
+
description: 'Check with `astryx docs cli/commands/doctor`.',
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
props: [
|
|
251
|
+
{
|
|
252
|
+
...DOC.props[0],
|
|
253
|
+
description:
|
|
254
|
+
'Like `{@link command:doctor}`, or {@link generic:nope}.',
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
propDescriptions: {tone: 'See `astryx docs cli/commands/doctor`.'},
|
|
258
|
+
examples: [
|
|
259
|
+
{
|
|
260
|
+
label: 'From `astryx docs cli/commands/doctor`',
|
|
261
|
+
code: '{@link command:doctor}',
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
});
|
|
265
|
+
expect(problems).toEqual([
|
|
266
|
+
{
|
|
267
|
+
target: 'generic:nope',
|
|
268
|
+
message: expect.any(String),
|
|
269
|
+
field: 'props[0].description',
|
|
270
|
+
},
|
|
271
|
+
]);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('names the same text fields textFields reads', async () => {
|
|
275
|
+
const {problems} = await linkFields(DOC, async target => ({
|
|
276
|
+
problem: `no ${target}`,
|
|
277
|
+
}));
|
|
278
|
+
const fields = textFields(DOC)
|
|
279
|
+
.filter(({text}) => text.replace(/`[^`]*`/g, '').includes('{@link'))
|
|
280
|
+
.map(({field}) => field);
|
|
281
|
+
expect([...new Set(problems.map(problem => problem.field))]).toEqual(
|
|
282
|
+
fields,
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -242,7 +242,8 @@ export function buildDocsTree({namespaces, docs, topics = []}) {
|
|
|
242
242
|
// without case, as topic names do, so `CLI` claims `cli`.
|
|
243
243
|
const cliRoutes = new Set(topics.length > 0 ? [UNORGANIZED] : []);
|
|
244
244
|
for (const topic of topics) {
|
|
245
|
-
if (topic.provider === CLI_PROVIDER)
|
|
245
|
+
if (topic.provider === CLI_PROVIDER)
|
|
246
|
+
cliRoutes.add(topic.name.toLowerCase());
|
|
246
247
|
}
|
|
247
248
|
// Every other name a topic answers to (the topics it replaced, directly or
|
|
248
249
|
// through a chain) is that topic's route too: `astryx docs <name>` opens the
|
|
@@ -375,6 +376,34 @@ export function buildDocsTree({namespaces, docs, topics = []}) {
|
|
|
375
376
|
return false;
|
|
376
377
|
}
|
|
377
378
|
const taken = byFoldedRoute.get(folded);
|
|
379
|
+
if (
|
|
380
|
+
taken &&
|
|
381
|
+
taken.provider === CLI_PROVIDER &&
|
|
382
|
+
node.provider !== CLI_PROVIDER &&
|
|
383
|
+
!node.generated
|
|
384
|
+
) {
|
|
385
|
+
// Astryx's own doc keeps its route: name both docs as an author knows
|
|
386
|
+
// them, never by their ids, and say what to change.
|
|
387
|
+
const what = (/** @type {TreeNode} */ n) =>
|
|
388
|
+
n.kind === 'namespace'
|
|
389
|
+
? 'namespace'
|
|
390
|
+
: n.kind === 'generic'
|
|
391
|
+
? 'topic'
|
|
392
|
+
: `${n.kind} doc`;
|
|
393
|
+
const scope = String(node.provider).split('/').pop() ?? '';
|
|
394
|
+
const suggestion = `${
|
|
395
|
+
scope
|
|
396
|
+
.replace(/[^a-z0-9]+/gi, '-')
|
|
397
|
+
.replace(/^-|-$/g, '')
|
|
398
|
+
.toLowerCase() || 'my'
|
|
399
|
+
}-${node.name.toLowerCase()}`;
|
|
400
|
+
report(
|
|
401
|
+
'duplicate_route',
|
|
402
|
+
at,
|
|
403
|
+
`The ${what(node)} "${node.name}" from ${node.provider} and Astryx's own ${what(taken)} "${taken.name}" both have the route "${node.route}", so \`astryx docs ${node.route}\` cannot open both. Fix: rename "${node.name}" (its \`name\` and its file), such as \`name: '${suggestion}'\`${node.route.includes('/') ? ', or place it elsewhere' : ''}.`,
|
|
404
|
+
);
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
378
407
|
if (taken) {
|
|
379
408
|
report(
|
|
380
409
|
'duplicate_route',
|
|
@@ -171,6 +171,13 @@ describe('buildDocsTree', () => {
|
|
|
171
171
|
['duplicate_route', expect.stringContaining('takes the route "UNORGANIZED", which the CLI\'s own docs keep')],
|
|
172
172
|
]),
|
|
173
173
|
);
|
|
174
|
+
// It names both docs as their authors know them, never by artifact id,
|
|
175
|
+
// and says what to change.
|
|
176
|
+
const taken = problems(tree).find(([, message]) => message.includes('route "CLI"'))?.[1];
|
|
177
|
+
expect(taken).toBe(
|
|
178
|
+
`The topic "CLI" from ${P} and Astryx's own namespace "cli" both have the route "CLI", so \`astryx docs CLI\` cannot open both. Fix: rename "CLI" (its \`name\` and its file), such as \`name: 'kit-cli'\`.`,
|
|
179
|
+
);
|
|
180
|
+
expect(taken).not.toContain('astryx:artifact');
|
|
174
181
|
expect(tree.getFolded('THEME')?.provider).toBe(CLI);
|
|
175
182
|
// A CLI topic whose own name has capitals keeps its route against a
|
|
176
183
|
// lowercase namespace, although namespaces go into the tree first.
|
|
@@ -21,7 +21,8 @@ export function importUserModule(file: string, { fresh }?: {
|
|
|
21
21
|
/**
|
|
22
22
|
* Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
|
|
23
23
|
* Package specifiers resolve from the consumer project, while relative paths
|
|
24
|
-
* resolve from that same project root.
|
|
24
|
+
* resolve from that same project root. An import of an existing `.css` file
|
|
25
|
+
* loads as an empty module.
|
|
25
26
|
* @param {string} specifier
|
|
26
27
|
* @param {string} cwd
|
|
27
28
|
* @returns {Promise<Record<string, unknown>>}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* user-authored module (`.ts` via jiti, `.mjs`/`.js` via native dynamic
|
|
8
8
|
* import) and (b) find conventional files by basename in a fixed
|
|
9
9
|
* load-precedence order. Generated theme artifacts also use a dedicated jiti
|
|
10
|
-
* path that resolves extensionless JSX/TSX registry imports
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* path that resolves extensionless JSX/TSX registry imports and loads the
|
|
11
|
+
* stylesheets they import as empty modules. These helpers centralize that
|
|
12
|
+
* behavior so callers stay in lockstep. A module's stdout writes go to stderr
|
|
13
|
+
* while it loads, so project code that prints cannot corrupt a `--json`
|
|
14
|
+
* envelope.
|
|
13
15
|
*
|
|
14
16
|
* `loadModuleWithParser` builds on these primitives to provide the single
|
|
15
17
|
* load/validation boundary shared by config, integration, codemod, and
|
|
@@ -125,6 +127,56 @@ const THEME_ARTIFACT_EXTENSIONS = [
|
|
|
125
127
|
'.cts',
|
|
126
128
|
];
|
|
127
129
|
|
|
130
|
+
/**
|
|
131
|
+
* @param {string | symbol} specifier
|
|
132
|
+
* @returns {specifier is string}
|
|
133
|
+
*/
|
|
134
|
+
function isStylesheetSpecifier(specifier) {
|
|
135
|
+
return typeof specifier === 'string' && specifier.endsWith('.css');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Whether `specifier`, resolved from the module at `from`, names an existing
|
|
140
|
+
* `.css` file.
|
|
141
|
+
* @param {string} specifier
|
|
142
|
+
* @param {string} from
|
|
143
|
+
*/
|
|
144
|
+
function resolvesToStylesheet(specifier, from) {
|
|
145
|
+
try {
|
|
146
|
+
return createRequire(from).resolve(specifier).endsWith('.css');
|
|
147
|
+
} catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A built theme module may import a stylesheet so that the app's bundler emits
|
|
154
|
+
* it. Node cannot load a stylesheet, so an import that ends in `.css` and
|
|
155
|
+
* resolves from the theme module to an existing `.css` file loads as an empty
|
|
156
|
+
* module. Any other import loads as before: a missing stylesheet fails like
|
|
157
|
+
* any missing import, and `./tokens.css` loads `tokens.css.js` when that is
|
|
158
|
+
* the file it names. jiti shows only the import text, so the check resolves it
|
|
159
|
+
* from the theme module's folder, not from the importing module's. A module in
|
|
160
|
+
* another folder fails on a stylesheet it reaches by a different relative
|
|
161
|
+
* path, and passes on a missing stylesheet whose path exists from the theme
|
|
162
|
+
* module's folder.
|
|
163
|
+
* @param {() => string} themeModule returns the theme module's path
|
|
164
|
+
* @returns {Record<string, unknown>}
|
|
165
|
+
*/
|
|
166
|
+
function themeArtifactStylesheets(themeModule) {
|
|
167
|
+
return new Proxy(
|
|
168
|
+
{},
|
|
169
|
+
{
|
|
170
|
+
has: (_target, specifier) =>
|
|
171
|
+
specifier !== themeModule() &&
|
|
172
|
+
isStylesheetSpecifier(specifier) &&
|
|
173
|
+
resolvesToStylesheet(specifier, themeModule()),
|
|
174
|
+
get: (_target, specifier) =>
|
|
175
|
+
isStylesheetSpecifier(specifier) ? {} : undefined,
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
128
180
|
class ThemeArtifactNotFoundError extends Error {
|
|
129
181
|
code = 'ERR_THEME_ARTIFACT_NOT_FOUND';
|
|
130
182
|
|
|
@@ -153,17 +205,20 @@ function isMissingPackageExport(error) {
|
|
|
153
205
|
/**
|
|
154
206
|
* Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
|
|
155
207
|
* Package specifiers resolve from the consumer project, while relative paths
|
|
156
|
-
* resolve from that same project root.
|
|
208
|
+
* resolve from that same project root. An import of an existing `.css` file
|
|
209
|
+
* loads as an empty module.
|
|
157
210
|
* @param {string} specifier
|
|
158
211
|
* @param {string} cwd
|
|
159
212
|
* @returns {Promise<Record<string, unknown>>}
|
|
160
213
|
*/
|
|
161
214
|
export async function importThemeArtifact(specifier, cwd) {
|
|
215
|
+
let themeModule = path.join(cwd, 'package.json');
|
|
162
216
|
const loader = createJiti(path.join(cwd, 'package.json'), {
|
|
163
217
|
moduleCache: false,
|
|
164
218
|
jsx: true,
|
|
165
219
|
interopDefault: true,
|
|
166
220
|
extensions: THEME_ARTIFACT_EXTENSIONS,
|
|
221
|
+
virtualModules: themeArtifactStylesheets(() => themeModule),
|
|
167
222
|
});
|
|
168
223
|
let target;
|
|
169
224
|
if (specifier.startsWith('.') || path.isAbsolute(specifier)) {
|
|
@@ -179,6 +234,7 @@ export async function importThemeArtifact(specifier, cwd) {
|
|
|
179
234
|
if (!fs.existsSync(target)) {
|
|
180
235
|
throw new ThemeArtifactNotFoundError(specifier);
|
|
181
236
|
}
|
|
237
|
+
themeModule = target;
|
|
182
238
|
return await withStdoutOnStderr(() => loader.import(target));
|
|
183
239
|
}
|
|
184
240
|
|
|
@@ -9,6 +9,7 @@ import {pathToFileURL} from 'node:url';
|
|
|
9
9
|
import {z} from 'zod';
|
|
10
10
|
import {
|
|
11
11
|
findPresentFiles,
|
|
12
|
+
importThemeArtifact,
|
|
12
13
|
importUserModule,
|
|
13
14
|
loadModuleWithParser,
|
|
14
15
|
} from './module-loader.mjs';
|
|
@@ -155,6 +156,199 @@ process.stdout.write(JSON.stringify({first: first.default?.answer, fresh: fresh.
|
|
|
155
156
|
});
|
|
156
157
|
});
|
|
157
158
|
|
|
159
|
+
describe('importThemeArtifact', () => {
|
|
160
|
+
const STYLESHEET_RAN = '__astryxThemeArtifactStylesheetRan';
|
|
161
|
+
|
|
162
|
+
/** @param {string} file @param {string} content */
|
|
163
|
+
function write(file, content) {
|
|
164
|
+
const target = path.join(tmpDir, file);
|
|
165
|
+
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
166
|
+
fs.writeFileSync(target, content);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
write('package.json', JSON.stringify({type: 'module'}));
|
|
171
|
+
write(
|
|
172
|
+
'ocean.css',
|
|
173
|
+
'[data-astryx-theme="ocean"] { --color-text: black; }\n',
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
afterEach(() => {
|
|
178
|
+
Reflect.deleteProperty(globalThis, STYLESHEET_RAN);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('loads a built module that imports its stylesheet, without running the stylesheet', async () => {
|
|
182
|
+
// Valid JavaScript, so running this stylesheet would leave a trace.
|
|
183
|
+
write('ran.css', `globalThis.${STYLESHEET_RAN} = true;\n`);
|
|
184
|
+
write(
|
|
185
|
+
'ocean.js',
|
|
186
|
+
"import './ocean.css';\nimport './ran.css';\nexport const oceanTheme = {name: 'ocean'};\n",
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const mod = await importThemeArtifact('./ocean.js', tmpDir);
|
|
190
|
+
|
|
191
|
+
expect(mod.oceanTheme).toEqual({name: 'ocean'});
|
|
192
|
+
expect(Reflect.get(globalThis, STYLESHEET_RAN)).toBeUndefined();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('loads a CommonJS built module that requires its stylesheet', async () => {
|
|
196
|
+
write('commonjs/package.json', JSON.stringify({type: 'commonjs'}));
|
|
197
|
+
write(
|
|
198
|
+
'commonjs/ocean.css',
|
|
199
|
+
'[data-astryx-theme="ocean"] { --color-text: black; }\n',
|
|
200
|
+
);
|
|
201
|
+
write(
|
|
202
|
+
'commonjs/ocean.js',
|
|
203
|
+
"require('./ocean.css');\nexports.oceanTheme = {name: 'ocean'};\n",
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const mod = await importThemeArtifact('./commonjs/ocean.js', tmpDir);
|
|
207
|
+
|
|
208
|
+
expect(mod.oceanTheme).toEqual({name: 'ocean'});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('loads stylesheets imported by a nested module, through a package export, and dynamically', async () => {
|
|
212
|
+
const packageDir = 'node_modules/@acme/themes';
|
|
213
|
+
write(
|
|
214
|
+
`${packageDir}/package.json`,
|
|
215
|
+
JSON.stringify({
|
|
216
|
+
name: '@acme/themes',
|
|
217
|
+
type: 'module',
|
|
218
|
+
exports: {
|
|
219
|
+
'./themes/ocean': './dist/ocean.js',
|
|
220
|
+
'./themes/ocean.css': './dist/ocean.css',
|
|
221
|
+
},
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
write(
|
|
225
|
+
`${packageDir}/dist/ocean.css`,
|
|
226
|
+
'[data-astryx-theme="ocean"] { --color-text: black; }\n',
|
|
227
|
+
);
|
|
228
|
+
write(
|
|
229
|
+
`${packageDir}/dist/tokens.js`,
|
|
230
|
+
"import '@acme/themes/themes/ocean.css';\nexport const tokens = {};\n",
|
|
231
|
+
);
|
|
232
|
+
write(
|
|
233
|
+
`${packageDir}/dist/ocean.js`,
|
|
234
|
+
"import {tokens} from './tokens.js';\nawait import('./ocean.css');\nexport const oceanTheme = {name: 'ocean', tokens};\n",
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const mod = await importThemeArtifact('@acme/themes/themes/ocean', tmpDir);
|
|
238
|
+
|
|
239
|
+
expect(mod.oceanTheme).toEqual({name: 'ocean', tokens: {}});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('still resolves an extensionless import to its directory index beside a same-named stylesheet', async () => {
|
|
243
|
+
write('ocean/index.js', "export const oceanTheme = {name: 'ocean'};\n");
|
|
244
|
+
write(
|
|
245
|
+
'entry.js',
|
|
246
|
+
"import './ocean.css';\nexport {oceanTheme} from './ocean';\n",
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const mod = await importThemeArtifact('./entry.js', tmpDir);
|
|
250
|
+
|
|
251
|
+
expect(mod.oceanTheme).toEqual({name: 'ocean'});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('loads a module whose import ends in .css but names a JavaScript file', async () => {
|
|
255
|
+
write('tokens.css.js', "export const vars = {accent: 'blue'};\n");
|
|
256
|
+
write(
|
|
257
|
+
'ocean.js',
|
|
258
|
+
"import './ocean.css';\nimport {vars} from './tokens.css';\nexport const oceanTheme = {name: 'ocean', vars};\n",
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const mod = await importThemeArtifact('./ocean.js', tmpDir);
|
|
262
|
+
|
|
263
|
+
expect(mod.oceanTheme).toEqual({name: 'ocean', vars: {accent: 'blue'}});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it.each([
|
|
267
|
+
['a missing file', "import './fonts.css';\n", /fonts\.css/],
|
|
268
|
+
[
|
|
269
|
+
'a package that is not installed',
|
|
270
|
+
"import '@acme/missing-fonts/inter.css';\n",
|
|
271
|
+
/@acme\/missing-fonts\/inter\.css/,
|
|
272
|
+
],
|
|
273
|
+
])(
|
|
274
|
+
'still rejects a stylesheet import of %s',
|
|
275
|
+
async (_label, stylesheetImport, expected) => {
|
|
276
|
+
write(
|
|
277
|
+
'ocean.js',
|
|
278
|
+
`import './ocean.css';\n${stylesheetImport}export const oceanTheme = {name: 'ocean'};\n`,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
await expect(importThemeArtifact('./ocean.js', tmpDir)).rejects.toThrow(
|
|
282
|
+
expected,
|
|
283
|
+
);
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
it('still rejects a theme module path that names a stylesheet', async () => {
|
|
288
|
+
await expect(importThemeArtifact('./ocean.css', tmpDir)).rejects.toThrow(
|
|
289
|
+
/Unknown file extension "\.css"/,
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('still rejects a stylesheet import that its package does not export', async () => {
|
|
294
|
+
const packageDir = 'node_modules/@acme/themes';
|
|
295
|
+
write(
|
|
296
|
+
`${packageDir}/package.json`,
|
|
297
|
+
JSON.stringify({
|
|
298
|
+
name: '@acme/themes',
|
|
299
|
+
type: 'module',
|
|
300
|
+
exports: {'./themes/ocean': './dist/ocean.js'},
|
|
301
|
+
}),
|
|
302
|
+
);
|
|
303
|
+
write(
|
|
304
|
+
`${packageDir}/dist/ocean.css`,
|
|
305
|
+
'[data-astryx-theme="ocean"] { --color-text: black; }\n',
|
|
306
|
+
);
|
|
307
|
+
write(
|
|
308
|
+
`${packageDir}/dist/ocean.js`,
|
|
309
|
+
"import '@acme/themes/themes/ocean.css';\nexport const oceanTheme = {name: 'ocean'};\n",
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
await expect(
|
|
313
|
+
importThemeArtifact('@acme/themes/themes/ocean', tmpDir),
|
|
314
|
+
).rejects.toThrow(/not defined by "exports"/);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it.each([
|
|
318
|
+
[
|
|
319
|
+
'a missing dependency',
|
|
320
|
+
"import './missing.js';\nexport const oceanTheme = {name: 'ocean'};\n",
|
|
321
|
+
/missing\.js/,
|
|
322
|
+
],
|
|
323
|
+
[
|
|
324
|
+
'a syntax error in a module it imports',
|
|
325
|
+
"import './broken.js';\nexport const oceanTheme = {name: 'ocean'};\n",
|
|
326
|
+
/ParseError/,
|
|
327
|
+
],
|
|
328
|
+
[
|
|
329
|
+
'a throwing module',
|
|
330
|
+
"throw new Error('broken theme module');\n",
|
|
331
|
+
/broken theme module/,
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
'an asset that is not a stylesheet',
|
|
335
|
+
"import './logo.svg';\nexport const oceanTheme = {name: 'ocean'};\n",
|
|
336
|
+
/Unknown file extension "\.svg"/,
|
|
337
|
+
],
|
|
338
|
+
])(
|
|
339
|
+
'still rejects a built module that imports its stylesheet and has %s',
|
|
340
|
+
async (_label, rest, expected) => {
|
|
341
|
+
write('logo.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>\n');
|
|
342
|
+
write('broken.js', 'export const broken = ;\n');
|
|
343
|
+
write('ocean.js', `import './ocean.css';\n${rest}`);
|
|
344
|
+
|
|
345
|
+
await expect(importThemeArtifact('./ocean.js', tmpDir)).rejects.toThrow(
|
|
346
|
+
expected,
|
|
347
|
+
);
|
|
348
|
+
},
|
|
349
|
+
);
|
|
350
|
+
});
|
|
351
|
+
|
|
158
352
|
describe('loadModuleWithParser', () => {
|
|
159
353
|
// Temp module files live under a repo-local dir (not /tmp): Vite's dynamic
|
|
160
354
|
// import blocks /tmp, so we mirror the existing repo-local temp pattern.
|
|
@@ -95,6 +95,17 @@ export function compareIdentities(local: ContributionIdentities, packed: Contrib
|
|
|
95
95
|
* @returns {string[]} unregistered PascalCase names
|
|
96
96
|
*/
|
|
97
97
|
export function findSourceOnlyCandidates(componentsRoot: string | undefined, registeredNames: string[]): string[];
|
|
98
|
+
/**
|
|
99
|
+
* Find `.tsx` files directly in a templates root that have no same-stem
|
|
100
|
+
* template metadata, so template discovery never lists them. Like the
|
|
101
|
+
* component check, it scans only direct children of the root: a file in a
|
|
102
|
+
* subfolder may be a helper a template imports. A file with a dotted stem (a
|
|
103
|
+
* test, story, or similar companion) is never a candidate.
|
|
104
|
+
*
|
|
105
|
+
* @param {string|undefined} templatesRoot absolute path
|
|
106
|
+
* @returns {string[]} basenames of the unpaired sources, sorted
|
|
107
|
+
*/
|
|
108
|
+
export function findTemplateSourceOnlyCandidates(templatesRoot: string | undefined): string[];
|
|
98
109
|
export type FileInventoryRoot = {
|
|
99
110
|
kind: "themes" | "components" | "templates" | "codemods" | "docs";
|
|
100
111
|
/**
|
|
@@ -319,8 +319,11 @@ export async function collectIdentities(loaded) {
|
|
|
319
319
|
|
|
320
320
|
if (loaded.docs && fs.existsSync(loaded.docs)) {
|
|
321
321
|
try {
|
|
322
|
-
const {
|
|
323
|
-
|
|
322
|
+
const {
|
|
323
|
+
records,
|
|
324
|
+
guides,
|
|
325
|
+
errors: docErrors,
|
|
326
|
+
} = await discoverIntegrationDocs(loaded);
|
|
324
327
|
for (const docError of docErrors) {
|
|
325
328
|
errors.push({kind: 'docs', message: docError.message});
|
|
326
329
|
}
|
|
@@ -503,3 +506,48 @@ export function findSourceOnlyCandidates(componentsRoot, registeredNames) {
|
|
|
503
506
|
}
|
|
504
507
|
return candidates.sort();
|
|
505
508
|
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Metadata suffixes that pair a template source with its spec: the canonical
|
|
512
|
+
* `.doc.*` family and the released `.template.*` compatibility family.
|
|
513
|
+
*/
|
|
514
|
+
const TEMPLATE_DOC_SUFFIXES = [
|
|
515
|
+
'.doc.ts',
|
|
516
|
+
'.doc.mjs',
|
|
517
|
+
'.doc.js',
|
|
518
|
+
'.template.ts',
|
|
519
|
+
'.template.mjs',
|
|
520
|
+
'.template.js',
|
|
521
|
+
];
|
|
522
|
+
|
|
523
|
+
/** A `.tsx` source and its stem, which may hold a dot (`landing.page`). */
|
|
524
|
+
const TSX_SOURCE = /^(.+)\.tsx$/u;
|
|
525
|
+
|
|
526
|
+
/** A test, spec or story stem: never a template. */
|
|
527
|
+
const NOT_A_TEMPLATE = /\.(?:test|spec|stories)$/u;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Find `.tsx` files directly in a templates root that have no same-stem
|
|
531
|
+
* template metadata, so template discovery never lists them. Like the
|
|
532
|
+
* component check, it scans only direct children of the root: a file in a
|
|
533
|
+
* subfolder may be a helper a template imports. A file with a dotted stem (a
|
|
534
|
+
* test, story, or similar companion) is never a candidate.
|
|
535
|
+
*
|
|
536
|
+
* @param {string|undefined} templatesRoot absolute path
|
|
537
|
+
* @returns {string[]} basenames of the unpaired sources, sorted
|
|
538
|
+
*/
|
|
539
|
+
export function findTemplateSourceOnlyCandidates(templatesRoot) {
|
|
540
|
+
if (!templatesRoot || !fs.existsSync(templatesRoot)) return [];
|
|
541
|
+
/** @type {string[]} */
|
|
542
|
+
const candidates = [];
|
|
543
|
+
for (const entry of fs.readdirSync(templatesRoot, {withFileTypes: true})) {
|
|
544
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
545
|
+
const match = entry.name.match(TSX_SOURCE);
|
|
546
|
+
if (!match || NOT_A_TEMPLATE.test(match[1])) continue;
|
|
547
|
+
const paired = TEMPLATE_DOC_SUFFIXES.some(suffix =>
|
|
548
|
+
fs.existsSync(path.join(templatesRoot, `${match[1]}${suffix}`)),
|
|
549
|
+
);
|
|
550
|
+
if (!paired) candidates.push(entry.name);
|
|
551
|
+
}
|
|
552
|
+
return candidates.sort();
|
|
553
|
+
}
|
|
@@ -15,4 +15,10 @@ export interface AstryxIntegrationIssue {
|
|
|
15
15
|
code: string;
|
|
16
16
|
severity: 'warning' | 'error';
|
|
17
17
|
message: string;
|
|
18
|
+
/** What to change, ready to paste, when the check knows it. */
|
|
19
|
+
fix?: string;
|
|
20
|
+
/** The file the issue is in, relative to the package. */
|
|
21
|
+
file?: string;
|
|
22
|
+
/** The 1-based line in `file`, when the check can locate it. */
|
|
23
|
+
line?: number;
|
|
18
24
|
}
|
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
import * as fs from 'node:fs';
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {isValidSemver} from '../env/semver.mjs';
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
findSourceOnlyCandidates,
|
|
29
|
+
findTemplateSourceOnlyCandidates,
|
|
30
|
+
} from './contribution-inventory.mjs';
|
|
28
31
|
import {
|
|
29
32
|
CODEMOD_FILE_RE,
|
|
30
33
|
CODEMOD_SKIP_DIRS,
|
|
@@ -295,6 +298,32 @@ async function checkTemplates(integration, issues) {
|
|
|
295
298
|
issueError('invalid_template', /** @type {any} */ (err).message),
|
|
296
299
|
);
|
|
297
300
|
}
|
|
301
|
+
checkTemplateSourcesWithoutDoc(integration, issues);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Warn about a `.tsx` directly in the templates root with no same-stem template
|
|
306
|
+
* metadata: template discovery pairs sources with docs, so `astryx template`
|
|
307
|
+
* never lists it. A PascalCase file directly in a shared components root is
|
|
308
|
+
* left to the component check, which already warns about it.
|
|
309
|
+
* @param {LoadedIntegration} integration loaded-integration-shaped object
|
|
310
|
+
* @param {Issue[]} issues
|
|
311
|
+
*/
|
|
312
|
+
function checkTemplateSourcesWithoutDoc(integration, issues) {
|
|
313
|
+
const root = /** @type {string} */ (integration.templates);
|
|
314
|
+
const sharedComponents =
|
|
315
|
+
integration.components != null &&
|
|
316
|
+
path.resolve(integration.components) === path.resolve(root);
|
|
317
|
+
for (const file of findTemplateSourceOnlyCandidates(root)) {
|
|
318
|
+
if (sharedComponents && /^[A-Z]/u.test(file)) continue;
|
|
319
|
+
const stem = file.slice(0, -'.tsx'.length);
|
|
320
|
+
issues.push(
|
|
321
|
+
issueWarning(
|
|
322
|
+
'source_without_template_doc',
|
|
323
|
+
`Template source "${file}" has no same-stem metadata file ${stem}.doc.mjs, so \`astryx template\` never lists it. Fix: add ${stem}.doc.mjs beside it with type: 'page' or 'block'; \`astryx docs authoring integration-template-doc\` lists its fields. If it is not a template, move it out of the templates root.`,
|
|
324
|
+
),
|
|
325
|
+
);
|
|
326
|
+
}
|
|
298
327
|
}
|
|
299
328
|
|
|
300
329
|
/**
|