Skip to content

Commit 4e0ffcd

Browse files
committed
feat(tailwindcss-patch): publish restore result json schema
1 parent 1ed3b24 commit 4e0ffcd

7 files changed

Lines changed: 103 additions & 5 deletions

File tree

.changeset/tidy-kids-care.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"tailwindcss-patch": patch
3+
---
4+
5+
Publish JSON schema for restore and validate outputs.
6+
7+
- add `tailwindcss-patch/restore-result.schema.json` for `tw-patch restore --json` and `tw-patch validate --json`
8+
- expose the schema through package exports (source and publish configs)
9+
- add tests and docs to keep schema fields aligned with public report constants

packages/tailwindcss-patch/MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Migration mapping:
9393
- `tw-patch restore` validates report metadata when present, rejects unknown kinds/newer schema versions, and keeps legacy metadata-free reports backward compatible.
9494
- `tw-patch restore --json` now exposes report metadata fields (`reportKind`, `reportSchemaVersion`) when available for easier diagnostics.
9595
- `tw-patch validate` can validate migration report compatibility in dry-run mode without restoring files.
96-
- Migration report tooling now has public exports from package entry (`migrateConfigFiles`, `restoreConfigFiles`, report constants/types) and a published JSON schema subpath: `tailwindcss-patch/migration-report.schema.json`.
96+
- Migration report tooling now has public exports from package entry (`migrateConfigFiles`, `restoreConfigFiles`, report constants/types) and published JSON schema subpaths: `tailwindcss-patch/migration-report.schema.json`, `tailwindcss-patch/restore-result.schema.json`.
9797
- Commands resolve configuration from `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Existing configuration files continue to work without changes.
9898

9999
## 4. Cache handling

packages/tailwindcss-patch/README-cn.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ CLI 会通过 `@tailwindcss-mangle/config` 加载 `tailwindcss-patch.config.ts`
106106

107107
`tw-patch validate` 会以 dry-run 模式执行迁移报告校验,不写回任何恢复文件,同时校验报告 schema 与备份引用状态。
108108

109-
迁移报告 JSON Schema 通过子路径发布:`tailwindcss-patch/migration-report.schema.json`
109+
JSON Schema 通过子路径发布:
110+
`tailwindcss-patch/migration-report.schema.json`
111+
`tailwindcss-patch/restore-result.schema.json`
110112
编程场景也可直接从包入口导入报告相关导出:
111113
`migrateConfigFiles``restoreConfigFiles``MIGRATION_REPORT_KIND``MIGRATION_REPORT_SCHEMA_VERSION``ConfigFileMigrationReport`
112114

packages/tailwindcss-patch/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ With `--json`, restore output includes `reportKind` / `reportSchemaVersion` when
163163

164164
`tw-patch validate` performs migration report compatibility checks without writing restored files. It runs report schema validation and scans backup references in dry-run mode.
165165

166-
Migration report schema is published at package subpath: `tailwindcss-patch/migration-report.schema.json`.
166+
Schemas are published at package subpaths:
167+
`tailwindcss-patch/migration-report.schema.json`,
168+
`tailwindcss-patch/restore-result.schema.json`.
167169
Programmatic consumers can also import report helpers/types from package entry:
168170
`migrateConfigFiles`, `restoreConfigFiles`, `MIGRATION_REPORT_KIND`, `MIGRATION_REPORT_SCHEMA_VERSION`, `ConfigFileMigrationReport`.
169171

packages/tailwindcss-patch/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"import": "./src/index.ts",
2626
"require": "./src/index.ts"
2727
},
28-
"./migration-report.schema.json": "./schema/migration-report.schema.json"
28+
"./migration-report.schema.json": "./schema/migration-report.schema.json",
29+
"./restore-result.schema.json": "./schema/restore-result.schema.json"
2930
},
3031
"main": "./src/index.ts",
3132
"module": "./src/index.ts",
@@ -61,7 +62,8 @@
6162
"import": "./dist/index.mjs",
6263
"require": "./dist/index.js"
6364
},
64-
"./migration-report.schema.json": "./schema/migration-report.schema.json"
65+
"./migration-report.schema.json": "./schema/migration-report.schema.json",
66+
"./restore-result.schema.json": "./schema/restore-result.schema.json"
6567
},
6668
"main": "./dist/index.js",
6769
"module": "./dist/index.mjs",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://mangle.icebreaker.top/schemas/tailwindcss-patch/restore-result.schema.json",
4+
"title": "tailwindcss-patch restore/validate result",
5+
"description": "Schema for JSON output from `tw-patch restore --json` and `tw-patch validate --json`.",
6+
"type": "object",
7+
"required": [
8+
"cwd",
9+
"reportFile",
10+
"dryRun",
11+
"strict",
12+
"scannedEntries",
13+
"restorableEntries",
14+
"restoredFiles",
15+
"missingBackups",
16+
"skippedEntries",
17+
"restored"
18+
],
19+
"properties": {
20+
"cwd": {
21+
"type": "string"
22+
},
23+
"reportFile": {
24+
"type": "string"
25+
},
26+
"reportKind": {
27+
"type": "string",
28+
"const": "tw-patch-migrate-report"
29+
},
30+
"reportSchemaVersion": {
31+
"type": "integer",
32+
"minimum": 1
33+
},
34+
"dryRun": {
35+
"type": "boolean"
36+
},
37+
"strict": {
38+
"type": "boolean"
39+
},
40+
"scannedEntries": {
41+
"type": "integer",
42+
"minimum": 0
43+
},
44+
"restorableEntries": {
45+
"type": "integer",
46+
"minimum": 0
47+
},
48+
"restoredFiles": {
49+
"type": "integer",
50+
"minimum": 0
51+
},
52+
"missingBackups": {
53+
"type": "integer",
54+
"minimum": 0
55+
},
56+
"skippedEntries": {
57+
"type": "integer",
58+
"minimum": 0
59+
},
60+
"restored": {
61+
"type": "array",
62+
"items": {
63+
"type": "string"
64+
}
65+
}
66+
},
67+
"additionalProperties": false
68+
}

packages/tailwindcss-patch/test/migration-report.schema.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,18 @@ describe('migration report json schema', () => {
3232
)
3333
})
3434
})
35+
36+
describe('restore result json schema', () => {
37+
it('ships a restore-result schema file aligned with exported constants', async () => {
38+
const schemaPath = path.resolve(process.cwd(), 'schema/restore-result.schema.json')
39+
const schema = await fs.readJSON(schemaPath) as Record<string, any>
40+
41+
expect(schema.$schema).toContain('json-schema.org')
42+
expect(schema.type).toBe('object')
43+
expect(schema.required).toEqual(
44+
expect.arrayContaining(['reportFile', 'dryRun', 'restored', 'missingBackups']),
45+
)
46+
expect(schema.properties.reportKind.const).toBe(MIGRATION_REPORT_KIND)
47+
expect(schema.properties.reportSchemaVersion.minimum).toBe(MIGRATION_REPORT_SCHEMA_VERSION)
48+
})
49+
})

0 commit comments

Comments
 (0)