@r_masseater/msch 0.91.5 → 0.93.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.
- package/dist/publish.mjs +495 -57
- package/dist/publish.mjs.map +1 -1
- package/dist/wake.mjs +1 -1
- package/package.json +1 -1
- package/skills/msch-publishing/SKILL.md +6 -0
package/dist/publish.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { decodePackageJson, readPackageJson, readRawPackageJson, readVersionedPa
|
|
|
8
8
|
import semver from "semver";
|
|
9
9
|
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
10
10
|
import { dual } from "effect/Function";
|
|
11
|
-
import { mask, mustSucceed, outputOf, succeeds, writeOutputs } from "@r_masseater/masseater-utils/github-workflow";
|
|
11
|
+
import { finished, mask, mustSucceed, outputOf, succeeds, writeOutputs } from "@r_masseater/masseater-utils/github-workflow";
|
|
12
12
|
import { arch, platform } from "node:os";
|
|
13
13
|
import { Base64 } from "effect/encoding";
|
|
14
14
|
// src/features/publish-workspace/model/export-targets.ts
|
|
@@ -129,6 +129,137 @@ const smokeTargetsOf = (manifest) => {
|
|
|
129
129
|
bins: binFilesOf(bin)
|
|
130
130
|
};
|
|
131
131
|
};
|
|
132
|
+
// src/features/publish-workspace/model/compat-start.ts
|
|
133
|
+
const NOT_LOADED = String.raw`ERR_(MODULE_NOT_FOUND|PACKAGE_|INVALID_PACKAGE|UNKNOWN_FILE|UNSUPPORTED_DIR|REQUIRE_ESM)|SyntaxError`;
|
|
134
|
+
/** @internal */
|
|
135
|
+
const LOAD_FAILURE = `/${NOT_LOADED}/u`;
|
|
136
|
+
/** @internal */
|
|
137
|
+
const CRASH = String.raw`/${NOT_LOADED}|\n\s+at\s.+:\d+:\d+/u`;
|
|
138
|
+
/** @internal */
|
|
139
|
+
const BIN_ARGUMENTS = [["--help"], ["--compat-unknown-flag"]];
|
|
140
|
+
const spawnChecked = (failure) => `import { spawnSync } from "node:child_process"; const { stderr } = spawnSync(process.execPath, process.argv.slice(1), { encoding: "utf8", stdio: ["ignore", "ignore", "pipe"], timeout: 60000 }); if (${failure}.test(stderr)) { process.stderr.write(stderr); process.exit(1); }`;
|
|
141
|
+
/** @internal */
|
|
142
|
+
const loadsCleanly = ({ runtime, consumer, failure, args }) => mustSucceed({
|
|
143
|
+
command: runtime,
|
|
144
|
+
args: [
|
|
145
|
+
"--input-type=module",
|
|
146
|
+
"-e",
|
|
147
|
+
spawnChecked(failure),
|
|
148
|
+
"--",
|
|
149
|
+
...args
|
|
150
|
+
],
|
|
151
|
+
cwd: consumer
|
|
152
|
+
});
|
|
153
|
+
// src/features/publish-workspace/model/plugin-lock.ts
|
|
154
|
+
const PLUGIN_FILE = ".claude-plugin/plugin.json";
|
|
155
|
+
const PACKED_ROOT = "package";
|
|
156
|
+
const NPM_LOCK$1 = "package-lock.json";
|
|
157
|
+
const NPM_REGISTRY = "https://registry.npmjs.org/";
|
|
158
|
+
/** @internal */
|
|
159
|
+
const PLUGIN_LOCK = "npm-shrinkwrap.json";
|
|
160
|
+
/** @internal */
|
|
161
|
+
const NPM_QUIET = [
|
|
162
|
+
"--ignore-scripts",
|
|
163
|
+
"--no-audit",
|
|
164
|
+
"--no-fund"
|
|
165
|
+
];
|
|
166
|
+
/** @internal */
|
|
167
|
+
const isPlugin = Effect.fn("publish.isPlugin")(function* isPlugin(directory) {
|
|
168
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
169
|
+
const path = yield* Path.Path;
|
|
170
|
+
return yield* fileSystem.exists(path.join(directory, PLUGIN_FILE));
|
|
171
|
+
});
|
|
172
|
+
/** @internal */
|
|
173
|
+
const unpacked = Effect.fn("publish.unpacked")(function* unpacked(tarball, directory) {
|
|
174
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
175
|
+
const path = yield* Path.Path;
|
|
176
|
+
yield* fileSystem.makeDirectory(directory, { recursive: true });
|
|
177
|
+
yield* mustSucceed({
|
|
178
|
+
command: "tar",
|
|
179
|
+
args: [
|
|
180
|
+
"-xzf",
|
|
181
|
+
tarball,
|
|
182
|
+
"-C",
|
|
183
|
+
directory
|
|
184
|
+
]
|
|
185
|
+
});
|
|
186
|
+
return path.join(directory, PACKED_ROOT);
|
|
187
|
+
});
|
|
188
|
+
/** @internal */
|
|
189
|
+
const installsDependencies = Effect.fn("publish.installsDependencies")(function* installsDependencies(root) {
|
|
190
|
+
const { dependencies } = yield* readVersionedPackageJson(root);
|
|
191
|
+
return pipe(Option.fromUndefinedOr(dependencies), Option.exists((held) => !Record.isEmptyRecord(held)));
|
|
192
|
+
});
|
|
193
|
+
/** @internal */
|
|
194
|
+
const lockPlugin = Effect.fn("publish.lockPlugin")(function* lockPlugin(tarball, temporary) {
|
|
195
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
196
|
+
const path = yield* Path.Path;
|
|
197
|
+
const directory = path.join(temporary, "locked");
|
|
198
|
+
const root = yield* unpacked(tarball, directory);
|
|
199
|
+
if (!(yield* installsDependencies(root))) return;
|
|
200
|
+
yield* mustSucceed({
|
|
201
|
+
command: "npm",
|
|
202
|
+
args: [
|
|
203
|
+
"install",
|
|
204
|
+
"--package-lock-only",
|
|
205
|
+
`--registry=${NPM_REGISTRY}`,
|
|
206
|
+
...NPM_QUIET
|
|
207
|
+
],
|
|
208
|
+
cwd: root
|
|
209
|
+
});
|
|
210
|
+
yield* fileSystem.rename(path.join(root, NPM_LOCK$1), path.join(root, PLUGIN_LOCK));
|
|
211
|
+
yield* mustSucceed({
|
|
212
|
+
command: "tar",
|
|
213
|
+
args: [
|
|
214
|
+
"-czf",
|
|
215
|
+
tarball,
|
|
216
|
+
"-C",
|
|
217
|
+
directory,
|
|
218
|
+
PACKED_ROOT
|
|
219
|
+
]
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
// src/features/publish-workspace/model/compat-plugin.ts
|
|
223
|
+
const NPM_LOCK = "package-lock.json";
|
|
224
|
+
const installed = Effect.fn("compat.pluginInstalled")(function* installed(name, root) {
|
|
225
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
226
|
+
const path = yield* Path.Path;
|
|
227
|
+
const lock = path.join(root, PLUGIN_LOCK);
|
|
228
|
+
if (!(yield* fileSystem.exists(lock))) return yield* IncompatiblePackage.make({ message: `${name} is a Claude Code plugin with dependencies, but its tarball has no ${PLUGIN_LOCK}, so Claude Code installs none of them` });
|
|
229
|
+
yield* fileSystem.copyFile(lock, path.join(root, NPM_LOCK));
|
|
230
|
+
return yield* mustSucceed({
|
|
231
|
+
command: "npm",
|
|
232
|
+
args: ["ci", ...NPM_QUIET],
|
|
233
|
+
cwd: root
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
const startsBins = Effect.fn("compat.pluginBins")(function* startsBins(manifest, root) {
|
|
237
|
+
const path = yield* Path.Path;
|
|
238
|
+
const startOf = (file) => {
|
|
239
|
+
const started = Array.prepend(path.join(root, file));
|
|
240
|
+
return pipe(BIN_ARGUMENTS, Array.map(started));
|
|
241
|
+
};
|
|
242
|
+
const runs = pipe(smokeTargetsOf(manifest).bins, Array.flatMap(startOf));
|
|
243
|
+
yield* Effect.forEach(runs, (args) => loadsCleanly({
|
|
244
|
+
runtime: process.execPath,
|
|
245
|
+
consumer: root,
|
|
246
|
+
failure: CRASH,
|
|
247
|
+
args
|
|
248
|
+
}), {
|
|
249
|
+
concurrency: 1,
|
|
250
|
+
discard: true
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
/** @internal */
|
|
254
|
+
const checkPluginInstall = Effect.fn("compat.plugin")(function* checkPluginInstall(directory, manifest, tarballs) {
|
|
255
|
+
const tarball = Record.get(tarballs, manifest.name);
|
|
256
|
+
if (!(yield* isPlugin(directory)) || Option.isNone(tarball)) return;
|
|
257
|
+
const cache = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped();
|
|
258
|
+
const root = yield* unpacked(tarball.value, cache);
|
|
259
|
+
if (yield* installsDependencies(root)) yield* installed(manifest.name, root);
|
|
260
|
+
yield* Console.log(`${manifest.name} plugin: installed the way Claude Code caches it`);
|
|
261
|
+
yield* startsBins(manifest, root);
|
|
262
|
+
}, Effect.scoped);
|
|
132
263
|
// src/features/publish-workspace/model/platforms.ts
|
|
133
264
|
const RUNNERS = {
|
|
134
265
|
linux: "ubuntu-latest",
|
|
@@ -213,8 +344,8 @@ const writeNative = Effect.fn("publish.writeNative")(function* writeNative(direc
|
|
|
213
344
|
}), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
|
|
214
345
|
return target;
|
|
215
346
|
});
|
|
216
|
-
// src/features/publish-workspace/model/
|
|
217
|
-
const HOOK_FILE = "
|
|
347
|
+
// src/features/publish-workspace/model/pack-hook.ts
|
|
348
|
+
const HOOK_FILE = "pack-hook.mjs";
|
|
218
349
|
/** @internal */
|
|
219
350
|
const WIDEN_RANGES = `const EXACT = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/u;
|
|
220
351
|
const widen = (held) =>
|
|
@@ -230,10 +361,19 @@ export const hooks = {
|
|
|
230
361
|
};
|
|
231
362
|
`;
|
|
232
363
|
/** @internal */
|
|
233
|
-
const
|
|
364
|
+
const LOCKABLE_PLUGIN = `export const hooks = {
|
|
365
|
+
beforePacking: ({ devDependencies, ...manifest }) => manifest,
|
|
366
|
+
};
|
|
367
|
+
`;
|
|
368
|
+
const hookOf = (plugin) => {
|
|
369
|
+
if (plugin) return LOCKABLE_PLUGIN;
|
|
370
|
+
return WIDEN_RANGES;
|
|
371
|
+
};
|
|
372
|
+
/** @internal */
|
|
373
|
+
const packHookEnv = Effect.fn("publish.packHook")(function* packHookEnv(directory, plugin) {
|
|
234
374
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
235
375
|
const hook = (yield* Path.Path).join(directory, HOOK_FILE);
|
|
236
|
-
yield* fileSystem.writeFileString(hook,
|
|
376
|
+
yield* fileSystem.writeFileString(hook, hookOf(plugin));
|
|
237
377
|
return { pnpm_config_pnpmfile: hook };
|
|
238
378
|
});
|
|
239
379
|
// src/features/publish-workspace/model/pack.ts
|
|
@@ -244,7 +384,8 @@ const pack = Effect.fn("publish.pack")(function* pack(directory) {
|
|
|
244
384
|
const path = yield* Path.Path;
|
|
245
385
|
const temporary = yield* fileSystem.makeTempDirectoryScoped();
|
|
246
386
|
const tarball = path.join(temporary, TARBALL);
|
|
247
|
-
const
|
|
387
|
+
const plugin = yield* isPlugin(directory);
|
|
388
|
+
const env = yield* packHookEnv(temporary, plugin);
|
|
248
389
|
yield* mustSucceed({
|
|
249
390
|
command: "vp",
|
|
250
391
|
args: [
|
|
@@ -256,11 +397,12 @@ const pack = Effect.fn("publish.pack")(function* pack(directory) {
|
|
|
256
397
|
env,
|
|
257
398
|
cwd: directory
|
|
258
399
|
});
|
|
400
|
+
if (plugin) yield* lockPlugin(tarball, temporary);
|
|
259
401
|
return tarball;
|
|
260
402
|
});
|
|
261
403
|
// src/features/publish-workspace/model/compat-native.ts
|
|
262
404
|
const HOST_PREFIX = `${platform()}-${arch()}-`;
|
|
263
|
-
const builtOf = (directory, manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.flatMap(({ binary, targets }) => pipe(targets, Array.findFirst(String$1.startsWith(HOST_PREFIX)), Option.map((target) => ({
|
|
405
|
+
const builtOf$1 = (directory, manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.flatMap(({ binary, targets }) => pipe(targets, Array.findFirst(String$1.startsWith(HOST_PREFIX)), Option.map((target) => ({
|
|
264
406
|
directory,
|
|
265
407
|
manifest,
|
|
266
408
|
binary,
|
|
@@ -279,7 +421,7 @@ const packedNative = Effect.fn("compat.packedNative")(function* packedNative({ d
|
|
|
279
421
|
/** @internal */
|
|
280
422
|
const nativeTarballs = Effect.fn("compat.native")(function* nativeTarballs(directory, manifest) {
|
|
281
423
|
const none = [];
|
|
282
|
-
return yield* pipe(builtOf(directory, manifest), Option.match({
|
|
424
|
+
return yield* pipe(builtOf$1(directory, manifest), Option.match({
|
|
283
425
|
onNone: () => Effect.succeed(none),
|
|
284
426
|
onSome: packedNative
|
|
285
427
|
}));
|
|
@@ -294,6 +436,7 @@ const closureOf = (known, names, seen) => {
|
|
|
294
436
|
const inner = closureOf(known, runtimeDependencyNames(found.value.manifest), [...seen, found.value]);
|
|
295
437
|
return closureOf(known, rest, inner);
|
|
296
438
|
};
|
|
439
|
+
/** @internal */
|
|
297
440
|
const workspacesBeside = Effect.fn("compat.workspaces")(function* workspacesBeside(directory) {
|
|
298
441
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
299
442
|
const path = yield* Path.Path;
|
|
@@ -340,14 +483,7 @@ const meetsPeer = (peers) => ({ name, version }) => Option.match(Record.get(peer
|
|
|
340
483
|
const tarballsFor = (peers) => (local) => pipe(local, Array.filter(meetsPeer(peers)), Array.flatMap(({ tarballs }) => Record.toEntries(tarballs)), Record.fromEntries);
|
|
341
484
|
// src/features/publish-workspace/model/compat.ts
|
|
342
485
|
const INSTALL_FLAGS = ["--no-audit", "--no-fund"];
|
|
343
|
-
const NOT_LOADED = String.raw`ERR_(MODULE_NOT_FOUND|PACKAGE_|INVALID_PACKAGE|UNKNOWN_FILE|UNSUPPORTED_DIR|REQUIRE_ESM)|SyntaxError`;
|
|
344
|
-
/** @internal */
|
|
345
|
-
const LOAD_FAILURE = `/${NOT_LOADED}/u`;
|
|
346
|
-
/** @internal */
|
|
347
|
-
const CRASH = String.raw`/${NOT_LOADED}|\n\s+at\s.+:\d+:\d+/u`;
|
|
348
|
-
const BIN_ARGUMENTS = [["--help"], ["--compat-unknown-flag"]];
|
|
349
486
|
const IMPORT_ONLY = "await import(process.argv[1])";
|
|
350
|
-
const spawnChecked = (failure) => `import { spawnSync } from "node:child_process"; const { stderr } = spawnSync(process.execPath, process.argv.slice(1), { encoding: "utf8", stdio: ["ignore", "ignore", "pipe"], timeout: 60000 }); if (${failure}.test(stderr)) { process.stderr.write(stderr); process.exit(1); }`;
|
|
351
487
|
const Versions$1 = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
|
|
352
488
|
const installedNode = Effect.fn("compat.node")(function* installedNode(directory, range) {
|
|
353
489
|
const path = yield* Path.Path;
|
|
@@ -423,17 +559,6 @@ const installedConsumer = Effect.fn("compat.consumer")(function* installedConsum
|
|
|
423
559
|
if (Record.has(consumer.peers, "vite-plus")) yield* withViteOfVitePlus(directory);
|
|
424
560
|
return directory;
|
|
425
561
|
});
|
|
426
|
-
const loadsCleanly = ({ runtime, consumer, failure, args }) => mustSucceed({
|
|
427
|
-
command: runtime,
|
|
428
|
-
args: [
|
|
429
|
-
"--input-type=module",
|
|
430
|
-
"-e",
|
|
431
|
-
spawnChecked(failure),
|
|
432
|
-
"--",
|
|
433
|
-
...args
|
|
434
|
-
],
|
|
435
|
-
cwd: consumer
|
|
436
|
-
});
|
|
437
562
|
const importsOf = (manifest, compat) => {
|
|
438
563
|
if (compat.label === "npx") return [];
|
|
439
564
|
return smokeTargetsOf(manifest).imports;
|
|
@@ -490,7 +615,7 @@ const checkCompat = Effect.fn("publish.compat")(function* checkCompat(directory)
|
|
|
490
615
|
const cases = compatCasesOf(manifest);
|
|
491
616
|
if (Array.isReadonlyArrayEmpty(cases)) return yield* IncompatiblePackage.make({ message: `${manifest.name} declares no engines.node, so there is no supported Node.js range to check` });
|
|
492
617
|
const local = yield* workspaceTarballs(directory, manifest);
|
|
493
|
-
|
|
618
|
+
yield* Effect.forEach(cases, (compat) => runCase({
|
|
494
619
|
manifest,
|
|
495
620
|
local,
|
|
496
621
|
compat
|
|
@@ -498,6 +623,341 @@ const checkCompat = Effect.fn("publish.compat")(function* checkCompat(directory)
|
|
|
498
623
|
concurrency: 1,
|
|
499
624
|
discard: true
|
|
500
625
|
});
|
|
626
|
+
return yield* checkPluginInstall(directory, manifest, tarballsFor({})(local));
|
|
627
|
+
}, Effect.scoped);
|
|
628
|
+
// src/features/publish-workspace/model/broker.ts
|
|
629
|
+
const Issued = Schema.Record(Schema.String, Schema.Unknown);
|
|
630
|
+
const issued = Effect.fn("publish.issued")(function* issued(broker, oidc, { kind, field }) {
|
|
631
|
+
const client = yield* HttpClient.HttpClient;
|
|
632
|
+
const request = HttpClientRequest.post(`${broker.url}?only=${kind}`).pipe(HttpClientRequest.bearerToken(oidc));
|
|
633
|
+
const response = yield* HttpClient.filterStatusOk(client).execute(request);
|
|
634
|
+
const body = yield* HttpClientResponse.schemaBodyJson(Issued)(response);
|
|
635
|
+
const token = Option.filter(Option.fromNullishOr(body[field]), (value) => typeof value === "string" && value !== "");
|
|
636
|
+
yield* Effect.forEach(Option.toArray(token), mask, {
|
|
637
|
+
concurrency: 1,
|
|
638
|
+
discard: true
|
|
639
|
+
});
|
|
640
|
+
return token;
|
|
641
|
+
});
|
|
642
|
+
/** @internal */
|
|
643
|
+
const credentialFrom = Effect.fn("publish.credentialFrom")(function* credentialFrom(broker, credential) {
|
|
644
|
+
if (Option.isNone(broker)) return Option.none();
|
|
645
|
+
return yield* actionsOidcToken(broker.value).pipe(Effect.flatMap(Option.match({
|
|
646
|
+
onNone: () => Effect.succeedNone,
|
|
647
|
+
onSome: (oidc) => issued(broker.value, oidc, credential)
|
|
648
|
+
})), Effect.tapError(() => Console.log(`The credential broker gave no ${credential.field}`)), Effect.orElseSucceed(() => Option.none()));
|
|
649
|
+
});
|
|
650
|
+
/** @internal */
|
|
651
|
+
const brokerCredential = Effect.fn("publish.brokerCredential")(function* brokerCredential(credential) {
|
|
652
|
+
const broker = yield* repositoryBroker;
|
|
653
|
+
return yield* credentialFrom(broker, credential);
|
|
654
|
+
});
|
|
655
|
+
// src/features/publish-workspace/model/consumer-build.ts
|
|
656
|
+
const PNPMFILE = ".pnpmfile.cjs";
|
|
657
|
+
const TASK = "msch";
|
|
658
|
+
const SUCCESS$1 = 0;
|
|
659
|
+
const TARBALLS_ENV = "MSCH_CONSUMER_TARBALLS";
|
|
660
|
+
const TaskGraph$1 = Schema.Struct({ tasks: Schema.Record(Schema.String, Schema.Unknown) }).pipe(Schema.fromJsonString);
|
|
661
|
+
const Tarballed = Schema.Struct({
|
|
662
|
+
tarballs: Schema.Record(Schema.String, Schema.String),
|
|
663
|
+
natives: Schema.Record(Schema.String, Schema.Array(Schema.String))
|
|
664
|
+
}).pipe(Schema.fromJsonString);
|
|
665
|
+
/** @internal */
|
|
666
|
+
const PNPMFILE_SOURCE = Array.join([
|
|
667
|
+
`const { tarballs, natives } = JSON.parse(process.env.${TARBALLS_ENV});`,
|
|
668
|
+
"const fields = [\"dependencies\", \"devDependencies\", \"optionalDependencies\"];",
|
|
669
|
+
"module.exports = {",
|
|
670
|
+
" hooks: {",
|
|
671
|
+
" readPackage(manifest) {",
|
|
672
|
+
" for (const field of fields) {",
|
|
673
|
+
" for (const [name, file] of Object.entries(tarballs)) {",
|
|
674
|
+
" if (name in (manifest[field] || {})) manifest[field][name] = \"file:\" + file;",
|
|
675
|
+
" }",
|
|
676
|
+
" }",
|
|
677
|
+
" for (const name of natives[manifest.name] || []) {",
|
|
678
|
+
" manifest.optionalDependencies = { ...manifest.optionalDependencies, [name]: \"file:\" + tarballs[name] };",
|
|
679
|
+
" }",
|
|
680
|
+
" return manifest;",
|
|
681
|
+
" },",
|
|
682
|
+
" },",
|
|
683
|
+
"};",
|
|
684
|
+
""
|
|
685
|
+
], "\n");
|
|
686
|
+
const headerOf = (token) => `http.https://github.com/.extraheader=Authorization: basic ${Base64.encode(`x-access-token:${token}`)}`;
|
|
687
|
+
/** @internal */
|
|
688
|
+
const cloneArguments = ({ fullName, directory, token }) => [
|
|
689
|
+
...Option.match(token, {
|
|
690
|
+
onNone: () => [],
|
|
691
|
+
onSome: (value) => ["-c", headerOf(value)]
|
|
692
|
+
}),
|
|
693
|
+
"clone",
|
|
694
|
+
"--depth",
|
|
695
|
+
"1",
|
|
696
|
+
"--quiet",
|
|
697
|
+
`https://github.com/${fullName}.git`,
|
|
698
|
+
directory
|
|
699
|
+
];
|
|
700
|
+
const stateOf = Effect.fn("consumers.state")(function* stateOf(directory) {
|
|
701
|
+
return `${yield* outputOf({
|
|
702
|
+
command: "git",
|
|
703
|
+
args: [
|
|
704
|
+
"status",
|
|
705
|
+
"--porcelain=v1",
|
|
706
|
+
"--untracked-files=all"
|
|
707
|
+
],
|
|
708
|
+
cwd: directory
|
|
709
|
+
})}\n${yield* outputOf({
|
|
710
|
+
command: "git",
|
|
711
|
+
args: ["diff"],
|
|
712
|
+
cwd: directory
|
|
713
|
+
})}`;
|
|
714
|
+
});
|
|
715
|
+
const hasTask = Effect.fn("consumers.hasTask")(function* hasTask(directory) {
|
|
716
|
+
const listed = yield* outputOf({
|
|
717
|
+
command: "vp",
|
|
718
|
+
args: ["run", "--json"],
|
|
719
|
+
cwd: directory
|
|
720
|
+
});
|
|
721
|
+
const { tasks } = yield* Schema.decodeEffect(TaskGraph$1)(listed);
|
|
722
|
+
return Record.has(tasks, TASK);
|
|
723
|
+
});
|
|
724
|
+
const REPORTED_LINES = 40;
|
|
725
|
+
const tailOf = (output) => pipe(String$1.split("\n")(output), Array.takeRight(REPORTED_LINES), Array.join("\n"));
|
|
726
|
+
const brokenReason = Effect.fn("consumers.reason")(function* brokenReason(directory) {
|
|
727
|
+
const before = yield* stateOf(directory);
|
|
728
|
+
const { code, output } = yield* finished({
|
|
729
|
+
command: "vp",
|
|
730
|
+
args: [
|
|
731
|
+
"run",
|
|
732
|
+
"--no-cache",
|
|
733
|
+
TASK
|
|
734
|
+
],
|
|
735
|
+
cwd: directory
|
|
736
|
+
});
|
|
737
|
+
const after = yield* stateOf(directory);
|
|
738
|
+
if (code !== SUCCESS$1) return Option.some(`vp run ${TASK} exited with ${String(code)}:\n${tailOf(output)}`);
|
|
739
|
+
return Option.liftPredicate(after, (state) => state !== before).pipe(Option.map((state) => `vp run ${TASK} rewrote files:\n${state}`));
|
|
740
|
+
});
|
|
741
|
+
const install = (directory, options) => mustSucceed({
|
|
742
|
+
command: "vp",
|
|
743
|
+
args: ["install", options.flag],
|
|
744
|
+
cwd: directory,
|
|
745
|
+
env: options.env
|
|
746
|
+
});
|
|
747
|
+
const withNewBuild = Effect.fn("consumers.withNewBuild")(function* withNewBuild(directory, build) {
|
|
748
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
749
|
+
const pnpmfile = (yield* Path.Path).join(directory, PNPMFILE);
|
|
750
|
+
const encoded = yield* Schema.encodeEffect(Tarballed)(build);
|
|
751
|
+
yield* fileSystem.writeFileString(pnpmfile, PNPMFILE_SOURCE);
|
|
752
|
+
yield* install(directory, {
|
|
753
|
+
flag: "--no-frozen-lockfile",
|
|
754
|
+
env: { [TARBALLS_ENV]: encoded }
|
|
755
|
+
});
|
|
756
|
+
yield* fileSystem.remove(pnpmfile);
|
|
757
|
+
yield* mustSucceed({
|
|
758
|
+
command: "git",
|
|
759
|
+
args: [
|
|
760
|
+
"checkout",
|
|
761
|
+
"--",
|
|
762
|
+
"."
|
|
763
|
+
],
|
|
764
|
+
cwd: directory
|
|
765
|
+
});
|
|
766
|
+
return yield* brokenReason(directory);
|
|
767
|
+
});
|
|
768
|
+
const onItsOwnMain = Effect.fn("consumers.onItsOwnMain")(function* onItsOwnMain(directory) {
|
|
769
|
+
yield* mustSucceed({
|
|
770
|
+
command: "git",
|
|
771
|
+
args: [
|
|
772
|
+
"checkout",
|
|
773
|
+
"--",
|
|
774
|
+
"."
|
|
775
|
+
],
|
|
776
|
+
cwd: directory
|
|
777
|
+
});
|
|
778
|
+
yield* mustSucceed({
|
|
779
|
+
command: "git",
|
|
780
|
+
args: ["clean", "-fdq"],
|
|
781
|
+
cwd: directory
|
|
782
|
+
});
|
|
783
|
+
yield* install(directory, {
|
|
784
|
+
flag: "--frozen-lockfile",
|
|
785
|
+
env: {}
|
|
786
|
+
});
|
|
787
|
+
return yield* brokenReason(directory);
|
|
788
|
+
});
|
|
789
|
+
const cloned = Effect.fn("consumers.clone")(function* cloned({ consumer, token }) {
|
|
790
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
791
|
+
const path = yield* Path.Path;
|
|
792
|
+
const root = yield* fileSystem.makeTempDirectoryScoped();
|
|
793
|
+
const directory = path.join(root, "consumer");
|
|
794
|
+
yield* mustSucceed({
|
|
795
|
+
command: "git",
|
|
796
|
+
args: cloneArguments({
|
|
797
|
+
fullName: consumer.fullName,
|
|
798
|
+
directory,
|
|
799
|
+
token
|
|
800
|
+
})
|
|
801
|
+
});
|
|
802
|
+
return directory;
|
|
803
|
+
});
|
|
804
|
+
const verdict = Effect.fn("consumers.verdict")(function* verdict({ consumer, build }, directory) {
|
|
805
|
+
const reason = yield* withNewBuild(directory, build);
|
|
806
|
+
if (Option.isNone(reason)) {
|
|
807
|
+
yield* Console.log(`${consumer.fullName}: ${TASK} passes with the new build`);
|
|
808
|
+
return reason;
|
|
809
|
+
}
|
|
810
|
+
const baseline = yield* onItsOwnMain(directory);
|
|
811
|
+
if (Option.isSome(baseline)) {
|
|
812
|
+
yield* Console.log(`${consumer.fullName}: already fails on its own main, skipped`);
|
|
813
|
+
return Option.none();
|
|
814
|
+
}
|
|
815
|
+
return Option.some(`${consumer.fullName}: ${reason.value}`);
|
|
816
|
+
});
|
|
817
|
+
/** @internal */
|
|
818
|
+
const checkConsumer = Effect.fn("consumers.check")(function* checkConsumer(checked) {
|
|
819
|
+
const directory = yield* cloned(checked);
|
|
820
|
+
if (!(yield* hasTask(directory))) {
|
|
821
|
+
yield* Console.log(`${checked.consumer.fullName}: has no ${TASK} task, skipped`);
|
|
822
|
+
return Option.none();
|
|
823
|
+
}
|
|
824
|
+
return yield* verdict(checked, directory);
|
|
825
|
+
}, Effect.scoped);
|
|
826
|
+
// src/features/publish-workspace/model/consumer-repositories.ts
|
|
827
|
+
const GH = "gh";
|
|
828
|
+
const SUCCESS = 0;
|
|
829
|
+
const READ_RAW = "Accept: application/vnd.github.raw+json";
|
|
830
|
+
const MANIFESTS = ["package.json", "pnpm-workspace.yaml"];
|
|
831
|
+
const REMOTE = /[:/](?<owner>[^/:]+)\/(?<name>[^/]+?)(?:\.git)?$/u;
|
|
832
|
+
const INSTALLATION = "/installation/repositories";
|
|
833
|
+
const OWNED = "/user/repos?affiliation=owner";
|
|
834
|
+
const REPOSITORY_FIELDS = "{full_name,archived,fork}|tojson";
|
|
835
|
+
const Repository = Schema.Struct({
|
|
836
|
+
full_name: Schema.String,
|
|
837
|
+
archived: Schema.Boolean,
|
|
838
|
+
fork: Schema.Boolean
|
|
839
|
+
});
|
|
840
|
+
const decodeRepository = Schema.decodeUnknownOption(Schema.fromJsonString(Repository));
|
|
841
|
+
/** @internal */
|
|
842
|
+
const repositoriesOf = (lines) => pipe(String$1.split("\n")(lines), Array.flatMap((line) => Option.toArray(decodeRepository(line))), Array.filter(({ archived, fork }) => !archived && !fork), Array.map(({ full_name: fullName }) => ({ fullName })));
|
|
843
|
+
/** @internal */
|
|
844
|
+
const remoteOf = (url) => pipe(Option.fromNullishOr(REMOTE.exec(url)), Option.flatMapNullishOr(({ groups }) => groups), Option.map(({ owner, name }) => `${owner ?? ""}/${name ?? ""}`));
|
|
845
|
+
/** @internal */
|
|
846
|
+
const consumersOf = (repositories) => (self) => {
|
|
847
|
+
const prefix = pipe(String$1.split("/")(self), Array.head, Option.getOrElse(() => ""));
|
|
848
|
+
return pipe(repositories, Array.filter(({ fullName }) => String$1.startsWith(`${prefix}/`)(fullName) && fullName !== self));
|
|
849
|
+
};
|
|
850
|
+
/** @internal */
|
|
851
|
+
const mentionsAny = (names) => (text) => pipe(names, Array.some((name) => String$1.includes(name)(text)));
|
|
852
|
+
const envOf = (token) => Option.match(token, {
|
|
853
|
+
onNone: () => ({}),
|
|
854
|
+
onSome: (value) => ({ GH_TOKEN: value })
|
|
855
|
+
});
|
|
856
|
+
const apiOutput = (args, token) => finished({
|
|
857
|
+
command: GH,
|
|
858
|
+
args: ["api", ...args],
|
|
859
|
+
env: envOf(token)
|
|
860
|
+
}).pipe(Effect.map(({ output, code }) => pipe(Option.some(output), Option.filter(() => code === SUCCESS))));
|
|
861
|
+
const listing = (path, expression, token) => apiOutput([
|
|
862
|
+
"--paginate",
|
|
863
|
+
path,
|
|
864
|
+
"--jq",
|
|
865
|
+
expression
|
|
866
|
+
], token).pipe(Effect.map(Option.map(repositoriesOf)));
|
|
867
|
+
/** @internal */
|
|
868
|
+
const listRepositories = (token) => listing(INSTALLATION, `.repositories[]|${REPOSITORY_FIELDS}`, token).pipe(Effect.flatMap(Option.match({
|
|
869
|
+
onNone: () => listing(OWNED, `.[]|${REPOSITORY_FIELDS}`, token),
|
|
870
|
+
onSome: (found) => Effect.succeedSome(found)
|
|
871
|
+
})));
|
|
872
|
+
/** @internal */
|
|
873
|
+
const manifestsOf = (token) => ({ fullName }) => Effect.forEach(MANIFESTS, (file) => apiOutput([
|
|
874
|
+
`repos/${fullName}/contents/${file}`,
|
|
875
|
+
"-H",
|
|
876
|
+
READ_RAW
|
|
877
|
+
], token).pipe(Effect.map(Option.getOrElse(() => ""))), { concurrency: 1 }).pipe(Effect.map(Array.join("\n")));
|
|
878
|
+
// src/features/publish-workspace/model/consumers.ts
|
|
879
|
+
const MANIFEST_READ_CONCURRENCY = 4;
|
|
880
|
+
/** @internal */
|
|
881
|
+
const dependentsOf = (known) => (names) => {
|
|
882
|
+
const reached = pipe(known, Record.filter(({ manifest }) => pipe(runtimeDependencyNames(manifest), Array.some((name) => Array.contains(names, name)))), Record.keys);
|
|
883
|
+
const added = pipe(reached, Array.filter((name) => !Array.contains(names, name)));
|
|
884
|
+
if (Array.isReadonlyArrayEmpty(added)) return names;
|
|
885
|
+
return dependentsOf(known)([...names, ...added]);
|
|
886
|
+
};
|
|
887
|
+
const tokenOf = Effect.fn("consumers.token")(function* tokenOf() {
|
|
888
|
+
const given = yield* Config.option(Config.String("GITHUB_APP_TOKEN"));
|
|
889
|
+
if (Option.isSome(given)) return given;
|
|
890
|
+
return yield* brokerCredential({
|
|
891
|
+
kind: "github",
|
|
892
|
+
field: "githubToken"
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
const selfOf = Effect.fn("consumers.self")(function* selfOf() {
|
|
896
|
+
const given = yield* Config.option(Config.String("GITHUB_REPOSITORY"));
|
|
897
|
+
if (Option.isSome(given)) return given.value;
|
|
898
|
+
const url = yield* outputOf({
|
|
899
|
+
command: "git",
|
|
900
|
+
args: [
|
|
901
|
+
"remote",
|
|
902
|
+
"get-url",
|
|
903
|
+
"origin"
|
|
904
|
+
]
|
|
905
|
+
});
|
|
906
|
+
return Option.getOrElse(remoteOf(url), () => "");
|
|
907
|
+
});
|
|
908
|
+
const nativesOf = (local) => pipe(local, Array.map(({ name, tarballs }) => [name, pipe(Record.keys(tarballs), Array.filter((entry) => entry !== name))]), Record.fromEntries);
|
|
909
|
+
const builtOf = Effect.fn("consumers.built")(function* builtOf(directories) {
|
|
910
|
+
const built = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.flatMap((manifest) => workspaceTarballs(directory, manifest))), { concurrency: 1 });
|
|
911
|
+
const local = Array.flatten(built);
|
|
912
|
+
return {
|
|
913
|
+
tarballs: tarballsFor({})(local),
|
|
914
|
+
natives: nativesOf(local)
|
|
915
|
+
};
|
|
916
|
+
});
|
|
917
|
+
const mentioning = Effect.fn("consumers.mentioning")(function* mentioning(candidates, names, token) {
|
|
918
|
+
return yield* Effect.filter(candidates, (consumer) => manifestsOf(token)(consumer).pipe(Effect.map(mentionsAny(names))), { concurrency: MANIFEST_READ_CONCURRENCY });
|
|
919
|
+
});
|
|
920
|
+
const namesAffected = Effect.fn("consumers.affected")(function* namesAffected(directories) {
|
|
921
|
+
const [first = "."] = directories;
|
|
922
|
+
const known = yield* workspacesBeside(first);
|
|
923
|
+
const own = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.map(({ name }) => name)), { concurrency: 1 });
|
|
924
|
+
return dependentsOf(known)(own);
|
|
925
|
+
});
|
|
926
|
+
const unlisted = Effect.fn("consumers.unlisted")(function* unlisted() {
|
|
927
|
+
if (yield* Config.Boolean("GITHUB_ACTIONS").pipe(Config.withDefault(false))) return yield* IncompatiblePackage.make({ message: "The consumers of the new build could not be listed, so none of them was checked" });
|
|
928
|
+
return yield* Console.log("consumers skipped: no GitHub access to list them");
|
|
929
|
+
});
|
|
930
|
+
const failing = Effect.fn("consumers.failing")(function* failing(found, build, token) {
|
|
931
|
+
const reasons = yield* Effect.forEach(found, (consumer) => checkConsumer({
|
|
932
|
+
consumer,
|
|
933
|
+
build,
|
|
934
|
+
token
|
|
935
|
+
}), { concurrency: 1 });
|
|
936
|
+
return Array.getSomes(reasons);
|
|
937
|
+
});
|
|
938
|
+
const consumersAffected = Effect.fn("consumers.found")(function* consumersAffected(directories, token) {
|
|
939
|
+
const listed = yield* listRepositories(token);
|
|
940
|
+
if (Option.isNone(listed)) return Option.none();
|
|
941
|
+
const self = yield* selfOf();
|
|
942
|
+
const names = yield* namesAffected(directories);
|
|
943
|
+
const found = yield* mentioning(consumersOf(listed.value)(self), names, token);
|
|
944
|
+
const listedNames = pipe(found, Array.map(({ fullName }) => fullName));
|
|
945
|
+
yield* Console.log(`consumers: ${Array.join(listedNames, ", ")}`);
|
|
946
|
+
return Option.some(found);
|
|
947
|
+
});
|
|
948
|
+
const verified = Effect.fn("consumers.verified")(function* verified(directories, found, token) {
|
|
949
|
+
const build = yield* builtOf(directories);
|
|
950
|
+
const broken = yield* failing(found, build, token);
|
|
951
|
+
if (Array.isReadonlyArrayNonEmpty(broken)) return yield* IncompatiblePackage.make({ message: `The new build breaks its consumers:\n${Array.join(broken, "\n")}` });
|
|
952
|
+
return yield* Effect.void;
|
|
953
|
+
});
|
|
954
|
+
/** @internal */
|
|
955
|
+
const checkConsumers = Effect.fn("publish.consumers")(function* checkConsumers(directories) {
|
|
956
|
+
if (Array.isReadonlyArrayEmpty(directories)) return yield* Effect.void;
|
|
957
|
+
const token = yield* tokenOf();
|
|
958
|
+
const found = yield* consumersAffected(directories, token);
|
|
959
|
+
if (Option.isNone(found)) return yield* unlisted();
|
|
960
|
+
return yield* verified(directories, found.value, token);
|
|
501
961
|
}, Effect.scoped);
|
|
502
962
|
// src/features/publish-workspace/model/manifest.ts
|
|
503
963
|
const UNVERSIONED$1 = "0.0.0";
|
|
@@ -576,33 +1036,6 @@ const requirePublishedDependencies = (dependent) => missingDependencies(dependen
|
|
|
576
1036
|
times: WAIT_ATTEMPTS,
|
|
577
1037
|
while: Schema.is(UnpublishedDependencies)
|
|
578
1038
|
}));
|
|
579
|
-
// src/features/publish-workspace/model/broker.ts
|
|
580
|
-
const Issued = Schema.Record(Schema.String, Schema.Unknown);
|
|
581
|
-
const issued = Effect.fn("publish.issued")(function* issued(broker, oidc, { kind, field }) {
|
|
582
|
-
const client = yield* HttpClient.HttpClient;
|
|
583
|
-
const request = HttpClientRequest.post(`${broker.url}?only=${kind}`).pipe(HttpClientRequest.bearerToken(oidc));
|
|
584
|
-
const response = yield* HttpClient.filterStatusOk(client).execute(request);
|
|
585
|
-
const body = yield* HttpClientResponse.schemaBodyJson(Issued)(response);
|
|
586
|
-
const token = Option.filter(Option.fromNullishOr(body[field]), (value) => typeof value === "string" && value !== "");
|
|
587
|
-
yield* Effect.forEach(Option.toArray(token), mask, {
|
|
588
|
-
concurrency: 1,
|
|
589
|
-
discard: true
|
|
590
|
-
});
|
|
591
|
-
return token;
|
|
592
|
-
});
|
|
593
|
-
/** @internal */
|
|
594
|
-
const credentialFrom = Effect.fn("publish.credentialFrom")(function* credentialFrom(broker, credential) {
|
|
595
|
-
if (Option.isNone(broker)) return Option.none();
|
|
596
|
-
return yield* actionsOidcToken(broker.value).pipe(Effect.flatMap(Option.match({
|
|
597
|
-
onNone: () => Effect.succeedNone,
|
|
598
|
-
onSome: (oidc) => issued(broker.value, oidc, credential)
|
|
599
|
-
})), Effect.tapError(() => Console.log(`The credential broker gave no ${credential.field}`)), Effect.orElseSucceed(() => Option.none()));
|
|
600
|
-
});
|
|
601
|
-
/** @internal */
|
|
602
|
-
const brokerCredential = Effect.fn("publish.brokerCredential")(function* brokerCredential(credential) {
|
|
603
|
-
const broker = yield* repositoryBroker;
|
|
604
|
-
return yield* credentialFrom(broker, credential);
|
|
605
|
-
});
|
|
606
1039
|
// src/features/publish-workspace/model/provenance.ts
|
|
607
1040
|
const ATTESTATIONS = "https://registry.npmjs.org/-/npm/v1/attestations/";
|
|
608
1041
|
const SLSA = /slsa\.dev\/provenance/u;
|
|
@@ -952,10 +1385,11 @@ const checkChangedCompat = Effect.fn("publish.compatChanged")(function* checkCha
|
|
|
952
1385
|
const graph = yield* graphTasks;
|
|
953
1386
|
const chosen = selectedWorkspaces(workspacesOf(graph), directories);
|
|
954
1387
|
const checked = yield* Effect.filter(chosen, isChecked, { concurrency: 1 });
|
|
955
|
-
|
|
1388
|
+
yield* Effect.forEach(checked, checkCompat, {
|
|
956
1389
|
concurrency: 1,
|
|
957
1390
|
discard: true
|
|
958
1391
|
});
|
|
1392
|
+
return yield* checkConsumers(checked);
|
|
959
1393
|
});
|
|
960
1394
|
// src/features/publish-workspace/model/npm.ts
|
|
961
1395
|
const authEnv = Effect.fn("publish.authEnv")(function* authEnv() {
|
|
@@ -1168,12 +1602,13 @@ const Arguments = Schema.Tuple([Schema.Literals([
|
|
|
1168
1602
|
"npm",
|
|
1169
1603
|
"release",
|
|
1170
1604
|
"compat",
|
|
1171
|
-
"compat-plan"
|
|
1605
|
+
"compat-plan",
|
|
1606
|
+
"consumers"
|
|
1172
1607
|
]), Schema.String]);
|
|
1173
1608
|
const ChangedArguments = Schema.TupleWithRest(Schema.Tuple([Schema.Literal("compat-changed")]), [Schema.String]);
|
|
1174
1609
|
const taggedError = Schema.TaggedError;
|
|
1175
1610
|
var UsageError = class extends taggedError()("UsageError", { message: Schema.String }) {};
|
|
1176
|
-
const USAGE = "usage: msch-publish <plan|npm|release|compat|compat-plan> <workspace directory> | msch-publish dispatch <ref> | msch-publish compat-changed [workspace directory...]";
|
|
1611
|
+
const USAGE = "usage: msch-publish <plan|npm|release|compat|compat-plan|consumers> <workspace directory> | msch-publish dispatch <ref> | msch-publish compat-changed [workspace directory...]";
|
|
1177
1612
|
const steps = {
|
|
1178
1613
|
dispatch: dispatchPending,
|
|
1179
1614
|
plan: Effect.fn("plan")(function* plan(directory) {
|
|
@@ -1182,6 +1617,9 @@ const steps = {
|
|
|
1182
1617
|
npm: publishToNpm,
|
|
1183
1618
|
release: publishRelease,
|
|
1184
1619
|
compat: checkCompat,
|
|
1620
|
+
consumers: Effect.fn("consumers")(function* consumers(directory) {
|
|
1621
|
+
return yield* checkConsumers([directory]);
|
|
1622
|
+
}),
|
|
1185
1623
|
"compat-plan": Effect.fn("compat-plan")(function* compatPlan() {
|
|
1186
1624
|
return yield* writeCompatPlan();
|
|
1187
1625
|
})
|