@astryxdesign/cli 0.6.3-canary.7210f0d → 0.6.3-canary.7ada42e
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 +2 -0
- package/api/upgrade/_adapter.d.mts +22 -4
- package/api/upgrade/_adapter.mjs +19 -6
- package/api/upgrade/run/run.mjs +355 -59
- package/api/upgrade/upgrade.doc.mjs +5 -1
- package/api/upgrade/upgrade.type.d.mts +34 -0
- package/api/upgrade/upgrade.type.mjs +15 -0
- package/assets/codemods/__tests__/runner.test.mjs +330 -8
- package/assets/codemods/integration-runner.mjs +56 -4
- package/assets/codemods/integration-runner.protection.test.mjs +153 -0
- package/assets/codemods/run-codemod.mjs +177 -34
- package/assets/codemods/runner.mjs +248 -110
- package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs +63 -0
- package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +4 -0
- package/assets/codemods/transforms/next/index.mjs +8 -0
- package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
- package/assets/docs/cli-integrations.doc.mjs +13 -0
- package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +14 -0
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +100 -0
- package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
- package/authoring/codemod/type.ts +12 -0
- package/clients/cli/commands/build-theme.mjs +10 -44
- package/clients/cli/commands/docs.mjs +1 -1
- package/clients/cli/commands/text-json-parity.test.mjs +719 -0
- package/clients/cli/commands/theme-targets.behavior.test.mjs +4 -3
- package/clients/cli/commands/upgrade.doc.mjs +2 -1
- package/clients/cli/commands/upgrade.file-protection.test.mjs +228 -0
- package/clients/cli/commands/upgrade.mjs +29 -7
- package/clients/cli/formatters/index.mjs +2 -0
- package/clients/cli/formatters/index.test.mjs +6 -0
- package/foundation/fs/file-protection.d.mts +33 -0
- package/foundation/fs/file-protection.mjs +825 -0
- package/foundation/fs/file-protection.test.mjs +250 -0
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +2 -0
- package/foundation/response/error-codes.doc.mjs +10 -0
- package/foundation/response/error-codes.mjs +6 -0
- package/foundation/response/error-codes.test.mjs +55 -11
- package/package.json +10 -9
|
@@ -12,7 +12,8 @@ import * as fs from 'node:fs';
|
|
|
12
12
|
import * as path from 'node:path';
|
|
13
13
|
import * as p from './term-log.mjs';
|
|
14
14
|
import {humanLog} from '../../foundation/response/json.mjs';
|
|
15
|
-
import {runConfigCodemod} from './run-codemod.mjs';
|
|
15
|
+
import {runCodeCodemod, runConfigCodemod} from './run-codemod.mjs';
|
|
16
|
+
import {createFileProtectionResolver} from '../../foundation/fs/file-protection.mjs';
|
|
16
17
|
|
|
17
18
|
// Known corruption patterns that indicate a broken transform.
|
|
18
19
|
// Each entry: [regex, human-readable description]
|
|
@@ -46,20 +47,30 @@ export function fixDirectiveCorruption(code) {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
|
-
* Directories a source scan must never descend into
|
|
50
|
-
*
|
|
50
|
+
* Directories a source scan must never descend into. Generated-looking names
|
|
51
|
+
* are intentionally absent: protection comes from checkout declarations, not a
|
|
52
|
+
* directory-name heuristic.
|
|
51
53
|
*/
|
|
52
54
|
const IGNORED_DIRS = new Set([
|
|
53
55
|
'node_modules',
|
|
56
|
+
'bower_components',
|
|
57
|
+
'jspm_packages',
|
|
54
58
|
'.git',
|
|
55
|
-
'
|
|
56
|
-
'
|
|
57
|
-
'out',
|
|
58
|
-
'.next',
|
|
59
|
-
'coverage',
|
|
59
|
+
'.hg',
|
|
60
|
+
'.sl',
|
|
60
61
|
]);
|
|
61
62
|
export {IGNORED_DIRS};
|
|
62
63
|
|
|
64
|
+
/** @param {string} root @param {string} fullPath @param {string} name */
|
|
65
|
+
export function isIgnoredDirectory(root, fullPath, name) {
|
|
66
|
+
if (IGNORED_DIRS.has(name)) return true;
|
|
67
|
+
const parts = path.relative(root, fullPath).split(path.sep);
|
|
68
|
+
return (
|
|
69
|
+
parts[0] === '.yarn' &&
|
|
70
|
+
['__virtual__', 'cache', 'sdks', 'unplugged'].includes(parts[1])
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
/**
|
|
64
75
|
* Recursively find all source files in a directory.
|
|
65
76
|
* @param {string} dir
|
|
@@ -81,8 +92,17 @@ function findSourceFiles(dir) {
|
|
|
81
92
|
'.less',
|
|
82
93
|
]);
|
|
83
94
|
|
|
84
|
-
/** @param {string} currentDir */
|
|
85
|
-
function walk(currentDir) {
|
|
95
|
+
/** @param {string} currentDir @param {Set<string>} [ancestors] */
|
|
96
|
+
function walk(currentDir, ancestors = new Set()) {
|
|
97
|
+
let realDirectory;
|
|
98
|
+
try {
|
|
99
|
+
realDirectory = fs.realpathSync(currentDir);
|
|
100
|
+
} catch {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (ancestors.has(realDirectory)) return;
|
|
104
|
+
const nextAncestors = new Set(ancestors);
|
|
105
|
+
nextAncestors.add(realDirectory);
|
|
86
106
|
let entries;
|
|
87
107
|
try {
|
|
88
108
|
entries = fs.readdirSync(currentDir, {withFileTypes: true});
|
|
@@ -91,16 +111,27 @@ function findSourceFiles(dir) {
|
|
|
91
111
|
}
|
|
92
112
|
for (const entry of entries) {
|
|
93
113
|
const fullPath = path.join(currentDir, entry.name);
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
// Symlinked files and descendants remain read-only candidates so a
|
|
115
|
+
// required change can be reported. Real-path ancestors prevent cycles.
|
|
116
|
+
if (entry.isSymbolicLink()) {
|
|
117
|
+
try {
|
|
118
|
+
const target = fs.statSync(fullPath);
|
|
119
|
+
if (target.isFile() && extensions.has(path.extname(entry.name))) {
|
|
120
|
+
results.push(fullPath);
|
|
121
|
+
} else if (target.isDirectory()) {
|
|
122
|
+
walk(fullPath, nextAncestors);
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
// Broken links have no source bytes to evaluate.
|
|
126
|
+
}
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
99
129
|
if (entry.isDirectory()) {
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
// Only hard boundaries are skipped by name. Generated and vendored
|
|
131
|
+
// content is discovered, transformed in memory, and classified by the
|
|
132
|
+
// shared protection resolver so required changes can be reported.
|
|
133
|
+
if (isIgnoredDirectory(dir, fullPath, entry.name)) continue;
|
|
134
|
+
walk(fullPath, nextAncestors);
|
|
104
135
|
} else if (extensions.has(path.extname(entry.name))) {
|
|
105
136
|
results.push(fullPath);
|
|
106
137
|
}
|
|
@@ -213,10 +244,13 @@ function toUnifiedEntry(transformEntry, version) {
|
|
|
213
244
|
* the file contract.
|
|
214
245
|
*
|
|
215
246
|
* @param {{name: string, transform: unknown}} transformEntry
|
|
216
|
-
* @param {{apply: boolean, root: string, log: {success: (m: string) => void, warn: (m: string) => void, error: (m: string) => void}}} options
|
|
217
|
-
* @returns {Promise<
|
|
247
|
+
* @param {{apply: boolean, root: string, protection: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, log: {success: (m: string) => void, warn: (m: string) => void, error: (m: string) => void}}} options
|
|
248
|
+
* @returns {Promise<import('../../authoring/codemod/type').CodemodRunResult & {stagedOverrides?: Map<string, string|null>}>}
|
|
218
249
|
*/
|
|
219
|
-
async function runProjectCodemod(
|
|
250
|
+
async function runProjectCodemod(
|
|
251
|
+
{name, transform},
|
|
252
|
+
{apply, root, protection, log},
|
|
253
|
+
) {
|
|
220
254
|
/** @param {string} file */
|
|
221
255
|
const rel = file => path.relative(root, file).split(path.sep).join('/');
|
|
222
256
|
/** @type {ProjectCodemodPlan} */
|
|
@@ -230,7 +264,9 @@ async function runProjectCodemod({name, transform}, {apply, root, log}) {
|
|
|
230
264
|
log.error(` ✗ ${message}`);
|
|
231
265
|
return {
|
|
232
266
|
filesChanged: 0,
|
|
267
|
+
changedFiles: [],
|
|
233
268
|
writtenFiles: [],
|
|
269
|
+
protectedFiles: [],
|
|
234
270
|
errors: [{file: '.', codemod: name, error: message}],
|
|
235
271
|
};
|
|
236
272
|
}
|
|
@@ -240,7 +276,9 @@ async function runProjectCodemod({name, transform}, {apply, root, log}) {
|
|
|
240
276
|
}
|
|
241
277
|
return {
|
|
242
278
|
filesChanged: 0,
|
|
279
|
+
changedFiles: [],
|
|
243
280
|
writtenFiles: [],
|
|
281
|
+
protectedFiles: [],
|
|
244
282
|
errors: plan.problems.map(({file, message}) => ({
|
|
245
283
|
file,
|
|
246
284
|
codemod: name,
|
|
@@ -248,9 +286,93 @@ async function runProjectCodemod({name, transform}, {apply, root, log}) {
|
|
|
248
286
|
})),
|
|
249
287
|
};
|
|
250
288
|
}
|
|
289
|
+
|
|
290
|
+
const candidates = [
|
|
291
|
+
...plan.writes.map(write => ({
|
|
292
|
+
file: write.path,
|
|
293
|
+
existing: fs.existsSync(write.path),
|
|
294
|
+
})),
|
|
295
|
+
...plan.deletes.map(file => ({file, existing: true})),
|
|
296
|
+
];
|
|
297
|
+
/** @param {{file: string, existing: boolean}} candidate */
|
|
298
|
+
const currentDeclarations = candidate =>
|
|
299
|
+
protection
|
|
300
|
+
.classify(candidate.file)
|
|
301
|
+
.filter(
|
|
302
|
+
item =>
|
|
303
|
+
candidate.existing ||
|
|
304
|
+
['outside-root', 'dependency', 'vcs', 'symlink'].includes(
|
|
305
|
+
item.reason,
|
|
306
|
+
),
|
|
307
|
+
);
|
|
308
|
+
const currentlyBlocked = new Set(
|
|
309
|
+
candidates
|
|
310
|
+
.filter(candidate => currentDeclarations(candidate).length > 0)
|
|
311
|
+
.map(candidate => candidate.file),
|
|
312
|
+
);
|
|
313
|
+
/** @type {Map<string, string|null>} */
|
|
314
|
+
const stagedOverrides = new Map();
|
|
315
|
+
for (const write of plan.writes) {
|
|
316
|
+
if (!currentlyBlocked.has(write.path)) {
|
|
317
|
+
stagedOverrides.set(write.path, write.contents);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for (const file of plan.deletes) {
|
|
321
|
+
if (!currentlyBlocked.has(file)) stagedOverrides.set(file, null);
|
|
322
|
+
}
|
|
323
|
+
// A plan cannot introduce a protection declaration and then overwrite the
|
|
324
|
+
// file it protects in the same transaction. Only declarations whose own
|
|
325
|
+
// writes are allowed participate in the staged view.
|
|
326
|
+
const stagedProtection = createFileProtectionResolver(root, {
|
|
327
|
+
overrides: stagedOverrides,
|
|
328
|
+
});
|
|
329
|
+
/** @type {import('../../authoring/codemod/type').CodemodRunResult['protectedFiles']} */
|
|
330
|
+
const protectedFiles = [];
|
|
331
|
+
const blocked = new Set();
|
|
332
|
+
for (const candidate of candidates) {
|
|
333
|
+
const file = candidate.file;
|
|
334
|
+
const declarations = [
|
|
335
|
+
...currentDeclarations(candidate),
|
|
336
|
+
...stagedProtection.classify(file),
|
|
337
|
+
]
|
|
338
|
+
.filter(
|
|
339
|
+
item =>
|
|
340
|
+
candidate.existing ||
|
|
341
|
+
['outside-root', 'dependency', 'vcs', 'symlink'].includes(
|
|
342
|
+
item.reason,
|
|
343
|
+
),
|
|
344
|
+
)
|
|
345
|
+
.filter(
|
|
346
|
+
(item, index, all) =>
|
|
347
|
+
all.findIndex(
|
|
348
|
+
candidate =>
|
|
349
|
+
candidate.file === item.file &&
|
|
350
|
+
candidate.reason === item.reason &&
|
|
351
|
+
candidate.declaration === item.declaration,
|
|
352
|
+
) === index,
|
|
353
|
+
);
|
|
354
|
+
if (declarations.length === 0) continue;
|
|
355
|
+
blocked.add(file);
|
|
356
|
+
const rows = declarations.map(item => ({
|
|
357
|
+
file: item.file,
|
|
358
|
+
codemod: name,
|
|
359
|
+
reason: item.reason,
|
|
360
|
+
declaration: item.declaration,
|
|
361
|
+
generated: item.reason === 'generated',
|
|
362
|
+
...(item.command ? {command: item.command} : {}),
|
|
363
|
+
}));
|
|
364
|
+
protectedFiles.push(...rows);
|
|
365
|
+
log.warn(
|
|
366
|
+
` ! ${rel(file)} — protected by ${rows.map(item => item.declaration).join('; ')}`,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const writes = plan.writes.filter(write => !blocked.has(write.path));
|
|
371
|
+
const deletes = plan.deletes.filter(file => !blocked.has(file));
|
|
372
|
+
const changedFiles = [...writes.map(write => write.path), ...deletes];
|
|
251
373
|
/** @type {string[]} */
|
|
252
374
|
const writtenFiles = [];
|
|
253
|
-
for (const write of
|
|
375
|
+
for (const write of writes) {
|
|
254
376
|
if (apply) {
|
|
255
377
|
fs.mkdirSync(path.dirname(write.path), {recursive: true});
|
|
256
378
|
fs.writeFileSync(write.path, write.contents, 'utf-8');
|
|
@@ -261,7 +383,7 @@ async function runProjectCodemod({name, transform}, {apply, root, log}) {
|
|
|
261
383
|
}
|
|
262
384
|
}
|
|
263
385
|
// Deletions go last, so a failed write leaves a state a rerun completes.
|
|
264
|
-
for (const file of
|
|
386
|
+
for (const file of deletes) {
|
|
265
387
|
if (apply) {
|
|
266
388
|
fs.rmSync(file);
|
|
267
389
|
writtenFiles.push(file);
|
|
@@ -270,9 +392,16 @@ async function runProjectCodemod({name, transform}, {apply, root, log}) {
|
|
|
270
392
|
log.warn(` ~ ${rel(file)} (would remove)`);
|
|
271
393
|
}
|
|
272
394
|
}
|
|
395
|
+
/** @type {Map<string, string|null>} */
|
|
396
|
+
const appliedOverrides = new Map();
|
|
397
|
+
for (const write of writes) appliedOverrides.set(write.path, write.contents);
|
|
398
|
+
for (const file of deletes) appliedOverrides.set(file, null);
|
|
273
399
|
return {
|
|
274
|
-
filesChanged:
|
|
400
|
+
filesChanged: changedFiles.length,
|
|
401
|
+
changedFiles,
|
|
275
402
|
writtenFiles,
|
|
403
|
+
protectedFiles,
|
|
404
|
+
stagedOverrides: appliedOverrides,
|
|
276
405
|
errors: [],
|
|
277
406
|
};
|
|
278
407
|
}
|
|
@@ -288,7 +417,8 @@ async function runProjectCodemod({name, transform}, {apply, root, log}) {
|
|
|
288
417
|
* @param {Set<string>} [options.skipCodemods] - Transform names to exclude
|
|
289
418
|
* @param {boolean} [options.silent] - Suppress all human-facing output (for --json)
|
|
290
419
|
* @param {string} [options.root] - Project root a project codemod reads (default: the process cwd)
|
|
291
|
-
* @
|
|
420
|
+
* @param {{root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}} [options.protection] - Preloaded protection resolver
|
|
421
|
+
* @returns {Promise<{totalFilesChanged: number, totalTransformsApplied: number, totalValidationBlocked: number, changedFiles: string[], writtenFiles: string[], stagedContents: Map<string, string>, protectedFiles: import('../../authoring/codemod/type').CodemodRunResult['protectedFiles'], errors: Array<{file: string, codemod: string, error: string}>, skippedOptional: Array<{name: string, meta: {title: string, description?: string, fileExtensions?: string[], codemodType?: string}, version: string}>} | {ok: false, reason: string, resolvedPath: string}>}
|
|
292
422
|
*/
|
|
293
423
|
export async function runCodemods(
|
|
294
424
|
versionManifests,
|
|
@@ -299,6 +429,7 @@ export async function runCodemods(
|
|
|
299
429
|
skipCodemods,
|
|
300
430
|
silent = false,
|
|
301
431
|
root = process.cwd(),
|
|
432
|
+
protection: providedProtection,
|
|
302
433
|
},
|
|
303
434
|
) {
|
|
304
435
|
// No-op stub object so silent mode skips log output entirely without
|
|
@@ -311,6 +442,13 @@ export async function runCodemods(
|
|
|
311
442
|
};
|
|
312
443
|
|
|
313
444
|
const resolvedPath = path.resolve(srcPath);
|
|
445
|
+
// Eager construction is the fail-closed barrier: every working-tree
|
|
446
|
+
// declaration is read and parsed before the first codemod can write.
|
|
447
|
+
let protection =
|
|
448
|
+
providedProtection ?? createFileProtectionResolver(path.resolve(root));
|
|
449
|
+
/** @type {Map<string, string|null>} */
|
|
450
|
+
const protectionOverrides = new Map();
|
|
451
|
+
let protectionWriteCount = 0;
|
|
314
452
|
|
|
315
453
|
// Config and project codemods never read the files under --path, so a
|
|
316
454
|
// missing --path should not block them. Only hard-fail on a missing source
|
|
@@ -353,8 +491,14 @@ export async function runCodemods(
|
|
|
353
491
|
let totalValidationBlocked = 0;
|
|
354
492
|
/** @type {Array<{file: string, codemod: string, error: string}>} */
|
|
355
493
|
const errors = [];
|
|
494
|
+
/** In-memory pipeline state keeps ordered dry-runs equivalent to apply. */
|
|
495
|
+
const virtualContents = new Map();
|
|
496
|
+
/** @type {string[]} */
|
|
497
|
+
const changedFiles = [];
|
|
356
498
|
/** @type {string[]} */
|
|
357
499
|
const writtenFiles = [];
|
|
500
|
+
/** @type {import('../../authoring/codemod/type').CodemodRunResult['protectedFiles']} */
|
|
501
|
+
const protectedFiles = [];
|
|
358
502
|
/** @type {Array<{name: string, meta: {title: string, description?: string, fileExtensions?: string[], codemodType?: string}, version: string}>} */
|
|
359
503
|
const skippedOptional = [];
|
|
360
504
|
for (const {version, transforms} of versionManifests) {
|
|
@@ -366,10 +510,7 @@ export async function runCodemods(
|
|
|
366
510
|
// Exclude explicitly skipped codemods (by transform name).
|
|
367
511
|
if (skipCodemods?.has(transformEntry.name)) continue;
|
|
368
512
|
|
|
369
|
-
const {name,
|
|
370
|
-
const transformExtensions = new Set(
|
|
371
|
-
meta.fileExtensions ?? ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs'],
|
|
372
|
-
);
|
|
513
|
+
const {name, meta, optional} = transformEntry;
|
|
373
514
|
|
|
374
515
|
// Skip optional codemods unless explicitly requested via --codemod
|
|
375
516
|
if (optional && !codemod) {
|
|
@@ -377,6 +518,13 @@ export async function runCodemods(
|
|
|
377
518
|
continue;
|
|
378
519
|
}
|
|
379
520
|
|
|
521
|
+
if (apply && writtenFiles.length !== protectionWriteCount) {
|
|
522
|
+
protection = createFileProtectionResolver(path.resolve(root), {
|
|
523
|
+
overrides: protectionOverrides,
|
|
524
|
+
});
|
|
525
|
+
protectionWriteCount = writtenFiles.length;
|
|
526
|
+
}
|
|
527
|
+
|
|
380
528
|
log.info(` ${meta.title}`);
|
|
381
529
|
|
|
382
530
|
// Config codemods are routed through the SAME shared runner that
|
|
@@ -388,102 +536,74 @@ export async function runCodemods(
|
|
|
388
536
|
const result = await runProjectCodemod(transformEntry, {
|
|
389
537
|
apply,
|
|
390
538
|
root,
|
|
539
|
+
protection,
|
|
391
540
|
log,
|
|
392
541
|
});
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
542
|
+
errors.push(...result.errors);
|
|
543
|
+
protectedFiles.push(...result.protectedFiles);
|
|
544
|
+
changedFiles.push(...result.changedFiles);
|
|
545
|
+
writtenFiles.push(...result.writtenFiles);
|
|
546
|
+
if (result.stagedOverrides) {
|
|
547
|
+
for (const [file, contents] of result.stagedOverrides) {
|
|
548
|
+
protectionOverrides.set(file, contents);
|
|
549
|
+
if (contents !== null) virtualContents.set(file, contents);
|
|
550
|
+
}
|
|
551
|
+
protection = createFileProtectionResolver(path.resolve(root), {
|
|
552
|
+
overrides: protectionOverrides,
|
|
553
|
+
});
|
|
554
|
+
protectionWriteCount = writtenFiles.length;
|
|
555
|
+
}
|
|
556
|
+
if (result.filesChanged > 0) {
|
|
396
557
|
totalFilesChanged += result.filesChanged;
|
|
397
558
|
totalTransformsApplied += 1;
|
|
398
|
-
writtenFiles.push(...result.writtenFiles);
|
|
399
559
|
}
|
|
400
560
|
continue;
|
|
401
561
|
}
|
|
402
562
|
|
|
403
563
|
if (meta?.codemodType === 'config') {
|
|
404
|
-
const result = runConfigCodemod(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
564
|
+
const result = runConfigCodemod(
|
|
565
|
+
toUnifiedEntry(transformEntry, version),
|
|
566
|
+
{
|
|
567
|
+
apply,
|
|
568
|
+
log,
|
|
569
|
+
jscodeshift,
|
|
570
|
+
root,
|
|
571
|
+
protection,
|
|
572
|
+
contents: virtualContents,
|
|
573
|
+
},
|
|
574
|
+
);
|
|
575
|
+
errors.push(...result.errors);
|
|
576
|
+
protectedFiles.push(...result.protectedFiles);
|
|
577
|
+
changedFiles.push(...result.changedFiles);
|
|
578
|
+
writtenFiles.push(...result.writtenFiles);
|
|
579
|
+
if (result.filesChanged > 0) {
|
|
412
580
|
totalFilesChanged += result.filesChanged;
|
|
413
581
|
totalTransformsApplied += result.filesChanged;
|
|
414
|
-
writtenFiles.push(...result.writtenFiles);
|
|
415
582
|
}
|
|
416
583
|
continue;
|
|
417
584
|
}
|
|
418
585
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
report: () => {},
|
|
438
|
-
};
|
|
439
|
-
const file = {source, path: filePath};
|
|
440
|
-
|
|
441
|
-
let result = transform(file, api);
|
|
442
|
-
|
|
443
|
-
if (result != null && result !== source) {
|
|
444
|
-
// Fix known jscodeshift output corruption before validation
|
|
445
|
-
result = fixDirectiveCorruption(result);
|
|
446
|
-
|
|
447
|
-
// Validate output before writing
|
|
448
|
-
const validation = validateOutput(result, source, j, {
|
|
449
|
-
parse: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs'].includes(
|
|
450
|
-
ext,
|
|
451
|
-
),
|
|
452
|
-
});
|
|
453
|
-
if (!validation.valid) {
|
|
454
|
-
totalValidationBlocked++;
|
|
455
|
-
log.error(` ✗ ${relativePath} — ${validation.reason}`);
|
|
456
|
-
errors.push({
|
|
457
|
-
file: relativePath,
|
|
458
|
-
codemod: name,
|
|
459
|
-
error: validation.reason,
|
|
460
|
-
});
|
|
461
|
-
continue;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
filesChanged++;
|
|
465
|
-
totalFilesChanged++;
|
|
466
|
-
totalTransformsApplied++;
|
|
467
|
-
|
|
468
|
-
if (apply) {
|
|
469
|
-
fs.writeFileSync(filePath, result, 'utf-8');
|
|
470
|
-
writtenFiles.push(filePath);
|
|
471
|
-
log.success(` ✓ ${relativePath}`);
|
|
472
|
-
} else {
|
|
473
|
-
log.warn(` ~ ${relativePath} (would change)`);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
} catch (err) {
|
|
477
|
-
const message = /** @type {any} */ (err).message;
|
|
478
|
-
log.error(` ✗ ${relativePath} — ${message}`);
|
|
479
|
-
errors.push({file: relativePath, codemod: name, error: message});
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (filesChanged > 0) {
|
|
586
|
+
const result = runCodeCodemod(
|
|
587
|
+
toUnifiedEntry(transformEntry, version),
|
|
588
|
+
files,
|
|
589
|
+
{apply, log, jscodeshift, root, protection, contents: virtualContents},
|
|
590
|
+
);
|
|
591
|
+
errors.push(...result.errors);
|
|
592
|
+
protectedFiles.push(...result.protectedFiles);
|
|
593
|
+
changedFiles.push(...result.changedFiles);
|
|
594
|
+
writtenFiles.push(...result.writtenFiles);
|
|
595
|
+
totalFilesChanged += result.filesChanged;
|
|
596
|
+
totalTransformsApplied += result.filesChanged;
|
|
597
|
+
totalValidationBlocked += result.errors.filter(
|
|
598
|
+
error =>
|
|
599
|
+
error.error.startsWith('transform produced unparseable output') ||
|
|
600
|
+
error.error.startsWith('detected corruption:'),
|
|
601
|
+
).length;
|
|
602
|
+
|
|
603
|
+
if (result.filesChanged > 0) {
|
|
484
604
|
const verb = apply ? 'Updated' : 'Would update';
|
|
485
605
|
log.info(
|
|
486
|
-
` ${verb} ${filesChanged} file${filesChanged === 1 ? '' : 's'}`,
|
|
606
|
+
` ${verb} ${result.filesChanged} file${result.filesChanged === 1 ? '' : 's'}`,
|
|
487
607
|
);
|
|
488
608
|
}
|
|
489
609
|
}
|
|
@@ -510,8 +630,23 @@ export async function runCodemods(
|
|
|
510
630
|
);
|
|
511
631
|
}
|
|
512
632
|
|
|
513
|
-
if (
|
|
633
|
+
if (protectedFiles.length > 0) {
|
|
634
|
+
const files = [...new Set(protectedFiles.map(item => item.file))];
|
|
635
|
+
log.warn(
|
|
636
|
+
`${files.length} protected file${files.length === 1 ? '' : 's'} require${files.length === 1 ? 's' : ''} regeneration or manual review.`,
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (
|
|
641
|
+
totalFilesChanged === 0 &&
|
|
642
|
+
errors.length === 0 &&
|
|
643
|
+
protectedFiles.length === 0
|
|
644
|
+
) {
|
|
514
645
|
log.success('No changes needed — your code is already up to date!');
|
|
646
|
+
} else if (apply && protectedFiles.length > 0) {
|
|
647
|
+
log.warn(
|
|
648
|
+
`Applied ${totalTransformsApplied} owned change${totalTransformsApplied === 1 ? '' : 's'} across ${totalFilesChanged} file${totalFilesChanged === 1 ? '' : 's'}; protected changes remain.`,
|
|
649
|
+
);
|
|
515
650
|
} else if (apply) {
|
|
516
651
|
log.success(
|
|
517
652
|
`Done! Applied ${totalTransformsApplied} change${totalTransformsApplied === 1 ? '' : 's'} across ${totalFilesChanged} file${totalFilesChanged === 1 ? '' : 's'}.`,
|
|
@@ -548,7 +683,10 @@ export async function runCodemods(
|
|
|
548
683
|
totalFilesChanged,
|
|
549
684
|
totalTransformsApplied,
|
|
550
685
|
totalValidationBlocked,
|
|
686
|
+
changedFiles,
|
|
551
687
|
writtenFiles,
|
|
688
|
+
protectedFiles,
|
|
689
|
+
stagedContents: virtualContents,
|
|
552
690
|
errors,
|
|
553
691
|
skippedOptional,
|
|
554
692
|
};
|
package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../migrate-native-picker-to-presentation.mjs';
|
|
5
|
+
|
|
6
|
+
async function applyTransform(source) {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const j = jscodeshift.withParser('tsx');
|
|
9
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
10
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('migrate-native-picker-to-presentation', () => {
|
|
14
|
+
it('maps DateInput and DateTimeInput values (FR3)', async () => {
|
|
15
|
+
const output =
|
|
16
|
+
await applyTransform(`import {DateInput, DateTimeInput} from '@astryxdesign/core';
|
|
17
|
+
const a = <DateInput label="d" nativePicker="touch" />;
|
|
18
|
+
const b = <DateInput label="d" nativePicker="always" />;
|
|
19
|
+
const c = <DateTimeInput label="dt" nativePicker="never" />;`);
|
|
20
|
+
|
|
21
|
+
expect(output).toContain("presentation='adaptive-native'");
|
|
22
|
+
expect(output).toContain("presentation='native'");
|
|
23
|
+
expect(output).toContain("presentation='adaptive-bottom-sheet'");
|
|
24
|
+
expect(output).not.toContain('nativePicker');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('maps TimeInput never to text-input (FR3)', async () => {
|
|
28
|
+
const output =
|
|
29
|
+
await applyTransform(`import {TimeInput} from '@astryxdesign/core';
|
|
30
|
+
const a = <TimeInput label="t" nativePicker="never" />;
|
|
31
|
+
const b = <TimeInput label="t" nativePicker={'touch'} />;`);
|
|
32
|
+
|
|
33
|
+
expect(output).toContain("presentation='text-input'");
|
|
34
|
+
expect(output).toContain("presentation={'adaptive-native'}");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('drops nativePicker when presentation is already set (FR4)', async () => {
|
|
38
|
+
const output =
|
|
39
|
+
await applyTransform(`import {DateInput} from '@astryxdesign/core';
|
|
40
|
+
const a = <DateInput label="d" presentation="popover" nativePicker="always" />;`);
|
|
41
|
+
|
|
42
|
+
expect(output).toContain('presentation="popover"');
|
|
43
|
+
expect(output).not.toContain('nativePicker');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('leaves dynamic values and unrelated components unchanged', async () => {
|
|
47
|
+
const source = `import {DateInput, Selector} from '@astryxdesign/core';
|
|
48
|
+
const a = <DateInput label="d" nativePicker={mode} />;
|
|
49
|
+
const b = <Selector nativePicker="never" />;`;
|
|
50
|
+
expect(await applyTransform(source)).toBe(source);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('leaves a mixed static/dynamic conditional byte-identical when a sibling migrates', async () => {
|
|
54
|
+
const output =
|
|
55
|
+
await applyTransform(`import {TimeInput} from '@astryxdesign/core';
|
|
56
|
+
const a = <TimeInput label="t" nativePicker="touch" />;
|
|
57
|
+
const b = <TimeInput label="t" nativePicker={flag ? 'always' : mode} />;`);
|
|
58
|
+
|
|
59
|
+
expect(output).toContain("presentation='adaptive-native'");
|
|
60
|
+
expect(output).toContain("nativePicker={flag ? 'always' : mode}");
|
|
61
|
+
expect(output).not.toContain("'native'");
|
|
62
|
+
});
|
|
63
|
+
});
|
package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs
CHANGED
|
@@ -81,6 +81,7 @@ describe('migrate-theme-catalog-to-descriptors', () => {
|
|
|
81
81
|
it('is staged for the next release as a project codemod', () => {
|
|
82
82
|
expect(manifest.map(t => [t.name, t.meta.codemodType])).toEqual([
|
|
83
83
|
['migrate-theme-catalog-to-descriptors', 'project'],
|
|
84
|
+
['migrate-native-picker-to-presentation', undefined],
|
|
84
85
|
]);
|
|
85
86
|
});
|
|
86
87
|
|
|
@@ -135,6 +136,9 @@ describe('migrate-theme-catalog-to-descriptors', () => {
|
|
|
135
136
|
|
|
136
137
|
it('previews without writing, even with no source folder', async () => {
|
|
137
138
|
writeKit([entry('ocean')]);
|
|
139
|
+
// A staged code codemod (migrate-native-picker-to-presentation) requires
|
|
140
|
+
// the source folder to exist; an empty one exercises the same preview.
|
|
141
|
+
fs.mkdirSync(path.join(root, 'src'), {recursive: true});
|
|
138
142
|
|
|
139
143
|
const result = await run(false, path.join(root, 'src'));
|
|
140
144
|
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
import migrateThemeCatalogToDescriptors, {
|
|
11
11
|
meta as migrateThemeCatalogToDescriptorsMeta,
|
|
12
12
|
} from './migrate-theme-catalog-to-descriptors.mjs';
|
|
13
|
+
import migrateNativePickerToPresentation, {
|
|
14
|
+
meta as migrateNativePickerToPresentationMeta,
|
|
15
|
+
} from './migrate-native-picker-to-presentation.mjs';
|
|
13
16
|
|
|
14
17
|
export default [
|
|
15
18
|
{
|
|
@@ -17,4 +20,9 @@ export default [
|
|
|
17
20
|
transform: migrateThemeCatalogToDescriptors,
|
|
18
21
|
meta: migrateThemeCatalogToDescriptorsMeta,
|
|
19
22
|
},
|
|
23
|
+
{
|
|
24
|
+
name: 'migrate-native-picker-to-presentation',
|
|
25
|
+
transform: migrateNativePickerToPresentation,
|
|
26
|
+
meta: migrateNativePickerToPresentationMeta,
|
|
27
|
+
},
|
|
20
28
|
];
|