用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/carrot-foundation/schemas --skill rule-schema-versioning命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | rule-schema-versioning |
| description | Schema version injection, $id format, and SCHEMA_VERSION environment variable |
Apply this rule whenever work touches:
src/shared/schema-version.tsscripts/**Schema versioning ensures every generated JSON Schema has a correct, traceable $id URL that points to the exact version of the schema definition. This is critical for schema consumers who validate data against specific versions.
$id URL formatEvery generated JSON Schema includes a $id field with this format:
https://raw.githubusercontent.com/carrot-foundation/schemas/refs/tags/v{version}/schemas/ipfs/{type}/{type}.schema.json
Example for a MassID schema at version 1.2.3:
https://raw.githubusercontent.com/carrot-foundation/schemas/refs/tags/v1.2.3/schemas/ipfs/mass-id/mass-id.schema.json
This URL must resolve to the actual file in the GitHub repository at the tagged release, enabling consumers to fetch and validate against the exact schema version.
The version flows through this chain:
SCHEMA_VERSION environment variable (set in CI/CD or locally)version field in package.jsontsup config uses env to set process.env.SCHEMA_VERSION at build timesrc/shared/schema-version.ts exports the resolved version$id URLsSCHEMA_VERSION env var
|
v
tsup.config.ts (env: { SCHEMA_VERSION: ... })
|
v
schema-version.ts (exports getSchemaVersionOrDefault())
|
v
JSON Schema generation (embeds version in $id URLs)
schema-version.ts moduleThis module is the single source of truth for version resolution at runtime:
// src/shared/schema-version.ts
export function getSchemaVersionOrDefault(): string {
return process.env['SCHEMA_VERSION'] || getPackageJsonVersion();
}
Never import the version from any other source. Always use getSchemaVersionOrDefault().
The tsup.config.ts injects the version at build time:
export default defineConfig({
// ...
env: {
SCHEMA_VERSION: process.env.SCHEMA_VERSION || getPackageJsonVersion(),
},
});
This sets process.env.SCHEMA_VERSION in the built output so the version is available at runtime without requiring the environment variable to be set by consumers.
There is no separate versioning logic for development vs production. The same chain applies:
SCHEMA_VERSION set, falls back to package.json versionSCHEMA_VERSION set to the release version (e.g., from git tag)This ensures consistency — the version resolution path is identical everywhere.
Run the verification script to ensure all generated schemas have correct version references:
pnpm verify-schema-versions
This checks:
$id URLs contain a valid version segment$id matches the expected schema versionProduction releases are automated via GitHub Actions using conventional commits — do not manually bump versions for release.
To test a specific version locally:
SCHEMA_VERSION=1.2.3 pnpm generate-ipfs-schemaspnpm verify-schema-versions to validate// BAD: hardcoded version
const schemaId =
'https://raw.githubusercontent.com/.../refs/tags/v1.2.3/schemas/...';
// GOOD: dynamic version
const schemaId = `https://raw.githubusercontent.com/.../refs/tags/v${getSchemaVersionOrDefault()}/schemas/...`;
// BAD: reading version directly from package.json at runtime
import pkg from '../package.json';
const version = pkg.version;
// GOOD: using the version module
import { getSchemaVersionOrDefault } from './shared/schema-version';
const version = getSchemaVersionOrDefault();
$id updatesNever manually edit $id URLs in generated JSON Schema files. They are overwritten on every generation. Fix the version source instead.