Skip to content

Commit 4fc6a94

Browse files
committed
feat(tailwindcss-patch): publish validate result json schema
1 parent d143d48 commit 4fc6a94

9 files changed

Lines changed: 102 additions & 8 deletions

File tree

.changeset/metal-horses-work.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 schema for validate JSON output.
6+
7+
- add `tailwindcss-patch/validate-result.schema.json` for `tw-patch validate --json`
8+
- include failure payload contract (`reason`, `exitCode`, `message`) alongside success shape reference
9+
- export `VALIDATE_FAILURE_REASONS` and align schema tests with public validate constants

packages/tailwindcss-patch/MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Migration mapping:
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.
9696
- `tw-patch validate` now uses dedicated failure exit codes for CI diagnostics (`21`/`22`/`23`/`24`).
97-
- 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`.
97+
- 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`, `tailwindcss-patch/validate-result.schema.json`.
9898
- Commands resolve configuration from `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Existing configuration files continue to work without changes.
9999

100100
## 4. Cache handling

packages/tailwindcss-patch/README-cn.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ CLI 会通过 `@tailwindcss-mangle/config` 加载 `tailwindcss-patch.config.ts`
110110

111111
JSON Schema 通过子路径发布:
112112
`tailwindcss-patch/migration-report.schema.json`
113-
`tailwindcss-patch/restore-result.schema.json`
113+
`tailwindcss-patch/restore-result.schema.json`
114+
`tailwindcss-patch/validate-result.schema.json`
114115
编程场景也可直接从包入口导入报告相关导出:
115-
`migrateConfigFiles``restoreConfigFiles``MIGRATION_REPORT_KIND``MIGRATION_REPORT_SCHEMA_VERSION``ConfigFileMigrationReport`
116+
`migrateConfigFiles``restoreConfigFiles``MIGRATION_REPORT_KIND``MIGRATION_REPORT_SCHEMA_VERSION``ConfigFileMigrationReport``VALIDATE_EXIT_CODES`
116117

117118
### `tokens` 常用参数
118119

packages/tailwindcss-patch/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ On failure, validate uses dedicated exit codes for CI:
167167

168168
Schemas are published at package subpaths:
169169
`tailwindcss-patch/migration-report.schema.json`,
170-
`tailwindcss-patch/restore-result.schema.json`.
170+
`tailwindcss-patch/restore-result.schema.json`,
171+
`tailwindcss-patch/validate-result.schema.json`.
171172
Programmatic consumers can also import report helpers/types from package entry:
172-
`migrateConfigFiles`, `restoreConfigFiles`, `MIGRATION_REPORT_KIND`, `MIGRATION_REPORT_SCHEMA_VERSION`, `ConfigFileMigrationReport`.
173+
`migrateConfigFiles`, `restoreConfigFiles`, `MIGRATION_REPORT_KIND`, `MIGRATION_REPORT_SCHEMA_VERSION`, `ConfigFileMigrationReport`, `VALIDATE_EXIT_CODES`.
173174

174175
### Token report options
175176

packages/tailwindcss-patch/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"require": "./src/index.ts"
2727
},
2828
"./migration-report.schema.json": "./schema/migration-report.schema.json",
29-
"./restore-result.schema.json": "./schema/restore-result.schema.json"
29+
"./restore-result.schema.json": "./schema/restore-result.schema.json",
30+
"./validate-result.schema.json": "./schema/validate-result.schema.json"
3031
},
3132
"main": "./src/index.ts",
3233
"module": "./src/index.ts",
@@ -63,7 +64,8 @@
6364
"require": "./dist/index.js"
6465
},
6566
"./migration-report.schema.json": "./schema/migration-report.schema.json",
66-
"./restore-result.schema.json": "./schema/restore-result.schema.json"
67+
"./restore-result.schema.json": "./schema/restore-result.schema.json",
68+
"./validate-result.schema.json": "./schema/validate-result.schema.json"
6769
},
6870
"main": "./dist/index.js",
6971
"module": "./dist/index.mjs",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://mangle.icebreaker.top/schemas/tailwindcss-patch/validate-result.schema.json",
4+
"title": "tailwindcss-patch validate result",
5+
"description": "Schema for JSON output from `tw-patch validate --json`.",
6+
"oneOf": [
7+
{
8+
"$ref": "./restore-result.schema.json"
9+
},
10+
{
11+
"$ref": "#/$defs/failure"
12+
}
13+
],
14+
"$defs": {
15+
"failure": {
16+
"type": "object",
17+
"required": [
18+
"ok",
19+
"reason",
20+
"exitCode",
21+
"message"
22+
],
23+
"properties": {
24+
"ok": {
25+
"type": "boolean",
26+
"const": false
27+
},
28+
"reason": {
29+
"type": "string",
30+
"enum": [
31+
"report-incompatible",
32+
"missing-backups",
33+
"io-error",
34+
"unknown-error"
35+
]
36+
},
37+
"exitCode": {
38+
"type": "integer",
39+
"enum": [
40+
21,
41+
22,
42+
23,
43+
24
44+
]
45+
},
46+
"message": {
47+
"type": "string"
48+
}
49+
},
50+
"additionalProperties": false
51+
}
52+
}
53+
}

packages/tailwindcss-patch/src/cli/commands.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ export const VALIDATE_EXIT_CODES = {
3939
UNKNOWN_ERROR: 24,
4040
} as const
4141

42-
export type ValidateFailureReason = 'report-incompatible' | 'missing-backups' | 'io-error' | 'unknown-error'
42+
export const VALIDATE_FAILURE_REASONS = [
43+
'report-incompatible',
44+
'missing-backups',
45+
'io-error',
46+
'unknown-error',
47+
] as const
48+
49+
export type ValidateFailureReason = (typeof VALIDATE_FAILURE_REASONS)[number]
4350

4451
export interface ValidateFailureSummary {
4552
reason: ValidateFailureReason

packages/tailwindcss-patch/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export {
1515
type ValidateFailureSummary,
1616
ValidateCommandError,
1717
VALIDATE_EXIT_CODES,
18+
VALIDATE_FAILURE_REASONS,
1819
tailwindcssPatchCommands,
1920
} from './cli/commands'
2021
export {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { describe, expect, it } from 'vitest'
44
import {
55
MIGRATION_REPORT_KIND,
66
MIGRATION_REPORT_SCHEMA_VERSION,
7+
VALIDATE_EXIT_CODES,
8+
VALIDATE_FAILURE_REASONS,
79
migrateConfigFiles,
810
restoreConfigFiles,
911
} from '../src'
@@ -47,3 +49,21 @@ describe('restore result json schema', () => {
4749
expect(schema.properties.reportSchemaVersion.minimum).toBe(MIGRATION_REPORT_SCHEMA_VERSION)
4850
})
4951
})
52+
53+
describe('validate result json schema', () => {
54+
it('ships a validate-result schema aligned with validate failure contracts', async () => {
55+
const schemaPath = path.resolve(process.cwd(), 'schema/validate-result.schema.json')
56+
const schema = await fs.readJSON(schemaPath) as Record<string, any>
57+
58+
expect(schema.$schema).toContain('json-schema.org')
59+
expect(schema.oneOf).toHaveLength(2)
60+
expect(schema.oneOf[0].$ref).toContain('restore-result.schema.json')
61+
expect(schema.$defs.failure.properties.reason.enum).toEqual([...VALIDATE_FAILURE_REASONS])
62+
expect(schema.$defs.failure.properties.exitCode.enum).toEqual([
63+
VALIDATE_EXIT_CODES.REPORT_INCOMPATIBLE,
64+
VALIDATE_EXIT_CODES.MISSING_BACKUPS,
65+
VALIDATE_EXIT_CODES.IO_ERROR,
66+
VALIDATE_EXIT_CODES.UNKNOWN_ERROR,
67+
])
68+
})
69+
})

0 commit comments

Comments
 (0)