@astryxdesign/cli 0.7.3 → 0.7.4-canary.31e54e4
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 +5 -5
- package/api/discover/_adapter.mjs +22 -10
- package/api/discover/_catalog-view.d.mts +2 -0
- package/api/discover/_catalog-view.mjs +1 -0
- package/api/discover/_catalog-view.test.mjs +1 -0
- package/api/discover/detail/detail.mjs +1 -0
- package/api/discover/detail/detail.test.mjs +3 -0
- package/api/discover/detail/doc/doc.mjs +5 -1
- package/api/discover/detail/doc/doc.test.mjs +1 -0
- package/api/discover/detail/item/item.mjs +2 -0
- package/api/discover/detail/item/item.test.mjs +2 -0
- package/api/discover/discover.doc.mjs +4 -4
- package/api/discover/discover.type.d.mts +20 -0
- package/api/discover/discover.type.mjs +5 -0
- package/api/discover/list/list.test.mjs +2 -0
- package/api/discover/search/search.d.mts +3 -2
- package/api/discover/search/search.mjs +26 -7
- package/api/discover/search/search.test.mjs +67 -0
- package/api/doctor/_adapter.d.mts +40 -0
- package/api/doctor/_adapter.mjs +171 -1
- package/api/doctor/built-checks.d.mts +85 -0
- package/api/doctor/built-checks.mjs +807 -0
- package/api/doctor/built-checks.test.mjs +502 -0
- package/api/doctor/doctor.d.mts +6 -5
- package/api/doctor/doctor.doc.mjs +10 -0
- package/api/doctor/doctor.mjs +18 -3
- package/api/doctor/doctor.type.d.mts +6 -0
- package/api/doctor/doctor.type.mjs +3 -0
- package/api/integration/pack-check.mjs +6 -1
- package/api/integration/pack-check.test.mjs +14 -0
- package/api/theme/palette/generate/generate.d.mts +8 -0
- package/api/theme/palette/generate/generate.mjs +38 -11
- package/api/theme/palette/generate/generate.test.mjs +83 -4
- package/api/theme/palette/generate/generator.d.mts +6 -0
- package/api/theme/palette/generate/generator.mjs +6 -0
- package/api/theme/theme.type.d.mts +12 -1
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +54 -0
- package/assets/templates/themes/butter/butterPalettes.generated.receipt.json +1499 -0
- package/assets/templates/themes/butter/butterPalettes.generated.ts +550 -0
- package/assets/templates/themes/butter/butterTheme.ts +274 -234
- package/assets/templates/themes/butter/palette.config.json +484 -0
- package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +41 -0
- package/assets/templates/themes/gothic/gothicPalettes.generated.receipt.json +979 -0
- package/assets/templates/themes/gothic/gothicPalettes.generated.ts +271 -0
- package/assets/templates/themes/gothic/gothicTheme.ts +130 -160
- package/assets/templates/themes/gothic/palette.config.json +371 -0
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +51 -0
- package/assets/templates/themes/matcha/matchaPalettes.generated.receipt.json +1502 -0
- package/assets/templates/themes/matcha/matchaPalettes.generated.ts +501 -0
- package/assets/templates/themes/matcha/matchaPalettes.ts +21 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +164 -103
- package/assets/templates/themes/matcha/palette.config.json +448 -0
- package/assets/templates/themes/stone/palette.config.json +262 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +51 -0
- package/assets/templates/themes/stone/stonePalettes.generated.receipt.json +840 -0
- package/assets/templates/themes/stone/stonePalettes.generated.ts +501 -0
- package/assets/templates/themes/stone/stoneTheme.ts +190 -207
- package/assets/templates/themes/y2k/palette.config.json +166 -0
- package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +54 -0
- package/assets/templates/themes/y2k/y2kPalettes.generated.receipt.json +872 -0
- package/assets/templates/themes/y2k/y2kPalettes.generated.ts +550 -0
- package/assets/templates/themes/y2k/y2kPalettes.ts +257 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +164 -391
- package/clients/cli/commands/discover.mjs +1 -1
- package/clients/cli/commands/discover.sources.test.mjs +6 -0
- package/clients/cli/commands/doctor.doc.mjs +12 -0
- package/clients/cli/commands/doctor.mjs +23 -8
- package/foundation/response/error-codes.test.mjs +9 -0
- package/foundation/response/response-types.doc.mjs +5 -5
- package/foundation/response/response-types.doc.test.mjs +29 -0
- package/package.json +9 -9
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import {performance} from 'node:perf_hooks';
|
|
7
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
8
|
+
import {checkBuilt, scanBuilt} from './built-checks.mjs';
|
|
9
|
+
import {builtIntegrationPackages} from './_adapter.mjs';
|
|
10
|
+
import {runChecks} from './doctor.mjs';
|
|
11
|
+
import {runCli} from '../../test-utils/run-cli.mjs';
|
|
12
|
+
|
|
13
|
+
/** @type {string} */
|
|
14
|
+
let dir;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Record<string, string>} files relative path → contents
|
|
18
|
+
*/
|
|
19
|
+
function write(files) {
|
|
20
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
21
|
+
const file = path.join(dir, rel);
|
|
22
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
23
|
+
fs.writeFileSync(file, text);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {string} target @param {string[]} [packages] */
|
|
28
|
+
function check(target, packages = []) {
|
|
29
|
+
const [usage, purity] = checkBuilt(target, {cwd: dir, packages});
|
|
30
|
+
return {usage, purity};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-built-'));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('built-astryx-usage', () => {
|
|
42
|
+
it('fails a hand-written page with no Astryx at all, with the way to rebuild it', () => {
|
|
43
|
+
write({
|
|
44
|
+
'out/index.html':
|
|
45
|
+
'<!doctype html><html><head><style>.cat{display:flex}</style></head><body><div class="cat"><h1>Cats</h1></div></body></html>',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
for (const target of ['out', 'out/index.html']) {
|
|
49
|
+
const {usage, purity} = check(target);
|
|
50
|
+
expect(usage.status).toBe('fail');
|
|
51
|
+
expect(usage.message).toContain('does not use Astryx');
|
|
52
|
+
expect(usage.fix).toContain('build "<what the page is>"');
|
|
53
|
+
expect(usage.fix).toContain('Do not deliver');
|
|
54
|
+
// Built HTML is not source: the purity check says it did not run.
|
|
55
|
+
expect(purity.status).toBe('info');
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('passes source that imports Astryx components and uses them', () => {
|
|
60
|
+
write({
|
|
61
|
+
'src/Page.tsx':
|
|
62
|
+
'import {Button} from \'@astryxdesign/core/Button\';\nexport const Page = () => <Button label="Go" />;\n',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const {usage} = check('.');
|
|
66
|
+
expect(usage.status).toBe('pass');
|
|
67
|
+
expect(usage.message).toContain('1 import from @astryxdesign/core');
|
|
68
|
+
expect(usage.message).toContain('1 component use');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("counts an integration's components as Astryx, by the package names the project loads", () => {
|
|
72
|
+
write({
|
|
73
|
+
'app/page.tsx':
|
|
74
|
+
'import {AcmeBadge} from \'@acme/ui/Badge\';\nexport default () => <AcmeBadge label="New" />;\n',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(check('.').usage.status).toBe('fail');
|
|
78
|
+
const {usage} = check('.', ['@acme/ui']);
|
|
79
|
+
expect(usage.status).toBe('pass');
|
|
80
|
+
expect(usage.message).toContain('@acme/ui');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('passes built output that carries Astryx styles, minified', () => {
|
|
84
|
+
write({
|
|
85
|
+
'dist/assets/app.css':
|
|
86
|
+
'@layer reset,astryx-base,astryx-theme;@layer astryx-base{.x1{color:red}}',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const {usage, purity} = check('dist');
|
|
90
|
+
expect(usage.status).toBe('pass');
|
|
91
|
+
expect(usage.message).toContain('Astryx styles in assets/app.css');
|
|
92
|
+
expect(purity.status).toBe('info');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('reads a build folder inside a project for styles but never as source', () => {
|
|
96
|
+
write({
|
|
97
|
+
'src/page.tsx': '<div />',
|
|
98
|
+
'.next/static/chunk.js': 'var a="<div className=x>";',
|
|
99
|
+
'.next/static/app.css': ':root{--astryx-layer-modal:10}',
|
|
100
|
+
'node_modules/@astryxdesign/core/index.js':
|
|
101
|
+
"import '@astryxdesign/core';",
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const scan = scanBuilt(dir, []);
|
|
105
|
+
expect(scan.sourceFiles).toBe(1);
|
|
106
|
+
expect(scan.stylesheets).toEqual(['.next/static/app.css']);
|
|
107
|
+
expect(scan.imports).toBe(0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('fails a path that does not exist, saying nothing was checked', () => {
|
|
111
|
+
const [usage, ...rest] = checkBuilt('missing', {cwd: dir, packages: []});
|
|
112
|
+
expect(usage.status).toBe('fail');
|
|
113
|
+
expect(usage.message).toContain('does not exist');
|
|
114
|
+
expect(rest).toEqual([]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('built-astryx-purity', () => {
|
|
119
|
+
it("names each finding of the rubric's source check with its file and line", () => {
|
|
120
|
+
write({
|
|
121
|
+
'src/Page.tsx': [
|
|
122
|
+
"import {VStack} from '@astryxdesign/core/VStack';",
|
|
123
|
+
"import {Search} from 'lucide-react';",
|
|
124
|
+
"import './page.css';",
|
|
125
|
+
'// <div> in a comment is not a finding',
|
|
126
|
+
'export function Page() {',
|
|
127
|
+
' return (',
|
|
128
|
+
' <VStack>',
|
|
129
|
+
' <div className="row" style={{gap: 4}}>',
|
|
130
|
+
' <Search />',
|
|
131
|
+
' <svg viewBox="0 0 1 1"><path d="M0 0" /></svg>',
|
|
132
|
+
' <input type="hidden" name="x" />',
|
|
133
|
+
' </div>',
|
|
134
|
+
' </VStack>',
|
|
135
|
+
' );',
|
|
136
|
+
'}',
|
|
137
|
+
'',
|
|
138
|
+
].join('\n'),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const {usage, purity} = check('.');
|
|
142
|
+
expect(usage.status).toBe('pass');
|
|
143
|
+
expect(purity.status).toBe('warn');
|
|
144
|
+
expect(purity.message).toMatch(/^6 findings/);
|
|
145
|
+
expect(purity.message).toContain(
|
|
146
|
+
'src/Page.tsx:3 imports the stylesheet `./page.css`',
|
|
147
|
+
);
|
|
148
|
+
expect(purity.message).toContain('src/Page.tsx:8 raw `<div>`');
|
|
149
|
+
expect(purity.message).toContain(
|
|
150
|
+
'src/Page.tsx:9 `<Search>` from an icon library',
|
|
151
|
+
);
|
|
152
|
+
// The message names the first five and counts the rest.
|
|
153
|
+
expect(purity.message).toContain('and 1 more');
|
|
154
|
+
const all = scanBuilt(dir, [])
|
|
155
|
+
.findings.map(f => `${f.file}:${f.line} ${f.message}`)
|
|
156
|
+
.join('\n');
|
|
157
|
+
expect(all).toContain('src/Page.tsx:10 raw `<svg>`');
|
|
158
|
+
// A helper's SVG counts once, and hidden form state keeps its element.
|
|
159
|
+
expect(all).not.toContain('`<path>`');
|
|
160
|
+
expect(all).not.toContain('`<input>`');
|
|
161
|
+
expect(purity.fix).toContain('docs is-my-code-good');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('passes source with no raw element, icon or custom style', () => {
|
|
165
|
+
write({
|
|
166
|
+
'src/Page.tsx':
|
|
167
|
+
"import {Text} from '@astryxdesign/core/Text';\nimport type {ReactNode} from 'react';\nexport const Page = (): ReactNode => <Text>Hi</Text>;\n",
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(check('src').purity.status).toBe('pass');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('what a --built path counts', () => {
|
|
175
|
+
it('reads a bundle as build output: the source check says it was not inspected', () => {
|
|
176
|
+
write({
|
|
177
|
+
'dist/assets/index.js':
|
|
178
|
+
'import "./a.css";import{jsx as e}from"react/jsx-runtime";export default()=>e("div",{className:"x"});',
|
|
179
|
+
});
|
|
180
|
+
const {purity} = check('dist');
|
|
181
|
+
expect(purity.status).toBe('info');
|
|
182
|
+
expect(purity.message).toContain('Not inspected');
|
|
183
|
+
expect(purity.fix).toContain('doctor --built <project folder>');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('inspects JSX in a .js source file and a .tsx file inside a folder named build', () => {
|
|
187
|
+
write({
|
|
188
|
+
'src/page.js':
|
|
189
|
+
'export default function Page() {\n return <div>Hi</div>;\n}\n',
|
|
190
|
+
'src/build/Form.tsx': 'export const Form = () => <button>Go</button>;\n',
|
|
191
|
+
});
|
|
192
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
193
|
+
expect(scan.jsxFiles).toBe(2);
|
|
194
|
+
expect(scan.findings.map(f => `${f.file}:${f.message}`)).toEqual([
|
|
195
|
+
'build/Form.tsx:raw `<button>`: use `Button` or `IconButton`',
|
|
196
|
+
'page.js:raw `<div>`: use `VStack`, `HStack`, `Grid`, `Card`, `Section` or `Center`',
|
|
197
|
+
]);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('keeps a side-effect import apart from the import after it', () => {
|
|
201
|
+
write({
|
|
202
|
+
'src/Page.tsx':
|
|
203
|
+
"import './page.css';\nimport {Button} from '@astryxdesign/core/Button';\nexport const Page = () => <Button label=\"Go\" />;\n",
|
|
204
|
+
});
|
|
205
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
206
|
+
expect(scan.imports).toBe(1);
|
|
207
|
+
expect(scan.componentUses).toBe(1);
|
|
208
|
+
expect(scan.findings.map(f => f.message)).toContain(
|
|
209
|
+
'imports the stylesheet `./page.css`: use component props and tokens',
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('names the integrations by the declared dependencies that ship a manifest, running nothing', () => {
|
|
214
|
+
write({
|
|
215
|
+
'package.json': JSON.stringify({
|
|
216
|
+
name: 'app',
|
|
217
|
+
dependencies: {'@acme/ui': '1.0.0', 'left-pad': '1.0.0'},
|
|
218
|
+
}),
|
|
219
|
+
'astryx.config.mjs':
|
|
220
|
+
"import fs from 'node:fs';\nfs.writeFileSync(new URL('./ran.txt', import.meta.url), 'ran');\nexport default {};\n",
|
|
221
|
+
'node_modules/@acme/ui/package.json': '{"name":"@acme/ui"}',
|
|
222
|
+
'node_modules/@acme/ui/astryx.integration.mjs': 'export default {};\n',
|
|
223
|
+
'node_modules/left-pad/package.json': '{"name":"left-pad"}',
|
|
224
|
+
'out/index.html': '<p>x</p>',
|
|
225
|
+
});
|
|
226
|
+
expect(builtIntegrationPackages('out', dir)).toEqual(['@acme/ui']);
|
|
227
|
+
expect(fs.existsSync(path.join(dir, 'ran.txt'))).toBe(false);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe('--built limits and speed', () => {
|
|
232
|
+
it('finds an integration hoisted to the workspace root', () => {
|
|
233
|
+
write({
|
|
234
|
+
'package.json': JSON.stringify({name: 'root', workspaces: ['apps/*']}),
|
|
235
|
+
'node_modules/@acme/ui/package.json': '{"name":"@acme/ui"}',
|
|
236
|
+
'node_modules/@acme/ui/astryx.integration.mjs': 'export default {};\n',
|
|
237
|
+
'apps/web/package.json': JSON.stringify({
|
|
238
|
+
name: 'web',
|
|
239
|
+
dependencies: {'@acme/ui': '1.0.0'},
|
|
240
|
+
}),
|
|
241
|
+
'apps/web/out/index.html': '<p>x</p>',
|
|
242
|
+
});
|
|
243
|
+
expect(builtIntegrationPackages('apps/web/out', dir)).toEqual(['@acme/ui']);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('says not fully inspected when a source file is over the size limit', () => {
|
|
247
|
+
write({
|
|
248
|
+
'src/Page.tsx':
|
|
249
|
+
"import {Text} from '@astryxdesign/core/Text';\nexport const Page = () => <Text>Hi</Text>;\n",
|
|
250
|
+
'src/Huge.tsx': `export const Huge = () => null;\n${'// x\n'.repeat(1_100_000)}`,
|
|
251
|
+
});
|
|
252
|
+
const {purity} = check('src');
|
|
253
|
+
expect(purity.status).toBe('info');
|
|
254
|
+
expect(purity.message).toContain('Not fully inspected');
|
|
255
|
+
expect(purity.message).toContain('over 5 MB');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('places findings in a large JSX file quickly', () => {
|
|
259
|
+
const body = '<div>row</div>\n'.repeat(60_000);
|
|
260
|
+
write({'src/Big.tsx': `export const Big = () => (\n<>\n${body}</>);\n`});
|
|
261
|
+
const started = performance.now();
|
|
262
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
263
|
+
expect(scan.findings.length).toBe(60_000);
|
|
264
|
+
expect(scan.findings.at(-1)?.line).toBe(60_002);
|
|
265
|
+
expect(performance.now() - started).toBeLessThan(5_000);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('--built edge cases', () => {
|
|
270
|
+
it('reads the stylesheet a built page links when given the page alone', () => {
|
|
271
|
+
write({
|
|
272
|
+
'dist/index.html':
|
|
273
|
+
'<!doctype html><html><head><link rel="stylesheet" href="/assets/index.css"><script type="module" src="./assets/index.js"></script></head><body><div id="root"></div></body></html>',
|
|
274
|
+
'dist/assets/index.css': '@layer astryx-base{.x{color:red}}',
|
|
275
|
+
'dist/assets/index.js': 'console.log(1)',
|
|
276
|
+
});
|
|
277
|
+
const {usage} = check('dist/index.html');
|
|
278
|
+
expect(usage.status).toBe('pass');
|
|
279
|
+
expect(usage.message).toContain('Astryx styles in assets/index.css');
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('inspects a .js page whose JSX starts with a fragment', () => {
|
|
283
|
+
write({
|
|
284
|
+
'src/page.js':
|
|
285
|
+
'export default function Page() {\n return (\n <>\n <div>Hi</div>\n </>\n );\n}\n',
|
|
286
|
+
});
|
|
287
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
288
|
+
expect(scan.jsxFiles).toBe(1);
|
|
289
|
+
expect(scan.findings).toHaveLength(1);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('warns, not fails, when the file limit ends the read before any Astryx', () => {
|
|
293
|
+
for (let i = 0; i < 20_001; i++) {
|
|
294
|
+
const file = path.join(dir, 'a', String(i % 50), `${i}.txt`);
|
|
295
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
296
|
+
fs.writeFileSync(file, '');
|
|
297
|
+
}
|
|
298
|
+
const {usage} = check('.');
|
|
299
|
+
expect(usage.status).toBe('warn');
|
|
300
|
+
expect(usage.message).toContain('went unread');
|
|
301
|
+
}, 60_000);
|
|
302
|
+
|
|
303
|
+
it('finds a root-relative asset from the build root for a page in a subfolder', () => {
|
|
304
|
+
write({
|
|
305
|
+
'dist/about/index.html':
|
|
306
|
+
'<!doctype html><link rel="stylesheet" href="/assets/app.css"><div id="root"></div>',
|
|
307
|
+
'dist/assets/app.css': '@layer astryx-theme{.x{color:red}}',
|
|
308
|
+
});
|
|
309
|
+
expect(check('dist/about/index.html').usage.status).toBe('pass');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('warns, not fails, when a page links a file that is not there', () => {
|
|
313
|
+
write({
|
|
314
|
+
'out/index.html': '<link rel="stylesheet" href="./missing.css"><p>x</p>',
|
|
315
|
+
});
|
|
316
|
+
const {usage} = check('out/index.html');
|
|
317
|
+
expect(usage.status).toBe('warn');
|
|
318
|
+
expect(usage.message).toContain('not there');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('inspects JSX in a .js file wherever it opens', () => {
|
|
322
|
+
write({
|
|
323
|
+
'src/page.js':
|
|
324
|
+
'export const a = x || <div>A</div>;\nexport const b = [<span key="b">B</span>];\n',
|
|
325
|
+
});
|
|
326
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
327
|
+
expect(scan.jsxFiles).toBe(1);
|
|
328
|
+
expect(scan.findings).toHaveLength(2);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('fails an empty folder as nothing checked, and warns when the only source is too big to read', () => {
|
|
332
|
+
fs.mkdirSync(path.join(dir, 'empty'));
|
|
333
|
+
expect(check('empty').usage.message).toContain('nothing was checked');
|
|
334
|
+
write({
|
|
335
|
+
'big/Page.tsx': `import {Text} from '@astryxdesign/core/Text';\n${'// x\n'.repeat(1_100_000)}`,
|
|
336
|
+
});
|
|
337
|
+
const {usage} = check('big');
|
|
338
|
+
expect(usage.status).toBe('warn');
|
|
339
|
+
expect(usage.message).toContain('over 5 MB');
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('fails a page with no Astryx that links only a missing favicon', () => {
|
|
343
|
+
write({
|
|
344
|
+
'out/index.html':
|
|
345
|
+
'<link rel="icon" href="/favicon.ico"><link rel="manifest" href="/site.webmanifest"><p>x</p>',
|
|
346
|
+
});
|
|
347
|
+
expect(check('out/index.html').usage.status).toBe('fail');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('survives a .js file with a huge array literal', () => {
|
|
351
|
+
write({
|
|
352
|
+
'src/data.js': `export const rows = [${'0,'.repeat(200_000)}];\nexport const A = () => <p>x</p>;\n`,
|
|
353
|
+
});
|
|
354
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
355
|
+
expect(scan.jsxFiles).toBe(1);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('counts a .js file the parser cannot read as not inspected', () => {
|
|
359
|
+
write({
|
|
360
|
+
'src/page.js':
|
|
361
|
+
'export default function Page() {\n return <div>{</div>;\n}\n@@@\n',
|
|
362
|
+
});
|
|
363
|
+
const {purity} = check('src');
|
|
364
|
+
expect(purity.status).toBe('info');
|
|
365
|
+
expect(purity.status).not.toBe('pass');
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('keeps JSX after a "/*" string, such as a splat route', () => {
|
|
369
|
+
write({
|
|
370
|
+
'src/App.tsx':
|
|
371
|
+
'export const App = () => (\n <Route path="/*" element={<div>Home</div>} />\n);\n',
|
|
372
|
+
});
|
|
373
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
374
|
+
expect(scan.findings.map(f => f.line)).toContain(2);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('keeps JSX after a URL or a glob in JSX text', () => {
|
|
378
|
+
write({
|
|
379
|
+
'src/page.js':
|
|
380
|
+
'export const A = () => (\n <section>\n <p>See https://example.com and src/*</p>\n <div>Box</div>\n </section>\n);\n',
|
|
381
|
+
});
|
|
382
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
383
|
+
expect(scan.unread).toBe(0);
|
|
384
|
+
expect(scan.findings.map(f => f.line)).toEqual(
|
|
385
|
+
expect.arrayContaining([3, 4]),
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('reads a page whose link attributes are unquoted', () => {
|
|
390
|
+
write({
|
|
391
|
+
'dist/index.html':
|
|
392
|
+
'<!doctype html><link rel=stylesheet href=/assets/index.css><div id=root></div>',
|
|
393
|
+
'dist/assets/index.css': '@layer astryx-base{.x{color:red}}',
|
|
394
|
+
});
|
|
395
|
+
expect(check('dist/index.html').usage.status).toBe('pass');
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('counts a barrel re-export and a CSS @import of an Astryx package', () => {
|
|
399
|
+
write({
|
|
400
|
+
'src/ui.ts': "export {Button, Card} from '@astryxdesign/core';\n",
|
|
401
|
+
'src/index.css': "@import '@astryxdesign/core/styles.css';\n",
|
|
402
|
+
});
|
|
403
|
+
const {usage} = check('src');
|
|
404
|
+
expect(usage.status).toBe('pass');
|
|
405
|
+
expect(usage.message).toContain('@astryxdesign/core');
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('reads a .tsx with TypeScript and legacy decorators, and counts one nothing parses as unread', () => {
|
|
409
|
+
write({
|
|
410
|
+
'src/Ok.tsx':
|
|
411
|
+
'function track(t: any) { return t; }\n@track\nclass Store { value!: string; }\nexport const A = () => <div>Hi</div>;\n',
|
|
412
|
+
'src/Broken.tsx': 'export const B = () => <div>{</div>;\n@@ enum ;\n',
|
|
413
|
+
});
|
|
414
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
415
|
+
expect(scan.findings.filter(f => f.file === 'Ok.tsx')).toHaveLength(1);
|
|
416
|
+
expect(scan.unread).toBe(1);
|
|
417
|
+
expect(check('src').purity.status).not.toBe('pass');
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('does not count commented-out CSS as Astryx', () => {
|
|
421
|
+
write({
|
|
422
|
+
'dist/index.css':
|
|
423
|
+
"/* @import '@astryxdesign/core/styles.css'; */\n/* --astryx-color: red; */\n.x { color: red; }\n",
|
|
424
|
+
});
|
|
425
|
+
expect(check('dist').usage.status).toBe('fail');
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('does not count an import written only in a string or JSX text', () => {
|
|
429
|
+
write({
|
|
430
|
+
'src/Page.tsx': [
|
|
431
|
+
"const sample = `import {Button} from '@astryxdesign/core/Button';`;",
|
|
432
|
+
'export const Page = () => (',
|
|
433
|
+
" <pre>import {Text} from '@astryxdesign/core/Text';</pre>",
|
|
434
|
+
');',
|
|
435
|
+
'',
|
|
436
|
+
].join('\n'),
|
|
437
|
+
});
|
|
438
|
+
expect(check('src').usage.status).toBe('fail');
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('ignores a stylesheet link inside an HTML comment', () => {
|
|
442
|
+
write({
|
|
443
|
+
'out/index.html':
|
|
444
|
+
'<!-- <link rel="stylesheet" href="./astryx.css"> --><!-- <link rel="stylesheet" href="./gone.css"> --><p>x</p>',
|
|
445
|
+
'out/astryx.css': '@layer astryx-base{.x{color:red}}',
|
|
446
|
+
});
|
|
447
|
+
expect(check('out/index.html').usage.status).toBe('fail');
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it('names unread source files in purity, with findings and without JSX', () => {
|
|
451
|
+
write({
|
|
452
|
+
'src/Page.tsx': 'export const Page = () => <div>Hi</div>;\n',
|
|
453
|
+
'src/Broken.tsx': 'export const B = () => <div>{</div>;\n@@ enum ;\n',
|
|
454
|
+
});
|
|
455
|
+
const withFindings = check('src').purity;
|
|
456
|
+
expect(withFindings.status).toBe('warn');
|
|
457
|
+
expect(withFindings.message).toContain('not inspected: Broken.tsx');
|
|
458
|
+
fs.rmSync(path.join(dir, 'src', 'Page.tsx'));
|
|
459
|
+
const none = check('src').purity;
|
|
460
|
+
expect(none.status).toBe('info');
|
|
461
|
+
expect(none.message).toContain('Broken.tsx');
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it('survives a file with more findings than a call can spread', () => {
|
|
465
|
+
write({
|
|
466
|
+
'src/Rows.tsx': `export const Rows = () => (\n<>\n${'<p/>\n'.repeat(200_000)}</>);\n`,
|
|
467
|
+
});
|
|
468
|
+
const scan = scanBuilt(path.join(dir, 'src'), []);
|
|
469
|
+
expect(scan.findings.length).toBe(200_000);
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
describe('doctor --built', () => {
|
|
474
|
+
it('composes with --json: one envelope with the two checks last, exit 1 on a failed build', async () => {
|
|
475
|
+
write({'out/index.html': '<div>no astryx</div>'});
|
|
476
|
+
const result = await runCli(['--json', 'doctor', '--built', 'out'], dir);
|
|
477
|
+
const envelope = JSON.parse(result.stdout);
|
|
478
|
+
const ids = envelope.data.checks.map(
|
|
479
|
+
(/** @type {{id: string}} */ c) => c.id,
|
|
480
|
+
);
|
|
481
|
+
expect(ids.slice(-2)).toEqual([
|
|
482
|
+
'built-astryx-usage',
|
|
483
|
+
'built-astryx-purity',
|
|
484
|
+
]);
|
|
485
|
+
expect(result.status).toBe(1);
|
|
486
|
+
}, 60_000);
|
|
487
|
+
|
|
488
|
+
it('adds the two checks after the others, and plain doctor runs without them', async () => {
|
|
489
|
+
write({'out/index.html': '<div>no astryx</div>'});
|
|
490
|
+
|
|
491
|
+
const plain = await runChecks({cwd: dir});
|
|
492
|
+
const built = await runChecks({cwd: dir, built: 'out'});
|
|
493
|
+
|
|
494
|
+
expect(plain.checks.some(c => c.id.startsWith('built-'))).toBe(false);
|
|
495
|
+
expect(built.checks.map(c => c.id)).toEqual([
|
|
496
|
+
...plain.checks.map(c => c.id),
|
|
497
|
+
'built-astryx-usage',
|
|
498
|
+
'built-astryx-purity',
|
|
499
|
+
]);
|
|
500
|
+
expect(built.summary.fail).toBe(plain.summary.fail + 1);
|
|
501
|
+
});
|
|
502
|
+
});
|
package/api/doctor/doctor.d.mts
CHANGED
|
@@ -281,22 +281,23 @@ export function checkComputerIntegrationsAvailable({ installed, candidates, inst
|
|
|
281
281
|
*
|
|
282
282
|
* @param {object} [options]
|
|
283
283
|
* @param {string} [options.cwd] - Directory to diagnose (default: process.cwd()).
|
|
284
|
+
* @param {string} [options.built] - A finished build to check for Astryx
|
|
285
|
+
* use: a project folder, a build output folder, or one built file
|
|
286
|
+
* (built-checks.mjs). Without it, the checks are unchanged.
|
|
284
287
|
* @returns {Promise<DoctorReport>}
|
|
285
288
|
*/
|
|
286
289
|
export function runChecks(options?: {
|
|
287
290
|
cwd?: string | undefined;
|
|
291
|
+
built?: string | undefined;
|
|
288
292
|
}): Promise<DoctorReport>;
|
|
289
293
|
/**
|
|
290
294
|
* Programmatic API: run the doctor and return the same envelope shape that
|
|
291
295
|
* `astryx doctor --json` emits.
|
|
292
296
|
*
|
|
293
|
-
* @param {
|
|
294
|
-
* @param {string} [options.cwd]
|
|
297
|
+
* @param {import('./doctor.type.mjs').DoctorOptions} [options]
|
|
295
298
|
* @returns {Promise<{type: 'doctor', data: DoctorReport}>}
|
|
296
299
|
*/
|
|
297
|
-
export function doctor(options?: {
|
|
298
|
-
cwd?: string | undefined;
|
|
299
|
-
}): Promise<{
|
|
300
|
+
export function doctor(options?: import("./doctor.type.mjs").DoctorOptions): Promise<{
|
|
300
301
|
type: "doctor";
|
|
301
302
|
data: DoctorReport;
|
|
302
303
|
}>;
|
|
@@ -37,6 +37,12 @@ export const doc = {
|
|
|
37
37
|
'Directory to diagnose. A directory outside any project, a missing one included, gets the computer checks.',
|
|
38
38
|
default: 'process.cwd()',
|
|
39
39
|
},
|
|
40
|
+
{
|
|
41
|
+
name: 'options.built',
|
|
42
|
+
type: 'string',
|
|
43
|
+
description:
|
|
44
|
+
'A finished build to check before you deliver it: a project folder, a build output folder, or one built `.html` file, relative to `cwd`. Adds two checks after the others. `built-astryx-usage` fails when the path holds no import from an Astryx package (any `@astryxdesign/*` package or an integration the project installs), no component imported from one, and no Astryx styles in built CSS or HTML. `built-astryx-purity` warns with the source check of `astryx docs is-my-code-good`: raw elements Astryx has a component for, raw SVG and icon-library icons, inline styles, classes, `stylex.create` and imported stylesheets, each with its file and line, in `.tsx` and `.jsx` files and JSX in `.js` source, found by parsing it; it is info, not inspected, when the path holds no source with JSX, such as a bundle. It reads at most 20,000 files, each up to 5 MB, skipping installs and version control; when either limit leaves source unread and nothing was found, the purity check is info, not fully inspected, and when the file limit ends the read before any Astryx turns up, `built-astryx-usage` warns that the rest went unread instead of failing. Given one built `.html` file, it also reads the local stylesheets and scripts that page links, finding a root-relative link from the nearest folder above the page that holds it; a linked file that is not there makes `built-astryx-usage` warn instead of fail. An empty folder fails with nothing checked, like a missing path. A source tree counts as using Astryx through an import, a re-export (`export … from`) or a stylesheet `@import` of an Astryx package. `--built` goes with `doctor` alone; a `doctor integration` check refuses it. A path that does not exist fails `built-astryx-usage` with nothing checked, and the purity check is left out. The integrations that count are the dependencies the nearest package.json above the path declares whose installed copy, found the way the CLI autolinks (a hoisted workspace copy included), has an integration manifest. The files under the path, and that configuration, are only read, never run. Without it, doctor runs exactly as before.',
|
|
45
|
+
},
|
|
40
46
|
],
|
|
41
47
|
returns: [
|
|
42
48
|
{
|
|
@@ -54,6 +60,10 @@ export const doc = {
|
|
|
54
60
|
label: 'Diagnose a directory',
|
|
55
61
|
code: "await doctor({cwd: '/path/to/app'});",
|
|
56
62
|
},
|
|
63
|
+
{
|
|
64
|
+
label: 'Check a finished build before delivering it',
|
|
65
|
+
code: "const r = await doctor({built: 'dist'});\nif (r.data.summary.fail > 0) throw new Error('Not built with Astryx');",
|
|
66
|
+
},
|
|
57
67
|
],
|
|
58
68
|
command: 'doctor',
|
|
59
69
|
related: ['init', 'upgrade'],
|
package/api/doctor/doctor.mjs
CHANGED
|
@@ -67,7 +67,8 @@ import {semverCompare, isValidSemver, satisfiesRange} from '../../foundation/env
|
|
|
67
67
|
import {checkAppThemes, checkThemes} from './theme-checks.mjs';
|
|
68
68
|
import {availableLine, RUN_FROM_PROJECT, upgradeLine} from '../../foundation/release/notices.mjs';
|
|
69
69
|
import {COMPUTER_COMMAND, COMPUTER_INSTALL_STEP} from '../../foundation/agent-docs/computer-agent-text.mjs';
|
|
70
|
-
import {alignCommand, addCliCommandFor, computerAgentTextState, installCommandFor, insideProjectElsewhere, projectCoreVersion, projectHasOwnCli, computerIntegrationsOutside, computerIntegrationsToAdd, displayHomePath, outsideProject, releaseFacts} from './_adapter.mjs';
|
|
70
|
+
import {alignCommand, addCliCommandFor, computerAgentTextState, installCommandFor, insideProjectElsewhere, projectCoreVersion, projectHasOwnCli, computerIntegrationsOutside, computerIntegrationsToAdd, displayHomePath, outsideProject, releaseFacts, builtIntegrationPackages} from './_adapter.mjs';
|
|
71
|
+
import {checkBuilt} from './built-checks.mjs';
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
74
|
* @typedef {'pass'|'warn'|'fail'|'info'} DoctorStatus
|
|
@@ -1910,9 +1911,24 @@ export const SYNC_CHECKS = [
|
|
|
1910
1911
|
*
|
|
1911
1912
|
* @param {object} [options]
|
|
1912
1913
|
* @param {string} [options.cwd] - Directory to diagnose (default: process.cwd()).
|
|
1914
|
+
* @param {string} [options.built] - A finished build to check for Astryx
|
|
1915
|
+
* use: a project folder, a build output folder, or one built file
|
|
1916
|
+
* (built-checks.mjs). Without it, the checks are unchanged.
|
|
1913
1917
|
* @returns {Promise<DoctorReport>}
|
|
1914
1918
|
*/
|
|
1915
1919
|
export async function runChecks(options = {}) {
|
|
1920
|
+
if (options.built != null) {
|
|
1921
|
+
const {built, ...rest} = options;
|
|
1922
|
+
const report = await runChecks(rest);
|
|
1923
|
+
const cwd = rest.cwd ?? process.cwd();
|
|
1924
|
+
const checks = [
|
|
1925
|
+
...report.checks,
|
|
1926
|
+
...checkBuilt(built, {cwd, packages: builtIntegrationPackages(built, cwd)}),
|
|
1927
|
+
];
|
|
1928
|
+
const summary = {pass: 0, warn: 0, fail: 0, info: 0};
|
|
1929
|
+
for (const c of checks) summary[c.status] += 1;
|
|
1930
|
+
return {checks, summary};
|
|
1931
|
+
}
|
|
1916
1932
|
const cwd = options.cwd ?? process.cwd();
|
|
1917
1933
|
if (outsideProject(cwd)) return runComputerChecks(cwd);
|
|
1918
1934
|
const coreDir = findProjectCoreDir(cwd);
|
|
@@ -2120,8 +2136,7 @@ export async function runChecks(options = {}) {
|
|
|
2120
2136
|
* Programmatic API: run the doctor and return the same envelope shape that
|
|
2121
2137
|
* `astryx doctor --json` emits.
|
|
2122
2138
|
*
|
|
2123
|
-
* @param {
|
|
2124
|
-
* @param {string} [options.cwd]
|
|
2139
|
+
* @param {import('./doctor.type.mjs').DoctorOptions} [options]
|
|
2125
2140
|
* @returns {Promise<{type: 'doctor', data: DoctorReport}>}
|
|
2126
2141
|
*/
|
|
2127
2142
|
export async function doctor(options = {}) {
|
|
@@ -51,4 +51,10 @@ export type DoctorResponse = {
|
|
|
51
51
|
*/
|
|
52
52
|
export type DoctorOptions = {
|
|
53
53
|
cwd?: string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* A finished build to check for Astryx use: a
|
|
56
|
+
* project folder, a build output folder, or one built file. Adds the
|
|
57
|
+
* `built-astryx-usage` and `built-astryx-purity` checks.
|
|
58
|
+
*/
|
|
59
|
+
built?: string | undefined;
|
|
54
60
|
};
|
|
@@ -44,6 +44,9 @@
|
|
|
44
44
|
* Options for `doctor()`.
|
|
45
45
|
* @typedef {object} DoctorOptions
|
|
46
46
|
* @property {string} [cwd]
|
|
47
|
+
* @property {string} [built] A finished build to check for Astryx use: a
|
|
48
|
+
* project folder, a build output folder, or one built file. Adds the
|
|
49
|
+
* `built-astryx-usage` and `built-astryx-purity` checks.
|
|
47
50
|
*/
|
|
48
51
|
|
|
49
52
|
export {};
|
|
@@ -230,7 +230,12 @@ export function parseNpmPackOutput(output) {
|
|
|
230
230
|
throw new Error('npm pack returned a result without a files array.');
|
|
231
231
|
}
|
|
232
232
|
return {
|
|
233
|
-
|
|
233
|
+
// npm 8 names a scoped package's tarball `@scope/name-1.0.0.tgz` in its
|
|
234
|
+
// JSON but writes `scope-name-1.0.0.tgz`, as every later npm reports.
|
|
235
|
+
filename:
|
|
236
|
+
typeof info.filename === 'string' && /^@[^/]+\//.test(info.filename)
|
|
237
|
+
? info.filename.slice(1).replace('/', '-')
|
|
238
|
+
: info.filename,
|
|
234
239
|
fileCount: info.entryCount,
|
|
235
240
|
size: info.size,
|
|
236
241
|
unpackedSize: info.unpackedSize,
|
|
@@ -2038,6 +2038,20 @@ describe('integrationPackCheck', () => {
|
|
|
2038
2038
|
).toEqual([]);
|
|
2039
2039
|
});
|
|
2040
2040
|
|
|
2041
|
+
it("reads npm 8's scoped tarball name as the file npm writes", () => {
|
|
2042
|
+
const entry = {entryCount: 1, size: 1, unpackedSize: 1, files: []};
|
|
2043
|
+
expect(
|
|
2044
|
+
parseNpmPackOutput(
|
|
2045
|
+
JSON.stringify([{...entry, filename: '@acme/kit-1.0.0.tgz'}]),
|
|
2046
|
+
).filename,
|
|
2047
|
+
).toBe('acme-kit-1.0.0.tgz');
|
|
2048
|
+
expect(
|
|
2049
|
+
parseNpmPackOutput(
|
|
2050
|
+
JSON.stringify([{...entry, filename: 'acme-kit-1.0.0.tgz'}]),
|
|
2051
|
+
).filename,
|
|
2052
|
+
).toBe('acme-kit-1.0.0.tgz');
|
|
2053
|
+
});
|
|
2054
|
+
|
|
2041
2055
|
it('rejects malformed npm pack output without a raw TypeError', () => {
|
|
2042
2056
|
expect(() =>
|
|
2043
2057
|
parseNpmPackOutput(
|