@astryxdesign/cli 0.7.5-canary.cd53c2d → 0.7.5-canary.ce34b37
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 +1 -1
- package/api/upgrade/_adapter.d.mts +2 -0
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/run.mjs +251 -10
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +12 -1
- package/api/upgrade/upgrade.type.mjs +17 -4
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +108 -10
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
- package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/pages/library/page.tsx +1 -2
- package/authoring/codemod/type.ts +10 -0
- package/clients/cli/commands/upgrade.doc.mjs +27 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.doc.mjs +3 -2
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/package.json +10 -9
|
@@ -199,6 +199,35 @@ describe('upgrade protected-file contract', () => {
|
|
|
199
199
|
});
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
+
it('keeps the error and adds the receipt when a hook leaves a protection declaration unreadable', () => {
|
|
203
|
+
seed();
|
|
204
|
+
write(
|
|
205
|
+
'astryx.config.mjs',
|
|
206
|
+
`export default {hooks: {postCodemod: [{name: 'regenerate', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify("require('node:fs').writeFileSync('.hgignore', 'syntax: regexp\\n[bad\\n')")}]})}]}};\n`,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const applied = run([...ARGS, '--apply']);
|
|
210
|
+
|
|
211
|
+
expect(applied.status).toBe(1);
|
|
212
|
+
expect(applied.envelope).not.toHaveProperty('type');
|
|
213
|
+
expect(applied.envelope).toMatchObject({
|
|
214
|
+
code: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
215
|
+
error: expect.stringContaining('.hgignore'),
|
|
216
|
+
receipt: {
|
|
217
|
+
complete: false,
|
|
218
|
+
errorCode: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
219
|
+
modifiedFiles: ['src/owned.tsx'],
|
|
220
|
+
protectedFiles: [
|
|
221
|
+
expect.objectContaining({file: 'generated/panel.tsx'}),
|
|
222
|
+
],
|
|
223
|
+
errors: [expect.objectContaining({codemod: 'file-protection'})],
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
227
|
+
'minSize: 200',
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
202
231
|
it('runs declared regeneration and clears a generated-file block after reevaluation', () => {
|
|
203
232
|
seed({hook: true});
|
|
204
233
|
|
|
@@ -226,4 +255,150 @@ describe('upgrade protected-file contract', () => {
|
|
|
226
255
|
expect(second.envelope.data.complete).toBe(true);
|
|
227
256
|
expect(second.envelope.data.filesChanged).toBe(0);
|
|
228
257
|
});
|
|
258
|
+
|
|
259
|
+
it('skips a vendored file that does not parse and completes the upgrade', () => {
|
|
260
|
+
seed();
|
|
261
|
+
write('.gitattributes', 'vendor/** linguist-vendored\n');
|
|
262
|
+
const bundle =
|
|
263
|
+
"/* minified */ import {useResizable} from '@astryxdesign/core';\n" +
|
|
264
|
+
'export const x = useResizable({minSizePx: 200;\n';
|
|
265
|
+
write('vendor/bundle.js', bundle);
|
|
266
|
+
rmGenerated();
|
|
267
|
+
|
|
268
|
+
const applied = run([...ARGS, '--apply']);
|
|
269
|
+
|
|
270
|
+
expect(applied.status, applied.stderr).toBe(0);
|
|
271
|
+
expect(applied.envelope).toMatchObject({
|
|
272
|
+
type: 'upgrade.run',
|
|
273
|
+
data: {
|
|
274
|
+
complete: true,
|
|
275
|
+
modifiedFiles: ['src/owned.tsx'],
|
|
276
|
+
protectedFiles: [],
|
|
277
|
+
declinedCandidates: [
|
|
278
|
+
{
|
|
279
|
+
file: 'vendor/bundle.js',
|
|
280
|
+
location: '2:46',
|
|
281
|
+
reason:
|
|
282
|
+
'unparseable protected file (vendored): Unexpected token, expected ","',
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
expect(applied.envelope.data.errors ?? []).toEqual([]);
|
|
288
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
289
|
+
'minSize: 200',
|
|
290
|
+
);
|
|
291
|
+
expect(fs.readFileSync(path.join(root, 'vendor/bundle.js'), 'utf8')).toBe(
|
|
292
|
+
bundle,
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const text = spawnSync(process.execPath, [CLI, 'upgrade', ...ARGS], {
|
|
296
|
+
cwd: root,
|
|
297
|
+
encoding: 'utf8',
|
|
298
|
+
timeout: 60_000,
|
|
299
|
+
env: {...process.env, FORCE_COLOR: '0', CI: ''},
|
|
300
|
+
});
|
|
301
|
+
expect(text.status, text.stderr).toBe(0);
|
|
302
|
+
expect(`${text.stdout}${text.stderr}`).toContain(
|
|
303
|
+
'1 protected file was skipped because it does not parse',
|
|
304
|
+
);
|
|
305
|
+
const declinedLine = `${text.stdout}${text.stderr}`
|
|
306
|
+
.split('\n')
|
|
307
|
+
.find(line => line.includes('vendor/bundle.js:2:46'));
|
|
308
|
+
expect(declinedLine).toMatch(/^ {2}vendor\/bundle\.js:2:46 - /);
|
|
309
|
+
// cli-surface output is plain ASCII.
|
|
310
|
+
expect(declinedLine).toMatch(/^[\x20-\x7e]*$/);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('still fails when an owned file does not parse', () => {
|
|
314
|
+
seed();
|
|
315
|
+
write(
|
|
316
|
+
'lib/broken.js',
|
|
317
|
+
"import {useResizable} from '@astryxdesign/core';\n" +
|
|
318
|
+
'export const x = useResizable({minSizePx: 200;\n',
|
|
319
|
+
);
|
|
320
|
+
rmGenerated();
|
|
321
|
+
|
|
322
|
+
const applied = run([...ARGS, '--apply']);
|
|
323
|
+
|
|
324
|
+
expect(applied.status).toBe(1);
|
|
325
|
+
expect(applied.envelope).toMatchObject({code: 'ERR_CODEMOD_FAILED'});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('reports a stylesheet the 0.6 and 0.7 theme codemods both need once, as protected', () => {
|
|
329
|
+
write('package.json', JSON.stringify({name: 'consumer', private: true}));
|
|
330
|
+
write(
|
|
331
|
+
'node_modules/@astryxdesign/core/package.json',
|
|
332
|
+
JSON.stringify({name: '@astryxdesign/core', version: CLI_VERSION}),
|
|
333
|
+
);
|
|
334
|
+
write('.gitattributes', 'vendor/** linguist-vendored\n');
|
|
335
|
+
write('vendor/bundle.css', 'a:: { color: red; }\n');
|
|
336
|
+
|
|
337
|
+
const result = run(['--from', '0.5.4', '--path', '.']);
|
|
338
|
+
const text = spawnSync(
|
|
339
|
+
process.execPath,
|
|
340
|
+
[CLI, 'upgrade', '--from', '0.5.4', '--path', '.'],
|
|
341
|
+
{
|
|
342
|
+
cwd: root,
|
|
343
|
+
encoding: 'utf8',
|
|
344
|
+
timeout: 60_000,
|
|
345
|
+
env: {...process.env, FORCE_COLOR: '0', CI: ''},
|
|
346
|
+
},
|
|
347
|
+
);
|
|
348
|
+
const output = `${text.stdout}${text.stderr}`;
|
|
349
|
+
expect(text.status).toBe(1);
|
|
350
|
+
expect(output).toContain('ERR_CODEMOD_PROTECTED');
|
|
351
|
+
expect(output).toMatch(/^ {2}vendor\/bundle\.css — /m);
|
|
352
|
+
expect(output).not.toContain('skipped because');
|
|
353
|
+
expect(output).not.toContain('unparseable protected file');
|
|
354
|
+
|
|
355
|
+
expect(result.status).toBe(1);
|
|
356
|
+
expect(result.envelope).toMatchObject({
|
|
357
|
+
type: 'upgrade.run',
|
|
358
|
+
data: {
|
|
359
|
+
complete: false,
|
|
360
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
361
|
+
protectedFiles: [expect.objectContaining({file: 'vendor/bundle.css'})],
|
|
362
|
+
declinedCandidates: [],
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('lists a generated file the hook regenerates into bytes that do not parse', () => {
|
|
368
|
+
seed();
|
|
369
|
+
const broken =
|
|
370
|
+
"// @generated\nimport {useResizable} from '@astryxdesign/core';\n" +
|
|
371
|
+
'export const usePanel = () => useResizable({minSizePx: 200;\n';
|
|
372
|
+
write(
|
|
373
|
+
'astryx.config.mjs',
|
|
374
|
+
`export default {hooks: {postCodemod: [{name: 'regenerate', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify(`require('node:fs').writeFileSync('generated/panel.tsx', ${JSON.stringify(broken)})`)}]})}]}};\n`,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const applied = run([...ARGS, '--apply']);
|
|
378
|
+
|
|
379
|
+
expect(applied.status, applied.stderr).toBe(0);
|
|
380
|
+
expect(applied.envelope).toMatchObject({
|
|
381
|
+
type: 'upgrade.run',
|
|
382
|
+
data: {
|
|
383
|
+
complete: true,
|
|
384
|
+
protectedFiles: [],
|
|
385
|
+
declinedCandidates: [
|
|
386
|
+
{
|
|
387
|
+
file: 'generated/panel.tsx',
|
|
388
|
+
location: expect.stringMatching(/^3:\d+$/),
|
|
389
|
+
reason: expect.stringMatching(
|
|
390
|
+
/^unparseable protected file \(generated\): /,
|
|
391
|
+
),
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
expect(
|
|
397
|
+
fs.readFileSync(path.join(root, 'generated/panel.tsx'), 'utf8'),
|
|
398
|
+
).toBe(broken);
|
|
399
|
+
});
|
|
229
400
|
});
|
|
401
|
+
|
|
402
|
+
function rmGenerated() {
|
|
403
|
+
fs.rmSync(path.join(root, 'generated'), {recursive: true, force: true});
|
|
404
|
+
}
|
|
@@ -175,6 +175,43 @@ describe('astryx upgrade exit codes', () => {
|
|
|
175
175
|
expect(status).toBe(1);
|
|
176
176
|
expect(envelope.code).toBe('ERR_CODEMOD_FAILED');
|
|
177
177
|
expect(envelope.error).toMatch(/Post-codemod hook failed/);
|
|
178
|
+
// Additive: the receipt names what the run had already changed.
|
|
179
|
+
expect(envelope).toMatchObject({
|
|
180
|
+
receipt: {
|
|
181
|
+
complete: false,
|
|
182
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
183
|
+
modifiedFiles: ['src/panel.tsx'],
|
|
184
|
+
errors: [
|
|
185
|
+
expect.objectContaining({
|
|
186
|
+
codemod: 'post-codemod-hook',
|
|
187
|
+
error: expect.stringMatching(/Post-codemod hook failed/),
|
|
188
|
+
}),
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}, SLOW);
|
|
193
|
+
|
|
194
|
+
it('reports what core codemods wrote when astryx.config then fails validation', async () => {
|
|
195
|
+
installPackage('@astryxdesign/core', '0.6.0');
|
|
196
|
+
write(
|
|
197
|
+
'src/panel.tsx',
|
|
198
|
+
"import {useResizable} from '@astryxdesign/core';\nexport const r = () => useResizable({minSizePx: 200});\n",
|
|
199
|
+
);
|
|
200
|
+
write('astryx.config.mjs', "export default {theme: 'neutral'};\n");
|
|
201
|
+
const {status, envelope} = await upgradeJson(['--from', '0.5.0', '--apply']);
|
|
202
|
+
expect(status).toBe(1);
|
|
203
|
+
expect(envelope).toMatchObject({
|
|
204
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
205
|
+
receipt: {
|
|
206
|
+
complete: false,
|
|
207
|
+
errorCode: 'ERR_INVALID_ARGUMENT',
|
|
208
|
+
modifiedFiles: ['src/panel.tsx'],
|
|
209
|
+
errors: [expect.objectContaining({codemod: 'config'})],
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src/panel.tsx'), 'utf8')).toContain(
|
|
213
|
+
'minSize: 200',
|
|
214
|
+
);
|
|
178
215
|
}, SLOW);
|
|
179
216
|
|
|
180
217
|
it('lists a missing jscodeshift and the refused flag combinations', () => {
|
|
@@ -17,6 +17,7 @@ import * as fs from 'node:fs';
|
|
|
17
17
|
import * as path from 'node:path';
|
|
18
18
|
import {Command} from 'commander';
|
|
19
19
|
import {registerUpgrade} from './upgrade.mjs';
|
|
20
|
+
import {isError} from '../../../api/json/parse.mjs';
|
|
20
21
|
import {Project} from '../../../foundation/config/project.mjs';
|
|
21
22
|
import {
|
|
22
23
|
generateCompressedIndex,
|
|
@@ -47,6 +48,7 @@ beforeEach(() => {
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
afterEach(() => {
|
|
51
|
+
process.exitCode = undefined;
|
|
50
52
|
process.chdir(originalCwd);
|
|
51
53
|
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
52
54
|
vi.restoreAllMocks();
|
|
@@ -298,6 +300,13 @@ describe('upgrade integration error policy (skip + warn)', () => {
|
|
|
298
300
|
]);
|
|
299
301
|
|
|
300
302
|
expect(result.code).toBe('ERR_CODEMOD_FAILED');
|
|
303
|
+
expect(result.receipt).toMatchObject({
|
|
304
|
+
complete: false,
|
|
305
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
306
|
+
agentDocsRefreshed: false,
|
|
307
|
+
modifiedFiles: ['src/index.ts'],
|
|
308
|
+
errors: [expect.objectContaining({codemod: 'post-codemod-hook'})],
|
|
309
|
+
});
|
|
301
310
|
expect(fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8')).toBe(
|
|
302
311
|
before,
|
|
303
312
|
);
|
|
@@ -476,3 +485,97 @@ describe('upgrade integration error policy (skip + warn)', () => {
|
|
|
476
485
|
expect(out).not.toContain('bar');
|
|
477
486
|
});
|
|
478
487
|
});
|
|
488
|
+
|
|
489
|
+
describe('upgrade failure receipt when a codemod fails', () => {
|
|
490
|
+
const codemods = {
|
|
491
|
+
'0.2.0/drop-foo.mjs': `export default {type: 'code', title: 'Drop foo', transform: file => file.source.replace(/foo/g, 'bar')};\n`,
|
|
492
|
+
'0.2.0/fail.mjs': `export default {type: 'code', title: 'Fail on boom', transform: file => { if (file.source.includes('boom')) throw new Error('codemod boom'); return undefined; }};\n`,
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
function scaffold() {
|
|
496
|
+
scaffoldIntegration(codemods);
|
|
497
|
+
writeInstalledCore('0.2.0');
|
|
498
|
+
writeSource();
|
|
499
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'broken.ts'), 'const boom = 1;\n');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const ARGS = ['upgrade', '--from', '0.1.0', '--path', 'src'];
|
|
503
|
+
|
|
504
|
+
it('keeps the error envelope and adds the receipt of what was written', async () => {
|
|
505
|
+
scaffold();
|
|
506
|
+
|
|
507
|
+
const result = await runJson(['--json', ...ARGS, '--apply']);
|
|
508
|
+
|
|
509
|
+
expect(exitCode).toBe(1);
|
|
510
|
+
expect(isError(result)).toBe(true);
|
|
511
|
+
expect(result).not.toHaveProperty('type');
|
|
512
|
+
expect(result).toMatchObject({
|
|
513
|
+
apiVersion: 1,
|
|
514
|
+
code: 'ERR_CODEMOD_FAILED',
|
|
515
|
+
error: 'Upgrade completed with 1 codemod error.',
|
|
516
|
+
receipt: {
|
|
517
|
+
complete: false,
|
|
518
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
519
|
+
filesChanged: 1,
|
|
520
|
+
modifiedFiles: ['src/index.ts'],
|
|
521
|
+
protectedFiles: [],
|
|
522
|
+
errors: [
|
|
523
|
+
{
|
|
524
|
+
file: 'src/broken.ts',
|
|
525
|
+
codemod: '@acme/widgets:fail',
|
|
526
|
+
error: 'codemod boom',
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src', 'index.ts'), 'utf-8')).toBe(
|
|
532
|
+
'const bar = 1;\n',
|
|
533
|
+
);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it('previews the same receipt in a dry run without writing', async () => {
|
|
537
|
+
scaffold();
|
|
538
|
+
|
|
539
|
+
const result = await runJson(['--json', ...ARGS]);
|
|
540
|
+
|
|
541
|
+
expect(result.code).toBe('ERR_CODEMOD_FAILED');
|
|
542
|
+
expect(result.receipt).toMatchObject({
|
|
543
|
+
complete: false,
|
|
544
|
+
modifiedFiles: ['src/index.ts'],
|
|
545
|
+
errors: [expect.objectContaining({file: 'src/broken.ts'})],
|
|
546
|
+
});
|
|
547
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src', 'index.ts'), 'utf-8')).toBe(
|
|
548
|
+
'const foo = 1;\n',
|
|
549
|
+
);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('still returns the protected-file receipt when a protected file remains', async () => {
|
|
553
|
+
scaffold();
|
|
554
|
+
fs.writeFileSync(
|
|
555
|
+
path.join(tmpDir, 'src', 'gen.ts'),
|
|
556
|
+
'// @generated\nconst foo = 2;\n',
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
const result = await runJson(['--json', ...ARGS, '--apply']);
|
|
560
|
+
|
|
561
|
+
expect(result).toMatchObject({
|
|
562
|
+
type: 'upgrade.run',
|
|
563
|
+
data: {
|
|
564
|
+
complete: false,
|
|
565
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
566
|
+
protectedFiles: [expect.objectContaining({file: 'src/gen.ts'})],
|
|
567
|
+
errors: [expect.objectContaining({file: 'src/broken.ts'})],
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it('keeps the human output and exit status in text mode', async () => {
|
|
573
|
+
scaffold();
|
|
574
|
+
|
|
575
|
+
await runJson([...ARGS, '--apply']);
|
|
576
|
+
|
|
577
|
+
expect(process.exitCode).toBe(1);
|
|
578
|
+
expect(logCalls.join('\n')).toMatch(/Upgrade failed/);
|
|
579
|
+
expect(logCalls.join('\n')).not.toMatch(/"receipt"/);
|
|
580
|
+
});
|
|
581
|
+
});
|
|
@@ -57,8 +57,15 @@ export function registerUpgrade(program) {
|
|
|
57
57
|
// already printed the error before throwing.
|
|
58
58
|
logger.setSilent(json);
|
|
59
59
|
if (e instanceof AstryxError) {
|
|
60
|
-
if (json)
|
|
61
|
-
|
|
60
|
+
if (json) {
|
|
61
|
+
// A failed migration still names the files it already changed.
|
|
62
|
+
jsonError(
|
|
63
|
+
e.message,
|
|
64
|
+
undefined,
|
|
65
|
+
e.code,
|
|
66
|
+
/** @type {any} */ (e).receipt,
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
62
69
|
// The logger was silent only for --list; replay the error there.
|
|
63
70
|
// Non-list failures were already printed by the API.
|
|
64
71
|
if (isList) logger.error(e.message);
|
|
@@ -34,6 +34,13 @@ export interface CLIError {
|
|
|
34
34
|
error: string;
|
|
35
35
|
code: ErrorCode;
|
|
36
36
|
suggestions?: Suggestion[];
|
|
37
|
+
/**
|
|
38
|
+
* What the command had already done when it failed, present only on errors
|
|
39
|
+
* from a command that changes files before it can fail (for example the
|
|
40
|
+
* `upgrade.run` data of a failed `astryx upgrade`). The error is still an
|
|
41
|
+
* error: branch on `code`.
|
|
42
|
+
*/
|
|
43
|
+
receipt?: Record<string, unknown>;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
/** Returned by the fallback hook for commands without --json support. */
|
|
@@ -150,7 +150,8 @@ export const doc = {
|
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
152
|
value: 'ERR_CODEMOD_FAILED',
|
|
153
|
-
description:
|
|
153
|
+
description:
|
|
154
|
+
'A codemod or post-codemod hook failed during an upgrade run; the error carries a `receipt` that lists the files the run already changed.',
|
|
154
155
|
},
|
|
155
156
|
{
|
|
156
157
|
value: 'ERR_CODEMOD_PROTECTED',
|
|
@@ -282,7 +283,7 @@ export const doc = {
|
|
|
282
283
|
{
|
|
283
284
|
value: 'ERR_VERSIONS_UNAVAILABLE',
|
|
284
285
|
description:
|
|
285
|
-
|
|
286
|
+
"Nothing could answer this run, and nothing was written: the project's own CLI could not start and nothing else could answer, or the Core a command needs outside a project could not be installed.",
|
|
286
287
|
},
|
|
287
288
|
{
|
|
288
289
|
value: 'ERR_PROJECT_REQUIRED',
|
|
@@ -172,7 +172,7 @@ export const ERROR_CODES = Object.freeze({
|
|
|
172
172
|
ERR_UNKNOWN_FEATURE: 'ERR_UNKNOWN_FEATURE',
|
|
173
173
|
/** A `--codemod` value did not match any registered codemod (upgrade). */
|
|
174
174
|
ERR_UNKNOWN_CODEMOD: 'ERR_UNKNOWN_CODEMOD',
|
|
175
|
-
/** One or more codemods failed during an upgrade run. */
|
|
175
|
+
/** One or more codemods, or a post-codemod hook, failed during an upgrade run. */
|
|
176
176
|
ERR_CODEMOD_FAILED: 'ERR_CODEMOD_FAILED',
|
|
177
177
|
/** A required codemod change remains blocked by a protected consumer file. */
|
|
178
178
|
ERR_CODEMOD_PROTECTED: 'ERR_CODEMOD_PROTECTED',
|
|
@@ -62,19 +62,26 @@ export function jsonOut(response: {
|
|
|
62
62
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
63
63
|
* @param {string} [code] - Explicit stable error code. Overrides any code
|
|
64
64
|
* carried on a thrown Error.
|
|
65
|
-
* @
|
|
65
|
+
* @param {Record<string, unknown>} [receipt] - What the failed command had
|
|
66
|
+
* already done, for a command that changes files before it can fail.
|
|
67
|
+
* Overrides a `receipt` carried on a thrown Error. Additive: the envelope
|
|
68
|
+
* is still an error with its `code`.
|
|
69
|
+
* @returns {{apiVersion: number, error: string, code: string, suggestions?: import('./base').Suggestion[], receipt?: Record<string, unknown>}}
|
|
66
70
|
*/
|
|
67
|
-
export function toErrorEnvelope(err: unknown, suggestions?: import("./base").Suggestion[], code?: string): {
|
|
71
|
+
export function toErrorEnvelope(err: unknown, suggestions?: import("./base").Suggestion[], code?: string, receipt?: Record<string, unknown>): {
|
|
68
72
|
apiVersion: number;
|
|
69
73
|
error: string;
|
|
70
74
|
code: string;
|
|
71
75
|
suggestions?: import("./base").Suggestion[];
|
|
76
|
+
receipt?: Record<string, unknown>;
|
|
72
77
|
};
|
|
73
78
|
/**
|
|
74
79
|
* Output a structured JSON error and exit.
|
|
75
80
|
* @param {string} message
|
|
76
81
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
77
82
|
* @param {string} [code] - Stable machine-readable error code (error-codes.mjs).
|
|
83
|
+
* @param {Record<string, unknown>} [receipt] - What the command had already
|
|
84
|
+
* done before it failed (see toErrorEnvelope).
|
|
78
85
|
*/
|
|
79
|
-
export function jsonError(message: string, suggestions?: import("./base").Suggestion[], code?: string): void;
|
|
86
|
+
export function jsonError(message: string, suggestions?: import("./base").Suggestion[], code?: string, receipt?: Record<string, unknown>): void;
|
|
80
87
|
export const API_VERSION: 1;
|
|
@@ -134,9 +134,13 @@ export function jsonOut(response) {
|
|
|
134
134
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
135
135
|
* @param {string} [code] - Explicit stable error code. Overrides any code
|
|
136
136
|
* carried on a thrown Error.
|
|
137
|
-
* @
|
|
137
|
+
* @param {Record<string, unknown>} [receipt] - What the failed command had
|
|
138
|
+
* already done, for a command that changes files before it can fail.
|
|
139
|
+
* Overrides a `receipt` carried on a thrown Error. Additive: the envelope
|
|
140
|
+
* is still an error with its `code`.
|
|
141
|
+
* @returns {{apiVersion: number, error: string, code: string, suggestions?: import('./base').Suggestion[], receipt?: Record<string, unknown>}}
|
|
138
142
|
*/
|
|
139
|
-
export function toErrorEnvelope(err, suggestions, code) {
|
|
143
|
+
export function toErrorEnvelope(err, suggestions, code, receipt) {
|
|
140
144
|
const message =
|
|
141
145
|
err instanceof Error ? err.message : typeof err === 'string' ? err : String(err);
|
|
142
146
|
const carried =
|
|
@@ -145,6 +149,12 @@ export function toErrorEnvelope(err, suggestions, code) {
|
|
|
145
149
|
/** @type {any} */
|
|
146
150
|
const env = {apiVersion: API_VERSION, error: message, code: resolvedCode};
|
|
147
151
|
if (Array.isArray(suggestions) && suggestions.length) env.suggestions = suggestions;
|
|
152
|
+
const carriedReceipt =
|
|
153
|
+
err && typeof err === 'object' ? /** @type {any} */ (err).receipt : undefined;
|
|
154
|
+
const resolvedReceipt = receipt ?? carriedReceipt;
|
|
155
|
+
if (resolvedReceipt && typeof resolvedReceipt === 'object') {
|
|
156
|
+
env.receipt = resolvedReceipt;
|
|
157
|
+
}
|
|
148
158
|
return env;
|
|
149
159
|
}
|
|
150
160
|
|
|
@@ -153,10 +163,12 @@ export function toErrorEnvelope(err, suggestions, code) {
|
|
|
153
163
|
* @param {string} message
|
|
154
164
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
155
165
|
* @param {string} [code] - Stable machine-readable error code (error-codes.mjs).
|
|
166
|
+
* @param {Record<string, unknown>} [receipt] - What the command had already
|
|
167
|
+
* done before it failed (see toErrorEnvelope).
|
|
156
168
|
*/
|
|
157
|
-
export function jsonError(message, suggestions, code) {
|
|
169
|
+
export function jsonError(message, suggestions, code, receipt) {
|
|
158
170
|
process.__xdsJsonHandled = true;
|
|
159
|
-
const err = toErrorEnvelope(message, suggestions, code);
|
|
171
|
+
const err = toErrorEnvelope(message, suggestions, code, receipt);
|
|
160
172
|
// No-op when cliError already classified this failure — first outcome wins.
|
|
161
173
|
setOutcome('error', {exitCode: 1, error: new Error(message), code: err.code});
|
|
162
174
|
console.log(JSON.stringify(err, null, 2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.5-canary.
|
|
3
|
+
"version": "0.7.5-canary.ce34b37",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -111,10 +111,10 @@
|
|
|
111
111
|
"zod": "^4.4.3"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|
|
114
|
-
"@astryxdesign/charts": "0.7.5-canary.
|
|
115
|
-
"@astryxdesign/core": "0.7.5-canary.
|
|
116
|
-
"@astryxdesign/lab": "0.7.5-canary.
|
|
117
|
-
"@astryxdesign/theme-neutral": "0.7.5-canary.
|
|
114
|
+
"@astryxdesign/charts": "0.7.5-canary.ce34b37",
|
|
115
|
+
"@astryxdesign/core": "0.7.5-canary.ce34b37",
|
|
116
|
+
"@astryxdesign/lab": "0.7.5-canary.ce34b37",
|
|
117
|
+
"@astryxdesign/theme-neutral": "0.7.5-canary.ce34b37"
|
|
118
118
|
},
|
|
119
119
|
"peerDependenciesMeta": {
|
|
120
120
|
"@astryxdesign/charts": {
|
|
@@ -131,10 +131,10 @@
|
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
133
|
"devDependencies": {
|
|
134
|
-
"@astryxdesign/charts": "0.7.5-canary.
|
|
135
|
-
"@astryxdesign/core": "0.7.5-canary.
|
|
136
|
-
"@astryxdesign/lab": "0.7.5-canary.
|
|
137
|
-
"@astryxdesign/theme-neutral": "0.7.5-canary.
|
|
134
|
+
"@astryxdesign/charts": "0.7.5-canary.ce34b37",
|
|
135
|
+
"@astryxdesign/core": "0.7.5-canary.ce34b37",
|
|
136
|
+
"@astryxdesign/lab": "0.7.5-canary.ce34b37",
|
|
137
|
+
"@astryxdesign/theme-neutral": "0.7.5-canary.ce34b37",
|
|
138
138
|
"@heroicons/react": "^2.2.0",
|
|
139
139
|
"@stylexjs/stylex": "^0.19.0",
|
|
140
140
|
"@types/babel__core": "^7.20.5",
|
|
@@ -146,6 +146,7 @@
|
|
|
146
146
|
"postinstall": "node scripts/postinstall.mjs",
|
|
147
147
|
"test": "cd ../.. && vitest run packages/cli",
|
|
148
148
|
"test:watch": "cd ../.. && vitest packages/cli",
|
|
149
|
+
"typecheck": "pnpm typecheck:template-docs && pnpm typecheck:strict",
|
|
149
150
|
"typecheck:template-docs": "tsc --project tsconfig.template-docs.json",
|
|
150
151
|
"typecheck:json-api": "tsc --project tsconfig.json-api.json",
|
|
151
152
|
"typecheck:strict": "tsc --project tsconfig.strict.json",
|