@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5
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/CHANGELOG.md +91 -3
- package/README.md +2 -2
- package/api/hook/detail/detail.test.mjs +11 -0
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/template/tokenizer-showcase.test.mjs +47 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
- package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +371 -113
- package/api/theme/build/build.project-core.test.mjs +63 -8
- package/api/theme/build/build.test.mjs +77 -0
- package/api/theme/build/icon-imports.d.mts +12 -2
- package/api/theme/build/icon-imports.mjs +36 -11
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +670 -44
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +36 -1
- package/api/upgrade/upgrade.type.mjs +29 -4
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- 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/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +119 -13
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -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.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
- package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
- package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
- package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
- 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/__tests__/validate-data-token-ownership.test.mjs +143 -70
- 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/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
- package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/v0.7.5/index.mjs +20 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/docs/README.md +13 -13
- package/assets/docs/author-a-theme.doc.mjs +5 -1
- package/assets/docs/getting-started.doc.mjs +5 -5
- package/assets/docs/icons.doc.mjs +82 -1
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +19 -6
- package/authoring/codemod/type.ts +10 -0
- package/authoring/config/config.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
- package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
- package/clients/cli/commands/upgrade.doc.mjs +47 -2
- 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/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/foundation/config/project.d.mts +1 -1
- package/foundation/config/project.mjs +1 -1
- package/foundation/debug/redact.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
- 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/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +13 -12
|
@@ -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);
|