Skip to content

Commit 203f58e

Browse files
[codex] Fix desktop packaging patched dependencies (#2944)
Co-authored-by: codex <codex@users.noreply.github.com>
1 parent 52ae8e8 commit 203f58e

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

scripts/build-desktop-artifact.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
55
import * as Option from "effect/Option";
66

77
import {
8+
createStagePnpmConfig,
89
resolveDesktopRuntimeDependencies,
910
resolveBuildOptions,
1011
resolveDesktopBuildIconAssets,
@@ -64,6 +65,21 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
6465
);
6566
});
6667

68+
it("carries workspace patch metadata into staged desktop installs", () => {
69+
assert.deepStrictEqual(
70+
createStagePnpmConfig({
71+
"@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
72+
}),
73+
{
74+
patchedDependencies: {
75+
"@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
76+
},
77+
},
78+
);
79+
80+
assert.equal(createStagePnpmConfig({}), undefined);
81+
});
82+
6783
it("falls back to the default mock update port when the configured port is blank", () => {
6884
assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
6985
assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");

scripts/build-desktop-artifact.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const BuildArch = Schema.Literals(["arm64", "x64", "universal"]);
3232
const WorkspaceConfig = Schema.Struct({
3333
catalog: Schema.optional(Schema.Record(Schema.String, Schema.String)),
3434
overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
35+
patchedDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
3536
});
3637
type WorkspaceConfig = typeof WorkspaceConfig.Type;
3738

@@ -270,6 +271,15 @@ interface StagePackageJson {
270271
readonly electron: string;
271272
};
272273
readonly overrides: Record<string, unknown>;
274+
readonly pnpm?: {
275+
readonly patchedDependencies?: Record<string, string>;
276+
};
277+
}
278+
279+
export function createStagePnpmConfig(
280+
patchedDependencies: Record<string, string>,
281+
): StagePackageJson["pnpm"] | undefined {
282+
return Object.keys(patchedDependencies).length > 0 ? { patchedDependencies } : undefined;
273283
}
274284

275285
const AzureTrustedSigningOptionsConfig = Config.all({
@@ -757,6 +767,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
757767
const workspaceConfig = yield* readWorkspaceConfig();
758768
const workspaceCatalog = workspaceConfig.catalog ?? {};
759769
const workspaceOverrides = workspaceConfig.overrides ?? {};
770+
const workspacePatchedDependencies = workspaceConfig.patchedDependencies ?? {};
760771

761772
const platformConfig = PLATFORM_CONFIG[options.platform];
762773
if (!platformConfig) {
@@ -867,6 +878,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
867878
// electron-builder is filtering out stageResourcesDir directory in the AppImage for production
868879
yield* fs.copy(stageResourcesDir, path.join(stageAppDir, "apps/desktop/prod-resources"));
869880

881+
const stagePnpmConfig = createStagePnpmConfig(workspacePatchedDependencies);
870882
const stagePackageJson: StagePackageJson = {
871883
name: "t3code",
872884
version: appVersion,
@@ -893,11 +905,16 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
893905
electron: electronVersion,
894906
},
895907
overrides: resolvedOverrides,
908+
...(stagePnpmConfig ? { pnpm: stagePnpmConfig } : {}),
896909
};
897910

898911
const stagePackageJsonString = yield* encodeJsonString(stagePackageJson);
899912
yield* fs.writeFileString(path.join(stageAppDir, "package.json"), `${stagePackageJsonString}\n`);
900913

914+
if (Object.keys(workspacePatchedDependencies).length > 0) {
915+
yield* fs.copy(path.join(repoRoot, "patches"), path.join(stageAppDir, "patches"));
916+
}
917+
901918
yield* Effect.log("[desktop-artifact] Installing staged production dependencies...");
902919
yield* runCommand(
903920
ChildProcess.make({

0 commit comments

Comments
 (0)