[codex] remove duplicated pnpm root config (#2939)
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
6a1c4da528
commit
37bf0f0d1d
11 files changed
+268
-94
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { parse as parseYaml } from "yaml";
|
||||
import { fromYaml } from "@t3tools/shared/schemaYaml";
|
||||
import rootPackageJson from "../package.json" with { type: "json" };
|
||||
import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
|
||||
import serverPackageJson from "../apps/server/package.json" with { type: "json" };
|
||||
@@ -29,22 +29,24 @@ const LINUX_ICON_SIZES = [16, 22, 24, 32, 48, 64, 128, 256, 512] as const;
|
||||
const BuildPlatform = Schema.Literals(["mac", "linux", "win"]);
|
||||
const BuildArch = Schema.Literals(["arm64", "x64", "universal"]);
|
||||
|
||||
interface WorkspaceConfig {
|
||||
readonly catalog?: Record<string, string>;
|
||||
readonly overrides?: Record<string, string>;
|
||||
}
|
||||
const WorkspaceConfig = Schema.Struct({
|
||||
catalog: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
||||
overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
||||
});
|
||||
type WorkspaceConfig = typeof WorkspaceConfig.Type;
|
||||
|
||||
const RepoRoot = Effect.service(Path.Path).pipe(
|
||||
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
|
||||
);
|
||||
const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
|
||||
const decodeWorkspaceConfig = Schema.decodeEffect(fromYaml(WorkspaceConfig));
|
||||
|
||||
const readWorkspaceConfig = Effect.fn("readWorkspaceConfig")(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const repoRoot = yield* RepoRoot;
|
||||
const workspaceYaml = yield* fs.readFileString(path.join(repoRoot, "pnpm-workspace.yaml"));
|
||||
return parseYaml(workspaceYaml) as WorkspaceConfig;
|
||||
return yield* decodeWorkspaceConfig(workspaceYaml);
|
||||
});
|
||||
|
||||
interface DesktopBuildIconAssets {
|
||||
@@ -776,7 +778,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
try: () => resolveCatalogDependencies(workspaceOverrides, workspaceCatalog, "apps/desktop"),
|
||||
catch: (cause) =>
|
||||
new BuildScriptError({
|
||||
message: "Could not resolve overrides from package.json.",
|
||||
message: "Could not resolve overrides from pnpm-workspace.yaml.",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ export interface ReferenceRepo {
|
||||
readonly prefix: string;
|
||||
readonly repository: string;
|
||||
readonly latestRef: string;
|
||||
readonly packageJsonPath: string;
|
||||
readonly versionSourcePath: string;
|
||||
readonly packageVersionPath: ReadonlyArray<string>;
|
||||
readonly versionTagPrefix: string;
|
||||
}
|
||||
@@ -14,8 +14,8 @@ export const referenceRepos: ReadonlyArray<ReferenceRepo> = [
|
||||
prefix: ".repos/effect-smol",
|
||||
repository: "https://github.com/Effect-TS/effect-smol.git",
|
||||
latestRef: "main",
|
||||
packageJsonPath: "package.json",
|
||||
packageVersionPath: ["workspaces", "catalog", "effect"],
|
||||
versionSourcePath: "pnpm-workspace.yaml",
|
||||
packageVersionPath: ["catalog", "effect"],
|
||||
versionTagPrefix: "effect@",
|
||||
},
|
||||
{
|
||||
@@ -23,7 +23,7 @@ export const referenceRepos: ReadonlyArray<ReferenceRepo> = [
|
||||
prefix: ".repos/alchemy-effect",
|
||||
repository: "https://github.com/alchemy-run/alchemy-effect.git",
|
||||
latestRef: "main",
|
||||
packageJsonPath: "infra/relay/package.json",
|
||||
versionSourcePath: "infra/relay/package.json",
|
||||
packageVersionPath: ["dependencies", "alchemy"],
|
||||
versionTagPrefix: "v",
|
||||
},
|
||||
|
||||
@@ -63,8 +63,8 @@ it.layer(NodeServices.layer)("sync-reference-repos", (it) => {
|
||||
prefix: "sync-reference-repos-version-",
|
||||
});
|
||||
yield* fs.writeFileString(
|
||||
path.join(rootDir, "package.json"),
|
||||
'{"workspaces":{"catalog":{"effect":"4.0.0-beta.73"}}}',
|
||||
path.join(rootDir, "pnpm-workspace.yaml"),
|
||||
"catalog:\n effect: 4.0.0-beta.73\n",
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
@@ -110,8 +110,8 @@ it.layer(NodeServices.layer)("sync-reference-repos", (it) => {
|
||||
prefix: "sync-reference-repos-plan-",
|
||||
});
|
||||
yield* fs.writeFileString(
|
||||
path.join(rootDir, "package.json"),
|
||||
'{"workspaces":{"catalog":{"effect":"4.0.0-beta.73"}}}',
|
||||
path.join(rootDir, "pnpm-workspace.yaml"),
|
||||
"catalog:\n effect: 4.0.0-beta.73\n",
|
||||
);
|
||||
|
||||
const addPlan = yield* planReferenceRepoSync(effectSmol, rootDir, false);
|
||||
@@ -140,8 +140,8 @@ it.layer(NodeServices.layer)("sync-reference-repos", (it) => {
|
||||
prefix: "sync-reference-repos-run-",
|
||||
});
|
||||
yield* fs.writeFileString(
|
||||
path.join(rootDir, "package.json"),
|
||||
'{"workspaces":{"catalog":{"effect":"4.0.0-beta.73"}}}',
|
||||
path.join(rootDir, "pnpm-workspace.yaml"),
|
||||
"catalog:\n effect: 4.0.0-beta.73\n",
|
||||
);
|
||||
|
||||
yield* syncReferenceRepos({ rootDir, repoId: "effect-smol" }).pipe(
|
||||
|
||||
@@ -12,6 +12,7 @@ import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { Command, Flag } from "effect/unstable/cli";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { fromYaml } from "@t3tools/shared/schemaYaml";
|
||||
|
||||
import { referenceRepos, type ReferenceRepo } from "./lib/reference-repos.ts";
|
||||
|
||||
@@ -36,7 +37,8 @@ export class ReferenceRepoSyncError extends Data.TaggedError("ReferenceRepoSyncE
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
const decodePackageJson = Schema.decodeUnknownEffect(Schema.UnknownFromJsonString);
|
||||
const decodeJsonSource = Schema.decodeUnknownEffect(Schema.UnknownFromJsonString);
|
||||
const decodeYamlSource = Schema.decodeEffect(fromYaml(Schema.Unknown));
|
||||
|
||||
const collectStreamAsString = <E>(stream: Stream.Stream<Uint8Array, E>): Effect.Effect<string, E> =>
|
||||
stream.pipe(
|
||||
@@ -58,6 +60,33 @@ function readNestedString(input: unknown, keys: ReadonlyArray<string>): string |
|
||||
return typeof value === "string" && value.length > 0 ? value : undefined;
|
||||
}
|
||||
|
||||
function decodeVersionSource(
|
||||
sourcePath: string,
|
||||
content: string,
|
||||
): Effect.Effect<unknown, ReferenceRepoSyncError> {
|
||||
if (sourcePath.endsWith(".yaml") || sourcePath.endsWith(".yml")) {
|
||||
return decodeYamlSource(content).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ReferenceRepoSyncError({
|
||||
message: `Unable to parse version source ${sourcePath}.`,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return decodeJsonSource(content).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ReferenceRepoSyncError({
|
||||
message: `Unable to parse version source ${sourcePath}.`,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function getSelectedRepos(
|
||||
repoId: string | undefined,
|
||||
): Effect.Effect<ReadonlyArray<ReferenceRepo>, ReferenceRepoSyncError> {
|
||||
@@ -88,22 +117,22 @@ export const resolveReferenceRepoRef = Effect.fn("resolveReferenceRepoRef")(func
|
||||
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const packageJsonPath = path.join(rootDir, repo.packageJsonPath);
|
||||
const packageJson = yield* fs.readFileString(packageJsonPath).pipe(
|
||||
Effect.flatMap(decodePackageJson),
|
||||
const versionSourcePath = path.join(rootDir, repo.versionSourcePath);
|
||||
const versionSourceContent = yield* fs.readFileString(versionSourcePath).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ReferenceRepoSyncError({
|
||||
message: `Unable to read package version for '${repo.id}' from ${packageJsonPath}.`,
|
||||
message: `Unable to read package version for '${repo.id}' from ${versionSourcePath}.`,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const version = readNestedString(packageJson, repo.packageVersionPath);
|
||||
const versionSource = yield* decodeVersionSource(repo.versionSourcePath, versionSourceContent);
|
||||
const version = readNestedString(versionSource, repo.packageVersionPath);
|
||||
|
||||
if (!version) {
|
||||
return yield* new ReferenceRepoSyncError({
|
||||
message: `Unable to resolve package version for '${repo.id}' at ${repo.packageJsonPath}:${repo.packageVersionPath.join(
|
||||
message: `Unable to resolve package version for '${repo.id}' at ${repo.versionSourcePath}:${repo.packageVersionPath.join(
|
||||
".",
|
||||
)}.`,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user