@astryxdesign/cli 0.7.4-canary.626f01e → 0.7.4-canary.78641f8
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 +63 -63
- package/api/integration/example-checks.no-npm.test.mjs +140 -0
- package/api/integration/example-checks.test.mjs +776 -0
- package/api/integration/validate-integration-case-disk.test.mjs +12 -2
- package/api/integration/validate-integration-gaps.test.mjs +36 -15
- package/api/integration/validate-integration.mjs +16 -0
- package/api/integration/validate-integration.type.d.mts +13 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/template/template-suffix.test.mjs +26 -0
- package/clients/cli/commands/doctor.mjs +10 -0
- package/foundation/discovery/template-adapter.mjs +11 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +4 -0
- package/foundation/integrations/validate-contributions.d.mts +53 -0
- package/foundation/integrations/validate-contributions.mjs +788 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* When npm cannot list a package's files, `template_asset_not_packed` still
|
|
5
|
+
* reports an asset no `files` entry can reach and lists every other asset as
|
|
6
|
+
* not checked (architecture:cli-surface INV35), never passing it silently.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as os from 'node:os';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import {Command} from 'commander';
|
|
13
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
14
|
+
|
|
15
|
+
vi.mock('../../foundation/release/cache.mjs', () => ({
|
|
16
|
+
npmCommand: () => {
|
|
17
|
+
throw new Error('npm is not installed');
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const {validateIntegration} = await import('./validate-integration.mjs');
|
|
22
|
+
const {integrationCheck} = await import('./check/check.mjs');
|
|
23
|
+
const {registerDoctor} = await import('../../clients/cli/commands/doctor.mjs');
|
|
24
|
+
|
|
25
|
+
/** @type {string} */
|
|
26
|
+
let dir;
|
|
27
|
+
|
|
28
|
+
/** @param {Record<string, string>} files */
|
|
29
|
+
function write(files) {
|
|
30
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
31
|
+
const file = path.join(dir, rel);
|
|
32
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
33
|
+
fs.writeFileSync(file, text);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {string[]} files */
|
|
38
|
+
function packageWith(files) {
|
|
39
|
+
write({
|
|
40
|
+
'package.json': JSON.stringify({
|
|
41
|
+
name: '@acme/kit',
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
files,
|
|
44
|
+
}),
|
|
45
|
+
'astryx.integration.mjs': "export default {templates: './templates'};\n",
|
|
46
|
+
'templates/img/hero.png': 'png',
|
|
47
|
+
'assets/cat.png': 'png',
|
|
48
|
+
'templates/card.doc.mjs':
|
|
49
|
+
"export default {type: 'block', name: 'card', displayName: 'Card', description: 'A block.'};\n",
|
|
50
|
+
'templates/card.tsx': [
|
|
51
|
+
"const hero = new URL('./img/hero.png', import.meta.url);",
|
|
52
|
+
"const cat = new URL('../assets/cat.png', import.meta.url);",
|
|
53
|
+
'export default () => null;',
|
|
54
|
+
'',
|
|
55
|
+
].join('\n'),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-no-npm-'));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('template assets when npm gives no answer', () => {
|
|
68
|
+
it('reports an asset no entry can reach and lists the others as not checked', async () => {
|
|
69
|
+
packageWith(['templates', '!templates/img']);
|
|
70
|
+
const {data} = await validateIntegration(undefined, {cwd: dir});
|
|
71
|
+
const notes = (data.notes ?? []).filter(
|
|
72
|
+
note => note.code === 'template_asset_not_packed',
|
|
73
|
+
);
|
|
74
|
+
expect(notes).toHaveLength(1);
|
|
75
|
+
expect(notes[0].message).toContain('loads assets/cat.png');
|
|
76
|
+
expect(data.exampleAssets).toEqual({
|
|
77
|
+
status: 'checked',
|
|
78
|
+
findings: [],
|
|
79
|
+
unchecked: [
|
|
80
|
+
{
|
|
81
|
+
file: 'templates/card.tsx',
|
|
82
|
+
asset: 'templates/img/hero.png',
|
|
83
|
+
reason: 'npm was not found, and a `files` entry may reach it',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const check = await integrationCheck({cwd: dir});
|
|
89
|
+
expect(check.data.unchecked).toBeGreaterThanOrEqual(1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('lists an asset not checked when there is no files field but an ignore file', async () => {
|
|
93
|
+
packageWith(['templates']);
|
|
94
|
+
const pkg = JSON.parse(
|
|
95
|
+
fs.readFileSync(path.join(dir, 'package.json'), 'utf8'),
|
|
96
|
+
);
|
|
97
|
+
delete pkg.files;
|
|
98
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkg));
|
|
99
|
+
fs.writeFileSync(path.join(dir, '.npmignore'), 'templates/img\n');
|
|
100
|
+
const {data} = await validateIntegration(undefined, {cwd: dir});
|
|
101
|
+
expect(
|
|
102
|
+
data.exampleAssets?.unchecked.map(each => each.asset).sort(),
|
|
103
|
+
).toEqual(['assets/cat.png', 'templates/img/hero.png']);
|
|
104
|
+
expect(
|
|
105
|
+
data.exampleAssets?.unchecked.every(each =>
|
|
106
|
+
each.reason.includes('.npmignore may drop it'),
|
|
107
|
+
),
|
|
108
|
+
).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('shows the assets it could not check in text output', async () => {
|
|
112
|
+
packageWith(['templates', '!templates/img']);
|
|
113
|
+
/** @type {string[]} */
|
|
114
|
+
const lines = [];
|
|
115
|
+
vi.spyOn(console, 'log').mockImplementation((...args) => {
|
|
116
|
+
lines.push(args.join(' '));
|
|
117
|
+
});
|
|
118
|
+
const previous = process.cwd();
|
|
119
|
+
process.chdir(dir);
|
|
120
|
+
try {
|
|
121
|
+
const program = new Command();
|
|
122
|
+
program.exitOverride();
|
|
123
|
+
program.option('--json', 'Output as typed JSON');
|
|
124
|
+
registerDoctor(program);
|
|
125
|
+
await program.parseAsync([
|
|
126
|
+
'node',
|
|
127
|
+
'astryx',
|
|
128
|
+
'doctor',
|
|
129
|
+
'integration',
|
|
130
|
+
'validate',
|
|
131
|
+
]);
|
|
132
|
+
} finally {
|
|
133
|
+
process.chdir(previous);
|
|
134
|
+
vi.restoreAllMocks();
|
|
135
|
+
}
|
|
136
|
+
const out = lines.join('\n');
|
|
137
|
+
expect(out).toContain('Template assets not checked: 1');
|
|
138
|
+
expect(out).toContain('templates/img/hero.png');
|
|
139
|
+
});
|
|
140
|
+
});
|