Skip to content

Commit 1c6bdc8

Browse files
committed
chore(release): clean npm publish metadata
1 parent f939a6a commit 1c6bdc8

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

apps/server/scripts/cli.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ class CliError extends Data.TaggedError("CliError")<{
4646
readonly cause?: unknown;
4747
}> {}
4848

49+
const normalizePublishBin = (bin: Record<string, string>) =>
50+
Object.fromEntries(
51+
Object.entries(bin).map(([name, command]) => [
52+
name,
53+
command.startsWith("./") ? command.slice(2) : command,
54+
]),
55+
);
56+
57+
const normalizePublishRepository = (repository: PackageJson["repository"]) => {
58+
const prefixedUrl = repository.url.startsWith("git+") ? repository.url : `git+${repository.url}`;
59+
const url = prefixedUrl.endsWith(".git") ? prefixedUrl : `${prefixedUrl}.git`;
60+
61+
return {
62+
...repository,
63+
url,
64+
};
65+
};
66+
4967
const RepoRoot = Effect.service(Path.Path).pipe(
5068
Effect.flatMap((path) => path.fromFileUrl(new URL("../../..", import.meta.url))),
5169
);
@@ -67,18 +85,24 @@ interface PublishIconBackup {
6785
readonly backupPath: string;
6886
}
6987

88+
interface PublishIconBackups {
89+
readonly rootPath: string;
90+
readonly entries: ReadonlyArray<PublishIconBackup>;
91+
}
92+
7093
const applyPublishIconOverrides = Effect.fn("applyPublishIconOverrides")(function* (
7194
repoRoot: string,
7295
serverDir: string,
7396
) {
7497
const path = yield* Path.Path;
7598
const fs = yield* FileSystem.FileSystem;
99+
const backupRoot = yield* fs.makeTempDirectory({ prefix: "t3code-publish-icons-" });
76100
const backups: PublishIconBackup[] = [];
77101

78102
for (const override of PUBLISH_ICON_OVERRIDES) {
79103
const sourcePath = path.join(repoRoot, override.sourceRelativePath);
80104
const targetPath = path.join(serverDir, override.targetRelativePath);
81-
const backupPath = `${targetPath}.publish-bak`;
105+
const backupPath = path.join(backupRoot, override.targetRelativePath.replace(/[\\/]/g, "__"));
82106

83107
if (!(yield* fs.exists(sourcePath))) {
84108
return yield* new CliError({
@@ -97,19 +121,23 @@ const applyPublishIconOverrides = Effect.fn("applyPublishIconOverrides")(functio
97121
}
98122

99123
yield* Effect.log("[cli] Applied publish icon overrides to dist/client");
100-
return backups as ReadonlyArray<PublishIconBackup>;
124+
return {
125+
entries: backups,
126+
rootPath: backupRoot,
127+
} satisfies PublishIconBackups;
101128
});
102129

103130
const restorePublishIconOverrides = Effect.fn("restorePublishIconOverrides")(function* (
104-
backups: ReadonlyArray<PublishIconBackup>,
131+
backups: PublishIconBackups,
105132
) {
106133
const fs = yield* FileSystem.FileSystem;
107-
for (const backup of backups) {
134+
for (const backup of backups.entries) {
108135
if (!(yield* fs.exists(backup.backupPath))) {
109136
continue;
110137
}
111138
yield* fs.rename(backup.backupPath, backup.targetPath);
112139
}
140+
yield* fs.remove(backups.rootPath, { force: true, recursive: true });
113141
});
114142

115143
const applyDevelopmentIconOverrides = Effect.fn("applyDevelopmentIconOverrides")(function* (
@@ -219,8 +247,8 @@ const publishCmd = Command.make(
219247
const version = Option.getOrElse(config.appVersion, () => serverPackageJson.version);
220248
const pkg: PackageJson = {
221249
name: PublishedPackageName,
222-
repository: serverPackageJson.repository,
223-
bin: serverPackageJson.bin,
250+
repository: normalizePublishRepository(serverPackageJson.repository),
251+
bin: normalizePublishBin(serverPackageJson.bin),
224252
type: serverPackageJson.type,
225253
version,
226254
engines: serverPackageJson.engines,
@@ -265,7 +293,7 @@ const publishCmd = Command.make(
265293
);
266294
}),
267295
// Release: restore
268-
(resource: { readonly iconBackups: ReadonlyArray<PublishIconBackup> }) =>
296+
(resource: { readonly iconBackups: PublishIconBackups }) =>
269297
Effect.gen(function* () {
270298
yield* restorePublishIconOverrides(resource.iconBackups).pipe(
271299
Effect.catch((error) =>

0 commit comments

Comments
 (0)