Repository navigation
rework config parsing, rewrite config tests #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b7435ea
14d4c1f
867f2f6
28b2f88
f9fb81d
95d5473
150c9b0
1609d80
890432f
9498ccb
c4a61f3
472bcbd
64ce897
6b4cff2
8a40d3b
cdcb2d9
da30645
29857c3
bd27256
81c5c34
67786ce
aafc4e2
28de0d8
36cf429
12092db
065534b
b209968
6bbf821
b2717a8
2d9c427
26f5e45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| "@changesets/config": major | ||
| --- | ||
|
|
||
| Removed `read` and `parse` functions in favor of `readConfig`, which returns `{ config, warnings, errors }` instead of throwing on issues. | ||
|
|
||
| ```ts | ||
| // before.ts | ||
| import { parse } from "@changesets/config"; | ||
| import { getPackages } from "@manypkg/get-packages"; | ||
|
|
||
| const config = parse({ commit: true }, await getPackages()); | ||
|
|
||
| try { | ||
| return parse({ commit: true }, packages); | ||
| } catch (err) { | ||
| if (err instanceof ValidationError) { | ||
| console.error(`Invalid config: ${err.message}`); | ||
| } else { | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| // after.ts | ||
| import { readConfig } from "@changesets/config"; | ||
| import { getPackages } from "@manypkg/get-packages"; | ||
|
|
||
| // both arguments are optional | ||
| const { config, warnings, errors } = readConfig( | ||
| process.cwd(), | ||
| await getPackages(), | ||
| ); | ||
|
|
||
| if (warnings.length !== 0) { | ||
| console.warn(warnings.join("\n")); | ||
| } | ||
| if (config == null) { | ||
| console.error(errors.join("\n")); | ||
| } | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@changesets/errors": minor | ||
| --- | ||
|
|
||
| Added `cause` option to `ExitError` to help surface the cause behind exiting. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@changesets/config": minor | ||
| --- | ||
|
|
||
| Refactored config parsing to use Valibot and validation rules. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@changesets/errors": major | ||
| --- | ||
|
|
||
| Removed `ValidationError`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import c from "@changesets/color"; | ||
| import { readConfig as originalReadConfig } from "@changesets/config"; | ||
| import { ExitError } from "@changesets/errors"; | ||
| import type { Config, Packages } from "@changesets/types"; | ||
| import { log } from "@clack/prompts"; | ||
|
|
||
| export async function readConfig(packages: Packages): Promise<Config> { | ||
| const { config, warnings, errors } = await originalReadConfig( | ||
| packages.rootDir, | ||
| packages, | ||
| ); | ||
|
|
||
| const messages: string[] = []; | ||
|
|
||
| for (const warning of warnings) { | ||
| messages.push(c.yellow(warning)); | ||
| } | ||
| if (errors != null) { | ||
| for (const error of errors) { | ||
| messages.push(c.red(error)); | ||
| } | ||
| } | ||
|
|
||
| const logFn = errors != null ? log.error : log.warn; | ||
| if (messages.length !== 0) { | ||
| logFn(`Found issues in your config:\n- ${messages.join("\n- ")}`); | ||
| } | ||
|
|
||
| if (errors != null) { | ||
| throw new ExitError(1, { cause: new Error(errors.join("\n")) }); | ||
| } | ||
|
|
||
| return config; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,10 @@ | |
| "./package.json": "./package.json", | ||
| "./schema.json": "./schema.json" | ||
| }, | ||
| "scripts": { | ||
| "generate-json-schema": "node scripts/generate-json-schema.ts" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we call this anywhere in an automated fashion? we should make sure the schema is up to date in our CI workflow and before publishing the package
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a snapshot test in |
||
| }, | ||
| "dependencies": { | ||
| "@changesets/errors": "workspace:^", | ||
| "@changesets/get-dependents-graph": "workspace:^", | ||
| "@changesets/should-skip-package": "workspace:^", | ||
| "@changesets/types": "workspace:^", | ||
|
|
@@ -29,10 +31,15 @@ | |
| "devDependencies": { | ||
| "@changesets/test-utils": "workspace:*", | ||
| "@types/picomatch": "4.0.3", | ||
| "@valibot/to-json-schema": "^1.7.0", | ||
| "outdent": "^0.8.0", | ||
| "valibot": "^1.4.0", | ||
| "vitest": "^4.1.6" | ||
| }, | ||
| "engines": { | ||
| "node": "^22.11 || ^24 || >=26" | ||
| }, | ||
| "inlinedDependencies": { | ||
| "valibot": "1.4.0" | ||
|
beeequeue marked this conversation as resolved.
|
||
| } | ||
| } | ||

Uh oh!
There was an error while loading. Please reload this page.