@r_masseater/msch 0.42.0 → 0.48.0

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 (71) hide show
  1. package/README.md +11 -9
  2. package/dist/cargo-inputs.d.mts +1 -0
  3. package/dist/cargo-inputs.mjs +149 -94
  4. package/dist/cargo-inputs.mjs.map +1 -1
  5. package/dist/changed.d.mts +1 -0
  6. package/dist/changed.mjs +178 -0
  7. package/dist/changed.mjs.map +1 -0
  8. package/dist/check-upstream-exits-BJNhgkLI.mjs +499 -0
  9. package/dist/check-upstream-exits-BJNhgkLI.mjs.map +1 -0
  10. package/dist/cli-contract-D7btWrEu.mjs +5 -0
  11. package/dist/cli-contract-D7btWrEu.mjs.map +1 -0
  12. package/dist/cli.mjs +865 -1070
  13. package/dist/cli.mjs.map +1 -1
  14. package/dist/{comment-directives-5-f_qs1E.mjs → comment-directives-CRAU6yNZ.mjs} +2 -1
  15. package/dist/comment-directives-CRAU6yNZ.mjs.map +1 -0
  16. package/dist/config.d.mts +3 -1
  17. package/dist/config.mjs +23 -9
  18. package/dist/config.mjs.map +1 -1
  19. package/dist/decision-rules.d.mts +1 -1
  20. package/dist/decision-rules.mjs +1 -1
  21. package/dist/{define-lint-preset-DKJku2ZR.mjs → define-lint-preset-BhT4RpHs.mjs} +16 -25
  22. package/dist/define-lint-preset-BhT4RpHs.mjs.map +1 -0
  23. package/dist/{package-vbK0Qycn.mjs → dependencies-v59cxwTD.mjs} +186 -165
  24. package/dist/dependencies-v59cxwTD.mjs.map +1 -0
  25. package/dist/exits.d.mts +1 -0
  26. package/dist/exits.mjs +58 -0
  27. package/dist/exits.mjs.map +1 -0
  28. package/dist/{ignored-directories-CfACwIvu.mjs → ignored-directories-thSB0IAT.mjs} +13 -6
  29. package/dist/ignored-directories-thSB0IAT.mjs.map +1 -0
  30. package/dist/{index-BwiAHe_u.d.mts → index-DL7PSp7j.d.mts} +3 -3
  31. package/dist/lint.d.mts +1 -1
  32. package/dist/lint.mjs +1 -1
  33. package/dist/locked-closure-paths-Dtqs8uBU.mjs +7 -0
  34. package/dist/locked-closure-paths-Dtqs8uBU.mjs.map +1 -0
  35. package/dist/locked-inputs.d.mts +12 -0
  36. package/dist/locked-inputs.mjs +20 -0
  37. package/dist/locked-inputs.mjs.map +1 -0
  38. package/dist/oxlint.mjs +3 -1
  39. package/dist/oxlint.mjs.map +1 -1
  40. package/dist/package-Bdv6W97F.mjs +144 -0
  41. package/dist/package-Bdv6W97F.mjs.map +1 -0
  42. package/dist/problem-u-p6QglA.mjs +39 -0
  43. package/dist/problem-u-p6QglA.mjs.map +1 -0
  44. package/dist/project-DeQcAglt.mjs +464 -0
  45. package/dist/project-DeQcAglt.mjs.map +1 -0
  46. package/dist/publish.mjs +413 -169
  47. package/dist/publish.mjs.map +1 -1
  48. package/dist/reachable-Cc-255L3.mjs +13 -0
  49. package/dist/reachable-Cc-255L3.mjs.map +1 -0
  50. package/dist/{repository-files-CPfBA4mf.mjs → repository-files-aXwrITdF.mjs} +3 -2
  51. package/dist/repository-files-aXwrITdF.mjs.map +1 -0
  52. package/dist/{runtime-Dc5gCUSF.mjs → runtime-BmlYnI7T.mjs} +3 -3
  53. package/dist/{runtime-Dc5gCUSF.mjs.map → runtime-BmlYnI7T.mjs.map} +1 -1
  54. package/dist/started-once-CkTooI_o.mjs +13 -0
  55. package/dist/started-once-CkTooI_o.mjs.map +1 -0
  56. package/dist/{cli-contract-DdTV5DaG.mjs → syntax-ct2fFLtv.mjs} +9 -45
  57. package/dist/syntax-ct2fFLtv.mjs.map +1 -0
  58. package/dist/workspace-settings.mjs +8 -32
  59. package/dist/workspace-settings.mjs.map +1 -1
  60. package/package.json +43 -34
  61. package/skills/msch-checks/SKILL.md +10 -1
  62. package/skills/publishing/SKILL.md +6 -4
  63. package/skills/repository-config/SKILL.md +14 -9
  64. package/skills/workspace-settings/SKILL.md +33 -3
  65. package/src/app/vite.d.ts +2 -0
  66. package/dist/cli-contract-DdTV5DaG.mjs.map +0 -1
  67. package/dist/comment-directives-5-f_qs1E.mjs.map +0 -1
  68. package/dist/define-lint-preset-DKJku2ZR.mjs.map +0 -1
  69. package/dist/ignored-directories-CfACwIvu.mjs.map +0 -1
  70. package/dist/package-vbK0Qycn.mjs.map +0 -1
  71. package/dist/repository-files-CPfBA4mf.mjs.map +0 -1
package/dist/publish.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { t as runCli } from "./runtime-Dc5gCUSF.mjs";
2
+ import { t as runCli } from "./runtime-BmlYnI7T.mjs";
3
3
  import { Array, Config, Console, Effect, FileSystem, Option, Order, Path, Predicate, Record, Redacted, Schema, Stdio, Stream, String, pipe } from "effect";
4
4
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
5
+ import semver from "semver";
5
6
  import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
6
- import "effect/encoding";
7
+ import { Base64 } from "effect/encoding";
7
8
  // ../github-workflow/src/shared/api/github.ts
8
9
  const API = "https://api.github.com";
9
10
  const HEADERS = {
@@ -27,8 +28,8 @@ Effect.fn("withBody")(function* withBody(method, path, body) {
27
28
  });
28
29
  // ../github-workflow/src/shared/lib/process.ts
29
30
  const SUCCESS = 0;
30
- const taggedError$2 = Schema.TaggedError;
31
- var CommandFailed = class extends taggedError$2()("CommandFailed", { message: Schema.String }) {};
31
+ const taggedError$3 = Schema.TaggedError;
32
+ var CommandFailed = class extends taggedError$3()("CommandFailed", { message: Schema.String }) {};
32
33
  const failed = ({ command, args }) => CommandFailed.make({ message: `${command} ${Array.join(args, " ")} failed` });
33
34
  const exitCodeOf = Effect.fn("exitCodeOf")(function* exitCodeOf({ command, args, env, cwd }) {
34
35
  return yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(command, args, {
@@ -64,8 +65,8 @@ const mustSucceed = mustSucceedWith;
64
65
  /** @internal */
65
66
  const outputOf = outputWith;
66
67
  // ../github-workflow/src/shared/lib/workflow.ts
67
- const taggedError$1 = Schema.TaggedError;
68
- var WorkflowFailed = class extends taggedError$1()("WorkflowFailed", { message: Schema.String }) {};
68
+ const taggedError$2 = Schema.TaggedError;
69
+ var WorkflowFailed = class extends taggedError$2()("WorkflowFailed", { message: Schema.String }) {};
69
70
  const appendTo = (variable, entries) => Effect.gen(function* appended() {
70
71
  const path = yield* Config.String(variable);
71
72
  const fs = yield* FileSystem.FileSystem;
@@ -80,10 +81,43 @@ Effect.fn("fail")(function* fail(message) {
80
81
  yield* Console.log(`::error::${message}`);
81
82
  return yield* WorkflowFailed.make({ message });
82
83
  });
84
+ // src/features/publish-workspace/model/broker.ts
85
+ const BROKER = "https://credentials.masseater.dev/";
86
+ const AUDIENCE = "masseater-dev-credential-broker";
87
+ const IdToken = Schema.Struct({ value: Schema.String });
88
+ const Issued = Schema.Record(Schema.String, Schema.Unknown);
89
+ const oidcToken = Effect.fn("publish.oidc")(function* oidcToken(requestUrl, requestToken) {
90
+ const client = yield* HttpClient.HttpClient;
91
+ const request = HttpClientRequest.get(`${requestUrl}&audience=${AUDIENCE}`).pipe(HttpClientRequest.bearerToken(Redacted.value(requestToken)));
92
+ const response = yield* HttpClient.filterStatusOk(client).execute(request);
93
+ const { value } = yield* HttpClientResponse.schemaBodyJson(IdToken)(response);
94
+ yield* mask(value);
95
+ return value;
96
+ });
97
+ const issued = Effect.fn("publish.issued")(function* issued(oidc, { kind, field }) {
98
+ const client = yield* HttpClient.HttpClient;
99
+ const request = HttpClientRequest.post(`${BROKER}?only=${kind}`).pipe(HttpClientRequest.bearerToken(oidc));
100
+ const response = yield* HttpClient.filterStatusOk(client).execute(request);
101
+ const body = yield* HttpClientResponse.schemaBodyJson(Issued)(response);
102
+ const token = Option.filter(Option.fromNullishOr(body[field]), (value) => typeof value === "string" && value !== "");
103
+ yield* Effect.forEach(Option.toArray(token), mask, {
104
+ concurrency: 1,
105
+ discard: true
106
+ });
107
+ return token;
108
+ });
109
+ /** @internal */
110
+ const brokerCredential = Effect.fn("publish.brokerCredential")(function* brokerCredential(credential) {
111
+ const requestUrl = yield* Config.option(Config.String("ACTIONS_ID_TOKEN_REQUEST_URL"));
112
+ const requestToken = yield* Config.option(Config.Redacted("ACTIONS_ID_TOKEN_REQUEST_TOKEN"));
113
+ if (Option.isNone(requestUrl) || Option.isNone(requestToken)) return Option.none();
114
+ return yield* oidcToken(requestUrl.value, requestToken.value).pipe(Effect.flatMap((oidc) => issued(oidc, credential)), Effect.tapError(() => Console.log(`The credential broker gave no ${credential.field}`)), Effect.orElseSucceed(() => Option.none()));
115
+ });
83
116
  // src/features/publish-workspace/model/manifest.ts
84
117
  const MANIFEST_FILE$1 = "package.json";
85
118
  const SCOPE = /^@[^/]+\//u;
86
- const UNVERSIONED = "0.0.0";
119
+ const UNVERSIONED$1 = "0.0.0";
120
+ const ROOT = ".";
87
121
  const Native = Schema.Struct({
88
122
  binary: Schema.String,
89
123
  targets: Schema.Array(Schema.String)
@@ -92,6 +126,7 @@ const ManifestSchema = Schema.Struct({
92
126
  name: Schema.String,
93
127
  version: Schema.String,
94
128
  private: Schema.optionalKey(Schema.Boolean),
129
+ dependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
95
130
  native: Schema.optionalKey(Native),
96
131
  "size-limit": Schema.optionalKey(Schema.Unknown)
97
132
  });
@@ -105,13 +140,51 @@ const manifestIn = Effect.fn("publish.manifest")(function* manifestIn(directory)
105
140
  /** @internal */
106
141
  const releaseName = ({ name }) => String.replace(SCOPE, "")(name);
107
142
  /** @internal */
108
- const tagOf = (manifest) => `${releaseName(manifest)}-v${manifest.version}`;
143
+ const isRoot = (directory) => directory === ROOT;
144
+ /** @internal */
145
+ const tagOf = ({ directory, name, version }) => {
146
+ if (isRoot(directory)) return `v${version}`;
147
+ return `${releaseName({ name })}-v${version}`;
148
+ };
109
149
  /** @internal */
110
150
  const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
111
151
  /** @internal */
112
- const isVersioned = ({ version }) => version !== UNVERSIONED;
152
+ const isVersioned = ({ version }) => version !== UNVERSIONED$1;
113
153
  /** @internal */
114
154
  const goesToNpm = (manifest) => !pipe(Option.fromUndefinedOr(manifest.private), Option.getOrElse(() => false));
155
+ // src/features/publish-workspace/model/dependencies.ts
156
+ const WORKSPACE_PROTOCOL = "workspace:";
157
+ const READ_CONCURRENCY = 8;
158
+ /** @internal */
159
+ const onNpm = ({ directory, name, version }) => succeeds({
160
+ command: "npm",
161
+ args: [
162
+ "view",
163
+ `${name}@${version}`,
164
+ "version"
165
+ ],
166
+ cwd: directory
167
+ });
168
+ const taggedError$1 = Schema.TaggedError;
169
+ /** @internal */
170
+ var UnpublishedDependencies = class extends taggedError$1()("UnpublishedDependencies", { message: Schema.String }) {};
171
+ const workspaceDependencies = (manifest) => pipe(Option.fromUndefinedOr(manifest.dependencies), Option.map((dependencies) => pipe(dependencies, Record.filter(String.startsWith(WORKSPACE_PROTOCOL)), Record.keys)), Option.getOrElse(() => []));
172
+ const failWhenMissing = (missing, manifest) => {
173
+ if (Array.isReadonlyArrayEmpty(missing)) return Effect.void;
174
+ const names = pipe(missing, Array.map(({ directory, name, version }) => `${name}@${version} (${directory})`), Array.join(", "));
175
+ return Effect.fail(UnpublishedDependencies.make({ message: `${manifest.name} depends on versions that are not on npm yet. Publish them first: ${names}` }));
176
+ };
177
+ /** @internal */
178
+ const requirePublishedDependencies = Effect.fn("publish.dependencies")(function* requirePublishedDependencies({ manifest, workspaces }) {
179
+ const wanted = workspaceDependencies(manifest);
180
+ const siblings = yield* Effect.forEach(workspaces, (directory) => manifestIn(directory).pipe(Effect.map((found) => ({
181
+ directory,
182
+ ...found
183
+ }))), { concurrency: READ_CONCURRENCY });
184
+ const internal = pipe(siblings, Array.filter((sibling) => Array.contains(wanted, sibling.name) && goesToNpm(sibling)));
185
+ const missing = yield* Effect.filter(internal, (sibling) => onNpm(sibling).pipe(Effect.map((published) => !published)), { concurrency: READ_CONCURRENCY });
186
+ yield* failWhenMissing(missing, manifest);
187
+ });
115
188
  // src/features/publish-workspace/model/platforms.ts
116
189
  const RUNNERS = {
117
190
  linux: "ubuntu-latest",
@@ -167,127 +240,30 @@ const nativeFields = (native) => {
167
240
  };
168
241
  /** @internal */
169
242
  const nativeReadme = ({ name, target }) => `# ${name}-${target}\n\nThe prebuilt ${target} native addon of [${name}](https://www.npmjs.com/package/${name}). Install ${name} instead; npm picks this package for your platform.\n`;
170
- // src/features/publish-workspace/model/plan.ts
171
- const HOOK = "release:publish";
172
- const NONE = 0;
173
- const TRAILING_SLASH = /\/$/u;
174
- const Task = Schema.Struct({
175
- package: Schema.String,
176
- name: Schema.String
177
- });
178
- const TaskGraph = Schema.fromJsonString(Schema.Struct({
179
- workspaceRoot: Schema.String,
180
- tasks: Schema.Record(Schema.String, Task)
181
- }));
182
- const Runner = Schema.Struct({
183
- os: Schema.String,
184
- runner: Schema.String
185
- });
186
- const NativeTarget = Schema.Struct({
187
- target: Schema.String,
188
- runner: Schema.String
189
- });
190
- const PlanSchema = Schema.Struct({
191
- directory: Schema.String,
192
- name: Schema.String,
193
- version: Schema.String,
194
- tag: Schema.String,
195
- environment: Schema.String,
196
- npm: Schema.Boolean,
197
- native: Schema.Array(NativeTarget),
198
- builds: Schema.Array(Runner),
199
- checks: Schema.Array(Runner),
200
- release: Schema.Boolean,
201
- hook: Schema.Boolean
202
- });
203
- const AssetCount = Schema.fromJsonString(Schema.Finite);
204
- const tasksOf = Effect.fn("publish.tasks")(function* tasksOf(directory) {
205
- const text = yield* outputOf({
206
- command: "vp",
207
- args: ["run", "--json"]
208
- });
209
- const graph = yield* Schema.decodeEffect(TaskGraph)(text);
210
- return pipe(Record.values(graph.tasks), Array.filter((task) => task.package === directory), Array.map(({ name }) => name));
211
- });
243
+ // src/features/publish-workspace/model/widened-ranges.ts
244
+ const HOOK_FILE = "widen-ranges.mjs";
212
245
  /** @internal */
213
- const onNpm = ({ directory, name, version }) => succeeds({
214
- command: "npm",
215
- args: [
216
- "view",
217
- `${name}@${version}`,
218
- "version"
219
- ],
220
- cwd: directory
221
- });
222
- /** @internal */
223
- const releasedWithAssets = Effect.fn("publish.releasedWithAssets")(function* releasedWithAssets(tag) {
224
- const view = [
225
- "release",
226
- "view",
227
- tag,
228
- "--repo",
229
- yield* Config.String("GITHUB_REPOSITORY")
230
- ];
231
- if (!(yield* succeeds({
232
- command: "gh",
233
- args: view
234
- }))) return false;
235
- return (yield* outputOf({
236
- command: "gh",
237
- args: [
238
- ...view,
239
- "--json",
240
- "assets",
241
- "--jq",
242
- ".assets | length"
243
- ]
244
- }).pipe(Effect.flatMap(Schema.decodeEffect(AssetCount)))) > NONE;
245
- });
246
- const keepWhen = (kept) => (items) => pipe(items, Array.filter(() => kept));
247
- const needsNpm = Effect.fn("publish.needsNpm")(function* needsNpm(directory, manifest) {
248
- if (!goesToNpm(manifest)) return false;
249
- return !(yield* onNpm({
250
- directory,
251
- ...manifest
252
- }));
253
- });
254
- const needsRelease = Effect.fn("publish.needsRelease")(function* needsRelease(manifest, builds) {
255
- if (!isVersioned(manifest) || Array.isReadonlyArrayEmpty(builds)) return false;
256
- return !(yield* releasedWithAssets(tagOf(manifest)));
257
- });
258
- const nativeOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.map(({ targets }) => nativeTargetsOf(targets)), Option.getOrElse(() => []));
259
- /** @internal */
260
- const planOf = Effect.fn("publish.plan")(function* planOf(directory) {
261
- const path = yield* Path.Path;
262
- const workspace = String.replace(TRAILING_SLASH, "")(path.normalize(directory));
263
- const manifest = yield* manifestIn(workspace);
264
- const tasks = yield* tasksOf(workspace);
265
- const npm = yield* needsNpm(workspace, manifest);
266
- const release = yield* needsRelease(manifest, buildsOf(tasks));
267
- const built = keepWhen(release || !isVersioned(manifest));
268
- return {
269
- directory: workspace,
270
- name: releaseName(manifest),
271
- version: manifest.version,
272
- tag: tagOf(manifest),
273
- environment: environmentOf(manifest),
274
- npm,
275
- native: keepWhen(npm)(nativeOf(manifest)),
276
- builds: built(buildsOf(tasks)),
277
- checks: built(checksOf(tasks)),
278
- release,
279
- hook: release && Array.contains(tasks, HOOK)
280
- };
281
- });
246
+ const WIDEN_RANGES = `const EXACT = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/u;
247
+ const widen = (held) =>
248
+ held === undefined
249
+ ? undefined
250
+ : Object.fromEntries(Object.entries(held).map(([name, specifier]) => [name, EXACT.test(specifier) ? \`^\${specifier}\` : specifier]));
251
+ export const hooks = {
252
+ beforePacking: (manifest) => ({
253
+ ...manifest,
254
+ dependencies: widen(manifest.dependencies),
255
+ peerDependencies: widen(manifest.peerDependencies),
256
+ }),
257
+ };
258
+ `;
282
259
  /** @internal */
283
- const writePlan = Effect.fn("publish.writePlan")(function* writePlan(plan) {
284
- const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(PlanSchema))(plan);
285
- yield* Effect.logInfo(encoded);
286
- yield* writeOutputs({ plan: encoded });
260
+ const widenRangesEnv = Effect.fn("publish.widenRanges")(function* widenRangesEnv(directory) {
261
+ const fileSystem = yield* FileSystem.FileSystem;
262
+ const hook = (yield* Path.Path).join(directory, HOOK_FILE);
263
+ yield* fileSystem.writeFileString(hook, WIDEN_RANGES);
264
+ return { pnpm_config_pnpmfile: hook };
287
265
  });
288
266
  // src/features/publish-workspace/model/npm.ts
289
- const BROKER = "https://credentials.masseater.dev/";
290
- const AUDIENCE = "masseater-dev-credential-broker";
291
267
  const TARBALL = "package.tgz";
292
268
  const NPM_DIR = "npm";
293
269
  const NATIVE_DIR = "native";
@@ -309,33 +285,11 @@ const PlatformManifest = Schema.fromJsonString(Schema.Struct({
309
285
  name: Schema.String,
310
286
  version: Schema.String
311
287
  }));
312
- const IdToken = Schema.Struct({ value: Schema.String });
313
- const Grants = Schema.Struct({ npmToken: Schema.optional(Schema.String) });
314
- const oidcToken = Effect.fn("publish.oidc")(function* oidcToken(requestUrl, requestToken) {
315
- const client = yield* HttpClient.HttpClient;
316
- const request = HttpClientRequest.get(`${requestUrl}&audience=${AUDIENCE}`).pipe(HttpClientRequest.bearerToken(Redacted.value(requestToken)));
317
- const response = yield* HttpClient.filterStatusOk(client).execute(request);
318
- const { value } = yield* HttpClientResponse.schemaBodyJson(IdToken)(response);
319
- yield* mask(value);
320
- return value;
321
- });
322
- const brokerToken = Effect.fn("publish.brokerToken")(function* brokerToken(oidc) {
323
- const client = yield* HttpClient.HttpClient;
324
- const request = HttpClientRequest.post(BROKER).pipe(HttpClientRequest.bearerToken(oidc));
325
- const response = yield* HttpClient.filterStatusOk(client).execute(request);
326
- const grants = yield* HttpClientResponse.schemaBodyJson(Grants)(response);
327
- const token = Option.fromUndefinedOr(grants.npmToken);
328
- yield* Effect.forEach(Option.toArray(token), mask, {
329
- concurrency: 1,
330
- discard: true
331
- });
332
- return token;
333
- });
334
288
  const authEnv = Effect.fn("publish.authEnv")(function* authEnv() {
335
- const requestUrl = yield* Config.option(Config.String("ACTIONS_ID_TOKEN_REQUEST_URL"));
336
- const requestToken = yield* Config.option(Config.Redacted("ACTIONS_ID_TOKEN_REQUEST_TOKEN"));
337
- if (Option.isNone(requestUrl) || Option.isNone(requestToken)) return {};
338
- const token = yield* oidcToken(requestUrl.value, requestToken.value).pipe(Effect.flatMap(brokerToken), Effect.tapError(() => Console.log("The credential broker gave no npm token; npm uses Trusted Publishing alone")), Effect.orElseSucceed(() => Option.none()));
289
+ const token = yield* brokerCredential({
290
+ kind: "npm",
291
+ field: "npmToken"
292
+ });
339
293
  return Option.match(token, {
340
294
  onNone: () => ({}),
341
295
  onSome: (value) => ({ NODE_AUTH_TOKEN: value })
@@ -430,6 +384,7 @@ const pack = Effect.fn("publish.pack")(function* pack(directory) {
430
384
  const path = yield* Path.Path;
431
385
  const temporary = yield* fileSystem.makeTempDirectoryScoped();
432
386
  const tarball = path.join(temporary, TARBALL);
387
+ const env = yield* widenRangesEnv(temporary);
433
388
  yield* mustSucceed({
434
389
  command: "vp",
435
390
  args: [
@@ -438,6 +393,7 @@ const pack = Effect.fn("publish.pack")(function* pack(directory) {
438
393
  "--out",
439
394
  tarball
440
395
  ],
396
+ env,
441
397
  cwd: directory
442
398
  });
443
399
  return tarball;
@@ -464,17 +420,57 @@ const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory)
464
420
  cwd: directory
465
421
  });
466
422
  }, Effect.scoped);
467
- // src/features/publish-workspace/model/release.ts
468
- const ASSETS = "release-assets";
469
- const tagRevision = Effect.fn("publish.tag")(function* tagRevision(tag) {
423
+ // src/features/publish-workspace/model/provenance.ts
424
+ const ATTESTATIONS = "https://registry.npmjs.org/-/npm/v1/attestations/";
425
+ const SLSA = /slsa\.dev\/provenance/u;
426
+ const Digest = Schema.Struct({ gitCommit: Schema.String });
427
+ const Dependency = Schema.Struct({ digest: Digest });
428
+ const BuildDefinition = Schema.Struct({ resolvedDependencies: Schema.Array(Dependency) });
429
+ const Predicate$1 = Schema.Struct({ buildDefinition: BuildDefinition });
430
+ const Statement = Schema.fromJsonString(Schema.Struct({ predicate: Predicate$1 }));
431
+ const Envelope = Schema.Struct({ payload: Schema.String });
432
+ const Bundle = Schema.Struct({ dsseEnvelope: Envelope });
433
+ const Attestation = Schema.Struct({
434
+ predicateType: Schema.String,
435
+ bundle: Bundle
436
+ });
437
+ const Attestations = Schema.Struct({ attestations: Schema.Array(Attestation) });
438
+ const commitOf = (payload) => pipe(Base64.decodeString(payload), Effect.fromResult, Effect.flatMap(Schema.decodeEffect(Statement)), Effect.map(({ predicate }) => pipe(Array.head(predicate.buildDefinition.resolvedDependencies), Option.map(({ digest }) => digest.gitCommit))), Effect.orElseSucceed(() => Option.none()));
439
+ /** @internal */
440
+ const provenanceCommit = Effect.fn("publish.provenanceCommit")(function* provenanceCommit({ name, version }) {
441
+ const client = yield* HttpClient.HttpClient;
442
+ const url = `${ATTESTATIONS}${String.replace("/", "%2f")(name)}@${version}`;
443
+ const found = yield* HttpClient.filterStatusOk(client).get(url).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Attestations)), Effect.map(({ attestations }) => Array.findFirst(attestations, ({ predicateType }) => SLSA.test(predicateType))), Effect.orElseSucceed(() => Option.none()));
444
+ if (Option.isNone(found)) return Option.none();
445
+ return yield* commitOf(found.value.bundle.dsseEnvelope.payload);
446
+ });
447
+ // src/features/publish-workspace/model/tags.ts
448
+ const UNVERSIONED = "0.0.0";
449
+ const LOOKUP_CONCURRENCY = 4;
450
+ const Versions = Schema.fromJsonString(Schema.Array(Schema.String));
451
+ /** @internal */
452
+ const tagged = Effect.fn("publish.tagged")(function* tagged(tag) {
470
453
  const repository = yield* Config.String("GITHUB_REPOSITORY");
471
- const sha = yield* Config.String("GITHUB_SHA");
472
- if (yield* succeeds({
454
+ return yield* succeeds({
473
455
  command: "gh",
474
456
  args: ["api", `repos/${repository}/git/ref/tags/${tag}`]
475
- })) return;
457
+ });
458
+ });
459
+ const tokenEnv = brokerCredential({
460
+ kind: "github",
461
+ field: "githubToken"
462
+ }).pipe(Effect.map(Option.match({
463
+ onNone: () => ({}),
464
+ onSome: (value) => ({ GH_TOKEN: value })
465
+ })));
466
+ /** @internal */
467
+ const createTag = Effect.fn("publish.createTag")(function* createTag({ tag, sha }) {
468
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
469
+ const env = yield* tokenEnv;
470
+ yield* Effect.logInfo(`tagging ${tag} at ${sha}`);
476
471
  yield* mustSucceed({
477
472
  command: "gh",
473
+ env,
478
474
  args: [
479
475
  "api",
480
476
  "-X",
@@ -487,6 +483,222 @@ const tagRevision = Effect.fn("publish.tag")(function* tagRevision(tag) {
487
483
  ]
488
484
  });
489
485
  });
486
+ const isRelease = (version) => version !== UNVERSIONED && semver.valid(version) !== null && semver.prerelease(version) === null;
487
+ const publishedVersions = Effect.fn("publish.publishedVersions")(function* publishedVersions({ directory, manifest }) {
488
+ if (!goesToNpm(manifest)) return [];
489
+ const text = yield* outputOf({
490
+ command: "npm",
491
+ args: [
492
+ "view",
493
+ manifest.name,
494
+ "versions",
495
+ "--json"
496
+ ],
497
+ cwd: directory
498
+ }).pipe(Effect.orElseSucceed(() => "[]"));
499
+ const versions = yield* Schema.decodeEffect(Versions)(text).pipe(Effect.orElseSucceed(() => []));
500
+ return pipe(versions, Array.filter((version) => isRelease(version) && version !== manifest.version));
501
+ });
502
+ /** @internal */
503
+ const untaggedVersions = Effect.fn("publish.untaggedVersions")(function* untaggedVersions(workspace) {
504
+ const versions = yield* publishedVersions(workspace);
505
+ return yield* Effect.filter(versions, (version) => tagged(tagOf({
506
+ directory: workspace.directory,
507
+ name: workspace.manifest.name,
508
+ version
509
+ })).pipe(Effect.map((found) => !found)), { concurrency: LOOKUP_CONCURRENCY });
510
+ });
511
+ const backfillVersion = Effect.fn("publish.backfillVersion")(function* backfillVersion(workspace, version) {
512
+ const { directory, manifest } = workspace;
513
+ const tag = tagOf({
514
+ directory,
515
+ name: manifest.name,
516
+ version
517
+ });
518
+ const commit = yield* provenanceCommit({
519
+ name: manifest.name,
520
+ version
521
+ });
522
+ if (Option.isNone(commit)) {
523
+ yield* Effect.logWarning(`${tag} has no npm provenance, so it stays untagged`);
524
+ return;
525
+ }
526
+ yield* createTag({
527
+ tag,
528
+ sha: commit.value
529
+ });
530
+ });
531
+ /** @internal */
532
+ const backfillTags = Effect.fn("publish.backfillTags")(function* backfillTags(workspace) {
533
+ const versions = yield* untaggedVersions(workspace);
534
+ yield* Effect.forEach(versions, (version) => backfillVersion(workspace, version), {
535
+ concurrency: 1,
536
+ discard: true
537
+ });
538
+ });
539
+ // src/features/publish-workspace/model/plan.ts
540
+ const HOOK = "release:publish";
541
+ const NONE = 0;
542
+ const TRAILING_SLASH = /\/$/u;
543
+ const Task = Schema.Struct({
544
+ package: Schema.String,
545
+ name: Schema.String
546
+ });
547
+ const TaskGraph = Schema.fromJsonString(Schema.Struct({
548
+ workspaceRoot: Schema.String,
549
+ tasks: Schema.Record(Schema.String, Task)
550
+ }));
551
+ const Runner = Schema.Struct({
552
+ os: Schema.String,
553
+ runner: Schema.String
554
+ });
555
+ const NativeTarget = Schema.Struct({
556
+ target: Schema.String,
557
+ runner: Schema.String
558
+ });
559
+ const PlanSchema = Schema.Struct({
560
+ directory: Schema.String,
561
+ name: Schema.String,
562
+ version: Schema.String,
563
+ tag: Schema.String,
564
+ environment: Schema.String,
565
+ npm: Schema.Boolean,
566
+ native: Schema.Array(NativeTarget),
567
+ builds: Schema.Array(Runner),
568
+ checks: Schema.Array(Runner),
569
+ release: Schema.Boolean,
570
+ tagged: Schema.Boolean,
571
+ hook: Schema.Boolean
572
+ });
573
+ const AssetCount = Schema.fromJsonString(Schema.Finite);
574
+ const graphTasks = outputOf({
575
+ command: "vp",
576
+ args: ["run", "--json"]
577
+ }).pipe(Effect.flatMap(Schema.decodeEffect(TaskGraph)), Effect.map(({ tasks }) => Record.values(tasks)));
578
+ const tasksIn = (tasks, directory) => pipe(tasks, Array.filter((task) => task.package === directory), Array.map(({ name }) => name));
579
+ const workspacesOf = (tasks) => pipe(tasks, Array.map((task) => task.package), Array.dedupe);
580
+ const allTagged = Effect.fn("publish.allTagged")(function* allTagged(directory, manifest) {
581
+ if (!isVersioned(manifest)) return true;
582
+ const current = yield* tagged(tagOf({
583
+ directory,
584
+ ...manifest
585
+ }));
586
+ const older = yield* untaggedVersions({
587
+ directory,
588
+ manifest
589
+ });
590
+ return current && Array.isReadonlyArrayEmpty(older);
591
+ });
592
+ const workspaceOf = (directory) => Path.Path.pipe(Effect.map((path) => String.replace(TRAILING_SLASH, "")(path.normalize(directory))));
593
+ /** @internal */
594
+ const released = Effect.fn("publish.released")(function* released(tag) {
595
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
596
+ return yield* succeeds({
597
+ command: "gh",
598
+ args: [
599
+ "release",
600
+ "view",
601
+ tag,
602
+ "--repo",
603
+ repository
604
+ ]
605
+ });
606
+ });
607
+ /** @internal */
608
+ const releasedWithAssets = Effect.fn("publish.releasedWithAssets")(function* releasedWithAssets(tag) {
609
+ const view = [
610
+ "release",
611
+ "view",
612
+ tag,
613
+ "--repo",
614
+ yield* Config.String("GITHUB_REPOSITORY")
615
+ ];
616
+ if (!(yield* released(tag))) return false;
617
+ return (yield* outputOf({
618
+ command: "gh",
619
+ args: [
620
+ ...view,
621
+ "--json",
622
+ "assets",
623
+ "--jq",
624
+ ".assets | length"
625
+ ]
626
+ }).pipe(Effect.flatMap(Schema.decodeEffect(AssetCount)))) > NONE;
627
+ });
628
+ const keepWhen = (kept) => (items) => pipe(items, Array.filter(() => kept));
629
+ const needsNpm = Effect.fn("publish.needsNpm")(function* needsNpm(directory, manifest, workspaces) {
630
+ if (!goesToNpm(manifest)) return false;
631
+ if (yield* onNpm({
632
+ directory,
633
+ ...manifest
634
+ })) return false;
635
+ yield* requirePublishedDependencies({
636
+ manifest,
637
+ workspaces
638
+ });
639
+ return true;
640
+ });
641
+ const needsRelease = Effect.fn("publish.needsRelease")(function* needsRelease(directory, manifest, builds) {
642
+ const tag = tagOf({
643
+ directory,
644
+ ...manifest
645
+ });
646
+ if (!isVersioned(manifest)) return false;
647
+ if (isRoot(directory)) return !(yield* released(tag));
648
+ if (Array.isReadonlyArrayEmpty(builds)) return false;
649
+ return !(yield* releasedWithAssets(tag));
650
+ });
651
+ const nativeOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.map(({ targets }) => nativeTargetsOf(targets)), Option.getOrElse(() => []));
652
+ /** @internal */
653
+ const planOf = Effect.fn("publish.plan")(function* planOf(directory) {
654
+ const workspace = yield* workspaceOf(directory);
655
+ const manifest = yield* manifestIn(workspace);
656
+ const graph = yield* graphTasks;
657
+ const tasks = tasksIn(graph, workspace);
658
+ const npm = yield* needsNpm(workspace, manifest, workspacesOf(graph));
659
+ const release = yield* needsRelease(workspace, manifest, buildsOf(tasks));
660
+ const built = keepWhen(release || !isVersioned(manifest));
661
+ const tag = tagOf({
662
+ directory: workspace,
663
+ ...manifest
664
+ });
665
+ return {
666
+ directory: workspace,
667
+ name: releaseName(manifest),
668
+ version: manifest.version,
669
+ tag,
670
+ tagged: yield* allTagged(workspace, manifest),
671
+ environment: environmentOf(manifest),
672
+ npm,
673
+ native: keepWhen(npm)(nativeOf(manifest)),
674
+ builds: built(buildsOf(tasks)),
675
+ checks: built(checksOf(tasks)),
676
+ release,
677
+ hook: release && Array.contains(tasks, HOOK)
678
+ };
679
+ });
680
+ /** @internal */
681
+ const writePlan = Effect.fn("publish.writePlan")(function* writePlan(plan) {
682
+ const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(PlanSchema))(plan);
683
+ yield* Effect.logInfo(encoded);
684
+ yield* writeOutputs({ plan: encoded });
685
+ });
686
+ // src/features/publish-workspace/model/release.ts
687
+ const ASSETS = "release-assets";
688
+ const revisionOf = Effect.fn("publish.revision")(function* revisionOf(manifest) {
689
+ const head = yield* Config.String("GITHUB_SHA");
690
+ if (!goesToNpm(manifest)) return head;
691
+ const published = yield* provenanceCommit(manifest);
692
+ return Option.getOrElse(published, () => head);
693
+ });
694
+ const tagRevision = Effect.fn("publish.tag")(function* tagRevision(tag, manifest) {
695
+ if (yield* tagged(tag)) return;
696
+ const sha = yield* revisionOf(manifest);
697
+ yield* createTag({
698
+ tag,
699
+ sha
700
+ });
701
+ });
490
702
  const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
491
703
  const fileSystem = yield* FileSystem.FileSystem;
492
704
  const path = yield* Path.Path;
@@ -496,7 +708,22 @@ const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
496
708
  const files = yield* Effect.filter(pipe(names, Array.map((name) => path.join(folder, name))), (file) => fileSystem.stat(file).pipe(Effect.map(({ type }) => type === "File"), Effect.orElseSucceed(() => false)));
497
709
  return Array.sort(files, Order.String);
498
710
  });
499
- const createRelease = Effect.fn("publish.createRelease")(function* createRelease(tag, title) {
711
+ const LIBRARY_NOTES = [
712
+ "--latest=false",
713
+ "--notes",
714
+ ""
715
+ ];
716
+ const ROOT_NOTES = ["--latest", "--generate-notes"];
717
+ const notesOf = (directory) => {
718
+ if (isRoot(directory)) return ROOT_NOTES;
719
+ return LIBRARY_NOTES;
720
+ };
721
+ const createRelease = Effect.fn("publish.createRelease")(function* createRelease({ directory, manifest }) {
722
+ const tag = tagOf({
723
+ directory,
724
+ ...manifest
725
+ });
726
+ const notes = notesOf(directory);
500
727
  const repository = yield* Config.String("GITHUB_REPOSITORY");
501
728
  if (yield* succeeds({
502
729
  command: "gh",
@@ -517,20 +744,24 @@ const createRelease = Effect.fn("publish.createRelease")(function* createRelease
517
744
  "--repo",
518
745
  repository,
519
746
  "--verify-tag",
520
- "--latest=false",
521
747
  "--title",
522
- title,
523
- "--notes",
524
- ""
748
+ `${releaseName(manifest)} v${manifest.version}`,
749
+ ...notes
525
750
  ]
526
751
  });
527
752
  });
528
- const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets(directory, manifest) {
529
- const tag = tagOf(manifest);
753
+ const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets({ directory, manifest }) {
754
+ const tag = tagOf({
755
+ directory,
756
+ ...manifest
757
+ });
530
758
  const files = yield* assetsIn(directory);
531
759
  if (Array.isReadonlyArrayEmpty(files) || (yield* releasedWithAssets(tag))) return;
532
760
  const repository = yield* Config.String("GITHUB_REPOSITORY");
533
- yield* createRelease(tag, `${releaseName(manifest)} v${manifest.version}`);
761
+ yield* createRelease({
762
+ directory,
763
+ manifest
764
+ });
534
765
  yield* mustSucceed({
535
766
  command: "gh",
536
767
  args: [
@@ -551,10 +782,23 @@ const publishRelease = Effect.fn("publish.release")(function* publishRelease(dir
551
782
  yield* Effect.logInfo(`${manifest.name} has no version to publish`);
552
783
  return;
553
784
  }
554
- const tag = tagOf(manifest);
555
- yield* tagRevision(tag);
785
+ const tag = tagOf({
786
+ directory,
787
+ ...manifest
788
+ });
789
+ yield* Effect.andThen(tagRevision(tag, manifest), backfillTags({
790
+ directory,
791
+ manifest
792
+ }));
556
793
  yield* writeOutputs({ tag });
557
- yield* uploadAssets(directory, manifest);
794
+ if (isRoot(directory)) yield* createRelease({
795
+ directory,
796
+ manifest
797
+ });
798
+ yield* uploadAssets({
799
+ directory,
800
+ manifest
801
+ });
558
802
  });
559
803
  // bin/msch-publish.ts
560
804
  const Arguments = Schema.Union([