@alchemy.run/pkg 2.0.0-beta.80 → 2.0.0-beta.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/Manifest.d.ts.map +1 -1
  2. package/dist/Manifest.js.map +1 -1
  3. package/dist/Protocol.d.ts +1 -1
  4. package/dist/Protocol.d.ts.map +1 -1
  5. package/dist/Protocol.js +3 -12
  6. package/dist/Protocol.js.map +1 -1
  7. package/dist/Registry/Bindings.d.ts.map +1 -1
  8. package/dist/Registry/Bindings.js.map +1 -1
  9. package/dist/Registry/GitHub.d.ts +2 -2
  10. package/dist/Registry/GitHub.d.ts.map +1 -1
  11. package/dist/Registry/GitHub.js +9 -36
  12. package/dist/Registry/GitHub.js.map +1 -1
  13. package/dist/Registry/Handler.d.ts +1 -1
  14. package/dist/Registry/Handler.d.ts.map +1 -1
  15. package/dist/Registry/Handler.js +10 -18
  16. package/dist/Registry/Handler.js.map +1 -1
  17. package/dist/Registry/KVCache.d.ts.map +1 -1
  18. package/dist/Registry/KVCache.js +1 -1
  19. package/dist/Registry/KVCache.js.map +1 -1
  20. package/dist/Registry/Sweep.d.ts.map +1 -1
  21. package/dist/Registry/Sweep.js +3 -8
  22. package/dist/Registry/Sweep.js.map +1 -1
  23. package/dist/Registry/Tags.d.ts.map +1 -1
  24. package/dist/Registry/Tags.js.map +1 -1
  25. package/dist/Registry.d.ts +1 -1
  26. package/dist/Registry.d.ts.map +1 -1
  27. package/dist/Registry.js +1 -1
  28. package/dist/Registry.js.map +1 -1
  29. package/dist/cli/bin.d.ts +1 -1
  30. package/dist/cli/bin.d.ts.map +1 -1
  31. package/dist/cli/bin.js +5 -9
  32. package/dist/cli/bin.js.map +1 -1
  33. package/dist/cli/pack.d.ts.map +1 -1
  34. package/dist/cli/pack.js +11 -23
  35. package/dist/cli/pack.js.map +1 -1
  36. package/dist/cli/publish.d.ts.map +1 -1
  37. package/dist/cli/publish.js +2 -2
  38. package/dist/cli/publish.js.map +1 -1
  39. package/package.json +19 -19
  40. package/src/Manifest.ts +1 -3
  41. package/src/Protocol.ts +12 -28
  42. package/src/Registry/Bindings.ts +1 -4
  43. package/src/Registry/GitHub.ts +24 -83
  44. package/src/Registry/Handler.ts +31 -87
  45. package/src/Registry/KVCache.ts +6 -17
  46. package/src/Registry/Sweep.ts +13 -26
  47. package/src/Registry/Tags.ts +7 -15
  48. package/src/Registry.ts +5 -15
  49. package/src/cli/bin.ts +8 -18
  50. package/src/cli/pack.ts +27 -73
  51. package/src/cli/publish.ts +11 -23
package/src/cli/bin.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { PlatformServices, runMain } from "alchemy/Util/PlatformServices";
3
+ import { CliConfig, CliError, Command, Flag, GlobalFlag } from "effect/cli";
3
4
  import * as Config from "effect/Config";
4
5
  import * as Effect from "effect/Effect";
5
- import * as Option from "effect/Option";
6
- import * as Layer from "effect/Layer";
7
- import { CliConfig, CliError, Command, Flag, GlobalFlag } from "effect/cli";
8
6
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
7
+ import * as Layer from "effect/Layer";
8
+ import * as Option from "effect/Option";
9
9
  import pkg from "../../package.json" with { type: "json" };
10
10
  import { Group, pack } from "./pack.ts";
11
11
  import { publish } from "./publish.ts";
@@ -38,16 +38,12 @@ export const packCommand = Command.make(
38
38
  registry: registryFlag,
39
39
  out: outFlag,
40
40
  since: Flag.String("since").pipe(
41
- Flag.withDescription(
42
- "Compare HEAD with this Git ref; defaults to the PR base in Actions",
43
- ),
41
+ Flag.withDescription("Compare HEAD with this Git ref; defaults to the PR base in Actions"),
44
42
  Flag.optional,
45
43
  ),
46
44
  all: Flag.Boolean("all").pipe(
47
45
  Flag.withDefault(false),
48
- Flag.withDescription(
49
- "Pack every configured package regardless of changes",
50
- ),
46
+ Flag.withDescription("Pack every configured package regardless of changes"),
51
47
  ),
52
48
  rebuildAllPaths: Flag.String("rebuild-all-path").pipe(
53
49
  Flag.withDescription(
@@ -98,17 +94,13 @@ export const publishCommand = Command.make(
98
94
  Command.withDescription(
99
95
  "Publish a pkg pack directory from the current GitHub Actions job, after its manifest artifact has been uploaded",
100
96
  ),
101
- Command.withExamples([
102
- { command: "pkg publish --registry https://pkg.alchemy.run" },
103
- ]),
97
+ Command.withExamples([{ command: "pkg publish --registry https://pkg.alchemy.run" }]),
104
98
  );
105
99
 
106
100
  export const root = Command.make("pkg", {}, () =>
107
101
  Effect.fail(new CliError.ShowHelp({ commandPath: ["pkg"], errors: [] })),
108
102
  ).pipe(
109
- Command.withDescription(
110
- "Pack and publish preview packages for pull requests.",
111
- ),
103
+ Command.withDescription("Pack and publish preview packages for pull requests."),
112
104
  Command.withSubcommands([packCommand, publishCommand]),
113
105
  );
114
106
 
@@ -117,9 +109,7 @@ Command.run(root, { version: pkg.version }).pipe(
117
109
  Layer.mergeAll(
118
110
  PlatformServices,
119
111
  FetchHttpClient.layer,
120
- CliConfig.layer({
121
- builtIns: [GlobalFlag.Help, GlobalFlag.Version],
122
- }),
112
+ CliConfig.layer({ builtIns: [GlobalFlag.Help, GlobalFlag.Version] }),
123
113
  ),
124
114
  ),
125
115
  runMain,
package/src/cli/pack.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { gunzipSync, gzipSync } from "node:zlib";
2
+ import { exec } from "alchemy/Util/exec";
3
+ import { sha256 } from "alchemy/Util/sha256";
1
4
  import * as Config from "effect/Config";
2
5
  import * as Console from "effect/Console";
3
6
  import * as Data from "effect/Data";
@@ -5,14 +8,11 @@ import * as Effect from "effect/Effect";
5
8
  import * as FileSystem from "effect/FileSystem";
6
9
  import * as Option from "effect/Option";
7
10
  import * as Path from "effect/Path";
11
+ import * as ChildProcess from "effect/process/ChildProcess";
8
12
  import * as Schema from "effect/Schema";
9
13
  import * as SchemaIssue from "effect/SchemaIssue";
10
14
  import * as SchemaTransformation from "effect/SchemaTransformation";
11
- import * as ChildProcess from "effect/process/ChildProcess";
12
- import { exec } from "alchemy/Util/exec";
13
- import { sha256 } from "alchemy/Util/sha256";
14
15
  import { packTar, unpackTar, type TarHeader } from "modern-tar";
15
- import { gunzipSync, gzipSync } from "node:zlib";
16
16
  import {
17
17
  GroupName,
18
18
  MANIFEST_FILE,
@@ -48,8 +48,7 @@ export const Group = Schema.String.pipe(
48
48
  .split(",")
49
49
  .map((attribute) => attribute.trim())
50
50
  .filter((attribute) => attribute.length > 0);
51
- return match &&
52
- attributes.every((attribute) => attribute === "Collapsed")
51
+ return match && attributes.every((attribute) => attribute === "Collapsed")
53
52
  ? Effect.succeed({
54
53
  name: match[1]!,
55
54
  pattern: match[3]!,
@@ -64,9 +63,7 @@ export const Group = Schema.String.pipe(
64
63
  );
65
64
  },
66
65
  encode: (group) =>
67
- Effect.succeed(
68
- `${group.name}${group.collapsed ? "[Collapsed]" : ""}=${group.pattern}`,
69
- ),
66
+ Effect.succeed(`${group.name}${group.collapsed ? "[Collapsed]" : ""}=${group.pattern}`),
70
67
  }),
71
68
  ),
72
69
  );
@@ -86,9 +83,7 @@ export const DEPENDENCY_SECTIONS = [
86
83
  "optionalDependencies",
87
84
  ] as const;
88
85
 
89
- const DependencyMap = Schema.optionalKey(
90
- Schema.Record(Schema.String, Schema.String),
91
- );
86
+ const DependencyMap = Schema.optionalKey(Schema.Record(Schema.String, Schema.String));
92
87
 
93
88
  export const DependencySections = Schema.Struct({
94
89
  dependencies: DependencyMap,
@@ -167,8 +162,7 @@ export const selectPackages = (
167
162
  changedFiles.some((file) =>
168
163
  [...REBUILD_ALL_PATHS, ...rebuildAllPaths].some((pattern) =>
169
164
  pattern.endsWith("/**")
170
- ? file === pattern.slice(0, -3) ||
171
- file.startsWith(pattern.slice(0, -2))
165
+ ? file === pattern.slice(0, -3) || file.startsWith(pattern.slice(0, -2))
172
166
  : file === pattern,
173
167
  ),
174
168
  )
@@ -180,9 +174,7 @@ export const selectPackages = (
180
174
  .filter((pkg) =>
181
175
  changedFiles.some(
182
176
  (file) =>
183
- file === pkg.dir ||
184
- file.startsWith(`${pkg.dir}/`) ||
185
- pkg.dir.startsWith(`${file}/`),
177
+ file === pkg.dir || file.startsWith(`${pkg.dir}/`) || pkg.dir.startsWith(`${file}/`),
186
178
  ),
187
179
  )
188
180
  .map((pkg) => pkg.name),
@@ -218,9 +210,7 @@ export const expandBraces = (pattern: string): string[] => {
218
210
  .split(",")
219
211
  .map((alternative) => alternative.trim())
220
212
  .filter((alternative) => alternative.length > 0)
221
- .flatMap((alternative) =>
222
- expandBraces(`${match[1]}${alternative}${match[3]}`),
223
- );
213
+ .flatMap((alternative) => expandBraces(`${match[1]}${alternative}${match[3]}`));
224
214
  };
225
215
 
226
216
  /**
@@ -236,10 +226,7 @@ const expand = Effect.fn("expandGlob")(function* (cwd: string, glob: string) {
236
226
  return [...new Set(results)];
237
227
  });
238
228
 
239
- const expandPattern = Effect.fn("expandPattern")(function* (
240
- cwd: string,
241
- pattern: string,
242
- ) {
229
+ const expandPattern = Effect.fn("expandPattern")(function* (cwd: string, pattern: string) {
243
230
  const fs = yield* FileSystem.FileSystem;
244
231
  const path = yield* Path.Path;
245
232
  if (pattern.includes("**")) {
@@ -324,10 +311,7 @@ export class GitError extends Data.TaggedError("GitError")<{
324
311
  }
325
312
 
326
313
  /** Run `git` in `cwd` and return trimmed stdout. */
327
- export const git = Effect.fn("git")(function* (
328
- cwd: string,
329
- args: ReadonlyArray<string>,
330
- ) {
314
+ export const git = Effect.fn("git")(function* (cwd: string, args: ReadonlyArray<string>) {
331
315
  const { exitCode, stdout, stderr } = yield* exec(
332
316
  ChildProcess.make("git", [...args], { cwd, shell: false }),
333
317
  ).pipe(Effect.scoped);
@@ -338,8 +322,7 @@ export const git = Effect.fn("git")(function* (
338
322
  });
339
323
 
340
324
  /** Absolute path of the repository (or submodule) that owns `cwd`. */
341
- export const toplevel = (cwd: string) =>
342
- git(cwd, ["rev-parse", "--show-toplevel"]);
325
+ export const toplevel = (cwd: string) => git(cwd, ["rev-parse", "--show-toplevel"]);
343
326
 
344
327
  /** Full HEAD SHA of the repository that owns `cwd`. */
345
328
  const gitHead = (cwd: string) => git(cwd, ["rev-parse", "HEAD"]);
@@ -349,24 +332,17 @@ export class PackError extends Data.TaggedError("PackError")<{
349
332
  readonly message: string;
350
333
  }> {}
351
334
 
352
- const PnpmPackOutput = Schema.fromJsonString(
353
- Schema.Struct({ filename: Schema.String }),
354
- );
335
+ const PnpmPackOutput = Schema.fromJsonString(Schema.Struct({ filename: Schema.String }));
355
336
 
356
337
  /**
357
338
  * Rewrite every dependency on a package in `links` to that package's
358
339
  * tarball URL. Returns the rewritten manifest text and the rewrites made.
359
340
  */
360
- export const rewriteDependencies = (
361
- manifestText: string,
362
- links: ReadonlyMap<string, string>,
363
- ) =>
341
+ export const rewriteDependencies = (manifestText: string, links: ReadonlyMap<string, string>) =>
364
342
  Effect.gen(function* () {
365
343
  const manifest = yield* Schema.decodeUnknownEffect(
366
344
  Schema.fromJsonString(
367
- Schema.StructWithRest(DependencySections, [
368
- Schema.Record(Schema.String, Schema.Unknown),
369
- ]),
345
+ Schema.StructWithRest(DependencySections, [Schema.Record(Schema.String, Schema.Unknown)]),
370
346
  ),
371
347
  )(manifestText);
372
348
  // Preserve source key order after validation: it contributes to the tarball hash.
@@ -454,16 +430,12 @@ export const packPackage = Effect.fn("packPackage")(function* (options: {
454
430
 
455
431
  let rewrites: PackedTarball["rewrites"] = [];
456
432
  const normalized: Array<{ header: TarHeader; data: Uint8Array }> = [];
457
- for (const entry of entries.sort((a, b) =>
458
- a.header.name.localeCompare(b.header.name),
459
- )) {
433
+ for (const entry of entries.sort((a, b) => a.header.name.localeCompare(b.header.name))) {
460
434
  let data = entry.data ?? new Uint8Array();
461
435
  if (entry.header.name === "package/package.json") {
462
436
  const text = yield* Effect.sync(() => new TextDecoder().decode(data));
463
437
  const result = yield* rewriteDependencies(text, options.links).pipe(
464
- Effect.mapError(
465
- (e) => new PackError({ dir: options.absDir, message: String(e) }),
466
- ),
438
+ Effect.mapError((e) => new PackError({ dir: options.absDir, message: String(e) })),
467
439
  );
468
440
  rewrites = result.rewrites;
469
441
  data = yield* Effect.sync(() => new TextEncoder().encode(result.text));
@@ -502,10 +474,7 @@ const PullRequestEvent = Schema.fromJsonString(
502
474
  const pullRequest = Effect.gen(function* () {
503
475
  const event = yield* Config.option(Config.String("GITHUB_EVENT_NAME"));
504
476
  const eventPath = yield* Config.option(Config.String("GITHUB_EVENT_PATH"));
505
- if (
506
- Option.getOrUndefined(event) !== "pull_request" ||
507
- Option.isNone(eventPath)
508
- ) {
477
+ if (Option.getOrUndefined(event) !== "pull_request" || Option.isNone(eventPath)) {
509
478
  return undefined;
510
479
  }
511
480
  const fs = yield* FileSystem.FileSystem;
@@ -530,8 +499,7 @@ export interface PackOptions {
530
499
  * replaced by `+`, a character package names cannot contain, so `@a/b-c`
531
500
  * and `@a-b/c` get distinct files.
532
501
  */
533
- export const tarballFile = (name: string) =>
534
- `${name.replace(/^@/, "").replace("/", "+")}.tgz`;
502
+ export const tarballFile = (name: string) => `${name.replace(/^@/, "").replace("/", "+")}.tgz`;
535
503
 
536
504
  /**
537
505
  * Pack every discovered package into `out` with a manifest describing each
@@ -562,17 +530,13 @@ export const pack = Effect.fn("pack")(function* (options: PackOptions) {
562
530
  for (const pkg of packages) {
563
531
  const manifest = yield* fs
564
532
  .readFileString(path.join(pkg.absDir, "package.json"))
565
- .pipe(
566
- Effect.flatMap(
567
- Schema.decodeUnknownEffect(Schema.fromJsonString(DependencySections)),
568
- ),
569
- );
533
+ .pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(DependencySections))));
570
534
  dependencies.set(
571
535
  pkg.name,
572
536
  new Set(
573
- DEPENDENCY_SECTIONS.flatMap((section) =>
574
- Object.keys(manifest[section] ?? {}),
575
- ).filter((name) => name !== pkg.name && byName.has(name)),
537
+ DEPENDENCY_SECTIONS.flatMap((section) => Object.keys(manifest[section] ?? {})).filter(
538
+ (name) => name !== pkg.name && byName.has(name),
539
+ ),
576
540
  ),
577
541
  );
578
542
  }
@@ -614,11 +578,7 @@ export const pack = Effect.fn("pack")(function* (options: PackOptions) {
614
578
  // subdirectory of the workspace: `--out .` would otherwise delete it.
615
579
  const outDir = path.resolve(options.cwd, options.out);
616
580
  const relative = path.relative(options.cwd, outDir);
617
- if (
618
- relative === "" ||
619
- relative.startsWith("..") ||
620
- path.isAbsolute(relative)
621
- ) {
581
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
622
582
  return yield* new WorkspaceError({
623
583
  message: `--out must be a subdirectory of ${options.cwd}, got ${outDir}`,
624
584
  });
@@ -657,10 +617,7 @@ export const pack = Effect.fn("pack")(function* (options: PackOptions) {
657
617
  { concurrency: 4 },
658
618
  );
659
619
  for (const entry of packedLevel) {
660
- links.set(
661
- entry.name,
662
- tarballUrl(options.registry, entry.name, entry.sha256),
663
- );
620
+ links.set(entry.name, tarballUrl(options.registry, entry.name, entry.sha256));
664
621
  packedByName.set(entry.name, entry);
665
622
  }
666
623
  }
@@ -670,10 +627,7 @@ export const pack = Effect.fn("pack")(function* (options: PackOptions) {
670
627
  // One entry per distinct group name, in the order the groups were given.
671
628
  const groups = [
672
629
  ...new Map(
673
- options.groups.map((group) => [
674
- group.name,
675
- { name: group.name, collapsed: group.collapsed },
676
- ]),
630
+ options.groups.map((group) => [group.name, { name: group.name, collapsed: group.collapsed }]),
677
631
  ).values(),
678
632
  ];
679
633
  const manifest: Manifest = {
@@ -3,9 +3,9 @@ import * as Console from "effect/Console";
3
3
  import * as Data from "effect/Data";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as FileSystem from "effect/FileSystem";
6
+ import * as HttpApiClient from "effect/http-api/HttpApiClient";
6
7
  import * as Path from "effect/Path";
7
8
  import * as Schema from "effect/Schema";
8
- import * as HttpApiClient from "effect/http-api/HttpApiClient";
9
9
  import { MANIFEST_FILE, ManifestJson, type Manifest } from "../Manifest.ts";
10
10
  import { PkgApi, type TarballRef } from "../Protocol.ts";
11
11
 
@@ -25,9 +25,7 @@ export interface PublishOptions {
25
25
  const currentRun = Effect.gen(function* () {
26
26
  const repo = yield* Config.String("GITHUB_REPOSITORY");
27
27
  const runId = yield* Config.Int("GITHUB_RUN_ID");
28
- const attempt = yield* Config.Int("GITHUB_RUN_ATTEMPT").pipe(
29
- Config.withDefault(1),
30
- );
28
+ const attempt = yield* Config.Int("GITHUB_RUN_ATTEMPT").pipe(Config.withDefault(1));
31
29
  return { repo, runId, attempt };
32
30
  }).pipe(
33
31
  Effect.mapError(
@@ -39,11 +37,10 @@ const currentRun = Effect.gen(function* () {
39
37
  );
40
38
 
41
39
  /** Render a registry or transport failure as a `PublishError`. */
42
- const failed =
43
- (what: string) => (e: { readonly _tag: string; readonly message?: string }) =>
44
- new PublishError({
45
- message: `${what}: ${e.message ? `${e._tag}: ${e.message}` : e._tag}`,
46
- });
40
+ const failed = (what: string) => (e: { readonly _tag: string; readonly message?: string }) =>
41
+ new PublishError({
42
+ message: `${what}: ${e.message ? `${e._tag}: ${e.message}` : e._tag}`,
43
+ });
47
44
 
48
45
  /**
49
46
  * Publish a `pkg pack` directory from the current GitHub Actions job. The
@@ -52,9 +49,7 @@ const failed =
52
49
  * through GitHub, then either reports the tarballs it lacks, which are
53
50
  * uploaded before trying again, or writes the tags.
54
51
  */
55
- export const publish = Effect.fn("publish")(function* (
56
- options: PublishOptions,
57
- ) {
52
+ export const publish = Effect.fn("publish")(function* (options: PublishOptions) {
58
53
  const fs = yield* FileSystem.FileSystem;
59
54
  const path = yield* Path.Path;
60
55
  const registry = options.registry.replace(/\/+$/, "");
@@ -63,8 +58,7 @@ export const publish = Effect.fn("publish")(function* (
63
58
 
64
59
  const dir = path.resolve(options.cwd, options.dir);
65
60
  const manifestText = yield* fs.readFileString(path.join(dir, MANIFEST_FILE));
66
- const manifest =
67
- yield* Schema.decodeUnknownEffect(ManifestJson)(manifestText);
61
+ const manifest = yield* Schema.decodeUnknownEffect(ManifestJson)(manifestText);
68
62
  if (manifest.registry !== registry) {
69
63
  return yield* new PublishError({
70
64
  message: `artifact was packed for ${manifest.registry}, not ${registry}`,
@@ -96,9 +90,7 @@ export const publish = Effect.fn("publish")(function* (
96
90
  ).pipe(
97
91
  Effect.andThen(
98
92
  Effect.forEach(
99
- manifest.packages.filter((pkg) =>
100
- wanted.has(`${pkg.name}@${pkg.sha256}`),
101
- ),
93
+ manifest.packages.filter((pkg) => wanted.has(`${pkg.name}@${pkg.sha256}`)),
102
94
  upload,
103
95
  { concurrency: 4, discard: true },
104
96
  ),
@@ -112,9 +104,7 @@ export const publish = Effect.fn("publish")(function* (
112
104
  const published = yield* attempt.pipe(
113
105
  // The first answer is usually the tarballs to upload; publish once more
114
106
  // after uploading them.
115
- Effect.catchTag("MissingTarballs", (e) =>
116
- Effect.andThen(uploadMissing(e.missing), attempt),
117
- ),
107
+ Effect.catchTag("MissingTarballs", (e) => Effect.andThen(uploadMissing(e.missing), attempt)),
118
108
  Effect.catchTag(
119
109
  "MissingTarballs",
120
110
  (e) =>
@@ -122,9 +112,7 @@ export const publish = Effect.fn("publish")(function* (
122
112
  message: `registry still reports missing tarballs after upload: ${e.missing.map((ref) => ref.name).join(", ")}`,
123
113
  }),
124
114
  ),
125
- Effect.mapError((e) =>
126
- e._tag === "PublishError" ? e : failed("publish")(e),
127
- ),
115
+ Effect.mapError((e) => (e._tag === "PublishError" ? e : failed("publish")(e))),
128
116
  );
129
117
 
130
118
  for (const pkg of published.packages) {