Skip to content

Commit e58544b

Browse files
author
Julius Marminge
committed
chore: remove duplicated pnpm root config
1 parent 6a1c4da commit e58544b

11 files changed

Lines changed: 268 additions & 94 deletions

File tree

‎apps/server/scripts/cli.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
} from "../../../scripts/lib/brand-assets.ts";
1818
import { resolveCatalogDependencies } from "../../../scripts/lib/resolve-catalog.ts";
1919
import { fromJsonStringPretty } from "@t3tools/shared/schemaJson";
20+
import { fromYaml } from "@t3tools/shared/schemaYaml";
2021
import serverPackageJson from "../package.json" with { type: "json" };
21-
import { parse as parseYaml } from "yaml";
2222

2323
interface PackageJson {
2424
name: string;
@@ -39,10 +39,12 @@ interface PackageJson {
3939
const PackageJsonPrettyJson = fromJsonStringPretty(Schema.Unknown);
4040
const encodePackageJson = Schema.encodeEffect(PackageJsonPrettyJson);
4141

42-
interface WorkspaceConfig {
43-
readonly catalog?: Record<string, string>;
44-
readonly overrides?: Record<string, string>;
45-
}
42+
const WorkspaceConfig = Schema.Struct({
43+
catalog: Schema.optional(Schema.Record(Schema.String, Schema.String)),
44+
overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
45+
});
46+
type WorkspaceConfig = typeof WorkspaceConfig.Type;
47+
const decodeWorkspaceConfig = Schema.decodeEffect(fromYaml(WorkspaceConfig));
4648

4749
class CliError extends Data.TaggedError("CliError")<{
4850
readonly message: string;
@@ -58,7 +60,7 @@ const readWorkspaceConfig = Effect.fn("readWorkspaceConfig")(function* () {
5860
const fs = yield* FileSystem.FileSystem;
5961
const repoRoot = yield* RepoRoot;
6062
const workspaceYaml = yield* fs.readFileString(path.join(repoRoot, "pnpm-workspace.yaml"));
61-
return parseYaml(workspaceYaml) as WorkspaceConfig;
63+
return yield* decodeWorkspaceConfig(workspaceYaml);
6264
});
6365

6466
const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Command) {

‎package.json‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
{
22
"name": "@t3tools/monorepo",
33
"private": true,
4-
"workspaces": {
5-
"packages": [
6-
"apps/*",
7-
"oxlint-plugin-t3code",
8-
"packages/*",
9-
"scripts"
10-
],
11-
"catalog": {
12-
"effect": "4.0.0-beta.73",
13-
"@effect/atom-react": "4.0.0-beta.73",
14-
"@effect/openapi-generator": "4.0.0-beta.73",
15-
"@effect/platform-bun": "4.0.0-beta.73",
16-
"@effect/platform-node": "4.0.0-beta.73",
17-
"@effect/platform-node-shared": "4.0.0-beta.73",
18-
"@effect/sql-sqlite-bun": "4.0.0-beta.73",
19-
"@effect/vitest": "4.0.0-beta.73",
20-
"@effect/tsgo": "0.11.4",
21-
"@pierre/diffs": "1.1.20",
22-
"@vitest/runner": "^4.1.8",
23-
"@types/bun": "^1.3.11",
24-
"@types/node": "24.12.4",
25-
"@typescript/native-preview": "7.0.0-dev.20260527.2",
26-
"typescript": "~6.0.3",
27-
"vitest": "npm:@voidzero-dev/vite-plus-test@latest",
28-
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
29-
"vite-plus": "latest",
30-
"yaml": "^2.9.0"
31-
}
32-
},
334
"type": "module",
345
"scripts": {
356
"prepare": "vp config && effect-tsgo patch",
@@ -75,19 +46,6 @@
7546
"@vitest/runner": "catalog:",
7647
"vite": "catalog:",
7748
"vite-plus": "catalog:",
78-
"vitest": "catalog:",
79-
"yaml": "catalog:"
80-
},
81-
"overrides": {
82-
"@effect/atom-react": "catalog:",
83-
"@effect/platform-bun": "catalog:",
84-
"@effect/platform-node": "catalog:",
85-
"@effect/platform-node-shared": "catalog:",
86-
"@effect/sql-sqlite-bun": "catalog:",
87-
"@effect/vitest": "catalog:",
88-
"@types/node": "catalog:",
89-
"effect": "catalog:",
90-
"vite": "catalog:",
9149
"vitest": "catalog:"
9250
},
9351
"engines": {
@@ -98,11 +56,5 @@
9856
"workerDirectory": [
9957
"apps/web/public"
10058
]
101-
},
102-
"patchedDependencies": {
103-
"@expo/[email protected]": "patches/@expo%[email protected]",
104-
"@pierre/[email protected]@1.1.20": "patches/@pierre%[email protected]",
105-
"[email protected]@4.0.0-beta.73": "patches/[email protected]",
106-
10759
}
10860
}

‎packages/shared/package.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
"types": "./src/schemaJson.ts",
5252
"import": "./src/schemaJson.ts"
5353
},
54+
"./schemaYaml": {
55+
"types": "./src/schemaYaml.ts",
56+
"import": "./src/schemaYaml.ts"
57+
},
5458
"./toolActivity": {
5559
"types": "./src/toolActivity.ts",
5660
"import": "./src/toolActivity.ts"
@@ -118,7 +122,8 @@
118122
},
119123
"dependencies": {
120124
"@t3tools/contracts": "workspace:*",
121-
"effect": "catalog:"
125+
"effect": "catalog:",
126+
"yaml": "catalog:"
122127
},
123128
"devDependencies": {
124129
"@effect/platform-node": "catalog:",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as Schema from "effect/Schema";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { fromYaml, fromYamlString } from "./schemaYaml.ts";
5+
6+
const ProjectConfig = Schema.Struct({
7+
name: Schema.String,
8+
enabled: Schema.Boolean,
9+
tags: Schema.Array(Schema.String),
10+
});
11+
12+
describe("schemaYaml helpers", () => {
13+
it("decodes YAML through a schema", () => {
14+
const decodeConfig = Schema.decodeUnknownSync(fromYaml(ProjectConfig));
15+
16+
expect(
17+
decodeConfig(`name: t3code
18+
enabled: true
19+
tags:
20+
- codex
21+
- effect
22+
`),
23+
).toEqual({
24+
name: "t3code",
25+
enabled: true,
26+
tags: ["codex", "effect"],
27+
});
28+
});
29+
30+
it("encodes values as YAML text", () => {
31+
const encodeConfig = Schema.encodeSync(fromYaml(ProjectConfig));
32+
33+
expect(
34+
encodeConfig({
35+
name: "t3code",
36+
enabled: true,
37+
tags: ["codex"],
38+
}),
39+
).toBe(`name: t3code
40+
enabled: true
41+
tags:
42+
- codex
43+
`);
44+
});
45+
46+
it("can be used as a schema transformation directly", () => {
47+
const schema = Schema.String.pipe(Schema.decodeTo(Schema.Unknown, fromYamlString));
48+
const decodeYaml = Schema.decodeUnknownSync(schema);
49+
50+
expect(decodeYaml("answer: 42\n")).toEqual({ answer: 42 });
51+
});
52+
53+
it("rejects malformed YAML", () => {
54+
const decodeYaml = Schema.decodeUnknownSync(fromYaml(Schema.Unknown));
55+
56+
expect(() => decodeYaml("name: ok\n bad-indent: nope\n")).toThrow();
57+
});
58+
});

‎packages/shared/src/schemaYaml.ts‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import * as Effect from "effect/Effect";
2+
import * as Option from "effect/Option";
3+
import * as Schema from "effect/Schema";
4+
import * as SchemaGetter from "effect/SchemaGetter";
5+
import * as SchemaIssue from "effect/SchemaIssue";
6+
import * as SchemaTransformation from "effect/SchemaTransformation";
7+
import {
8+
parse as parseYamlString,
9+
stringify as stringifyYamlValue,
10+
type CreateNodeOptions,
11+
type DocumentOptions,
12+
type ParseOptions,
13+
type SchemaOptions,
14+
type ToJSOptions,
15+
type ToStringOptions,
16+
} from "yaml";
17+
18+
export type YamlParseOptions = ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions;
19+
export type YamlStringifyOptions = DocumentOptions &
20+
SchemaOptions &
21+
ParseOptions &
22+
CreateNodeOptions &
23+
ToStringOptions;
24+
25+
function formatYamlError(error: unknown): string {
26+
return error instanceof Error ? error.message : String(error);
27+
}
28+
29+
/**
30+
* Parses a YAML string into a value.
31+
*
32+
* **When to use**
33+
*
34+
* Use when you need a schema getter to parse a present encoded YAML string
35+
* during decoding.
36+
*
37+
* **Details**
38+
*
39+
* Parse failures become `SchemaIssue.InvalidValue` values.
40+
*
41+
* **Example** (Parse YAML)
42+
*
43+
* ```ts
44+
* import { parseYaml } from "@t3tools/shared/schemaYaml"
45+
*
46+
* const parse = parseYaml<string>()
47+
* // Getter<unknown, string>
48+
* ```
49+
*
50+
* @see {@link stringifyYaml} for the inverse operation
51+
*/
52+
export function parseYaml<E extends string>(
53+
options?: YamlParseOptions,
54+
): SchemaGetter.Getter<unknown, E> {
55+
return SchemaGetter.transformOrFail((input: E) =>
56+
Effect.try({
57+
try: () => parseYamlString(input, options) as unknown,
58+
catch: (error) =>
59+
new SchemaIssue.InvalidValue(Option.some(input), { message: formatYamlError(error) }),
60+
}),
61+
);
62+
}
63+
64+
/**
65+
* Stringifies a present value as YAML.
66+
*
67+
* **When to use**
68+
*
69+
* Use when you need a schema getter to serialize a present decoded value to
70+
* YAML text during encoding.
71+
*
72+
* **Details**
73+
*
74+
* Stringify failures become `SchemaIssue.InvalidValue` values.
75+
*
76+
* **Example** (Stringify YAML)
77+
*
78+
* ```ts
79+
* import { stringifyYaml } from "@t3tools/shared/schemaYaml"
80+
*
81+
* const stringify = stringifyYaml()
82+
* // Getter<string, unknown>
83+
* ```
84+
*
85+
* @see {@link parseYaml} for the inverse operation
86+
*/
87+
export function stringifyYaml(
88+
options?: YamlStringifyOptions,
89+
): SchemaGetter.Getter<string, unknown> {
90+
return SchemaGetter.transformOrFail((input: unknown) =>
91+
Effect.try({
92+
try: () => stringifyYamlValue(input, options),
93+
catch: (error) =>
94+
new SchemaIssue.InvalidValue(Option.some(input), { message: formatYamlError(error) }),
95+
}),
96+
);
97+
}
98+
99+
/**
100+
* Decodes a YAML string and encodes a value as YAML text.
101+
*
102+
* **When to use**
103+
*
104+
* Use when you need a schema transformation to decode YAML stored or
105+
* transmitted as a string before validating the parsed structure.
106+
*
107+
* **Details**
108+
*
109+
* Decode and encode failures become `InvalidValue` schema issues.
110+
*
111+
* **Example** (Parsing YAML)
112+
*
113+
* ```ts
114+
* import * as Schema from "effect/Schema"
115+
* import { fromYamlString } from "@t3tools/shared/schemaYaml"
116+
*
117+
* const schema = Schema.String.pipe(Schema.decodeTo(Schema.Unknown, fromYamlString))
118+
* ```
119+
*/
120+
export const fromYamlString = new SchemaTransformation.Transformation<unknown, string>(
121+
parseYaml(),
122+
stringifyYaml(),
123+
);
124+
125+
/**
126+
* Build a schema that decodes a YAML string into `A`.
127+
*
128+
* Decode parses the input as YAML before validating the parsed value with the
129+
* provided schema. Encode validates the value and serializes it as YAML text.
130+
*/
131+
export const fromYaml = <S extends Schema.Top>(schema: S) =>
132+
Schema.String.pipe(Schema.decodeTo(schema, fromYamlString));

‎pnpm-lock.yaml‎

Lines changed: 8 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)