@r_masseater/msch 0.40.0 → 0.42.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 (41) hide show
  1. package/README.md +7 -0
  2. package/dist/cargo-inputs.d.mts +14 -0
  3. package/dist/cargo-inputs.mjs +226 -0
  4. package/dist/cargo-inputs.mjs.map +1 -0
  5. package/dist/{cli-contract-8SnKqhGw.mjs → cli-contract-DdTV5DaG.mjs} +2 -2
  6. package/dist/{cli-contract-8SnKqhGw.mjs.map → cli-contract-DdTV5DaG.mjs.map} +1 -1
  7. package/dist/cli.mjs +771 -723
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/config.d.mts +2 -2
  10. package/dist/config.mjs +9 -6
  11. package/dist/config.mjs.map +1 -1
  12. package/dist/decision-rules.d.mts +1 -1
  13. package/dist/decision-rules.mjs +1 -1
  14. package/dist/{define-lint-preset-BYMl7wof.mjs → define-lint-preset-DKJku2ZR.mjs} +124 -85
  15. package/dist/define-lint-preset-DKJku2ZR.mjs.map +1 -0
  16. package/dist/ignored-directories-CfACwIvu.mjs +50 -0
  17. package/dist/ignored-directories-CfACwIvu.mjs.map +1 -0
  18. package/dist/{index-lM4Pphgz.d.mts → index-BwiAHe_u.d.mts} +21 -16
  19. package/dist/{index-CcVKuHBw.d.mts → index-DdJXnW1q.d.mts} +2 -2
  20. package/dist/lint.d.mts +2 -2
  21. package/dist/lint.mjs +1 -1
  22. package/dist/oxlint.mjs +1 -1
  23. package/dist/{package-A62qq8pE.mjs → package-vbK0Qycn.mjs} +2 -2
  24. package/dist/{package-A62qq8pE.mjs.map → package-vbK0Qycn.mjs.map} +1 -1
  25. package/dist/publish.d.mts +1 -0
  26. package/dist/publish.mjs +578 -0
  27. package/dist/publish.mjs.map +1 -0
  28. package/dist/{repository-files-CorshdqY.mjs → repository-files-CPfBA4mf.mjs} +7 -1
  29. package/dist/repository-files-CPfBA4mf.mjs.map +1 -0
  30. package/dist/runtime-Dc5gCUSF.mjs +29 -0
  31. package/dist/runtime-Dc5gCUSF.mjs.map +1 -0
  32. package/dist/workspace-settings.d.mts +1 -1
  33. package/dist/workspace-settings.mjs +6 -63
  34. package/dist/workspace-settings.mjs.map +1 -1
  35. package/package.json +17 -7
  36. package/skills/msch-checks/SKILL.md +0 -5
  37. package/skills/publishing/SKILL.md +44 -0
  38. package/skills/repository-config/SKILL.md +8 -7
  39. package/src/app/vite.d.ts +4 -0
  40. package/dist/define-lint-preset-BYMl7wof.mjs.map +0 -1
  41. package/dist/repository-files-CorshdqY.mjs.map +0 -1
@@ -0,0 +1,578 @@
1
+ #!/usr/bin/env node
2
+ import { t as runCli } from "./runtime-Dc5gCUSF.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 { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
6
+ import "effect/encoding";
7
+ // ../github-workflow/src/shared/api/github.ts
8
+ const API = "https://api.github.com";
9
+ const HEADERS = {
10
+ accept: "application/vnd.github+json",
11
+ "user-agent": "masseater.dev",
12
+ "x-github-api-version": "2022-11-28"
13
+ };
14
+ const requestTo = Effect.fn("requestTo")(function* requestTo(method, path) {
15
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
16
+ const token = yield* Config.Redacted("GH_TOKEN").pipe(Config.orElse(() => Config.Redacted("GITHUB_TOKEN")));
17
+ return HttpClientRequest.make(method)(`${API}/repos/${repository}/${path}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)), HttpClientRequest.setHeaders(HEADERS));
18
+ });
19
+ const execute = Effect.fn("execute")(function* execute(request) {
20
+ const response = yield* (yield* HttpClient.HttpClient).execute(request);
21
+ return yield* HttpClientResponse.filterStatusOk(response);
22
+ });
23
+ Effect.fn("withBody")(function* withBody(method, path, body) {
24
+ const request = yield* requestTo(method, path);
25
+ const filled = yield* HttpClientRequest.bodyJson(request, body);
26
+ return yield* execute(filled);
27
+ });
28
+ // ../github-workflow/src/shared/lib/process.ts
29
+ const SUCCESS = 0;
30
+ const taggedError$2 = Schema.TaggedError;
31
+ var CommandFailed = class extends taggedError$2()("CommandFailed", { message: Schema.String }) {};
32
+ const failed = ({ command, args }) => CommandFailed.make({ message: `${command} ${Array.join(args, " ")} failed` });
33
+ const exitCodeOf = Effect.fn("exitCodeOf")(function* exitCodeOf({ command, args, env, cwd }) {
34
+ return yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(command, args, {
35
+ cwd,
36
+ env,
37
+ extendEnv: true,
38
+ stdin: "ignore",
39
+ stdout: "inherit",
40
+ stderr: "inherit"
41
+ }));
42
+ });
43
+ const succeedsWith = (command) => exitCodeOf(command).pipe(Effect.map((code) => code === SUCCESS));
44
+ const mustSucceedWith = (command) => succeedsWith(command).pipe(Effect.filterOrFail((passed) => passed, () => failed(command)), Effect.asVoid);
45
+ const collected = Effect.fn("collected")(function* collected({ command, args, env, cwd }) {
46
+ const handle = yield* ChildProcess.make(command, args, {
47
+ cwd,
48
+ env,
49
+ extendEnv: true,
50
+ stdin: "ignore",
51
+ stderr: "inherit"
52
+ });
53
+ const [output, code] = yield* Effect.all([handle.stdout.pipe(Stream.decodeText(), Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
54
+ return {
55
+ output,
56
+ code
57
+ };
58
+ });
59
+ const outputWith = (command) => collected(command).pipe(Effect.scoped, Effect.filterOrFail(({ code }) => code === SUCCESS, () => failed(command)), Effect.map(({ output }) => String.trim(output)));
60
+ /** @internal */
61
+ const succeeds = succeedsWith;
62
+ /** @internal */
63
+ const mustSucceed = mustSucceedWith;
64
+ /** @internal */
65
+ const outputOf = outputWith;
66
+ // ../github-workflow/src/shared/lib/workflow.ts
67
+ const taggedError$1 = Schema.TaggedError;
68
+ var WorkflowFailed = class extends taggedError$1()("WorkflowFailed", { message: Schema.String }) {};
69
+ const appendTo = (variable, entries) => Effect.gen(function* appended() {
70
+ const path = yield* Config.String(variable);
71
+ const fs = yield* FileSystem.FileSystem;
72
+ const lines = pipe(Record.toEntries(entries), Array.map(([name, value]) => `${name}=${value}\n`), Array.join(""));
73
+ yield* fs.writeFileString(path, lines, { flag: "a" });
74
+ });
75
+ const outputsOf = (outputs) => appendTo("GITHUB_OUTPUT", outputs);
76
+ /** @internal */
77
+ const writeOutputs = outputsOf;
78
+ const mask = (value) => Console.log(`::add-mask::${value}`);
79
+ Effect.fn("fail")(function* fail(message) {
80
+ yield* Console.log(`::error::${message}`);
81
+ return yield* WorkflowFailed.make({ message });
82
+ });
83
+ // src/features/publish-workspace/model/manifest.ts
84
+ const MANIFEST_FILE$1 = "package.json";
85
+ const SCOPE = /^@[^/]+\//u;
86
+ const UNVERSIONED = "0.0.0";
87
+ const Native = Schema.Struct({
88
+ binary: Schema.String,
89
+ targets: Schema.Array(Schema.String)
90
+ });
91
+ const ManifestSchema = Schema.Struct({
92
+ name: Schema.String,
93
+ version: Schema.String,
94
+ private: Schema.optionalKey(Schema.Boolean),
95
+ native: Schema.optionalKey(Native),
96
+ "size-limit": Schema.optionalKey(Schema.Unknown)
97
+ });
98
+ /** @internal */
99
+ const manifestIn = Effect.fn("publish.manifest")(function* manifestIn(directory) {
100
+ const fileSystem = yield* FileSystem.FileSystem;
101
+ const path = yield* Path.Path;
102
+ const text = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE$1));
103
+ return yield* Schema.decodeEffect(Schema.fromJsonString(ManifestSchema))(text);
104
+ });
105
+ /** @internal */
106
+ const releaseName = ({ name }) => String.replace(SCOPE, "")(name);
107
+ /** @internal */
108
+ const tagOf = (manifest) => `${releaseName(manifest)}-v${manifest.version}`;
109
+ /** @internal */
110
+ const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
111
+ /** @internal */
112
+ const isVersioned = ({ version }) => version !== UNVERSIONED;
113
+ /** @internal */
114
+ const goesToNpm = (manifest) => !pipe(Option.fromUndefinedOr(manifest.private), Option.getOrElse(() => false));
115
+ // src/features/publish-workspace/model/platforms.ts
116
+ const RUNNERS = {
117
+ linux: "ubuntu-latest",
118
+ windows: "windows-latest",
119
+ macos: "macos-latest"
120
+ };
121
+ const NODE_PLATFORMS = {
122
+ linux: "linux",
123
+ win32: "windows",
124
+ darwin: "macos"
125
+ };
126
+ const BUILD = "release:";
127
+ const CHECK = "release:check:";
128
+ const LIBC = {
129
+ gnu: "glibc",
130
+ musl: "musl"
131
+ };
132
+ const CPU_INDEX = 1;
133
+ const ABI_INDEX = 2;
134
+ const systems = Record.keys(RUNNERS);
135
+ const runnersFor = (tasks, prefix) => pipe(systems, Array.filter((os) => Array.contains(tasks, `${prefix}${os}`)), Array.map((os) => ({
136
+ os,
137
+ runner: RUNNERS[os]
138
+ })));
139
+ /** @internal */
140
+ const buildsOf = (tasks) => runnersFor(tasks, BUILD);
141
+ /** @internal */
142
+ const checksOf = (tasks) => runnersFor(tasks, CHECK);
143
+ /** @internal */
144
+ 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) => ({
145
+ target,
146
+ runner: RUNNERS[os]
147
+ })), Option.toArray)));
148
+ const libcOf = (parts) => pipe(Array.get(parts, ABI_INDEX), Option.flatMap((abi) => Record.get(LIBC, abi)), Option.match({
149
+ onNone: () => ({}),
150
+ onSome: (libc) => ({ libc: [libc] })
151
+ }));
152
+ /** @internal */
153
+ const nativeFileOf = ({ binary, target }) => `${binary}.${target}.node`;
154
+ /** @internal */
155
+ const nativeFields = (native) => {
156
+ const parts = String.split(native.target, "-");
157
+ const file = nativeFileOf(native);
158
+ return {
159
+ name: `${native.name}-${native.target}`,
160
+ version: native.version,
161
+ os: Option.toArray(Array.head(parts)),
162
+ cpu: Option.toArray(Array.get(parts, CPU_INDEX)),
163
+ ...libcOf(parts),
164
+ main: file,
165
+ files: [file]
166
+ };
167
+ };
168
+ /** @internal */
169
+ 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
+ });
212
+ /** @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
+ });
282
+ /** @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 });
287
+ });
288
+ // src/features/publish-workspace/model/npm.ts
289
+ const BROKER = "https://credentials.masseater.dev/";
290
+ const AUDIENCE = "masseater-dev-credential-broker";
291
+ const TARBALL = "package.tgz";
292
+ const NPM_DIR = "npm";
293
+ const NATIVE_DIR = "native";
294
+ const MANIFEST_FILE = "package.json";
295
+ const KEPT_FIELDS = [
296
+ "license",
297
+ "repository",
298
+ "homepage",
299
+ "bugs",
300
+ "engines"
301
+ ];
302
+ const PUBLISH_FLAGS = [
303
+ "--provenance",
304
+ "--access",
305
+ "public"
306
+ ];
307
+ const PackageJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
308
+ const PlatformManifest = Schema.fromJsonString(Schema.Struct({
309
+ name: Schema.String,
310
+ version: Schema.String
311
+ }));
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
+ 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()));
339
+ return Option.match(token, {
340
+ onNone: () => ({}),
341
+ onSome: (value) => ({ NODE_AUTH_TOKEN: value })
342
+ });
343
+ });
344
+ const verifyPackage = Effect.fn("publish.verify")(function* verifyPackage(directory, manifest) {
345
+ const tasks = [
346
+ "build",
347
+ "test",
348
+ ...pipe(Option.fromUndefinedOr(manifest["size-limit"]), Option.map(() => "size"), Option.toArray)
349
+ ];
350
+ yield* Effect.forEach(tasks, (task) => mustSucceed({
351
+ command: "vp",
352
+ args: ["run", task],
353
+ cwd: directory
354
+ }), {
355
+ concurrency: 1,
356
+ discard: true
357
+ });
358
+ });
359
+ const keptFields = Effect.fn("publish.keptFields")(function* keptFields(directory) {
360
+ const fileSystem = yield* FileSystem.FileSystem;
361
+ const path = yield* Path.Path;
362
+ const text = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE));
363
+ const raw = yield* Schema.decodeEffect(PackageJson)(text);
364
+ return pipe(raw, Record.filter((_value, key) => Array.contains(KEPT_FIELDS, key)));
365
+ });
366
+ const writeNative = Effect.fn("publish.writeNative")(function* writeNative(directory, native) {
367
+ const fileSystem = yield* FileSystem.FileSystem;
368
+ const path = yield* Path.Path;
369
+ const kept = yield* keptFields(directory);
370
+ const target = path.resolve(directory, NPM_DIR, native.target);
371
+ const file = nativeFileOf(native);
372
+ yield* fileSystem.makeDirectory(target, { recursive: true });
373
+ yield* fileSystem.copyFile(path.join(directory, NATIVE_DIR, file), path.join(target, file));
374
+ const text = yield* Schema.encodeEffect(PackageJson)({
375
+ ...kept,
376
+ ...nativeFields(native)
377
+ });
378
+ yield* Effect.all([fileSystem.writeFileString(path.join(target, MANIFEST_FILE), text), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
379
+ return target;
380
+ });
381
+ const publishNative = Effect.fn("publish.publishNative")(function* publishNative(target, env) {
382
+ const fileSystem = yield* FileSystem.FileSystem;
383
+ const path = yield* Path.Path;
384
+ const { name, version } = yield* fileSystem.readFileString(path.join(target, MANIFEST_FILE)).pipe(Effect.flatMap(Schema.decodeEffect(PlatformManifest)));
385
+ if (yield* onNpm({
386
+ directory: target,
387
+ name,
388
+ version
389
+ })) {
390
+ yield* Console.log(`${name}@${version} is already published, skipping`);
391
+ return name;
392
+ }
393
+ yield* mustSucceed({
394
+ command: "npm",
395
+ args: [
396
+ "publish",
397
+ ".",
398
+ ...PUBLISH_FLAGS
399
+ ],
400
+ env,
401
+ cwd: target
402
+ });
403
+ return name;
404
+ });
405
+ const addOptionalDependencies = Effect.fn("publish.optionalDependencies")(function* addOptionalDependencies(directory, names, version) {
406
+ const fileSystem = yield* FileSystem.FileSystem;
407
+ const file = (yield* Path.Path).join(directory, MANIFEST_FILE);
408
+ const manifest = yield* fileSystem.readFileString(file).pipe(Effect.flatMap(Schema.decodeEffect(PackageJson)));
409
+ const optionalDependencies = pipe(names, Array.map((name) => [name, version]), Record.fromEntries);
410
+ const updated = yield* Schema.encodeEffect(PackageJson)({
411
+ ...manifest,
412
+ optionalDependencies
413
+ });
414
+ yield* fileSystem.writeFileString(file, updated);
415
+ });
416
+ const publishNatives = Effect.fn("publish.publishNatives")(function* publishNatives(directory, manifest, env) {
417
+ if (Predicate.isUndefined(manifest.native)) return;
418
+ const { binary, targets } = manifest.native;
419
+ const written = yield* Effect.forEach(targets, (target) => writeNative(directory, {
420
+ name: manifest.name,
421
+ version: manifest.version,
422
+ binary,
423
+ target
424
+ }), { concurrency: 1 });
425
+ const names = yield* Effect.forEach(written, (target) => publishNative(target, env), { concurrency: 1 });
426
+ yield* addOptionalDependencies(directory, names, manifest.version);
427
+ });
428
+ const pack = Effect.fn("publish.pack")(function* pack(directory) {
429
+ const fileSystem = yield* FileSystem.FileSystem;
430
+ const path = yield* Path.Path;
431
+ const temporary = yield* fileSystem.makeTempDirectoryScoped();
432
+ const tarball = path.join(temporary, TARBALL);
433
+ yield* mustSucceed({
434
+ command: "vp",
435
+ args: [
436
+ "pm",
437
+ "pack",
438
+ "--out",
439
+ tarball
440
+ ],
441
+ cwd: directory
442
+ });
443
+ return tarball;
444
+ });
445
+ /** @internal */
446
+ const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory) {
447
+ const manifest = yield* manifestIn(directory);
448
+ if (yield* onNpm({
449
+ directory,
450
+ ...manifest
451
+ })) return yield* Console.log(`${manifest.name}@${manifest.version} is already published`);
452
+ const env = yield* authEnv();
453
+ yield* verifyPackage(directory, manifest);
454
+ yield* publishNatives(directory, manifest, env);
455
+ const tarball = yield* pack(directory);
456
+ return yield* mustSucceed({
457
+ command: "npm",
458
+ args: [
459
+ "publish",
460
+ tarball,
461
+ ...PUBLISH_FLAGS
462
+ ],
463
+ env,
464
+ cwd: directory
465
+ });
466
+ }, 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) {
470
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
471
+ const sha = yield* Config.String("GITHUB_SHA");
472
+ if (yield* succeeds({
473
+ command: "gh",
474
+ args: ["api", `repos/${repository}/git/ref/tags/${tag}`]
475
+ })) return;
476
+ yield* mustSucceed({
477
+ command: "gh",
478
+ args: [
479
+ "api",
480
+ "-X",
481
+ "POST",
482
+ `repos/${repository}/git/refs`,
483
+ "-f",
484
+ `ref=refs/tags/${tag}`,
485
+ "-f",
486
+ `sha=${sha}`
487
+ ]
488
+ });
489
+ });
490
+ const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
491
+ const fileSystem = yield* FileSystem.FileSystem;
492
+ const path = yield* Path.Path;
493
+ const folder = path.join(directory, ASSETS);
494
+ if (!(yield* fileSystem.exists(folder))) return [];
495
+ const names = yield* fileSystem.readDirectory(folder, { recursive: true });
496
+ 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
+ return Array.sort(files, Order.String);
498
+ });
499
+ const createRelease = Effect.fn("publish.createRelease")(function* createRelease(tag, title) {
500
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
501
+ if (yield* succeeds({
502
+ command: "gh",
503
+ args: [
504
+ "release",
505
+ "view",
506
+ tag,
507
+ "--repo",
508
+ repository
509
+ ]
510
+ })) return;
511
+ yield* mustSucceed({
512
+ command: "gh",
513
+ args: [
514
+ "release",
515
+ "create",
516
+ tag,
517
+ "--repo",
518
+ repository,
519
+ "--verify-tag",
520
+ "--latest=false",
521
+ "--title",
522
+ title,
523
+ "--notes",
524
+ ""
525
+ ]
526
+ });
527
+ });
528
+ const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets(directory, manifest) {
529
+ const tag = tagOf(manifest);
530
+ const files = yield* assetsIn(directory);
531
+ if (Array.isReadonlyArrayEmpty(files) || (yield* releasedWithAssets(tag))) return;
532
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
533
+ yield* createRelease(tag, `${releaseName(manifest)} v${manifest.version}`);
534
+ yield* mustSucceed({
535
+ command: "gh",
536
+ args: [
537
+ "release",
538
+ "upload",
539
+ tag,
540
+ ...files,
541
+ "--repo",
542
+ repository,
543
+ "--clobber"
544
+ ]
545
+ });
546
+ });
547
+ /** @internal */
548
+ const publishRelease = Effect.fn("publish.release")(function* publishRelease(directory) {
549
+ const manifest = yield* manifestIn(directory);
550
+ if (!isVersioned(manifest)) {
551
+ yield* Effect.logInfo(`${manifest.name} has no version to publish`);
552
+ return;
553
+ }
554
+ const tag = tagOf(manifest);
555
+ yield* tagRevision(tag);
556
+ yield* writeOutputs({ tag });
557
+ yield* uploadAssets(directory, manifest);
558
+ });
559
+ // bin/msch-publish.ts
560
+ const Arguments = Schema.Union([
561
+ Schema.Tuple([Schema.Literal("plan"), Schema.String]),
562
+ Schema.Tuple([Schema.Literal("npm"), Schema.String]),
563
+ Schema.Tuple([Schema.Literal("release"), Schema.String])
564
+ ]);
565
+ const taggedError = Schema.TaggedError;
566
+ var UsageError = class extends taggedError()("UsageError", { message: Schema.String }) {};
567
+ const USAGE = "usage: msch-publish <plan|npm|release> <workspace directory>";
568
+ const publish = Effect.gen(function* publish() {
569
+ const args = yield* (yield* Stdio.Stdio).args;
570
+ const [step, directory] = yield* Schema.decodeUnknownEffect(Arguments)(args).pipe(Effect.mapError(() => UsageError.make({ message: USAGE })));
571
+ if (step === "plan") return yield* planOf(directory).pipe(Effect.flatMap(writePlan));
572
+ if (step === "npm") return yield* publishToNpm(directory);
573
+ return yield* publishRelease(directory);
574
+ });
575
+ runCli(publish);
576
+ export {};
577
+
578
+ //# sourceMappingURL=publish.mjs.map