@r_masseater/msch 0.41.0 → 0.47.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 (63) hide show
  1. package/README.md +16 -8
  2. package/dist/cargo-inputs.d.mts +15 -0
  3. package/dist/cargo-inputs.mjs +281 -0
  4. package/dist/cargo-inputs.mjs.map +1 -0
  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/cli-contract-BY7vwgKc.mjs +41 -0
  9. package/dist/cli-contract-BY7vwgKc.mjs.map +1 -0
  10. package/dist/cli.mjs +1038 -1206
  11. package/dist/cli.mjs.map +1 -1
  12. package/dist/config.d.mts +4 -2
  13. package/dist/config.mjs +26 -13
  14. package/dist/config.mjs.map +1 -1
  15. package/dist/decision-rules.d.mts +1 -1
  16. package/dist/decision-rules.mjs +1 -1
  17. package/dist/{define-lint-preset-BYMl7wof.mjs → define-lint-preset-CxzPzVuB.mjs} +110 -80
  18. package/dist/define-lint-preset-CxzPzVuB.mjs.map +1 -0
  19. package/dist/{package-A62qq8pE.mjs → dependencies-v59cxwTD.mjs} +186 -165
  20. package/dist/dependencies-v59cxwTD.mjs.map +1 -0
  21. package/dist/ignored-directories-thSB0IAT.mjs +57 -0
  22. package/dist/ignored-directories-thSB0IAT.mjs.map +1 -0
  23. package/dist/{index-lM4Pphgz.d.mts → index-DL7PSp7j.d.mts} +21 -16
  24. package/dist/{index-CcVKuHBw.d.mts → index-DdJXnW1q.d.mts} +2 -2
  25. package/dist/lint.d.mts +2 -2
  26. package/dist/lint.mjs +1 -1
  27. package/dist/locked-closure-paths-Dtqs8uBU.mjs +7 -0
  28. package/dist/locked-closure-paths-Dtqs8uBU.mjs.map +1 -0
  29. package/dist/locked-inputs.d.mts +12 -0
  30. package/dist/locked-inputs.mjs +20 -0
  31. package/dist/locked-inputs.mjs.map +1 -0
  32. package/dist/oxlint.mjs +2 -1
  33. package/dist/oxlint.mjs.map +1 -1
  34. package/dist/package-Bdv6W97F.mjs +144 -0
  35. package/dist/package-Bdv6W97F.mjs.map +1 -0
  36. package/dist/project-DeQcAglt.mjs +464 -0
  37. package/dist/project-DeQcAglt.mjs.map +1 -0
  38. package/dist/publish.d.mts +1 -0
  39. package/dist/publish.mjs +822 -0
  40. package/dist/publish.mjs.map +1 -0
  41. package/dist/reachable-Cc-255L3.mjs +13 -0
  42. package/dist/reachable-Cc-255L3.mjs.map +1 -0
  43. package/dist/{repository-files-CorshdqY.mjs → repository-files-aXwrITdF.mjs} +9 -2
  44. package/dist/repository-files-aXwrITdF.mjs.map +1 -0
  45. package/dist/runtime-GbrDfB8K.mjs +29 -0
  46. package/dist/runtime-GbrDfB8K.mjs.map +1 -0
  47. package/dist/started-once-CkTooI_o.mjs +13 -0
  48. package/dist/started-once-CkTooI_o.mjs.map +1 -0
  49. package/dist/{cli-contract-8SnKqhGw.mjs → syntax-ct2fFLtv.mjs} +9 -45
  50. package/dist/syntax-ct2fFLtv.mjs.map +1 -0
  51. package/dist/workspace-settings.d.mts +1 -1
  52. package/dist/workspace-settings.mjs +11 -92
  53. package/dist/workspace-settings.mjs.map +1 -1
  54. package/package.json +52 -34
  55. package/skills/msch-checks/SKILL.md +1 -6
  56. package/skills/publishing/SKILL.md +46 -0
  57. package/skills/repository-config/SKILL.md +21 -15
  58. package/skills/workspace-settings/SKILL.md +33 -3
  59. package/src/app/vite.d.ts +6 -0
  60. package/dist/cli-contract-8SnKqhGw.mjs.map +0 -1
  61. package/dist/define-lint-preset-BYMl7wof.mjs.map +0 -1
  62. package/dist/package-A62qq8pE.mjs.map +0 -1
  63. package/dist/repository-files-CorshdqY.mjs.map +0 -1
@@ -0,0 +1,822 @@
1
+ #!/usr/bin/env node
2
+ import { t as runCli } from "./runtime-GbrDfB8K.mjs";
3
+ import { Array, Config, Console, Effect, FileSystem, Option, Order, Path, Predicate, Record, Redacted, Schema, Stdio, Stream, String, pipe } from "effect";
4
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
5
+ import semver from "semver";
6
+ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
7
+ import { Base64 } from "effect/encoding";
8
+ // ../github-workflow/src/shared/api/github.ts
9
+ const API = "https://api.github.com";
10
+ const HEADERS = {
11
+ accept: "application/vnd.github+json",
12
+ "user-agent": "masseater.dev",
13
+ "x-github-api-version": "2022-11-28"
14
+ };
15
+ const requestTo = Effect.fn("requestTo")(function* requestTo(method, path) {
16
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
17
+ const token = yield* Config.Redacted("GH_TOKEN").pipe(Config.orElse(() => Config.Redacted("GITHUB_TOKEN")));
18
+ return HttpClientRequest.make(method)(`${API}/repos/${repository}/${path}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)), HttpClientRequest.setHeaders(HEADERS));
19
+ });
20
+ const execute = Effect.fn("execute")(function* execute(request) {
21
+ const response = yield* (yield* HttpClient.HttpClient).execute(request);
22
+ return yield* HttpClientResponse.filterStatusOk(response);
23
+ });
24
+ Effect.fn("withBody")(function* withBody(method, path, body) {
25
+ const request = yield* requestTo(method, path);
26
+ const filled = yield* HttpClientRequest.bodyJson(request, body);
27
+ return yield* execute(filled);
28
+ });
29
+ // ../github-workflow/src/shared/lib/process.ts
30
+ const SUCCESS = 0;
31
+ const taggedError$3 = Schema.TaggedError;
32
+ var CommandFailed = class extends taggedError$3()("CommandFailed", { message: Schema.String }) {};
33
+ const failed = ({ command, args }) => CommandFailed.make({ message: `${command} ${Array.join(args, " ")} failed` });
34
+ const exitCodeOf = Effect.fn("exitCodeOf")(function* exitCodeOf({ command, args, env, cwd }) {
35
+ return yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(command, args, {
36
+ cwd,
37
+ env,
38
+ extendEnv: true,
39
+ stdin: "ignore",
40
+ stdout: "inherit",
41
+ stderr: "inherit"
42
+ }));
43
+ });
44
+ const succeedsWith = (command) => exitCodeOf(command).pipe(Effect.map((code) => code === SUCCESS));
45
+ const mustSucceedWith = (command) => succeedsWith(command).pipe(Effect.filterOrFail((passed) => passed, () => failed(command)), Effect.asVoid);
46
+ const collected = Effect.fn("collected")(function* collected({ command, args, env, cwd }) {
47
+ const handle = yield* ChildProcess.make(command, args, {
48
+ cwd,
49
+ env,
50
+ extendEnv: true,
51
+ stdin: "ignore",
52
+ stderr: "inherit"
53
+ });
54
+ const [output, code] = yield* Effect.all([handle.stdout.pipe(Stream.decodeText(), Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
55
+ return {
56
+ output,
57
+ code
58
+ };
59
+ });
60
+ const outputWith = (command) => collected(command).pipe(Effect.scoped, Effect.filterOrFail(({ code }) => code === SUCCESS, () => failed(command)), Effect.map(({ output }) => String.trim(output)));
61
+ /** @internal */
62
+ const succeeds = succeedsWith;
63
+ /** @internal */
64
+ const mustSucceed = mustSucceedWith;
65
+ /** @internal */
66
+ const outputOf = outputWith;
67
+ // ../github-workflow/src/shared/lib/workflow.ts
68
+ const taggedError$2 = Schema.TaggedError;
69
+ var WorkflowFailed = class extends taggedError$2()("WorkflowFailed", { message: Schema.String }) {};
70
+ const appendTo = (variable, entries) => Effect.gen(function* appended() {
71
+ const path = yield* Config.String(variable);
72
+ const fs = yield* FileSystem.FileSystem;
73
+ const lines = pipe(Record.toEntries(entries), Array.map(([name, value]) => `${name}=${value}\n`), Array.join(""));
74
+ yield* fs.writeFileString(path, lines, { flag: "a" });
75
+ });
76
+ const outputsOf = (outputs) => appendTo("GITHUB_OUTPUT", outputs);
77
+ /** @internal */
78
+ const writeOutputs = outputsOf;
79
+ const mask = (value) => Console.log(`::add-mask::${value}`);
80
+ Effect.fn("fail")(function* fail(message) {
81
+ yield* Console.log(`::error::${message}`);
82
+ return yield* WorkflowFailed.make({ message });
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
+ });
116
+ // src/features/publish-workspace/model/manifest.ts
117
+ const MANIFEST_FILE$1 = "package.json";
118
+ const SCOPE = /^@[^/]+\//u;
119
+ const UNVERSIONED$1 = "0.0.0";
120
+ const ROOT = ".";
121
+ const Native = Schema.Struct({
122
+ binary: Schema.String,
123
+ targets: Schema.Array(Schema.String)
124
+ });
125
+ const ManifestSchema = Schema.Struct({
126
+ name: Schema.String,
127
+ version: Schema.String,
128
+ private: Schema.optionalKey(Schema.Boolean),
129
+ dependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
130
+ native: Schema.optionalKey(Native),
131
+ "size-limit": Schema.optionalKey(Schema.Unknown)
132
+ });
133
+ /** @internal */
134
+ const manifestIn = Effect.fn("publish.manifest")(function* manifestIn(directory) {
135
+ const fileSystem = yield* FileSystem.FileSystem;
136
+ const path = yield* Path.Path;
137
+ const text = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE$1));
138
+ return yield* Schema.decodeEffect(Schema.fromJsonString(ManifestSchema))(text);
139
+ });
140
+ /** @internal */
141
+ const releaseName = ({ name }) => String.replace(SCOPE, "")(name);
142
+ /** @internal */
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
+ };
149
+ /** @internal */
150
+ const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
151
+ /** @internal */
152
+ const isVersioned = ({ version }) => version !== UNVERSIONED$1;
153
+ /** @internal */
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
+ });
188
+ // src/features/publish-workspace/model/platforms.ts
189
+ const RUNNERS = {
190
+ linux: "ubuntu-latest",
191
+ windows: "windows-latest",
192
+ macos: "macos-latest"
193
+ };
194
+ const NODE_PLATFORMS = {
195
+ linux: "linux",
196
+ win32: "windows",
197
+ darwin: "macos"
198
+ };
199
+ const BUILD = "release:";
200
+ const CHECK = "release:check:";
201
+ const LIBC = {
202
+ gnu: "glibc",
203
+ musl: "musl"
204
+ };
205
+ const CPU_INDEX = 1;
206
+ const ABI_INDEX = 2;
207
+ const systems = Record.keys(RUNNERS);
208
+ const runnersFor = (tasks, prefix) => pipe(systems, Array.filter((os) => Array.contains(tasks, `${prefix}${os}`)), Array.map((os) => ({
209
+ os,
210
+ runner: RUNNERS[os]
211
+ })));
212
+ /** @internal */
213
+ const buildsOf = (tasks) => runnersFor(tasks, BUILD);
214
+ /** @internal */
215
+ const checksOf = (tasks) => runnersFor(tasks, CHECK);
216
+ /** @internal */
217
+ const nativeTargetsOf = (targets) => pipe(targets, Array.flatMap((target) => pipe(Array.head(String.split(target, "-")), Option.flatMap((platform) => Record.get(NODE_PLATFORMS, platform)), Option.map((os) => ({
218
+ target,
219
+ runner: RUNNERS[os]
220
+ })), Option.toArray)));
221
+ const libcOf = (parts) => pipe(Array.get(parts, ABI_INDEX), Option.flatMap((abi) => Record.get(LIBC, abi)), Option.match({
222
+ onNone: () => ({}),
223
+ onSome: (libc) => ({ libc: [libc] })
224
+ }));
225
+ /** @internal */
226
+ const nativeFileOf = ({ binary, target }) => `${binary}.${target}.node`;
227
+ /** @internal */
228
+ const nativeFields = (native) => {
229
+ const parts = String.split(native.target, "-");
230
+ const file = nativeFileOf(native);
231
+ return {
232
+ name: `${native.name}-${native.target}`,
233
+ version: native.version,
234
+ os: Option.toArray(Array.head(parts)),
235
+ cpu: Option.toArray(Array.get(parts, CPU_INDEX)),
236
+ ...libcOf(parts),
237
+ main: file,
238
+ files: [file]
239
+ };
240
+ };
241
+ /** @internal */
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`;
243
+ // src/features/publish-workspace/model/widened-ranges.ts
244
+ const HOOK_FILE = "widen-ranges.mjs";
245
+ /** @internal */
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
+ `;
259
+ /** @internal */
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 };
265
+ });
266
+ // src/features/publish-workspace/model/npm.ts
267
+ const TARBALL = "package.tgz";
268
+ const NPM_DIR = "npm";
269
+ const NATIVE_DIR = "native";
270
+ const MANIFEST_FILE = "package.json";
271
+ const KEPT_FIELDS = [
272
+ "license",
273
+ "repository",
274
+ "homepage",
275
+ "bugs",
276
+ "engines"
277
+ ];
278
+ const PUBLISH_FLAGS = [
279
+ "--provenance",
280
+ "--access",
281
+ "public"
282
+ ];
283
+ const PackageJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
284
+ const PlatformManifest = Schema.fromJsonString(Schema.Struct({
285
+ name: Schema.String,
286
+ version: Schema.String
287
+ }));
288
+ const authEnv = Effect.fn("publish.authEnv")(function* authEnv() {
289
+ const token = yield* brokerCredential({
290
+ kind: "npm",
291
+ field: "npmToken"
292
+ });
293
+ return Option.match(token, {
294
+ onNone: () => ({}),
295
+ onSome: (value) => ({ NODE_AUTH_TOKEN: value })
296
+ });
297
+ });
298
+ const verifyPackage = Effect.fn("publish.verify")(function* verifyPackage(directory, manifest) {
299
+ const tasks = [
300
+ "build",
301
+ "test",
302
+ ...pipe(Option.fromUndefinedOr(manifest["size-limit"]), Option.map(() => "size"), Option.toArray)
303
+ ];
304
+ yield* Effect.forEach(tasks, (task) => mustSucceed({
305
+ command: "vp",
306
+ args: ["run", task],
307
+ cwd: directory
308
+ }), {
309
+ concurrency: 1,
310
+ discard: true
311
+ });
312
+ });
313
+ const keptFields = Effect.fn("publish.keptFields")(function* keptFields(directory) {
314
+ const fileSystem = yield* FileSystem.FileSystem;
315
+ const path = yield* Path.Path;
316
+ const text = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE));
317
+ const raw = yield* Schema.decodeEffect(PackageJson)(text);
318
+ return pipe(raw, Record.filter((_value, key) => Array.contains(KEPT_FIELDS, key)));
319
+ });
320
+ const writeNative = Effect.fn("publish.writeNative")(function* writeNative(directory, native) {
321
+ const fileSystem = yield* FileSystem.FileSystem;
322
+ const path = yield* Path.Path;
323
+ const kept = yield* keptFields(directory);
324
+ const target = path.resolve(directory, NPM_DIR, native.target);
325
+ const file = nativeFileOf(native);
326
+ yield* fileSystem.makeDirectory(target, { recursive: true });
327
+ yield* fileSystem.copyFile(path.join(directory, NATIVE_DIR, file), path.join(target, file));
328
+ const text = yield* Schema.encodeEffect(PackageJson)({
329
+ ...kept,
330
+ ...nativeFields(native)
331
+ });
332
+ yield* Effect.all([fileSystem.writeFileString(path.join(target, MANIFEST_FILE), text), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
333
+ return target;
334
+ });
335
+ const publishNative = Effect.fn("publish.publishNative")(function* publishNative(target, env) {
336
+ const fileSystem = yield* FileSystem.FileSystem;
337
+ const path = yield* Path.Path;
338
+ const { name, version } = yield* fileSystem.readFileString(path.join(target, MANIFEST_FILE)).pipe(Effect.flatMap(Schema.decodeEffect(PlatformManifest)));
339
+ if (yield* onNpm({
340
+ directory: target,
341
+ name,
342
+ version
343
+ })) {
344
+ yield* Console.log(`${name}@${version} is already published, skipping`);
345
+ return name;
346
+ }
347
+ yield* mustSucceed({
348
+ command: "npm",
349
+ args: [
350
+ "publish",
351
+ ".",
352
+ ...PUBLISH_FLAGS
353
+ ],
354
+ env,
355
+ cwd: target
356
+ });
357
+ return name;
358
+ });
359
+ const addOptionalDependencies = Effect.fn("publish.optionalDependencies")(function* addOptionalDependencies(directory, names, version) {
360
+ const fileSystem = yield* FileSystem.FileSystem;
361
+ const file = (yield* Path.Path).join(directory, MANIFEST_FILE);
362
+ const manifest = yield* fileSystem.readFileString(file).pipe(Effect.flatMap(Schema.decodeEffect(PackageJson)));
363
+ const optionalDependencies = pipe(names, Array.map((name) => [name, version]), Record.fromEntries);
364
+ const updated = yield* Schema.encodeEffect(PackageJson)({
365
+ ...manifest,
366
+ optionalDependencies
367
+ });
368
+ yield* fileSystem.writeFileString(file, updated);
369
+ });
370
+ const publishNatives = Effect.fn("publish.publishNatives")(function* publishNatives(directory, manifest, env) {
371
+ if (Predicate.isUndefined(manifest.native)) return;
372
+ const { binary, targets } = manifest.native;
373
+ const written = yield* Effect.forEach(targets, (target) => writeNative(directory, {
374
+ name: manifest.name,
375
+ version: manifest.version,
376
+ binary,
377
+ target
378
+ }), { concurrency: 1 });
379
+ const names = yield* Effect.forEach(written, (target) => publishNative(target, env), { concurrency: 1 });
380
+ yield* addOptionalDependencies(directory, names, manifest.version);
381
+ });
382
+ const pack = Effect.fn("publish.pack")(function* pack(directory) {
383
+ const fileSystem = yield* FileSystem.FileSystem;
384
+ const path = yield* Path.Path;
385
+ const temporary = yield* fileSystem.makeTempDirectoryScoped();
386
+ const tarball = path.join(temporary, TARBALL);
387
+ const env = yield* widenRangesEnv(temporary);
388
+ yield* mustSucceed({
389
+ command: "vp",
390
+ args: [
391
+ "pm",
392
+ "pack",
393
+ "--out",
394
+ tarball
395
+ ],
396
+ env,
397
+ cwd: directory
398
+ });
399
+ return tarball;
400
+ });
401
+ /** @internal */
402
+ const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory) {
403
+ const manifest = yield* manifestIn(directory);
404
+ if (yield* onNpm({
405
+ directory,
406
+ ...manifest
407
+ })) return yield* Console.log(`${manifest.name}@${manifest.version} is already published`);
408
+ const env = yield* authEnv();
409
+ yield* verifyPackage(directory, manifest);
410
+ yield* publishNatives(directory, manifest, env);
411
+ const tarball = yield* pack(directory);
412
+ return yield* mustSucceed({
413
+ command: "npm",
414
+ args: [
415
+ "publish",
416
+ tarball,
417
+ ...PUBLISH_FLAGS
418
+ ],
419
+ env,
420
+ cwd: directory
421
+ });
422
+ }, Effect.scoped);
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) {
453
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
454
+ return yield* succeeds({
455
+ command: "gh",
456
+ args: ["api", `repos/${repository}/git/ref/tags/${tag}`]
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}`);
471
+ yield* mustSucceed({
472
+ command: "gh",
473
+ env,
474
+ args: [
475
+ "api",
476
+ "-X",
477
+ "POST",
478
+ `repos/${repository}/git/refs`,
479
+ "-f",
480
+ `ref=refs/tags/${tag}`,
481
+ "-f",
482
+ `sha=${sha}`
483
+ ]
484
+ });
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
+ });
702
+ const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
703
+ const fileSystem = yield* FileSystem.FileSystem;
704
+ const path = yield* Path.Path;
705
+ const folder = path.join(directory, ASSETS);
706
+ if (!(yield* fileSystem.exists(folder))) return [];
707
+ const names = yield* fileSystem.readDirectory(folder, { recursive: true });
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)));
709
+ return Array.sort(files, Order.String);
710
+ });
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);
727
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
728
+ if (yield* succeeds({
729
+ command: "gh",
730
+ args: [
731
+ "release",
732
+ "view",
733
+ tag,
734
+ "--repo",
735
+ repository
736
+ ]
737
+ })) return;
738
+ yield* mustSucceed({
739
+ command: "gh",
740
+ args: [
741
+ "release",
742
+ "create",
743
+ tag,
744
+ "--repo",
745
+ repository,
746
+ "--verify-tag",
747
+ "--title",
748
+ `${releaseName(manifest)} v${manifest.version}`,
749
+ ...notes
750
+ ]
751
+ });
752
+ });
753
+ const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets({ directory, manifest }) {
754
+ const tag = tagOf({
755
+ directory,
756
+ ...manifest
757
+ });
758
+ const files = yield* assetsIn(directory);
759
+ if (Array.isReadonlyArrayEmpty(files) || (yield* releasedWithAssets(tag))) return;
760
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
761
+ yield* createRelease({
762
+ directory,
763
+ manifest
764
+ });
765
+ yield* mustSucceed({
766
+ command: "gh",
767
+ args: [
768
+ "release",
769
+ "upload",
770
+ tag,
771
+ ...files,
772
+ "--repo",
773
+ repository,
774
+ "--clobber"
775
+ ]
776
+ });
777
+ });
778
+ /** @internal */
779
+ const publishRelease = Effect.fn("publish.release")(function* publishRelease(directory) {
780
+ const manifest = yield* manifestIn(directory);
781
+ if (!isVersioned(manifest)) {
782
+ yield* Effect.logInfo(`${manifest.name} has no version to publish`);
783
+ return;
784
+ }
785
+ const tag = tagOf({
786
+ directory,
787
+ ...manifest
788
+ });
789
+ yield* Effect.andThen(tagRevision(tag, manifest), backfillTags({
790
+ directory,
791
+ manifest
792
+ }));
793
+ yield* writeOutputs({ tag });
794
+ if (isRoot(directory)) yield* createRelease({
795
+ directory,
796
+ manifest
797
+ });
798
+ yield* uploadAssets({
799
+ directory,
800
+ manifest
801
+ });
802
+ });
803
+ // bin/msch-publish.ts
804
+ const Arguments = Schema.Union([
805
+ Schema.Tuple([Schema.Literal("plan"), Schema.String]),
806
+ Schema.Tuple([Schema.Literal("npm"), Schema.String]),
807
+ Schema.Tuple([Schema.Literal("release"), Schema.String])
808
+ ]);
809
+ const taggedError = Schema.TaggedError;
810
+ var UsageError = class extends taggedError()("UsageError", { message: Schema.String }) {};
811
+ const USAGE = "usage: msch-publish <plan|npm|release> <workspace directory>";
812
+ const publish = Effect.gen(function* publish() {
813
+ const args = yield* (yield* Stdio.Stdio).args;
814
+ const [step, directory] = yield* Schema.decodeUnknownEffect(Arguments)(args).pipe(Effect.mapError(() => UsageError.make({ message: USAGE })));
815
+ if (step === "plan") return yield* planOf(directory).pipe(Effect.flatMap(writePlan));
816
+ if (step === "npm") return yield* publishToNpm(directory);
817
+ return yield* publishRelease(directory);
818
+ });
819
+ runCli(publish);
820
+ export {};
821
+
822
+ //# sourceMappingURL=publish.mjs.map