Skip to content

Commit 83c2edc

Browse files
committed
Merge branch 'main' into 2.0.0
2 parents 75cd295 + 3d5f92d commit 83c2edc

File tree

10 files changed

+275
-136
lines changed

10 files changed

+275
-136
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"update:website": "tsx ./scripts/update-website.ts"
5252
},
5353
"devDependencies": {
54+
"@effect/platform": "^0.90.6",
55+
"@effect/platform-node": "^0.96.0",
5456
"@eslint/config-inspector": "^1.2.0",
5557
"@eslint/markdown": "^7.1.0",
5658
"@local/configs": "workspace:*",
@@ -69,6 +71,7 @@
6971
"cspell": "^9.2.0",
7072
"dedent": "^1.6.0",
7173
"dprint": "^0.50.1",
74+
"effect": "^3.17.8",
7275
"esbuild": "^0.25.9",
7376
"eslint": "^9.33.0",
7477
"eslint-config-flat-gitignore": "^2.1.0",

pnpm-lock.yaml

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

scripts/effects/ignores.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as FileSystem from "@effect/platform/FileSystem";
2+
import * as Arr from "effect/Array";
3+
import * as Effect from "effect/Effect";
4+
import * as Fn from "effect/Function";
5+
import { not, or } from "effect/Predicate";
6+
import * as Str from "effect/String";
7+
8+
export const ignores = Fn.pipe(
9+
FileSystem.FileSystem,
10+
Effect.flatMap((fs) => fs.readFileString(".gitignore", "utf8")),
11+
Effect.map(Str.split("\n")),
12+
Effect.map(Arr.map(Str.trim)),
13+
Effect.map(Arr.filter(not(or(Str.startsWith("#"), Str.startsWith("!"))))),
14+
Effect.map(Arr.map(Str.replace(/^\//, ""))),
15+
Effect.map(Arr.filter(Str.isNonEmpty)),
16+
);

scripts/effects/version.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as FileSystem from "@effect/platform/FileSystem";
2+
import * as Effect from "effect/Effect";
3+
import * as Fn from "effect/Function";
4+
import * as Str from "effect/String";
5+
6+
export const version = Fn.pipe(
7+
FileSystem.FileSystem,
8+
Effect.flatMap((fs) => fs.readFileString("VERSION", "utf8")),
9+
Effect.map(Str.trim),
10+
Effect.map(Str.replace(/^v/, "")),
11+
);

scripts/lib/ignores.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/lib/version.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/update-version.ts

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,52 @@
1-
import fs from "node:fs";
2-
1+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
2+
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
3+
import * as FileSystem from "@effect/platform/FileSystem";
34
import ansis from "ansis";
5+
import * as Effect from "effect/Effect";
46
import { isMatching, match, P } from "ts-pattern";
57

6-
import { glob } from "./lib/glob";
7-
import { ignores } from "./lib/ignores";
8-
import { version } from "./lib/version";
8+
import { ignores } from "./effects/ignores";
9+
import { version } from "./effects/version";
10+
import { glob } from "./utils/glob";
911

1012
const GLOB_PACKAGE_JSON = [
1113
"package.json",
1214
"packages/*/package.json",
1315
"packages/*/*/package.json",
1416
];
1517

16-
async function update(path: string) {
17-
const packageJson = JSON.parse(fs.readFileSync(path, "utf8"));
18-
if (!isMatching({ version: P.string }, packageJson)) {
19-
throw new Error(`Invalid package.json at ${path}`);
20-
}
21-
const newVersion = version;
22-
const oldVersion = match(packageJson)
23-
.with({ version: P.select(P.string) }, (v) => v)
24-
.otherwise(() => "0.0.0");
25-
if (oldVersion === newVersion) {
26-
console.info(ansis.greenBright(`Skipping ${path} as it's already on version ${newVersion}`));
27-
return;
28-
}
29-
const packageJsonUpdated = {
30-
...packageJson,
31-
version: newVersion,
32-
};
33-
fs.writeFileSync(path, `${JSON.stringify(packageJsonUpdated, null, 2)}\n`);
34-
console.info(ansis.green(`Updated ${path} to version ${packageJsonUpdated.version}`));
18+
function update(path: string) {
19+
return Effect.gen(function*() {
20+
const fs = yield* FileSystem.FileSystem;
21+
const packageJsonText = yield* fs.readFileString(path, "utf8");
22+
const packageJson = JSON.parse(packageJsonText);
23+
if (!isMatching({ version: P.string }, packageJson)) {
24+
yield* Effect.fail(new Error(`Invalid package.json at ${path}: invalid or missing version field`));
25+
}
26+
const newVersion = yield* version;
27+
const oldVersion = match(packageJson)
28+
.with({ version: P.select(P.string) }, (v) => v)
29+
.otherwise(() => "0.0.0");
30+
if (oldVersion === newVersion) {
31+
yield* Effect.log(ansis.greenBright(`Skipping ${path} as it's already on version ${newVersion}`));
32+
return false;
33+
}
34+
const packageJsonUpdated = {
35+
...packageJson,
36+
version: newVersion,
37+
};
38+
yield* fs.writeFileString(path, `${JSON.stringify(packageJsonUpdated, null, 2)}\n`);
39+
yield* Effect.log(`Updated ${path} to version ${packageJsonUpdated.version}`);
40+
return true;
41+
});
3542
}
3643

37-
async function main() {
38-
const tasks = glob(GLOB_PACKAGE_JSON, ignores);
39-
await Promise.all(tasks.map((path) => update(path)));
40-
}
44+
const program = Effect.gen(function*() {
45+
const ignorePatterns = yield* ignores;
46+
return yield* Effect.all(glob(GLOB_PACKAGE_JSON, ignorePatterns).map(update), { concurrency: 8 });
47+
});
4148

42-
await main();
49+
program.pipe(
50+
Effect.provide(NodeFileSystem.layer),
51+
NodeRuntime.runMain,
52+
);

scripts/update-website.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
33

4-
import { glob } from "./lib/glob";
4+
import { glob } from "./utils/glob";
55

66
/**
77
* Build script for processing and copying documentation to the website
File renamed without changes.

scripts/verify-lockfile.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import ansis from "ansis";
2-
import { x } from "tinyexec";
1+
import { Command, CommandExecutor } from "@effect/platform";
2+
import { NodeCommandExecutor, NodeFileSystem, NodeRuntime } from "@effect/platform-node";
3+
import { Effect } from "effect";
34

4-
const { stdout } = await x("git", ["diff", "HEAD@{1}", "--stat", "--", "./pnpm-lock.yaml"]);
5+
const command = Command.make("git", "diff", "HEAD@{1}", "--stat", "--", "./pnpm-lock.yaml");
6+
const program = Effect.gen(function*() {
7+
const executor = yield* CommandExecutor.CommandExecutor;
8+
const output = yield* executor.lines(command);
9+
if (output.length === 0) {
10+
return;
11+
}
12+
yield* Effect.logWarning("Detected changes in pnpm-lock.yaml!");
13+
yield* Effect.logWarning("Please run `pnpm install --fix-lockfile && pnpm dedupe` to update local dependencies.");
14+
});
515

6-
if (stdout.split("\n").length > 0) {
7-
console.info("");
8-
console.info(ansis.yellow("Detected changes in pnpm-lock.yaml!"));
9-
console.info(
10-
ansis.yellowBright(
11-
"Please run `pnpm install --fix-lockfile && pnpm dedupe` to update local dependencies.",
12-
),
13-
);
14-
}
16+
program.pipe(
17+
Effect.provide(NodeCommandExecutor.layer),
18+
Effect.provide(NodeFileSystem.layer),
19+
NodeRuntime.runMain,
20+
);

0 commit comments

Comments
 (0)