@wp-typia/project-tools 0.16.12 → 0.16.13
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/dist/runtime/block-generator-service-core.d.ts +8 -0
- package/dist/runtime/block-generator-service-core.js +274 -0
- package/dist/runtime/block-generator-service-spec.d.ts +104 -0
- package/dist/runtime/block-generator-service-spec.js +139 -0
- package/dist/runtime/block-generator-service.d.ts +2 -110
- package/dist/runtime/block-generator-service.js +2 -389
- package/dist/runtime/cli-diagnostics.js +76 -4
- package/dist/runtime/cli-doctor-workspace.d.ts +9 -5
- package/dist/runtime/cli-doctor-workspace.js +18 -6
- package/dist/runtime/cli-help.js +1 -1
- package/dist/runtime/cli-scaffold.d.ts +8 -1
- package/dist/runtime/cli-scaffold.js +47 -4
- package/dist/runtime/migration-maintenance-fixtures.d.ts +23 -0
- package/dist/runtime/migration-maintenance-fixtures.js +126 -0
- package/dist/runtime/migration-maintenance-verify.d.ts +26 -0
- package/dist/runtime/migration-maintenance-verify.js +262 -0
- package/dist/runtime/migration-maintenance.d.ts +2 -51
- package/dist/runtime/migration-maintenance.js +2 -380
- package/dist/runtime/migrations.d.ts +0 -3
- package/dist/runtime/scaffold-apply-utils.d.ts +9 -0
- package/dist/runtime/scaffold-apply-utils.js +27 -4
- package/dist/runtime/scaffold-onboarding.d.ts +12 -0
- package/dist/runtime/scaffold-onboarding.js +42 -5
- package/dist/runtime/scaffold.js +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,29 @@ import { getPrimaryDevelopmentScript } from "./local-dev-presets.js";
|
|
|
6
6
|
import { getOptionalOnboardingNote, getOptionalOnboardingSteps, } from "./scaffold-onboarding.js";
|
|
7
7
|
import { OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE, isBuiltInTemplateId, } from "./template-registry.js";
|
|
8
8
|
import { resolveOptionalInteractiveExternalLayerId, } from "./external-layer-selection.js";
|
|
9
|
+
function validateCreateProjectInput(projectInput) {
|
|
10
|
+
const normalizedProjectInput = projectInput.trim();
|
|
11
|
+
if (normalizedProjectInput.length === 0) {
|
|
12
|
+
throw new Error("Project directory is required. Usage: wp-typia create <project-dir> (or wp-typia <project-dir> when <project-dir> is the only positional argument).");
|
|
13
|
+
}
|
|
14
|
+
const normalizedProjectPath = path.normalize(normalizedProjectInput).replace(/[\\/]+$/u, "") ||
|
|
15
|
+
path.normalize(normalizedProjectInput);
|
|
16
|
+
if (normalizedProjectPath === "." || normalizedProjectPath === "..") {
|
|
17
|
+
throw new Error("`wp-typia create` requires a new project directory. Use an explicit child directory instead of `.` or `..`.");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function collectProjectDirectoryWarnings(projectDir) {
|
|
21
|
+
const warnings = [];
|
|
22
|
+
const projectName = path.basename(projectDir);
|
|
23
|
+
if (/\s/u.test(projectName)) {
|
|
24
|
+
warnings.push(`Project directory "${projectName}" contains spaces. The generated next-step commands will be quoted, but a simple kebab-case directory name is usually easier to use with shells and downstream tooling.`);
|
|
25
|
+
}
|
|
26
|
+
const shellSensitiveCharacters = Array.from(new Set(projectName.match(/[^A-Za-z0-9._ -]/gu) ?? []));
|
|
27
|
+
if (shellSensitiveCharacters.length > 0) {
|
|
28
|
+
warnings.push(`Project directory "${projectName}" contains shell-sensitive characters (${shellSensitiveCharacters.join(", ")}). Prefer letters, numbers, ".", "_" and "-" when possible.`);
|
|
29
|
+
}
|
|
30
|
+
return warnings;
|
|
31
|
+
}
|
|
9
32
|
function templateUsesPersistenceSettings(templateId, options) {
|
|
10
33
|
if (templateId === "persistence") {
|
|
11
34
|
return true;
|
|
@@ -15,6 +38,19 @@ function templateUsesPersistenceSettings(templateId, options) {
|
|
|
15
38
|
}
|
|
16
39
|
return Boolean(options.dataStorageMode || options.persistencePolicy);
|
|
17
40
|
}
|
|
41
|
+
function templateSupportsPersistenceFlags(templateId) {
|
|
42
|
+
return templateId === "persistence" || templateId === "compound";
|
|
43
|
+
}
|
|
44
|
+
function validateCreateFlagContract(options) {
|
|
45
|
+
const { dataStorageMode, persistencePolicy, templateId, variant } = options;
|
|
46
|
+
if ((dataStorageMode || persistencePolicy) &&
|
|
47
|
+
!templateSupportsPersistenceFlags(templateId)) {
|
|
48
|
+
throw new Error("`--data-storage` and `--persistence-policy` are supported only for `wp-typia create --template persistence` or `--template compound`.");
|
|
49
|
+
}
|
|
50
|
+
if (variant && isBuiltInTemplateId(templateId)) {
|
|
51
|
+
throw new Error(`--variant is only supported for official external template configs. Received variant "${variant}" for built-in template "${templateId}".`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
18
54
|
function parseSelectableValue(label, value, isValue, allowedValues) {
|
|
19
55
|
if (isValue(value)) {
|
|
20
56
|
return value;
|
|
@@ -107,15 +143,19 @@ export async function runScaffoldFlow({ projectInput, cwd = process.cwd(), templ
|
|
|
107
143
|
externalLayerSource.trim().length > 0
|
|
108
144
|
? externalLayerSource.trim()
|
|
109
145
|
: undefined;
|
|
110
|
-
|
|
111
|
-
throw new Error("Project directory is required. Usage: wp-typia create <project-dir> (or wp-typia <project-dir> when <project-dir> is the only positional argument).");
|
|
112
|
-
}
|
|
146
|
+
validateCreateProjectInput(projectInput);
|
|
113
147
|
const resolvedTemplateId = await resolveTemplateId({
|
|
114
148
|
templateId,
|
|
115
149
|
yes,
|
|
116
150
|
isInteractive,
|
|
117
151
|
selectTemplate,
|
|
118
152
|
});
|
|
153
|
+
validateCreateFlagContract({
|
|
154
|
+
dataStorageMode,
|
|
155
|
+
persistencePolicy,
|
|
156
|
+
templateId: resolvedTemplateId,
|
|
157
|
+
variant,
|
|
158
|
+
});
|
|
119
159
|
const resolvedExternalLayerSelection = isBuiltInTemplateId(resolvedTemplateId) && isInteractive
|
|
120
160
|
? await resolveOptionalInteractiveExternalLayerId({
|
|
121
161
|
callerCwd: cwd,
|
|
@@ -237,7 +277,6 @@ export async function runScaffoldFlow({ projectInput, cwd = process.cwd(), templ
|
|
|
237
277
|
projectDir,
|
|
238
278
|
projectInput,
|
|
239
279
|
packageManager: resolvedPackageManager,
|
|
240
|
-
result,
|
|
241
280
|
nextSteps: getNextSteps({
|
|
242
281
|
projectInput,
|
|
243
282
|
projectDir,
|
|
@@ -245,6 +284,10 @@ export async function runScaffoldFlow({ projectInput, cwd = process.cwd(), templ
|
|
|
245
284
|
noInstall,
|
|
246
285
|
templateId: resolvedTemplateId,
|
|
247
286
|
}),
|
|
287
|
+
result: {
|
|
288
|
+
...result,
|
|
289
|
+
warnings: [...result.warnings, ...collectProjectDirectoryWarnings(projectDir)],
|
|
290
|
+
},
|
|
248
291
|
};
|
|
249
292
|
}
|
|
250
293
|
finally {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FixturesOptions, FuzzOptions } from './migration-command-surface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate or refresh migration fixtures for one or more legacy edges.
|
|
4
|
+
*
|
|
5
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
6
|
+
* @param options Fixture generation scope and refresh options.
|
|
7
|
+
* @returns Generated and skipped legacy versions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fixturesProjectMigrations(projectDir: string, { all, confirmOverwrite, force, fromMigrationVersion, isInteractive, renderLine, toMigrationVersion, }?: FixturesOptions): {
|
|
10
|
+
generatedVersions: string[];
|
|
11
|
+
skippedVersions: string[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Run seeded migration fuzz verification against generated fuzz artifacts.
|
|
15
|
+
*
|
|
16
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
17
|
+
* @param options Fuzz scope, iteration count, seed, and console rendering options.
|
|
18
|
+
* @returns Fuzzed legacy versions and the effective seed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fuzzProjectMigrations(projectDir: string, { all, fromMigrationVersion, iterations, renderLine, seed, }?: FuzzOptions): {
|
|
21
|
+
fuzzedVersions: string[];
|
|
22
|
+
seed: number | undefined;
|
|
23
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { createMigrationDiff } from './migration-diff.js';
|
|
5
|
+
import { ensureEdgeFixtureFile, } from './migration-fixtures.js';
|
|
6
|
+
import { collectFixtureTargets, formatScaffoldCommand, getSelectedEntriesByBlock, isLegacySingleBlockProject, resolveLegacyVersions, } from './migration-planning.js';
|
|
7
|
+
import { assertRuleHasNoTodos, getGeneratedDirForBlock, loadMigrationProject, } from './migration-project.js';
|
|
8
|
+
import { getLocalTsxBinary, isInteractiveTerminal, resolveTargetMigrationVersion, } from './migration-utils.js';
|
|
9
|
+
/**
|
|
10
|
+
* Generate or refresh migration fixtures for one or more legacy edges.
|
|
11
|
+
*
|
|
12
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
13
|
+
* @param options Fixture generation scope and refresh options.
|
|
14
|
+
* @returns Generated and skipped legacy versions.
|
|
15
|
+
*/
|
|
16
|
+
export function fixturesProjectMigrations(projectDir, { all = false, confirmOverwrite, force = false, fromMigrationVersion, isInteractive = isInteractiveTerminal(), renderLine = console.log, toMigrationVersion = 'current', } = {}) {
|
|
17
|
+
const state = loadMigrationProject(projectDir);
|
|
18
|
+
const targetMigrationVersion = resolveTargetMigrationVersion(state.config.currentMigrationVersion, toMigrationVersion);
|
|
19
|
+
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
20
|
+
if (targetVersions.length === 0) {
|
|
21
|
+
renderLine('No legacy migration versions configured for fixture generation.');
|
|
22
|
+
return { generatedVersions: [], skippedVersions: [] };
|
|
23
|
+
}
|
|
24
|
+
const generatedVersions = [];
|
|
25
|
+
const skippedVersions = [];
|
|
26
|
+
const fixtureTargets = collectFixtureTargets(state, targetVersions, targetMigrationVersion);
|
|
27
|
+
if (force) {
|
|
28
|
+
const overwriteTargets = fixtureTargets.filter(({ fixturePath }) => fs.existsSync(fixturePath));
|
|
29
|
+
if (isInteractive && overwriteTargets.length > 0) {
|
|
30
|
+
const confirmed = confirmOverwrite?.(`About to overwrite ${overwriteTargets.length} existing migration fixture file(s). Continue?`) ??
|
|
31
|
+
promptForConfirmation(`About to overwrite ${overwriteTargets.length} existing migration fixture file(s). Continue?`);
|
|
32
|
+
if (!confirmed) {
|
|
33
|
+
renderLine(`Cancelled fixture refresh. Kept ${overwriteTargets.length} existing fixture file(s).`);
|
|
34
|
+
return {
|
|
35
|
+
generatedVersions,
|
|
36
|
+
skippedVersions: overwriteTargets.map(({ scopedLabel }) => scopedLabel),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const { block, fixturePath, scopedLabel, version } of fixtureTargets) {
|
|
42
|
+
const existed = fs.existsSync(fixturePath);
|
|
43
|
+
const diff = createMigrationDiff(state, block, version, targetMigrationVersion);
|
|
44
|
+
const result = ensureEdgeFixtureFile(projectDir, block, version, targetMigrationVersion, diff, { force });
|
|
45
|
+
if (result.written) {
|
|
46
|
+
generatedVersions.push(scopedLabel);
|
|
47
|
+
renderLine(`${existed ? 'Refreshed' : 'Generated'} fixture ${path.relative(projectDir, fixturePath)}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
skippedVersions.push(scopedLabel);
|
|
51
|
+
renderLine(`Preserved existing fixture ${path.relative(projectDir, fixturePath)} (use --force to refresh)`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
generatedVersions,
|
|
56
|
+
skippedVersions,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Run seeded migration fuzz verification against generated fuzz artifacts.
|
|
61
|
+
*
|
|
62
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
63
|
+
* @param options Fuzz scope, iteration count, seed, and console rendering options.
|
|
64
|
+
* @returns Fuzzed legacy versions and the effective seed.
|
|
65
|
+
*/
|
|
66
|
+
export function fuzzProjectMigrations(projectDir, { all = false, fromMigrationVersion, iterations = 25, renderLine = console.log, seed, } = {}) {
|
|
67
|
+
const state = loadMigrationProject(projectDir);
|
|
68
|
+
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
69
|
+
const blockEntries = getSelectedEntriesByBlock(state, targetVersions, 'fuzz');
|
|
70
|
+
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
71
|
+
if (targetVersions.length === 0) {
|
|
72
|
+
renderLine('No legacy migration versions configured for fuzzing.');
|
|
73
|
+
return { fuzzedVersions: [], seed };
|
|
74
|
+
}
|
|
75
|
+
const tsxBinary = getLocalTsxBinary(projectDir);
|
|
76
|
+
for (const [blockKey, entries] of Object.entries(blockEntries)) {
|
|
77
|
+
const block = state.blocks.find((entry) => entry.key === blockKey);
|
|
78
|
+
if (!block || entries.length === 0) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
for (const entry of entries) {
|
|
82
|
+
assertRuleHasNoTodos(projectDir, block, entry.fromVersion, state.config.currentMigrationVersion);
|
|
83
|
+
}
|
|
84
|
+
const fuzzScriptPath = path.join(getGeneratedDirForBlock(state.paths, block), 'fuzz.ts');
|
|
85
|
+
if (!fs.existsSync(fuzzScriptPath)) {
|
|
86
|
+
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
87
|
+
throw new Error(`Generated fuzz script is missing for ${block.blockName} (${selectedVersionsForBlock.join(', ')}). ` +
|
|
88
|
+
`Run \`${formatScaffoldCommand(selectedVersionsForBlock)}\` first, then \`wp-typia migrate doctor --all\` if the workspace should already be scaffolded.`);
|
|
89
|
+
}
|
|
90
|
+
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
91
|
+
const args = [
|
|
92
|
+
fuzzScriptPath,
|
|
93
|
+
...(all ? ['--all'] : ['--from-migration-version', selectedVersionsForBlock[0]]),
|
|
94
|
+
'--iterations',
|
|
95
|
+
String(iterations),
|
|
96
|
+
...(seed === undefined ? [] : ['--seed', String(seed)]),
|
|
97
|
+
];
|
|
98
|
+
execFileSync(tsxBinary, args, {
|
|
99
|
+
cwd: projectDir,
|
|
100
|
+
shell: process.platform === 'win32',
|
|
101
|
+
stdio: 'inherit',
|
|
102
|
+
});
|
|
103
|
+
renderLine(legacySingleBlock
|
|
104
|
+
? `Fuzzed migrations for ${selectedVersionsForBlock.join(', ')}`
|
|
105
|
+
: `Fuzzed ${block.blockName} migrations for ${selectedVersionsForBlock.join(', ')}`);
|
|
106
|
+
}
|
|
107
|
+
return { fuzzedVersions: targetVersions, seed };
|
|
108
|
+
}
|
|
109
|
+
function promptForConfirmation(message) {
|
|
110
|
+
process.stdout.write(`${message} [y/N]: `);
|
|
111
|
+
const buffer = Buffer.alloc(1);
|
|
112
|
+
let answer = '';
|
|
113
|
+
while (true) {
|
|
114
|
+
const bytesRead = fs.readSync(process.stdin.fd, buffer, 0, 1, null);
|
|
115
|
+
if (bytesRead === 0) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const char = buffer.toString('utf8', 0, bytesRead);
|
|
119
|
+
if (char === '\n' || char === '\r') {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
answer += char;
|
|
123
|
+
}
|
|
124
|
+
const normalized = answer.trim().toLowerCase();
|
|
125
|
+
return normalized === 'y' || normalized === 'yes';
|
|
126
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { VerifyOptions } from './migration-command-surface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Run deterministic migration verification against generated fixtures.
|
|
4
|
+
*
|
|
5
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
6
|
+
* @param options Verification scope and console rendering options.
|
|
7
|
+
* @returns Verified legacy versions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function verifyProjectMigrations(projectDir: string, { all, fromMigrationVersion, renderLine, }?: VerifyOptions): {
|
|
10
|
+
verifiedVersions: string[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Validate the migration workspace without mutating files.
|
|
14
|
+
*
|
|
15
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
16
|
+
* @param options Doctor scope and console rendering options.
|
|
17
|
+
* @returns Structured doctor check results for the selected legacy versions.
|
|
18
|
+
*/
|
|
19
|
+
export declare function doctorProjectMigrations(projectDir: string, { all, fromMigrationVersion, renderLine, }?: VerifyOptions): {
|
|
20
|
+
checkedVersions: string[];
|
|
21
|
+
checks: {
|
|
22
|
+
detail: string;
|
|
23
|
+
label: string;
|
|
24
|
+
status: "fail" | "pass";
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { ROOT_PHP_MIGRATION_REGISTRY, } from './migration-constants.js';
|
|
5
|
+
import { createMigrationDiff } from './migration-diff.js';
|
|
6
|
+
import { createEdgeFixtureDocument, } from './migration-fixtures.js';
|
|
7
|
+
import { collectGeneratedMigrationEntries, } from './migration-generated-artifacts.js';
|
|
8
|
+
import { formatScaffoldCommand, getSelectedEntriesByBlock, hasSnapshotForVersion, isLegacySingleBlockProject, isSnapshotOptionalForBlockVersion, resolveLegacyVersions, } from './migration-planning.js';
|
|
9
|
+
import { assertRuleHasNoTodos, getFixtureFilePath, getGeneratedDirForBlock, getRuleFilePath, getSnapshotBlockJsonPath, getSnapshotManifestPath, getSnapshotRoot, getSnapshotSavePath, loadMigrationProject, readRuleMetadata, } from './migration-project.js';
|
|
10
|
+
import { renderFuzzFile, renderGeneratedDeprecatedFile, renderGeneratedMigrationIndexFile, renderMigrationRegistryFile, renderPhpMigrationRegistryFile, renderVerifyFile, } from './migration-render.js';
|
|
11
|
+
import { createMigrationRiskSummary, formatMigrationRiskSummary, } from './migration-risk.js';
|
|
12
|
+
import { getLocalTsxBinary, readJson, } from './migration-utils.js';
|
|
13
|
+
import { readWorkspaceInventory } from './workspace-inventory.js';
|
|
14
|
+
import { getInvalidWorkspaceProjectReason, tryResolveWorkspaceProject, } from './workspace-project.js';
|
|
15
|
+
/**
|
|
16
|
+
* Run deterministic migration verification against generated fixtures.
|
|
17
|
+
*
|
|
18
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
19
|
+
* @param options Verification scope and console rendering options.
|
|
20
|
+
* @returns Verified legacy versions.
|
|
21
|
+
*/
|
|
22
|
+
export function verifyProjectMigrations(projectDir, { all = false, fromMigrationVersion, renderLine = console.log, } = {}) {
|
|
23
|
+
const state = loadMigrationProject(projectDir);
|
|
24
|
+
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
25
|
+
const blockEntries = getSelectedEntriesByBlock(state, targetVersions, 'verify');
|
|
26
|
+
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
27
|
+
if (targetVersions.length === 0) {
|
|
28
|
+
renderLine('No legacy migration versions configured for verification.');
|
|
29
|
+
return { verifiedVersions: [] };
|
|
30
|
+
}
|
|
31
|
+
const tsxBinary = getLocalTsxBinary(projectDir);
|
|
32
|
+
for (const [blockKey, entries] of Object.entries(blockEntries)) {
|
|
33
|
+
const block = state.blocks.find((entry) => entry.key === blockKey);
|
|
34
|
+
if (!block || entries.length === 0) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
assertRuleHasNoTodos(projectDir, block, entry.fromVersion, state.config.currentMigrationVersion);
|
|
39
|
+
}
|
|
40
|
+
const verifyScriptPath = path.join(getGeneratedDirForBlock(state.paths, block), 'verify.ts');
|
|
41
|
+
if (!fs.existsSync(verifyScriptPath)) {
|
|
42
|
+
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
43
|
+
throw new Error(`Generated verify script is missing for ${block.blockName} (${selectedVersionsForBlock.join(', ')}). ` +
|
|
44
|
+
`Run \`${formatScaffoldCommand(selectedVersionsForBlock)}\` first, then \`wp-typia migrate doctor --all\` if the workspace should already be scaffolded.`);
|
|
45
|
+
}
|
|
46
|
+
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
47
|
+
const filteredArgs = all
|
|
48
|
+
? ['--all']
|
|
49
|
+
: ['--from-migration-version', selectedVersionsForBlock[0]];
|
|
50
|
+
execFileSync(tsxBinary, [verifyScriptPath, ...filteredArgs], {
|
|
51
|
+
cwd: projectDir,
|
|
52
|
+
shell: process.platform === 'win32',
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
});
|
|
55
|
+
renderLine(legacySingleBlock
|
|
56
|
+
? `Verified migrations for ${selectedVersionsForBlock.join(', ')}`
|
|
57
|
+
: `Verified ${block.blockName} migrations for ${selectedVersionsForBlock.join(', ')}`);
|
|
58
|
+
}
|
|
59
|
+
return { verifiedVersions: targetVersions };
|
|
60
|
+
}
|
|
61
|
+
function recordWorkspaceMigrationTargetAlignment(projectDir, state, recordCheck) {
|
|
62
|
+
let invalidWorkspaceReason = null;
|
|
63
|
+
let workspace;
|
|
64
|
+
try {
|
|
65
|
+
invalidWorkspaceReason = getInvalidWorkspaceProjectReason(projectDir);
|
|
66
|
+
workspace = tryResolveWorkspaceProject(projectDir);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
recordCheck('fail', 'Workspace migration targets', error instanceof Error ? error.message : String(error));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!workspace) {
|
|
73
|
+
if (invalidWorkspaceReason) {
|
|
74
|
+
recordCheck('fail', 'Workspace migration targets', invalidWorkspaceReason);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
80
|
+
const expectedTargets = inventory.blocks.map((block) => `${workspace.workspace.namespace}/${block.slug}`);
|
|
81
|
+
const configuredTargets = state.blocks.map((block) => block.blockName);
|
|
82
|
+
const expectedTargetSet = new Set(expectedTargets);
|
|
83
|
+
const configuredTargetSet = new Set(configuredTargets);
|
|
84
|
+
const missingTargets = expectedTargets.filter((target) => !configuredTargetSet.has(target));
|
|
85
|
+
const staleTargets = configuredTargets.filter((target) => !expectedTargetSet.has(target));
|
|
86
|
+
recordCheck(missingTargets.length === 0 && staleTargets.length === 0 ? 'pass' : 'fail', 'Workspace migration targets', missingTargets.length === 0 && staleTargets.length === 0
|
|
87
|
+
? `${expectedTargets.length} workspace block target(s) align with migration config`
|
|
88
|
+
: [
|
|
89
|
+
missingTargets.length > 0
|
|
90
|
+
? `Missing from migration config: ${missingTargets.join(', ')}`
|
|
91
|
+
: null,
|
|
92
|
+
staleTargets.length > 0
|
|
93
|
+
? `Not present in scripts/block-config.ts: ${staleTargets.join(', ')}`
|
|
94
|
+
: null,
|
|
95
|
+
]
|
|
96
|
+
.filter((detail) => typeof detail === 'string')
|
|
97
|
+
.join('; '));
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
recordCheck('fail', 'Workspace migration targets', error instanceof Error ? error.message : String(error));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validate the migration workspace without mutating files.
|
|
105
|
+
*
|
|
106
|
+
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
107
|
+
* @param options Doctor scope and console rendering options.
|
|
108
|
+
* @returns Structured doctor check results for the selected legacy versions.
|
|
109
|
+
*/
|
|
110
|
+
export function doctorProjectMigrations(projectDir, { all = false, fromMigrationVersion, renderLine = console.log, } = {}) {
|
|
111
|
+
const checks = [];
|
|
112
|
+
const recordCheck = (status, label, detail) => {
|
|
113
|
+
checks.push({ detail, label, status });
|
|
114
|
+
renderLine(`${status === 'pass' ? 'PASS' : 'FAIL'} ${label}: ${detail}`);
|
|
115
|
+
};
|
|
116
|
+
let state;
|
|
117
|
+
try {
|
|
118
|
+
state = loadMigrationProject(projectDir);
|
|
119
|
+
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
120
|
+
recordCheck('pass', 'Migration config', legacySingleBlock
|
|
121
|
+
? `Loaded ${state.blocks[0]?.blockName} @ ${state.config.currentMigrationVersion}`
|
|
122
|
+
: `Loaded ${state.blocks.length} block target(s) @ ${state.config.currentMigrationVersion}`);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
recordCheck('fail', 'Migration config', error instanceof Error ? error.message : String(error));
|
|
126
|
+
throw new Error('Migration doctor failed.');
|
|
127
|
+
}
|
|
128
|
+
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
129
|
+
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
130
|
+
const snapshotVersions = new Set(targetVersions.length > 0
|
|
131
|
+
? [state.config.currentMigrationVersion, ...targetVersions]
|
|
132
|
+
: state.config.supportedMigrationVersions);
|
|
133
|
+
recordWorkspaceMigrationTargetAlignment(projectDir, state, recordCheck);
|
|
134
|
+
for (const version of snapshotVersions) {
|
|
135
|
+
for (const block of state.blocks) {
|
|
136
|
+
const snapshotRoot = getSnapshotRoot(projectDir, block, version);
|
|
137
|
+
const blockJsonPath = getSnapshotBlockJsonPath(projectDir, block, version);
|
|
138
|
+
const manifestPath = getSnapshotManifestPath(projectDir, block, version);
|
|
139
|
+
const savePath = getSnapshotSavePath(projectDir, block, version);
|
|
140
|
+
const hasSnapshot = fs.existsSync(snapshotRoot);
|
|
141
|
+
const snapshotIsOptional = !hasSnapshot && isSnapshotOptionalForBlockVersion(state, block, version);
|
|
142
|
+
recordCheck(hasSnapshot || snapshotIsOptional ? 'pass' : 'fail', legacySingleBlock ? `Snapshot ${version}` : `Snapshot ${block.blockName} @ ${version}`, hasSnapshot
|
|
143
|
+
? path.relative(projectDir, snapshotRoot)
|
|
144
|
+
: 'Not present for this version');
|
|
145
|
+
if (!hasSnapshot) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
for (const targetPath of [blockJsonPath, manifestPath, savePath]) {
|
|
149
|
+
recordCheck(fs.existsSync(targetPath) ? 'pass' : 'fail', legacySingleBlock
|
|
150
|
+
? `Snapshot file ${version}`
|
|
151
|
+
: `Snapshot file ${block.blockName} @ ${version}`, fs.existsSync(targetPath)
|
|
152
|
+
? path.relative(projectDir, targetPath)
|
|
153
|
+
: `Missing ${path.relative(projectDir, targetPath)}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const generatedEntries = collectGeneratedMigrationEntries(state);
|
|
159
|
+
const expectedGeneratedFiles = new Map();
|
|
160
|
+
for (const block of state.blocks) {
|
|
161
|
+
const blockGeneratedEntries = generatedEntries.filter(({ entry }) => entry.block.key === block.key);
|
|
162
|
+
const entries = blockGeneratedEntries.map(({ entry }) => entry);
|
|
163
|
+
const generatedDir = getGeneratedDirForBlock(state.paths, block);
|
|
164
|
+
expectedGeneratedFiles.set(path.join(generatedDir, 'registry.ts'), renderMigrationRegistryFile(state, block.key, blockGeneratedEntries));
|
|
165
|
+
expectedGeneratedFiles.set(path.join(generatedDir, 'deprecated.ts'), renderGeneratedDeprecatedFile(state, block.key, entries));
|
|
166
|
+
expectedGeneratedFiles.set(path.join(generatedDir, 'verify.ts'), renderVerifyFile(state, block.key, entries));
|
|
167
|
+
expectedGeneratedFiles.set(path.join(generatedDir, 'fuzz.ts'), renderFuzzFile(state, block.key, blockGeneratedEntries));
|
|
168
|
+
}
|
|
169
|
+
expectedGeneratedFiles.set(path.join(state.paths.generatedDir, 'index.ts'), renderGeneratedMigrationIndexFile(state, generatedEntries.map(({ entry }) => entry)));
|
|
170
|
+
expectedGeneratedFiles.set(path.join(projectDir, ROOT_PHP_MIGRATION_REGISTRY), renderPhpMigrationRegistryFile(state, generatedEntries.map(({ entry }) => entry)));
|
|
171
|
+
for (const [filePath, expectedSource] of expectedGeneratedFiles) {
|
|
172
|
+
const inSync = fs.existsSync(filePath) && fs.readFileSync(filePath, 'utf8') === expectedSource;
|
|
173
|
+
recordCheck(inSync ? 'pass' : 'fail', `Generated ${path.relative(projectDir, filePath)}`, inSync
|
|
174
|
+
? 'In sync'
|
|
175
|
+
: 'Run `wp-typia migrate scaffold --from-migration-version <label>` or regenerate artifacts');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
recordCheck('fail', 'Generated artifacts', error instanceof Error ? error.message : String(error));
|
|
180
|
+
}
|
|
181
|
+
for (const version of targetVersions) {
|
|
182
|
+
for (const block of state.blocks) {
|
|
183
|
+
if (!hasSnapshotForVersion(state, block, version)) {
|
|
184
|
+
recordCheck('pass', `Snapshot coverage ${block.blockName} @ ${version}`, 'Target not present for this version');
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const rulePath = getRuleFilePath(state.paths, block, version, state.config.currentMigrationVersion);
|
|
188
|
+
const fixturePath = getFixtureFilePath(state.paths, block, version, state.config.currentMigrationVersion);
|
|
189
|
+
recordCheck(fs.existsSync(rulePath) ? 'pass' : 'fail', legacySingleBlock ? `Rule ${version}` : `Rule ${block.blockName} @ ${version}`, fs.existsSync(rulePath)
|
|
190
|
+
? path.relative(projectDir, rulePath)
|
|
191
|
+
: `Missing ${path.relative(projectDir, rulePath)}`);
|
|
192
|
+
recordCheck(fs.existsSync(fixturePath) ? 'pass' : 'fail', legacySingleBlock ? `Fixture ${version}` : `Fixture ${block.blockName} @ ${version}`, fs.existsSync(fixturePath)
|
|
193
|
+
? path.relative(projectDir, fixturePath)
|
|
194
|
+
: `Missing ${path.relative(projectDir, fixturePath)}`);
|
|
195
|
+
if (!fs.existsSync(rulePath) || !fs.existsSync(fixturePath)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
assertRuleHasNoTodos(projectDir, block, version, state.config.currentMigrationVersion);
|
|
200
|
+
recordCheck('pass', legacySingleBlock
|
|
201
|
+
? `Rule TODOs ${version}`
|
|
202
|
+
: `Rule TODOs ${block.blockName} @ ${version}`, 'No TODO MIGRATION markers remain');
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
recordCheck('fail', legacySingleBlock
|
|
206
|
+
? `Rule TODOs ${version}`
|
|
207
|
+
: `Rule TODOs ${block.blockName} @ ${version}`, error instanceof Error ? error.message : String(error));
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const ruleMetadata = readRuleMetadata(rulePath);
|
|
211
|
+
recordCheck(ruleMetadata.unresolved.length === 0 ? 'pass' : 'fail', legacySingleBlock
|
|
212
|
+
? `Rule unresolved ${version}`
|
|
213
|
+
: `Rule unresolved ${block.blockName} @ ${version}`, ruleMetadata.unresolved.length === 0
|
|
214
|
+
? 'No unresolved entries remain'
|
|
215
|
+
: ruleMetadata.unresolved.join(', '));
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
recordCheck('fail', legacySingleBlock
|
|
219
|
+
? `Rule unresolved ${version}`
|
|
220
|
+
: `Rule unresolved ${block.blockName} @ ${version}`, error instanceof Error ? error.message : String(error));
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const fixtureDocument = readJson(fixturePath);
|
|
224
|
+
recordCheck(Array.isArray(fixtureDocument.cases) && fixtureDocument.cases.length > 0
|
|
225
|
+
? 'pass'
|
|
226
|
+
: 'fail', legacySingleBlock
|
|
227
|
+
? `Fixture parse ${version}`
|
|
228
|
+
: `Fixture parse ${block.blockName} @ ${version}`, Array.isArray(fixtureDocument.cases) && fixtureDocument.cases.length > 0
|
|
229
|
+
? `${fixtureDocument.cases.length} case(s)`
|
|
230
|
+
: 'Fixture document has no cases');
|
|
231
|
+
const diff = createMigrationDiff(state, block, version, state.config.currentMigrationVersion);
|
|
232
|
+
const expectedFixture = createEdgeFixtureDocument(projectDir, block, version, state.config.currentMigrationVersion, diff);
|
|
233
|
+
const actualCaseNames = new Set((fixtureDocument.cases ?? []).map((fixtureCase) => fixtureCase.name));
|
|
234
|
+
const missingCases = expectedFixture.cases
|
|
235
|
+
.map((fixtureCase) => fixtureCase.name)
|
|
236
|
+
.filter((name) => !actualCaseNames.has(name));
|
|
237
|
+
recordCheck(missingCases.length === 0 ? 'pass' : 'fail', legacySingleBlock
|
|
238
|
+
? `Fixture coverage ${version}`
|
|
239
|
+
: `Fixture coverage ${block.blockName} @ ${version}`, missingCases.length === 0
|
|
240
|
+
? 'All expected fixture cases are present'
|
|
241
|
+
: `Missing ${missingCases.join(', ')}`);
|
|
242
|
+
recordCheck('pass', legacySingleBlock
|
|
243
|
+
? `Risk summary ${version}`
|
|
244
|
+
: `Risk summary ${block.blockName} @ ${version}`, formatMigrationRiskSummary(createMigrationRiskSummary(diff)));
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
recordCheck('fail', legacySingleBlock
|
|
248
|
+
? `Fixture parse ${version}`
|
|
249
|
+
: `Fixture parse ${block.blockName} @ ${version}`, error instanceof Error ? error.message : String(error));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const failedChecks = checks.filter((check) => check.status === 'fail');
|
|
254
|
+
renderLine(`${failedChecks.length === 0 ? 'PASS' : 'FAIL'} Migration doctor summary: ${checks.length - failedChecks.length}/${checks.length} checks passed`);
|
|
255
|
+
if (failedChecks.length > 0) {
|
|
256
|
+
throw new Error('Migration doctor failed.');
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
checkedVersions: targetVersions,
|
|
260
|
+
checks,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Run deterministic migration verification against generated fixtures.
|
|
4
|
-
*
|
|
5
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
6
|
-
* @param options Verification scope and console rendering options.
|
|
7
|
-
* @returns Verified legacy versions.
|
|
8
|
-
*/
|
|
9
|
-
export declare function verifyProjectMigrations(projectDir: string, { all, fromMigrationVersion, renderLine, }?: VerifyOptions): {
|
|
10
|
-
verifiedVersions: string[];
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Validate the migration workspace without mutating files.
|
|
14
|
-
*
|
|
15
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
16
|
-
* @param options Doctor scope and console rendering options.
|
|
17
|
-
* @returns Structured doctor check results for the selected legacy versions.
|
|
18
|
-
*/
|
|
19
|
-
export declare function doctorProjectMigrations(projectDir: string, { all, fromMigrationVersion, renderLine, }?: VerifyOptions): {
|
|
20
|
-
checkedVersions: string[];
|
|
21
|
-
checks: {
|
|
22
|
-
detail: string;
|
|
23
|
-
label: string;
|
|
24
|
-
status: "fail" | "pass";
|
|
25
|
-
}[];
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Generate or refresh migration fixtures for one or more legacy edges.
|
|
29
|
-
*
|
|
30
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
31
|
-
* @param options Fixture generation scope and refresh options.
|
|
32
|
-
* @returns Generated and skipped legacy versions.
|
|
33
|
-
*/
|
|
34
|
-
export declare function fixturesProjectMigrations(projectDir: string, { all, confirmOverwrite, force, fromMigrationVersion, isInteractive, renderLine, toMigrationVersion, }?: FixturesOptions): {
|
|
35
|
-
generatedVersions: string[];
|
|
36
|
-
skippedVersions: string[];
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Run seeded migration fuzz verification against generated fuzz artifacts.
|
|
40
|
-
*
|
|
41
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
42
|
-
* @param options Fuzz scope, iteration count, seed, and console rendering options.
|
|
43
|
-
* @returns Fuzzed legacy versions and the effective seed.
|
|
44
|
-
*/
|
|
45
|
-
export declare function fuzzProjectMigrations(projectDir: string, { all, fromMigrationVersion, iterations, renderLine, seed, }?: FuzzOptions): {
|
|
46
|
-
fuzzedVersions: never[];
|
|
47
|
-
seed?: undefined;
|
|
48
|
-
} | {
|
|
49
|
-
fuzzedVersions: string[];
|
|
50
|
-
seed: number | undefined;
|
|
51
|
-
};
|
|
1
|
+
export * from './migration-maintenance-verify.js';
|
|
2
|
+
export * from './migration-maintenance-fixtures.js';
|