@r_masseater/msch 0.99.0 → 0.101.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 (97) hide show
  1. package/README.md +1 -18
  2. package/dist/cargo-inputs.mjs +2 -2
  3. package/dist/cli.mjs +5639 -1095
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/config.d.mts +2 -2
  6. package/dist/config.mjs +2 -2
  7. package/dist/decision-rules.d.mts +1 -1
  8. package/dist/decision-rules.mjs +1 -1
  9. package/dist/{define-lint-preset-Ca94gIkh.mjs → define-lint-preset-BnOZuTNT.mjs} +8 -12
  10. package/dist/define-lint-preset-BnOZuTNT.mjs.map +1 -0
  11. package/dist/{ignored-directories-D-7Rm_2X.mjs → ignored-directories-B9ZYjMI4.mjs} +2 -2
  12. package/dist/{ignored-directories-D-7Rm_2X.mjs.map → ignored-directories-B9ZYjMI4.mjs.map} +1 -1
  13. package/dist/{index-Dm0Gg9wS.d.mts → index-Cdap8t_F.d.mts} +2 -2
  14. package/dist/{index-BeNrE8zK.d.mts → index-DbmdHsLx.d.mts} +24 -5
  15. package/dist/lint-rules.mjs +49 -16
  16. package/dist/lint-rules.mjs.map +1 -1
  17. package/dist/lint.d.mts +1 -1
  18. package/dist/lint.mjs +1 -1
  19. package/dist/oxlint.mjs +4 -3
  20. package/dist/oxlint.mjs.map +1 -1
  21. package/dist/{problem-DbuTeNvL.mjs → problem-BP2B-3M4.mjs} +2 -2
  22. package/dist/{problem-DbuTeNvL.mjs.map → problem-BP2B-3M4.mjs.map} +1 -1
  23. package/dist/{published-3eokcs_D.mjs → published-DFPG7vgX.mjs} +172 -6
  24. package/dist/published-DFPG7vgX.mjs.map +1 -0
  25. package/dist/{repository-files-DSwKJnrj.mjs → repository-files-DbZY3I_3.mjs} +10 -2
  26. package/dist/repository-files-DbZY3I_3.mjs.map +1 -0
  27. package/dist/{repository-text-BKEirzPk.mjs → repository-text-D0XVpjiD.mjs} +8 -8
  28. package/dist/repository-text-D0XVpjiD.mjs.map +1 -0
  29. package/dist/workspace-settings.d.mts +1 -1
  30. package/dist/workspace-settings.mjs +3 -4
  31. package/dist/workspace-settings.mjs.map +1 -1
  32. package/package.json +12 -13
  33. package/skills/msch-checks/SKILL.md +19 -11
  34. package/skills/msch-publishing/SKILL.md +12 -12
  35. package/skills/msch-repository-config/SKILL.md +2 -2
  36. package/dist/base-revision-Bl-4nxAd.mjs +0 -15
  37. package/dist/base-revision-Bl-4nxAd.mjs.map +0 -1
  38. package/dist/changed.d.mts +0 -1
  39. package/dist/changed.mjs +0 -245
  40. package/dist/changed.mjs.map +0 -1
  41. package/dist/cli-contract-D7btWrEu.mjs +0 -5
  42. package/dist/cli-contract-D7btWrEu.mjs.map +0 -1
  43. package/dist/define-lint-preset-Ca94gIkh.mjs.map +0 -1
  44. package/dist/exits.d.mts +0 -1
  45. package/dist/exits.mjs +0 -40
  46. package/dist/exits.mjs.map +0 -1
  47. package/dist/judge.d.mts +0 -1
  48. package/dist/judge.mjs +0 -415
  49. package/dist/judge.mjs.map +0 -1
  50. package/dist/lookup-report-L5OLXRMf.mjs +0 -29
  51. package/dist/lookup-report-L5OLXRMf.mjs.map +0 -1
  52. package/dist/manifest-texts-DPgsV8kj.mjs +0 -19
  53. package/dist/manifest-texts-DPgsV8kj.mjs.map +0 -1
  54. package/dist/output-DAvdel9H.mjs +0 -33
  55. package/dist/output-DAvdel9H.mjs.map +0 -1
  56. package/dist/package-routes-BQWX5ttU.mjs +0 -73
  57. package/dist/package-routes-BQWX5ttU.mjs.map +0 -1
  58. package/dist/package-versions-sx15IGwA.mjs +0 -92
  59. package/dist/package-versions-sx15IGwA.mjs.map +0 -1
  60. package/dist/pass-records-BcAAWgiQ.mjs +0 -437
  61. package/dist/pass-records-BcAAWgiQ.mjs.map +0 -1
  62. package/dist/publish.d.mts +0 -1
  63. package/dist/publish.mjs +0 -1596
  64. package/dist/publish.mjs.map +0 -1
  65. package/dist/published-3eokcs_D.mjs.map +0 -1
  66. package/dist/published.d.mts +0 -1
  67. package/dist/published.mjs +0 -134
  68. package/dist/published.mjs.map +0 -1
  69. package/dist/refs.d.mts +0 -1
  70. package/dist/refs.mjs +0 -232
  71. package/dist/refs.mjs.map +0 -1
  72. package/dist/registries-DePiYd3D.mjs +0 -11
  73. package/dist/registries-DePiYd3D.mjs.map +0 -1
  74. package/dist/registry-releases-BBtz4wGE.mjs +0 -62
  75. package/dist/registry-releases-BBtz4wGE.mjs.map +0 -1
  76. package/dist/repository-files-DSwKJnrj.mjs.map +0 -1
  77. package/dist/repository-text-BKEirzPk.mjs.map +0 -1
  78. package/dist/runtime-Djm7zMwu.mjs +0 -13
  79. package/dist/runtime-Djm7zMwu.mjs.map +0 -1
  80. package/dist/specifiers-BrCyPubD.mjs +0 -32
  81. package/dist/specifiers-BrCyPubD.mjs.map +0 -1
  82. package/dist/tree-sitter-BfzHNwTR.mjs +0 -41
  83. package/dist/tree-sitter-BfzHNwTR.mjs.map +0 -1
  84. package/dist/unbumped.d.mts +0 -1
  85. package/dist/unbumped.mjs +0 -19
  86. package/dist/unbumped.mjs.map +0 -1
  87. package/dist/upstream-exits-4bn4gblF.mjs +0 -357
  88. package/dist/upstream-exits-4bn4gblF.mjs.map +0 -1
  89. package/dist/upstream-record-DRNGym9S.mjs +0 -136
  90. package/dist/upstream-record-DRNGym9S.mjs.map +0 -1
  91. package/dist/upstream.d.mts +0 -1
  92. package/dist/upstream.mjs +0 -104
  93. package/dist/upstream.mjs.map +0 -1
  94. package/dist/workspace-manifest-BAVyPzbA.mjs +0 -8
  95. package/dist/workspace-manifest-BAVyPzbA.mjs.map +0 -1
  96. package/dist/workspace-projects-MpL8K7Nz.mjs +0 -172
  97. package/dist/workspace-projects-MpL8K7Nz.mjs.map +0 -1
package/dist/publish.mjs DELETED
@@ -1,1596 +0,0 @@
1
- #!/usr/bin/env node
2
- import { t as runCli } from "./runtime-Djm7zMwu.mjs";
3
- import { n as PUBLIC_REGISTRY } from "./registries-DePiYd3D.mjs";
4
- import { Array, Config, Console, Effect, FileSystem, Option, Order, Path, Predicate, Record, Schedule, Schema, Stdio, String as String$1, pipe } from "effect";
5
- import { PACKAGE_JSON_FILE, ROOT_SUBPATH, exportEntriesOf, importSpecifierOf, runtimeDependencyNames, unscopedNameOf } from "@r_masseater/masseater-utils/kestrion";
6
- import { decodePackageJson, readPackageJson, readRawPackageJson, readVersionedPackageJson, updatePackageJson, writePackageJson } from "@r_masseater/masseater-utils/kestrion/npm";
7
- import semver from "semver";
8
- import { HttpClient, HttpClientResponse } from "effect/http";
9
- import { dual } from "effect/Function";
10
- import { finished, mustSucceed, outputOf, succeeds, writeOutputs } from "@r_masseater/masseater-utils/github-workflow";
11
- import { arch, platform } from "node:os";
12
- import { Base64 } from "effect/encoding";
13
- // src/features/publish-workspace/model/export-targets.ts
14
- const PATTERN = "*";
15
- const taggedError$3 = Schema.TaggedError;
16
- /** @internal */
17
- var MissingExportTargets = class extends taggedError$3()("MissingExportTargets", { message: Schema.String }) {};
18
- const singleTarget = (target) => {
19
- if (String$1.includes(PATTERN)(target)) return [];
20
- return [target];
21
- };
22
- /** @internal */
23
- const foldExports = (cases) => (exports) => {
24
- if (Predicate.isString(exports)) return cases.string(exports);
25
- if (Array.isArray(exports)) return cases.array(exports);
26
- if (Predicate.isReadonlyObject(exports)) return cases.object(exports);
27
- return cases.other();
28
- };
29
- /** @internal */
30
- const exportTargetsOf = (exports) => foldExports({
31
- string: singleTarget,
32
- array: Array.flatMap(exportTargetsOf),
33
- object: (record) => Array.flatMap(Record.values(record), exportTargetsOf),
34
- other: () => []
35
- })(exports);
36
- const publishedExportsOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.publishConfig), Option.flatMap((config) => Option.fromUndefinedOr(config.exports)), Option.orElse(() => Option.fromUndefinedOr(manifest.exports)), Option.getOrUndefined);
37
- const missingMessage = (missing) => `The published exports point to files the build did not write: ${Array.join(missing, ", ")}`;
38
- /** @internal */
39
- const checkExportTargets = Effect.fn("publish.checkExportTargets")(function* checkExportTargets(directory) {
40
- const fileSystem = yield* FileSystem.FileSystem;
41
- const path = yield* Path.Path;
42
- const manifest = yield* readPackageJson(directory);
43
- const missing = yield* Effect.filter(exportTargetsOf(publishedExportsOf(manifest)), (target) => Effect.map(fileSystem.exists(path.join(directory, target)), (found) => !found));
44
- return yield* pipe(missing, Array.match({
45
- onEmpty: () => Effect.void,
46
- onNonEmpty: (list) => Effect.fail(MissingExportTargets.make({ message: missingMessage(list) }))
47
- }));
48
- });
49
- // src/features/publish-workspace/model/compat-manifest.ts
50
- const UNVERSIONED$2 = "0.0.0";
51
- const VITE = "vite";
52
- /** @internal */
53
- const VITE_PLUS = "vite-plus";
54
- const MODULE_EXTENSIONS = [
55
- ".js",
56
- ".mjs",
57
- ".cjs"
58
- ];
59
- const taggedError$2 = Schema.TaggedError;
60
- /** @internal */
61
- var IncompatiblePackage = class extends taggedError$2()("IncompatiblePackage", { message: Schema.String }) {};
62
- const lowestOf = (range) => pipe(Option.fromNullishOr(semver.validRange(range)), Option.flatMap(() => Option.fromNullishOr(semver.minVersion(range))), Option.map(({ version }) => version));
63
- const floorOf = (version) => {
64
- if (semver.prerelease(version) !== null) return version;
65
- return `~${String(semver.major(version))}.${String(semver.minor(version))}.0`;
66
- };
67
- const pinnedPeer = ([name, range]) => Option.match(lowestOf(range), {
68
- onNone: () => [],
69
- onSome: (version) => {
70
- if (version === UNVERSIONED$2) return [[name, range]];
71
- return [[name, floorOf(version)]];
72
- }
73
- });
74
- const floorPeers = (peers) => pipe(Record.toEntries(peers), Array.flatMap(pinnedPeer), Record.fromEntries);
75
- const nodeFloorOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.engines), Option.flatMap(({ node }) => Option.fromUndefinedOr(node)), Option.flatMap(lowestOf));
76
- const withoutViteOfVitePlus = (peers) => {
77
- if (Record.has(peers, "vite-plus")) return Record.remove(peers, VITE);
78
- return peers;
79
- };
80
- /** @internal */
81
- const viteAliasOf = (vitePlusManifest) => pipe(decodePackageJson(vitePlusManifest), Option.flatMapNullishOr(({ dependencies }) => dependencies), Option.flatMap(Record.get(VITE)), Option.map((spec) => `${VITE}@${spec}`));
82
- const casesOf = (manifest, floor) => {
83
- const declared = withoutViteOfVitePlus(manifest.peerDependencies ?? {});
84
- const latest = `^${String(semver.major(floor))}`;
85
- return [
86
- {
87
- label: "floor",
88
- node: floorOf(floor),
89
- peers: floorPeers(declared)
90
- },
91
- {
92
- label: "latest",
93
- node: latest,
94
- peers: declared
95
- },
96
- {
97
- label: "npx",
98
- node: latest,
99
- peers: {}
100
- }
101
- ];
102
- };
103
- /** @internal */
104
- const compatCasesOf = (manifest) => pipe(nodeFloorOf(manifest), Option.match({
105
- onNone: () => [],
106
- onSome: (floor) => casesOf(manifest, floor)
107
- }));
108
- const loadsAModule = (target) => pipe(exportTargetsOf(target), Array.some((file) => pipe(MODULE_EXTENSIONS, Array.some((extension) => String$1.endsWith(extension)(file)))));
109
- const exportedSubpaths = (exports) => pipe(exportEntriesOf(exports), Array.filter(([, target]) => loadsAModule(target)), Array.map(([subpath]) => subpath));
110
- const subpathsOf = foldExports({
111
- string: () => [ROOT_SUBPATH],
112
- array: () => [ROOT_SUBPATH],
113
- object: exportedSubpaths,
114
- other: () => []
115
- });
116
- const binFilesOf = (bin) => {
117
- if (Predicate.isUndefined(bin)) return [];
118
- if (Predicate.isString(bin)) return [bin];
119
- return Record.values(bin);
120
- };
121
- /** @internal */
122
- const smokeTargetsOf = (manifest) => {
123
- const published = Option.fromUndefinedOr(manifest.publishConfig);
124
- const exports = pipe(published, Option.flatMap(({ exports: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.exports));
125
- const bin = pipe(published, Option.flatMap(({ bin: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.bin));
126
- return {
127
- imports: pipe(subpathsOf(exports), Array.map((subpath) => importSpecifierOf(manifest.name, subpath))),
128
- bins: binFilesOf(bin)
129
- };
130
- };
131
- // src/features/publish-workspace/model/compat-start.ts
132
- const NOT_LOADED = String.raw`ERR_(MODULE_NOT_FOUND|PACKAGE_|INVALID_PACKAGE|UNKNOWN_FILE|UNSUPPORTED_DIR|REQUIRE_ESM)|SyntaxError`;
133
- /** @internal */
134
- const LOAD_FAILURE = `/${NOT_LOADED}/u`;
135
- /** @internal */
136
- const CRASH = String.raw`/${NOT_LOADED}|\n\s+at\s.+:\d+:\d+/u`;
137
- /** @internal */
138
- const BIN_ARGUMENTS = [["--help"], ["--compat-unknown-flag"]];
139
- 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); }`;
140
- /** @internal */
141
- const loadsCleanly = ({ runtime, consumer, failure, args }) => mustSucceed({
142
- command: runtime,
143
- args: [
144
- "--input-type=module",
145
- "-e",
146
- spawnChecked(failure),
147
- "--",
148
- ...args
149
- ],
150
- cwd: consumer
151
- });
152
- // src/features/publish-workspace/model/plugin-lock.ts
153
- const PLUGIN_FILE = ".claude-plugin/plugin.json";
154
- const PACKED_ROOT = "package";
155
- const NPM_LOCK$1 = "package-lock.json";
156
- const MINIMUM_RELEASE_AGE_DAYS = 1;
157
- const SCOPE = /^@[^/]+\//u;
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 agedFlags = ({ name, direct }) => pipe(Option.fromNullishOr(SCOPE.exec(name)), Option.map(([scope]) => `${scope}*`), Option.toArray, Array.appendAll(direct), Array.map((excluded) => `--min-release-age-exclude=${excluded}`), Array.prepend(`--min-release-age=${String(MINIMUM_RELEASE_AGE_DAYS)}`));
195
- const npmLock = (root, flags) => mustSucceed({
196
- command: "npm",
197
- args: [
198
- "install",
199
- "--package-lock-only",
200
- `--registry=${PUBLIC_REGISTRY}`,
201
- ...flags,
202
- ...NPM_QUIET
203
- ],
204
- cwd: root
205
- });
206
- const lockedOf = Effect.fn("publish.lockedOf")(function* lockedOf(root) {
207
- const { name, dependencies } = yield* readVersionedPackageJson(root);
208
- const direct = Record.keys(dependencies ?? {});
209
- if (Array.isReadonlyArrayEmpty(direct)) return Option.none();
210
- return Option.some({
211
- name,
212
- direct
213
- });
214
- });
215
- const writeLock = (root, locked) => npmLock(root, agedFlags(locked)).pipe(Effect.matchEffect({
216
- onFailure: () => Console.warn(`${locked.name}: no dependency set is a day old, so the lock takes newer versions`).pipe(Effect.andThen(npmLock(root, []))),
217
- onSuccess: () => Effect.void
218
- }));
219
- /** @internal */
220
- const lockPlugin = Effect.fn("publish.lockPlugin")(function* lockPlugin(tarball, temporary) {
221
- const fileSystem = yield* FileSystem.FileSystem;
222
- const path = yield* Path.Path;
223
- const unpackedTo = path.join(temporary, "locked");
224
- const root = yield* unpacked(tarball, unpackedTo);
225
- const locked = yield* lockedOf(root);
226
- if (Option.isNone(locked)) return;
227
- yield* writeLock(root, locked.value);
228
- yield* fileSystem.rename(path.join(root, NPM_LOCK$1), path.join(root, PLUGIN_LOCK));
229
- yield* mustSucceed({
230
- command: "tar",
231
- args: [
232
- "-czf",
233
- tarball,
234
- "-C",
235
- unpackedTo,
236
- PACKED_ROOT
237
- ]
238
- });
239
- });
240
- // src/features/publish-workspace/model/compat-plugin.ts
241
- const NPM_LOCK = "package-lock.json";
242
- const installed = Effect.fn("compat.pluginInstalled")(function* installed(name, root) {
243
- const fileSystem = yield* FileSystem.FileSystem;
244
- const path = yield* Path.Path;
245
- const lock = path.join(root, PLUGIN_LOCK);
246
- 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` });
247
- yield* fileSystem.copyFile(lock, path.join(root, NPM_LOCK));
248
- return yield* mustSucceed({
249
- command: "npm",
250
- args: ["ci", ...NPM_QUIET],
251
- cwd: root
252
- });
253
- });
254
- const startsBins = Effect.fn("compat.pluginBins")(function* startsBins(manifest, root) {
255
- const path = yield* Path.Path;
256
- const startOf = (file) => {
257
- const started = Array.prepend(path.join(root, file));
258
- return pipe(BIN_ARGUMENTS, Array.map(started));
259
- };
260
- const runs = pipe(smokeTargetsOf(manifest).bins, Array.flatMap(startOf));
261
- yield* Effect.forEach(runs, (args) => loadsCleanly({
262
- runtime: process.execPath,
263
- consumer: root,
264
- failure: CRASH,
265
- args
266
- }), {
267
- concurrency: 1,
268
- discard: true
269
- });
270
- });
271
- /** @internal */
272
- const checkPluginInstall = Effect.fn("compat.plugin")(function* checkPluginInstall(directory, manifest, tarballs) {
273
- const tarball = Record.get(tarballs, manifest.name);
274
- if (!(yield* isPlugin(directory)) || Option.isNone(tarball)) return;
275
- const cache = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped();
276
- const root = yield* unpacked(tarball.value, cache);
277
- if (yield* installsDependencies(root)) yield* installed(manifest.name, root);
278
- yield* Console.log(`${manifest.name} plugin: installed the way Claude Code caches it`);
279
- yield* startsBins(manifest, root);
280
- }, Effect.scoped);
281
- // src/features/publish-workspace/model/platforms.ts
282
- const RUNNERS = {
283
- linux: "ubuntu-latest",
284
- windows: "windows-latest",
285
- macos: "macos-latest"
286
- };
287
- const NODE_PLATFORMS = {
288
- linux: "linux",
289
- win32: "windows",
290
- darwin: "macos"
291
- };
292
- const BUILD = "release:";
293
- const CHECK = "release:check:";
294
- const LIBC = {
295
- gnu: "glibc",
296
- musl: "musl"
297
- };
298
- const CPU_INDEX = 1;
299
- const ABI_INDEX = 2;
300
- const systems = Record.keys(RUNNERS);
301
- const runnersFor = (tasks, prefix) => pipe(systems, Array.filter((os) => Array.contains(tasks, `${prefix}${os}`)), Array.map((os) => ({
302
- os,
303
- runner: RUNNERS[os]
304
- })));
305
- /** @internal */
306
- const buildsOf = (tasks) => runnersFor(tasks, BUILD);
307
- /** @internal */
308
- const checksOf = (tasks) => runnersFor(tasks, CHECK);
309
- /** @internal */
310
- const nativeTargetsOf = (targets) => pipe(targets, Array.flatMap((target) => pipe(Array.head(String$1.split(target, "-")), Option.flatMap((platform) => Record.get(NODE_PLATFORMS, platform)), Option.map((os) => ({
311
- target,
312
- runner: RUNNERS[os]
313
- })), Option.toArray)));
314
- const libcOf = (parts) => pipe(Array.get(parts, ABI_INDEX), Option.flatMap((abi) => Record.get(LIBC, abi)), Option.match({
315
- onNone: () => ({}),
316
- onSome: (libc) => ({ libc: [libc] })
317
- }));
318
- /** @internal */
319
- const nativeFileOf = ({ binary, target }) => `${binary}.${target}.node`;
320
- /** @internal */
321
- const nativeFields = (native) => {
322
- const parts = String$1.split(native.target, "-");
323
- const file = nativeFileOf(native);
324
- return {
325
- name: `${native.name}-${native.target}`,
326
- version: native.version,
327
- os: Option.toArray(Array.head(parts)),
328
- cpu: Option.toArray(Array.get(parts, CPU_INDEX)),
329
- ...libcOf(parts),
330
- main: file,
331
- files: [file]
332
- };
333
- };
334
- /** @internal */
335
- 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`;
336
- // src/features/publish-workspace/model/native-package.ts
337
- const NPM_DIR = "npm";
338
- const NATIVE_DIR = "native";
339
- const KEPT_FIELDS = [
340
- "license",
341
- "repository",
342
- "homepage",
343
- "bugs",
344
- "engines"
345
- ];
346
- const keptFields = Effect.fn("keptFields")(function* keptFields(directory) {
347
- const fields = yield* readRawPackageJson(directory);
348
- return pipe(fields, Record.filter((_value, key) => Array.contains(KEPT_FIELDS, key)));
349
- });
350
- /** @internal */
351
- const writeNative = Effect.fn("publish.writeNative")(function* writeNative(directory, native) {
352
- const fileSystem = yield* FileSystem.FileSystem;
353
- const path = yield* Path.Path;
354
- const kept = yield* keptFields(directory);
355
- const target = path.resolve(directory, NPM_DIR, native.target);
356
- const file = nativeFileOf(native);
357
- yield* fileSystem.makeDirectory(target, { recursive: true });
358
- yield* fileSystem.copyFile(path.join(directory, NATIVE_DIR, file), path.join(target, file));
359
- yield* Effect.all([writePackageJson(target, {
360
- ...kept,
361
- ...nativeFields(native)
362
- }), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
363
- return target;
364
- });
365
- // src/features/publish-workspace/model/pack-hook.ts
366
- const HOOK_FILE = "pack-hook.mjs";
367
- /** @internal */
368
- const WIDEN_RANGES = `const EXACT = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/u;
369
- const widen = (held) =>
370
- held === undefined
371
- ? undefined
372
- : Object.fromEntries(Object.entries(held).map(([name, specifier]) => [name, EXACT.test(specifier) ? \`^\${specifier}\` : specifier]));
373
- export const hooks = {
374
- beforePacking: (manifest) => ({
375
- ...manifest,
376
- dependencies: widen(manifest.dependencies),
377
- peerDependencies: widen(manifest.peerDependencies),
378
- }),
379
- };
380
- `;
381
- /** @internal */
382
- const LOCKABLE_PLUGIN = `export const hooks = {
383
- beforePacking: ({ devDependencies, ...manifest }) => manifest,
384
- };
385
- `;
386
- const hookOf = (plugin) => {
387
- if (plugin) return LOCKABLE_PLUGIN;
388
- return WIDEN_RANGES;
389
- };
390
- /** @internal */
391
- const packHookEnv = Effect.fn("publish.packHook")(function* packHookEnv(directory, plugin) {
392
- const fileSystem = yield* FileSystem.FileSystem;
393
- const hook = (yield* Path.Path).join(directory, HOOK_FILE);
394
- yield* fileSystem.writeFileString(hook, hookOf(plugin));
395
- return { pnpm_config_pnpmfile: hook };
396
- });
397
- // src/features/publish-workspace/model/pack.ts
398
- const TARBALL = "package.tgz";
399
- /** @internal */
400
- const pack = Effect.fn("publish.pack")(function* pack(directory) {
401
- const fileSystem = yield* FileSystem.FileSystem;
402
- const path = yield* Path.Path;
403
- const temporary = yield* fileSystem.makeTempDirectoryScoped();
404
- const tarball = path.join(temporary, TARBALL);
405
- const plugin = yield* isPlugin(directory);
406
- const env = yield* packHookEnv(temporary, plugin);
407
- yield* mustSucceed({
408
- command: "vp",
409
- args: [
410
- "pm",
411
- "pack",
412
- "--out",
413
- tarball
414
- ],
415
- env,
416
- cwd: directory
417
- });
418
- if (plugin) yield* lockPlugin(tarball, temporary);
419
- return tarball;
420
- });
421
- // src/features/publish-workspace/model/compat-native.ts
422
- const HOST_PREFIX = `${platform()}-${arch()}-`;
423
- 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) => ({
424
- directory,
425
- manifest,
426
- binary,
427
- target
428
- })))));
429
- const packedNative = Effect.fn("compat.packedNative")(function* packedNative({ directory, manifest, binary, target }) {
430
- const written = yield* writeNative(directory, {
431
- name: manifest.name,
432
- version: manifest.version,
433
- binary,
434
- target
435
- });
436
- const tarball = yield* pack(written);
437
- return [[`${manifest.name}-${target}`, tarball]];
438
- });
439
- /** @internal */
440
- const nativeTarballs = Effect.fn("compat.native")(function* nativeTarballs(directory, manifest) {
441
- const none = [];
442
- return yield* pipe(builtOf$1(directory, manifest), Option.match({
443
- onNone: () => Effect.succeed(none),
444
- onSome: packedNative
445
- }));
446
- });
447
- // src/features/publish-workspace/model/compat-workspace.ts
448
- const closureOf = (known, names, seen) => {
449
- const [name, ...rest] = names;
450
- if (Predicate.isUndefined(name)) return seen;
451
- const found = Record.get(known, name);
452
- const reached = pipe(seen, Array.some((item) => item.manifest.name === name));
453
- if (Option.isNone(found) || reached) return closureOf(known, rest, seen);
454
- const inner = closureOf(known, runtimeDependencyNames(found.value.manifest), [...seen, found.value]);
455
- return closureOf(known, rest, inner);
456
- };
457
- /** @internal */
458
- const workspacesBeside = Effect.fn("compat.workspaces")(function* workspacesBeside(directory) {
459
- const fileSystem = yield* FileSystem.FileSystem;
460
- const path = yield* Path.Path;
461
- const parent = path.dirname(path.resolve(directory));
462
- const entries = yield* fileSystem.readDirectory(parent);
463
- const found = yield* Effect.forEach(entries, (entry) => readVersionedPackageJson(path.join(parent, entry)).pipe(Effect.map((manifest) => [{
464
- directory: path.join(parent, entry),
465
- manifest
466
- }]), Effect.orElseSucceed(() => [])), { concurrency: 1 });
467
- return pipe(Array.flatten(found), Array.map((workspace) => [workspace.manifest.name, workspace]), Record.fromEntries);
468
- });
469
- const builtTarball = Effect.fn("compat.pack")(function* builtTarball(directory) {
470
- yield* mustSucceed({
471
- command: "vp",
472
- args: ["run", "build"],
473
- cwd: directory
474
- });
475
- return yield* pack(directory);
476
- });
477
- const tarballsOf = Effect.fn("compat.tarballs")(function* tarballsOf({ directory, manifest }) {
478
- const tarball = yield* builtTarball(directory);
479
- const natives = yield* nativeTarballs(directory, manifest);
480
- const own = [[manifest.name, tarball]];
481
- return {
482
- name: manifest.name,
483
- version: manifest.version,
484
- tarballs: Record.fromEntries([...own, ...natives])
485
- };
486
- });
487
- /** @internal */
488
- const workspaceTarballs = Effect.fn("compat.local")(function* workspaceTarballs(directory, manifest) {
489
- const known = yield* workspacesBeside(directory);
490
- const reached = closureOf(known, runtimeDependencyNames(manifest), [{
491
- directory,
492
- manifest
493
- }]);
494
- return yield* Effect.forEach(reached, tarballsOf, { concurrency: 1 });
495
- });
496
- const meetsPeer = (peers) => ({ name, version }) => Option.match(Record.get(peers, name), {
497
- onNone: () => true,
498
- onSome: (range) => semver.validRange(range) === null || semver.satisfies(version, range)
499
- });
500
- /** @internal */
501
- const tarballsFor = (peers) => (local) => pipe(local, Array.filter(meetsPeer(peers)), Array.flatMap(({ tarballs }) => Record.toEntries(tarballs)), Record.fromEntries);
502
- // src/features/publish-workspace/model/compat.ts
503
- const INSTALL_FLAGS = ["--no-audit", "--no-fund"];
504
- const IMPORT_ONLY = "await import(process.argv[1])";
505
- const Versions$1 = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
506
- const installedNode = Effect.fn("compat.node")(function* installedNode(directory, range) {
507
- const path = yield* Path.Path;
508
- yield* (yield* FileSystem.FileSystem).makeDirectory(directory, { recursive: true });
509
- const listed = yield* outputOf({
510
- command: "npm",
511
- args: [
512
- "view",
513
- "node",
514
- "versions",
515
- "--json"
516
- ],
517
- cwd: directory
518
- });
519
- const versions = yield* Schema.decodeEffect(Versions$1)(listed);
520
- const version = yield* Effect.fromOption(Option.fromNullishOr(semver.maxSatisfying([...versions], range))).pipe(Effect.mapError(() => IncompatiblePackage.make({ message: `No Node.js release satisfies ${range}` })));
521
- yield* mustSucceed({
522
- command: "npm",
523
- args: [
524
- "install",
525
- ...INSTALL_FLAGS,
526
- `node@${version}`
527
- ],
528
- cwd: directory
529
- });
530
- return {
531
- version,
532
- binary: path.join(directory, "node_modules", "node", "bin", "node")
533
- };
534
- });
535
- const consumerFields = ({ peers, tarballs }) => ({
536
- private: true,
537
- type: "module",
538
- dependencies: {
539
- ...peers,
540
- ...pipe(tarballs, Record.map((file) => `file:${file}`))
541
- },
542
- overrides: Record.fromIterableWith(Record.keys(tarballs), (sibling) => [sibling, `$${sibling}`])
543
- });
544
- const withViteOfVitePlus = Effect.fn("compat.vite")(function* withViteOfVitePlus(directory) {
545
- const fileSystem = yield* FileSystem.FileSystem;
546
- const path = yield* Path.Path;
547
- const text = yield* fileSystem.readFileString(path.join(directory, "node_modules", VITE_PLUS, PACKAGE_JSON_FILE));
548
- yield* Option.match(viteAliasOf(text), {
549
- onNone: () => Effect.void,
550
- onSome: (alias) => mustSucceed({
551
- command: "npm",
552
- args: [
553
- "install",
554
- "--ignore-scripts",
555
- "--force",
556
- ...INSTALL_FLAGS,
557
- alias
558
- ],
559
- cwd: directory
560
- })
561
- });
562
- });
563
- const installedConsumer = Effect.fn("compat.consumer")(function* installedConsumer(root, consumer) {
564
- const fileSystem = yield* FileSystem.FileSystem;
565
- const directory = (yield* Path.Path).join(root, "consumer");
566
- yield* fileSystem.makeDirectory(directory, { recursive: true });
567
- yield* writePackageJson(directory, consumerFields(consumer));
568
- yield* mustSucceed({
569
- command: "npm",
570
- args: [
571
- "install",
572
- "--ignore-scripts",
573
- ...INSTALL_FLAGS
574
- ],
575
- cwd: directory
576
- });
577
- if (Record.has(consumer.peers, "vite-plus")) yield* withViteOfVitePlus(directory);
578
- return directory;
579
- });
580
- const importsOf = (manifest, compat) => {
581
- if (compat.label === "npx") return [];
582
- return smokeTargetsOf(manifest).imports;
583
- };
584
- const smoke = Effect.fn("compat.smoke")(function* smoke({ manifest, compat, runtime, consumer }) {
585
- const path = yield* Path.Path;
586
- const importer = [
587
- "--input-type=module",
588
- "-e",
589
- IMPORT_ONLY
590
- ];
591
- const runs = pipe(smokeTargetsOf(manifest).bins, Array.flatMap((file) => pipe(BIN_ARGUMENTS, Array.map((args) => [path.join(consumer, "node_modules", manifest.name, file), ...args]))));
592
- yield* Effect.forEach(importsOf(manifest, compat), (specifier) => loadsCleanly({
593
- runtime,
594
- consumer,
595
- failure: LOAD_FAILURE,
596
- args: [...importer, specifier]
597
- }), {
598
- concurrency: 1,
599
- discard: true
600
- });
601
- yield* Effect.forEach(runs, (args) => loadsCleanly({
602
- runtime,
603
- consumer,
604
- failure: CRASH,
605
- args
606
- }), {
607
- concurrency: 1,
608
- discard: true
609
- });
610
- });
611
- const runCase = Effect.fn("compat.case")(function* runCase({ manifest, local, compat }) {
612
- const fileSystem = yield* FileSystem.FileSystem;
613
- const path = yield* Path.Path;
614
- const root = yield* fileSystem.makeTempDirectoryScoped();
615
- const runtime = yield* installedNode(path.join(root, "runtime"), compat.node);
616
- const tarballs = tarballsFor(compat.peers)(local);
617
- const consumer = yield* installedConsumer(root, {
618
- peers: compat.peers,
619
- tarballs
620
- });
621
- const peers = pipe(Record.toEntries(compat.peers), Array.map(([name, range]) => `${name}@${range}`), Array.join(", "));
622
- yield* Console.log(`${manifest.name} ${compat.label}: Node.js ${runtime.version}, peers ${peers}`);
623
- yield* smoke({
624
- manifest,
625
- compat,
626
- runtime: runtime.binary,
627
- consumer
628
- });
629
- }, Effect.scoped);
630
- /** @internal */
631
- const checkCompat = Effect.fn("publish.compat")(function* checkCompat(directory) {
632
- const manifest = yield* readVersionedPackageJson(directory);
633
- const cases = compatCasesOf(manifest);
634
- 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` });
635
- const local = yield* workspaceTarballs(directory, manifest);
636
- yield* Effect.forEach(cases, (compat) => runCase({
637
- manifest,
638
- local,
639
- compat
640
- }), {
641
- concurrency: 1,
642
- discard: true
643
- });
644
- return yield* checkPluginInstall(directory, manifest, tarballsFor({})(local));
645
- }, Effect.scoped);
646
- // src/features/publish-workspace/model/consumer-build.ts
647
- const PNPMFILE = ".pnpmfile.cjs";
648
- const TASK = "msch";
649
- const SUCCESS$1 = 0;
650
- const TARBALLS_ENV = "MSCH_CONSUMER_TARBALLS";
651
- const TaskGraph$1 = Schema.Struct({ tasks: Schema.Record(Schema.String, Schema.Unknown) }).pipe(Schema.fromJsonString);
652
- const Tarballed = Schema.Struct({
653
- tarballs: Schema.Record(Schema.String, Schema.String),
654
- natives: Schema.Record(Schema.String, Schema.Array(Schema.String))
655
- }).pipe(Schema.fromJsonString);
656
- /** @internal */
657
- const PNPMFILE_SOURCE = Array.join([
658
- `const { tarballs, natives } = JSON.parse(process.env.${TARBALLS_ENV});`,
659
- "const fields = [\"dependencies\", \"devDependencies\", \"optionalDependencies\"];",
660
- "module.exports = {",
661
- " hooks: {",
662
- " readPackage(manifest) {",
663
- " for (const field of fields) {",
664
- " for (const [name, file] of Object.entries(tarballs)) {",
665
- " if (name in (manifest[field] || {})) manifest[field][name] = \"file:\" + file;",
666
- " }",
667
- " }",
668
- " for (const name of natives[manifest.name] || []) {",
669
- " manifest.optionalDependencies = { ...manifest.optionalDependencies, [name]: \"file:\" + tarballs[name] };",
670
- " }",
671
- " return manifest;",
672
- " },",
673
- " },",
674
- "};",
675
- ""
676
- ], "\n");
677
- const headerOf = (token) => `http.https://github.com/.extraheader=Authorization: basic ${Base64.encode(`x-access-token:${token}`)}`;
678
- /** @internal */
679
- const cloneArguments = ({ fullName, directory, token }) => [
680
- ...Option.match(token, {
681
- onNone: () => [],
682
- onSome: (value) => ["-c", headerOf(value)]
683
- }),
684
- "clone",
685
- "--depth",
686
- "1",
687
- "--quiet",
688
- `https://github.com/${fullName}.git`,
689
- directory
690
- ];
691
- const stateOf = Effect.fn("consumers.state")(function* stateOf(directory) {
692
- return `${yield* outputOf({
693
- command: "git",
694
- args: [
695
- "status",
696
- "--porcelain=v1",
697
- "--untracked-files=all"
698
- ],
699
- cwd: directory
700
- })}\n${yield* outputOf({
701
- command: "git",
702
- args: ["diff"],
703
- cwd: directory
704
- })}`;
705
- });
706
- const hasTask = Effect.fn("consumers.hasTask")(function* hasTask(directory) {
707
- const listed = yield* outputOf({
708
- command: "vp",
709
- args: ["run", "--json"],
710
- cwd: directory
711
- });
712
- const { tasks } = yield* Schema.decodeEffect(TaskGraph$1)(listed);
713
- return Record.has(tasks, TASK);
714
- });
715
- const REPORTED_LINES = 40;
716
- const tailOf = (output) => pipe(String$1.split("\n")(output), Array.takeRight(REPORTED_LINES), Array.join("\n"));
717
- const brokenReason = Effect.fn("consumers.reason")(function* brokenReason(directory) {
718
- const before = yield* stateOf(directory);
719
- const { code, output } = yield* finished({
720
- command: "vp",
721
- args: [
722
- "run",
723
- "--no-cache",
724
- TASK
725
- ],
726
- cwd: directory
727
- });
728
- const after = yield* stateOf(directory);
729
- if (code !== SUCCESS$1) return Option.some(`vp run ${TASK} exited with ${String(code)}:\n${tailOf(output)}`);
730
- return Option.liftPredicate(after, (state) => state !== before).pipe(Option.map((state) => `vp run ${TASK} rewrote files:\n${state}`));
731
- });
732
- const install = (directory, options) => mustSucceed({
733
- command: "vp",
734
- args: ["install", options.flag],
735
- cwd: directory,
736
- env: options.env
737
- });
738
- const withNewBuild = Effect.fn("consumers.withNewBuild")(function* withNewBuild(directory, build) {
739
- const fileSystem = yield* FileSystem.FileSystem;
740
- const pnpmfile = (yield* Path.Path).join(directory, PNPMFILE);
741
- const encoded = yield* Schema.encodeEffect(Tarballed)(build);
742
- yield* fileSystem.writeFileString(pnpmfile, PNPMFILE_SOURCE);
743
- yield* install(directory, {
744
- flag: "--no-frozen-lockfile",
745
- env: { [TARBALLS_ENV]: encoded }
746
- });
747
- yield* fileSystem.remove(pnpmfile);
748
- yield* mustSucceed({
749
- command: "git",
750
- args: [
751
- "checkout",
752
- "--",
753
- "."
754
- ],
755
- cwd: directory
756
- });
757
- return yield* brokenReason(directory);
758
- });
759
- const onItsOwnMain = Effect.fn("consumers.onItsOwnMain")(function* onItsOwnMain(directory) {
760
- yield* mustSucceed({
761
- command: "git",
762
- args: [
763
- "checkout",
764
- "--",
765
- "."
766
- ],
767
- cwd: directory
768
- });
769
- yield* mustSucceed({
770
- command: "git",
771
- args: ["clean", "-fdq"],
772
- cwd: directory
773
- });
774
- yield* install(directory, {
775
- flag: "--frozen-lockfile",
776
- env: {}
777
- });
778
- return yield* brokenReason(directory);
779
- });
780
- const cloned = Effect.fn("consumers.clone")(function* cloned({ consumer, token }) {
781
- const fileSystem = yield* FileSystem.FileSystem;
782
- const path = yield* Path.Path;
783
- const root = yield* fileSystem.makeTempDirectoryScoped();
784
- const directory = path.join(root, "consumer");
785
- yield* mustSucceed({
786
- command: "git",
787
- args: cloneArguments({
788
- fullName: consumer.fullName,
789
- directory,
790
- token
791
- })
792
- });
793
- return directory;
794
- });
795
- const verdict = Effect.fn("consumers.verdict")(function* verdict({ consumer, build }, directory) {
796
- const reason = yield* withNewBuild(directory, build);
797
- if (Option.isNone(reason)) {
798
- yield* Console.log(`${consumer.fullName}: ${TASK} passes with the new build`);
799
- return reason;
800
- }
801
- const baseline = yield* onItsOwnMain(directory);
802
- if (Option.isSome(baseline)) {
803
- yield* Console.log(`${consumer.fullName}: already fails on its own main, skipped`);
804
- return Option.none();
805
- }
806
- return Option.some(`${consumer.fullName}: ${reason.value}`);
807
- });
808
- /** @internal */
809
- const checkConsumer = Effect.fn("consumers.check")(function* checkConsumer(checked) {
810
- const directory = yield* cloned(checked);
811
- if (!(yield* hasTask(directory))) {
812
- yield* Console.log(`${checked.consumer.fullName}: has no ${TASK} task, skipped`);
813
- return Option.none();
814
- }
815
- return yield* verdict(checked, directory);
816
- }, Effect.scoped);
817
- // src/features/publish-workspace/model/consumer-repositories.ts
818
- const GH = "gh";
819
- const SUCCESS = 0;
820
- const READ_RAW = "Accept: application/vnd.github.raw+json";
821
- const MANIFESTS = ["package.json", "pnpm-workspace.yaml"];
822
- const REMOTE = /[:/](?<owner>[^/:]+)\/(?<name>[^/]+?)(?:\.git)?$/u;
823
- const INSTALLATION = "/installation/repositories";
824
- const OWNED = "/user/repos?affiliation=owner";
825
- const REPOSITORY_FIELDS = "{full_name,archived,fork}|tojson";
826
- const Repository = Schema.Struct({
827
- full_name: Schema.String,
828
- archived: Schema.Boolean,
829
- fork: Schema.Boolean
830
- });
831
- const decodeRepository = Schema.decodeUnknownOption(Schema.fromJsonString(Repository));
832
- /** @internal */
833
- 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 })));
834
- /** @internal */
835
- const remoteOf = (url) => pipe(Option.fromNullishOr(REMOTE.exec(url)), Option.flatMapNullishOr(({ groups }) => groups), Option.map(({ owner, name }) => `${owner ?? ""}/${name ?? ""}`));
836
- /** @internal */
837
- const consumersOf = (repositories) => (self) => {
838
- const prefix = pipe(String$1.split("/")(self), Array.head, Option.getOrElse(() => ""));
839
- return pipe(repositories, Array.filter(({ fullName }) => String$1.startsWith(`${prefix}/`)(fullName) && fullName !== self));
840
- };
841
- /** @internal */
842
- const mentionsAny = (names) => (text) => pipe(names, Array.some((name) => String$1.includes(name)(text)));
843
- const envOf = (token) => Option.match(token, {
844
- onNone: () => ({}),
845
- onSome: (value) => ({ GH_TOKEN: value })
846
- });
847
- const apiOutput = (args, token) => finished({
848
- command: GH,
849
- args: ["api", ...args],
850
- env: envOf(token)
851
- }).pipe(Effect.map(({ output, code }) => pipe(Option.some(output), Option.filter(() => code === SUCCESS))));
852
- const listing = (path, expression, token) => apiOutput([
853
- "--paginate",
854
- path,
855
- "--jq",
856
- expression
857
- ], token).pipe(Effect.map(Option.map(repositoriesOf)));
858
- /** @internal */
859
- const listRepositories = (token) => listing(INSTALLATION, `.repositories[]|${REPOSITORY_FIELDS}`, token).pipe(Effect.flatMap(Option.match({
860
- onNone: () => listing(OWNED, `.[]|${REPOSITORY_FIELDS}`, token),
861
- onSome: (found) => Effect.succeedSome(found)
862
- })));
863
- /** @internal */
864
- const manifestsOf = (token) => ({ fullName }) => Effect.forEach(MANIFESTS, (file) => apiOutput([
865
- `repos/${fullName}/contents/${file}`,
866
- "-H",
867
- READ_RAW
868
- ], token).pipe(Effect.map(Option.getOrElse(() => ""))), { concurrency: 1 }).pipe(Effect.map(Array.join("\n")));
869
- // src/features/publish-workspace/model/consumers.ts
870
- const MANIFEST_READ_CONCURRENCY = 4;
871
- /** @internal */
872
- const dependentsOf = (known) => (names) => {
873
- const reached = pipe(known, Record.filter(({ manifest }) => pipe(runtimeDependencyNames(manifest), Array.some((name) => Array.contains(names, name)))), Record.keys);
874
- const added = pipe(reached, Array.filter((name) => !Array.contains(names, name)));
875
- if (Array.isReadonlyArrayEmpty(added)) return names;
876
- return dependentsOf(known)([...names, ...added]);
877
- };
878
- const tokenOf = Config.option(Config.String("GITHUB_APP_TOKEN"));
879
- const selfOf = Effect.fn("consumers.self")(function* selfOf() {
880
- const given = yield* Config.option(Config.String("GITHUB_REPOSITORY"));
881
- if (Option.isSome(given)) return given.value;
882
- const url = yield* outputOf({
883
- command: "git",
884
- args: [
885
- "remote",
886
- "get-url",
887
- "origin"
888
- ]
889
- });
890
- return Option.getOrElse(remoteOf(url), () => "");
891
- });
892
- const nativesOf = (local) => pipe(local, Array.map(({ name, tarballs }) => [name, pipe(Record.keys(tarballs), Array.filter((entry) => entry !== name))]), Record.fromEntries);
893
- const builtOf = Effect.fn("consumers.built")(function* builtOf(directories) {
894
- const built = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.flatMap((manifest) => workspaceTarballs(directory, manifest))), { concurrency: 1 });
895
- const local = Array.flatten(built);
896
- return {
897
- tarballs: tarballsFor({})(local),
898
- natives: nativesOf(local)
899
- };
900
- });
901
- const mentioning = Effect.fn("consumers.mentioning")(function* mentioning(candidates, names, token) {
902
- return yield* Effect.filter(candidates, (consumer) => manifestsOf(token)(consumer).pipe(Effect.map(mentionsAny(names))), { concurrency: MANIFEST_READ_CONCURRENCY });
903
- });
904
- const namesAffected = Effect.fn("consumers.affected")(function* namesAffected(directories) {
905
- const [first = "."] = directories;
906
- const known = yield* workspacesBeside(first);
907
- const own = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.map(({ name }) => name)), { concurrency: 1 });
908
- return dependentsOf(known)(own);
909
- });
910
- const unlisted = Effect.fn("consumers.unlisted")(function* unlisted() {
911
- 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" });
912
- return yield* Console.log("consumers skipped: no GitHub access to list them");
913
- });
914
- const failing = Effect.fn("consumers.failing")(function* failing(found, build, token) {
915
- const reasons = yield* Effect.forEach(found, (consumer) => checkConsumer({
916
- consumer,
917
- build,
918
- token
919
- }), { concurrency: 1 });
920
- return Array.getSomes(reasons);
921
- });
922
- const consumersAffected = Effect.fn("consumers.found")(function* consumersAffected(directories, token) {
923
- const listed = yield* listRepositories(token);
924
- if (Option.isNone(listed)) return Option.none();
925
- const self = yield* selfOf();
926
- const names = yield* namesAffected(directories);
927
- const found = yield* mentioning(consumersOf(listed.value)(self), names, token);
928
- const listedNames = pipe(found, Array.map(({ fullName }) => fullName));
929
- yield* Console.log(`consumers: ${Array.join(listedNames, ", ")}`);
930
- return Option.some(found);
931
- });
932
- const verified = Effect.fn("consumers.verified")(function* verified(directories, found, token) {
933
- const build = yield* builtOf(directories);
934
- const broken = yield* failing(found, build, token);
935
- if (Array.isReadonlyArrayNonEmpty(broken)) return yield* IncompatiblePackage.make({ message: `The new build breaks its consumers:\n${Array.join(broken, "\n")}` });
936
- return yield* Effect.void;
937
- });
938
- /** @internal */
939
- const checkConsumers = Effect.fn("publish.consumers")(function* checkConsumers(directories) {
940
- if (Array.isReadonlyArrayEmpty(directories)) return yield* Effect.void;
941
- const token = yield* tokenOf;
942
- const found = yield* consumersAffected(directories, token);
943
- if (Option.isNone(found)) return yield* unlisted();
944
- return yield* verified(directories, found.value, token);
945
- }, Effect.scoped);
946
- // src/features/publish-workspace/model/manifest.ts
947
- const UNVERSIONED$1 = "0.0.0";
948
- const ROOT = ".";
949
- /** @internal */
950
- const releaseName = ({ name }) => unscopedNameOf(name);
951
- /** @internal */
952
- const isRoot = (directory) => directory === ROOT;
953
- /** @internal */
954
- const tagOf = ({ directory, name, version }) => {
955
- if (isRoot(directory)) return `v${version}`;
956
- return `${releaseName({ name })}-v${version}`;
957
- };
958
- /** @internal */
959
- const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
960
- /** @internal */
961
- const isVersioned = ({ version }) => version !== UNVERSIONED$1;
962
- /** @internal */
963
- const goesToNpm = (manifest) => !pipe(Option.fromUndefinedOr(manifest.private), Option.getOrElse(() => false));
964
- // src/features/publish-workspace/model/dependencies.ts
965
- const WORKSPACE_PROTOCOL = "workspace:";
966
- const READ_CONCURRENCY = 8;
967
- const WAIT_INTERVAL = "30 seconds";
968
- const WAIT_ATTEMPTS = 120;
969
- /** @internal */
970
- const REGISTRY_FLAGS = ["--registry", PUBLIC_REGISTRY];
971
- /** @internal */
972
- const PUBLISH_FLAGS = [
973
- "--provenance",
974
- "--access",
975
- "public",
976
- ...REGISTRY_FLAGS
977
- ];
978
- /** @internal */
979
- const onNpm = Effect.fn("publish.onNpm")(function* onNpm({ directory, name, version }) {
980
- return yield* succeeds({
981
- command: "npm",
982
- args: [
983
- "view",
984
- `${name}@${version}`,
985
- "version",
986
- ...REGISTRY_FLAGS
987
- ],
988
- cwd: directory
989
- });
990
- });
991
- const taggedError$1 = Schema.TaggedError;
992
- /** @internal */
993
- var UnpublishedDependencies = class extends taggedError$1()("UnpublishedDependencies", { message: Schema.String }) {};
994
- const workspaceDependencies = (manifest) => pipe(Option.fromUndefinedOr(manifest.dependencies), Option.map((dependencies) => pipe(dependencies, Record.filter(String$1.startsWith(WORKSPACE_PROTOCOL)), Record.keys)), Option.getOrElse(() => []));
995
- const failWhenMissing = (missing, manifest) => {
996
- if (Array.isReadonlyArrayEmpty(missing)) return Effect.void;
997
- const names = pipe(missing, Array.map(({ directory, name, version }) => `${name}@${version} (${directory})`), Array.join(", "));
998
- return Effect.fail(UnpublishedDependencies.make({ message: `${manifest.name} depends on versions that are not on npm yet. Publish them first: ${names}` }));
999
- };
1000
- const missingDependencies = Effect.fn("publish.missingDependencies")(function* missingDependencies({ manifest, workspaces }) {
1001
- const wanted = workspaceDependencies(manifest);
1002
- const siblings = yield* Effect.forEach(workspaces, (directory) => readVersionedPackageJson(directory).pipe(Effect.map((found) => ({
1003
- directory,
1004
- ...found
1005
- }))), { concurrency: READ_CONCURRENCY });
1006
- const internal = pipe(siblings, Array.filter((sibling) => Array.contains(wanted, sibling.name) && goesToNpm(sibling)));
1007
- const missing = yield* Effect.filter(internal, (sibling) => onNpm(sibling).pipe(Effect.map((published) => !published)), { concurrency: READ_CONCURRENCY });
1008
- yield* failWhenMissing(missing, manifest);
1009
- });
1010
- /** @internal */
1011
- const requirePublishedDependencies = (dependent) => missingDependencies(dependent).pipe(Effect.tapError((missing) => Effect.logInfo(`waiting: ${missing.message}`)), Effect.retry({
1012
- schedule: Schedule.spaced(WAIT_INTERVAL),
1013
- times: WAIT_ATTEMPTS,
1014
- while: Schema.is(UnpublishedDependencies)
1015
- }));
1016
- // src/features/publish-workspace/model/provenance.ts
1017
- const ATTESTATIONS = "https://registry.npmjs.org/-/npm/v1/attestations/";
1018
- const SLSA = /slsa\.dev\/provenance/u;
1019
- const Digest = Schema.Struct({ gitCommit: Schema.String });
1020
- const Dependency = Schema.Struct({
1021
- uri: Schema.String,
1022
- digest: Digest
1023
- });
1024
- const BuildDefinition = Schema.Struct({ resolvedDependencies: Schema.Array(Dependency) });
1025
- const Predicate$1 = Schema.Struct({ buildDefinition: BuildDefinition });
1026
- const Statement = Schema.fromJsonString(Schema.Struct({ predicate: Predicate$1 }));
1027
- const Envelope = Schema.Struct({ payload: Schema.String });
1028
- const Bundle = Schema.Struct({ dsseEnvelope: Envelope });
1029
- const Attestation = Schema.Struct({
1030
- predicateType: Schema.String,
1031
- bundle: Bundle
1032
- });
1033
- const Attestations = Schema.Struct({ attestations: Schema.Array(Attestation) });
1034
- /** @internal */
1035
- const commitOf = (repository) => (payload) => pipe(Base64.decodeString(payload), Effect.fromResult, Effect.flatMap(Schema.decodeEffect(Statement)), Effect.map(({ predicate }) => pipe(Array.head(predicate.buildDefinition.resolvedDependencies), Option.filter(({ uri }) => String$1.includes(`github.com/${repository}@`)(uri)), Option.map(({ digest }) => digest.gitCommit))), Effect.orElseSucceed(() => Option.none()));
1036
- /** @internal */
1037
- const provenanceCommit = Effect.fn("publish.provenanceCommit")(function* provenanceCommit({ name, version }) {
1038
- const client = yield* HttpClient.HttpClient;
1039
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1040
- const url = `${ATTESTATIONS}${String$1.replace("/", "%2f")(name)}@${version}`;
1041
- 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()));
1042
- if (Option.isNone(found)) return Option.none();
1043
- return yield* commitOf(repository)(found.value.bundle.dsseEnvelope.payload);
1044
- });
1045
- // src/features/publish-workspace/model/tags.ts
1046
- const UNVERSIONED = "0.0.0";
1047
- const LOOKUP_CONCURRENCY = 4;
1048
- const Versions = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
1049
- /** @internal */
1050
- const tagged = Effect.fn("publish.tagged")(function* tagged(tag) {
1051
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1052
- return yield* succeeds({
1053
- command: "gh",
1054
- args: ["api", `repos/${repository}/git/ref/tags/${tag}`]
1055
- });
1056
- });
1057
- const tokenEnv = Config.option(Config.String("GITHUB_APP_TOKEN")).pipe(Effect.map(Option.match({
1058
- onNone: () => ({}),
1059
- onSome: (value) => ({ GH_TOKEN: value })
1060
- })));
1061
- /** @internal */
1062
- const createTag = Effect.fn("publish.createTag")(function* createTag({ tag, sha }) {
1063
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1064
- const env = yield* tokenEnv;
1065
- yield* Effect.logInfo(`tagging ${tag} at ${sha}`);
1066
- yield* mustSucceed({
1067
- command: "gh",
1068
- env,
1069
- args: [
1070
- "api",
1071
- "-X",
1072
- "POST",
1073
- `repos/${repository}/git/refs`,
1074
- "-f",
1075
- `ref=refs/tags/${tag}`,
1076
- "-f",
1077
- `sha=${sha}`
1078
- ]
1079
- });
1080
- });
1081
- const isRelease = (version) => version !== UNVERSIONED && semver.valid(version) !== null && semver.prerelease(version) === null;
1082
- const publishedVersions = Effect.fn("publish.publishedVersions")(function* publishedVersions({ directory, manifest }) {
1083
- if (!goesToNpm(manifest)) return [];
1084
- const text = yield* outputOf({
1085
- command: "npm",
1086
- args: [
1087
- "view",
1088
- manifest.name,
1089
- "versions",
1090
- "--json",
1091
- ...REGISTRY_FLAGS
1092
- ],
1093
- cwd: directory
1094
- }).pipe(Effect.orElseSucceed(() => "[]"));
1095
- const versions = yield* Schema.decodeEffect(Versions)(text).pipe(Effect.orElseSucceed(() => []));
1096
- return pipe(versions, Array.filter((version) => isRelease(version) && version !== manifest.version));
1097
- });
1098
- /** @internal */
1099
- const untaggedVersions = Effect.fn("publish.untaggedVersions")(function* untaggedVersions(workspace) {
1100
- const versions = yield* publishedVersions(workspace);
1101
- return yield* Effect.filter(versions, (version) => tagged(tagOf({
1102
- directory: workspace.directory,
1103
- name: workspace.manifest.name,
1104
- version
1105
- })).pipe(Effect.map((found) => !found)), { concurrency: LOOKUP_CONCURRENCY });
1106
- });
1107
- const backfillVersion = Effect.fn("publish.backfillVersion")(function* backfillVersion(workspace, version) {
1108
- const { directory, manifest } = workspace;
1109
- const tag = tagOf({
1110
- directory,
1111
- name: manifest.name,
1112
- version
1113
- });
1114
- const commit = yield* provenanceCommit({
1115
- name: manifest.name,
1116
- version
1117
- });
1118
- if (Option.isNone(commit)) {
1119
- yield* Effect.logWarning(`${tag} has no npm provenance, so it stays untagged`);
1120
- return;
1121
- }
1122
- yield* createTag({
1123
- tag,
1124
- sha: commit.value
1125
- });
1126
- });
1127
- /** @internal */
1128
- const backfillTags = Effect.fn("publish.backfillTags")(function* backfillTags(workspace) {
1129
- const versions = yield* untaggedVersions(workspace);
1130
- yield* Effect.forEach(versions, (version) => backfillVersion(workspace, version), {
1131
- concurrency: 1,
1132
- discard: true
1133
- });
1134
- });
1135
- // src/features/publish-workspace/model/plan.ts
1136
- const HOOK = "release:publish";
1137
- const WORKFLOW = "publish.yml";
1138
- const PLAN_CONCURRENCY = 4;
1139
- const NONE = 0;
1140
- const TRAILING_SLASH = /\/$/u;
1141
- const Task = Schema.Struct({
1142
- package: Schema.String,
1143
- name: Schema.String
1144
- });
1145
- const TaskGraph = Schema.fromJsonString(Schema.Struct({
1146
- workspaceRoot: Schema.String,
1147
- tasks: Schema.Record(Schema.String, Task)
1148
- }));
1149
- const Runner = Schema.Struct({
1150
- os: Schema.String,
1151
- runner: Schema.String
1152
- });
1153
- const NativeTarget = Schema.Struct({
1154
- target: Schema.String,
1155
- runner: Schema.String
1156
- });
1157
- const PlanSchema = Schema.Struct({
1158
- directory: Schema.String,
1159
- name: Schema.String,
1160
- version: Schema.String,
1161
- tag: Schema.String,
1162
- environment: Schema.String,
1163
- npm: Schema.Boolean,
1164
- native: Schema.Array(NativeTarget),
1165
- builds: Schema.Array(Runner),
1166
- checks: Schema.Array(Runner),
1167
- release: Schema.Boolean,
1168
- tagged: Schema.Boolean,
1169
- hook: Schema.Boolean
1170
- });
1171
- const AssetCount = Schema.fromJsonString(Schema.Finite);
1172
- /** @internal */
1173
- const graphTasks = outputOf({
1174
- command: "vp",
1175
- args: ["run", "--json"]
1176
- }).pipe(Effect.flatMap(Schema.decodeEffect(TaskGraph)), Effect.map(({ tasks }) => Record.values(tasks)));
1177
- const tasksIn = (tasks, directory) => pipe(tasks, Array.filter((task) => task.package === directory), Array.map(({ name }) => name));
1178
- /** @internal */
1179
- const workspacesOf = (tasks) => pipe(tasks, Array.map((task) => task.package), Array.dedupe);
1180
- const allTagged = Effect.fn("publish.allTagged")(function* allTagged(directory, manifest) {
1181
- if (!isVersioned(manifest)) return true;
1182
- const current = yield* tagged(tagOf({
1183
- directory,
1184
- ...manifest
1185
- }));
1186
- const older = yield* untaggedVersions({
1187
- directory,
1188
- manifest
1189
- });
1190
- return current && Array.isReadonlyArrayEmpty(older);
1191
- });
1192
- const workspaceOf = (directory) => Path.Path.pipe(Effect.map((path) => String$1.replace(TRAILING_SLASH, "")(path.normalize(directory))));
1193
- /** @internal */
1194
- const released = Effect.fn("publish.released")(function* released(tag) {
1195
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1196
- return yield* succeeds({
1197
- command: "gh",
1198
- args: [
1199
- "release",
1200
- "view",
1201
- tag,
1202
- "--repo",
1203
- repository
1204
- ]
1205
- });
1206
- });
1207
- /** @internal */
1208
- const releasedWithAssets = Effect.fn("publish.releasedWithAssets")(function* releasedWithAssets(tag) {
1209
- const view = [
1210
- "release",
1211
- "view",
1212
- tag,
1213
- "--repo",
1214
- yield* Config.String("GITHUB_REPOSITORY")
1215
- ];
1216
- if (!(yield* released(tag))) return false;
1217
- return (yield* outputOf({
1218
- command: "gh",
1219
- args: [
1220
- ...view,
1221
- "--json",
1222
- "assets",
1223
- "--jq",
1224
- ".assets | length"
1225
- ]
1226
- }).pipe(Effect.flatMap(Schema.decodeEffect(AssetCount)))) > NONE;
1227
- });
1228
- const keepWhen = (kept) => (items) => pipe(items, Array.filter(() => kept));
1229
- const unpublished = Effect.fn("publish.unpublished")(function* unpublished(directory, manifest) {
1230
- if (!goesToNpm(manifest)) return false;
1231
- return !(yield* onNpm({
1232
- directory,
1233
- ...manifest
1234
- }));
1235
- });
1236
- const needsNpm = Effect.fn("publish.needsNpm")(function* needsNpm(directory, manifest, workspaces) {
1237
- if (!(yield* unpublished(directory, manifest))) return false;
1238
- yield* requirePublishedDependencies({
1239
- manifest,
1240
- workspaces
1241
- });
1242
- return true;
1243
- });
1244
- const needsRelease = Effect.fn("publish.needsRelease")(function* needsRelease(directory, manifest, builds) {
1245
- const tag = tagOf({
1246
- directory,
1247
- ...manifest
1248
- });
1249
- if (!isVersioned(manifest)) return false;
1250
- if (isRoot(directory)) return !(yield* released(tag));
1251
- if (Array.isReadonlyArrayEmpty(builds)) return false;
1252
- return !(yield* releasedWithAssets(tag));
1253
- });
1254
- const nativeOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.map(({ targets }) => nativeTargetsOf(targets)), Option.getOrElse(() => []));
1255
- /** @internal */
1256
- const planOf = Effect.fn("publish.plan")(function* planOf(directory) {
1257
- const workspace = yield* workspaceOf(directory);
1258
- const manifest = yield* readVersionedPackageJson(workspace);
1259
- const graph = yield* graphTasks;
1260
- const tasks = tasksIn(graph, workspace);
1261
- const npm = yield* needsNpm(workspace, manifest, workspacesOf(graph));
1262
- const release = yield* needsRelease(workspace, manifest, buildsOf(tasks));
1263
- const built = keepWhen(release || !isVersioned(manifest));
1264
- const tag = tagOf({
1265
- directory: workspace,
1266
- ...manifest
1267
- });
1268
- return {
1269
- directory: workspace,
1270
- name: releaseName(manifest),
1271
- version: manifest.version,
1272
- tag,
1273
- tagged: yield* allTagged(workspace, manifest),
1274
- environment: environmentOf(manifest),
1275
- npm,
1276
- native: keepWhen(npm)(nativeOf(manifest)),
1277
- builds: built(buildsOf(tasks)),
1278
- checks: built(checksOf(tasks)),
1279
- release,
1280
- hook: release && Array.contains(tasks, HOOK)
1281
- };
1282
- });
1283
- const untaggedCurrent = Effect.fn("publish.untaggedCurrent")(function* untaggedCurrent(directory, manifest) {
1284
- if (!isVersioned(manifest)) return false;
1285
- return !(yield* tagged(tagOf({
1286
- directory,
1287
- ...manifest
1288
- })));
1289
- });
1290
- const pending = Effect.fn("publish.pending")(function* pending(graph, directory) {
1291
- const manifest = yield* readVersionedPackageJson(directory);
1292
- const builds = buildsOf(tasksIn(graph, directory));
1293
- const needed = yield* Effect.all([
1294
- unpublished(directory, manifest),
1295
- needsRelease(directory, manifest, builds),
1296
- untaggedCurrent(directory, manifest)
1297
- ], { concurrency: "unbounded" });
1298
- return pipe(needed, Array.contains(true));
1299
- });
1300
- /** @internal */
1301
- const dispatchPending = Effect.fn("publish.dispatchPending")(function* dispatchPending(ref) {
1302
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1303
- const graph = yield* graphTasks;
1304
- const directories = yield* Effect.filter(workspacesOf(graph), (directory) => pending(graph, directory), { concurrency: PLAN_CONCURRENCY });
1305
- yield* Effect.forEach(directories, (directory) => Effect.logInfo(`publishing ${directory}`).pipe(Effect.andThen(mustSucceed({
1306
- command: "gh",
1307
- args: [
1308
- "workflow",
1309
- "run",
1310
- WORKFLOW,
1311
- "--repo",
1312
- repository,
1313
- "--ref",
1314
- ref,
1315
- "-f",
1316
- `workspace=${directory}`
1317
- ]
1318
- }))), {
1319
- concurrency: 1,
1320
- discard: true
1321
- });
1322
- });
1323
- /** @internal */
1324
- const writePlan = Effect.fn("publish.writePlan")(function* writePlan(plan) {
1325
- const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(PlanSchema))(plan);
1326
- yield* Effect.logInfo(encoded);
1327
- yield* writeOutputs({ plan: encoded });
1328
- });
1329
- // src/features/publish-workspace/model/compat-plan.ts
1330
- const Directories = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
1331
- /** @internal */
1332
- const isChecked = Effect.fn("compat.isChecked")(function* isChecked(directory) {
1333
- const manifest = yield* readVersionedPackageJson(directory);
1334
- return goesToNpm(manifest) && !Array.isReadonlyArrayEmpty(compatCasesOf(manifest));
1335
- });
1336
- /** @internal */
1337
- const writeCompatPlan = Effect.fn("publish.compatPlan")(function* writeCompatPlan() {
1338
- const graph = yield* graphTasks;
1339
- const checked = yield* Effect.filter(workspacesOf(graph), isChecked, { concurrency: 1 });
1340
- const encoded = yield* Schema.encodeEffect(Directories)(checked);
1341
- yield* Effect.logInfo(encoded);
1342
- yield* writeOutputs({ directories: encoded });
1343
- });
1344
- // src/features/publish-workspace/model/compat-changed.ts
1345
- const LOCAL_ONLY = "the compat jobs of the verify workflow run it for every package in CI";
1346
- const ARITY = 2;
1347
- const selected = (workspaces, directories) => {
1348
- if (Array.isReadonlyArrayEmpty(directories)) return workspaces;
1349
- return pipe(workspaces, Array.filter((workspace) => Array.contains(directories, workspace)));
1350
- };
1351
- /** @internal */
1352
- const selectedWorkspaces = dual(ARITY, selected);
1353
- /** @internal */
1354
- const checkChangedCompat = Effect.fn("publish.compatChanged")(function* checkChangedCompat(directories) {
1355
- if (yield* Config.Boolean("GITHUB_ACTIONS").pipe(Config.withDefault(false))) return yield* Console.log(`compat skipped: ${LOCAL_ONLY}`);
1356
- const graph = yield* graphTasks;
1357
- const chosen = selectedWorkspaces(workspacesOf(graph), directories);
1358
- const checked = yield* Effect.filter(chosen, isChecked, { concurrency: 1 });
1359
- yield* Effect.forEach(checked, checkCompat, {
1360
- concurrency: 1,
1361
- discard: true
1362
- });
1363
- return yield* checkConsumers(checked);
1364
- });
1365
- // src/features/publish-workspace/model/npm.ts
1366
- const verifyPackage = Effect.fn("publish.verify")(function* verifyPackage(directory, manifest) {
1367
- const tasks = [
1368
- "build",
1369
- "test",
1370
- ...pipe(Option.fromUndefinedOr(manifest["size-limit"]), Option.map(() => "size"), Option.toArray)
1371
- ];
1372
- yield* Effect.forEach(tasks, (task) => mustSucceed({
1373
- command: "vp",
1374
- args: ["run", task],
1375
- cwd: directory
1376
- }), {
1377
- concurrency: 1,
1378
- discard: true
1379
- });
1380
- yield* checkExportTargets(directory);
1381
- yield* checkCompat(directory);
1382
- });
1383
- const publishNative = Effect.fn("publish.publishNative")(function* publishNative(target) {
1384
- const { name, version } = yield* readVersionedPackageJson(target);
1385
- if (yield* onNpm({
1386
- directory: target,
1387
- name,
1388
- version
1389
- })) {
1390
- yield* Console.log(`${name}@${version} is already published, skipping`);
1391
- return name;
1392
- }
1393
- yield* mustSucceed({
1394
- command: "npm",
1395
- args: [
1396
- "publish",
1397
- ".",
1398
- ...PUBLISH_FLAGS
1399
- ],
1400
- cwd: target
1401
- });
1402
- return name;
1403
- });
1404
- const addOptionalDependencies = (directory, names, version) => updatePackageJson(directory, { optionalDependencies: pipe(names, Array.map((name) => [name, version]), Record.fromEntries) }).pipe(Effect.withSpan("publish.optionalDependencies"));
1405
- const publishNatives = Effect.fn("publish.publishNatives")(function* publishNatives(directory, manifest) {
1406
- if (Predicate.isUndefined(manifest.native)) return;
1407
- const { binary, targets } = manifest.native;
1408
- const written = yield* Effect.forEach(targets, (target) => writeNative(directory, {
1409
- name: manifest.name,
1410
- version: manifest.version,
1411
- binary,
1412
- target
1413
- }), { concurrency: 1 });
1414
- const names = yield* Effect.forEach(written, publishNative, { concurrency: 1 });
1415
- yield* addOptionalDependencies(directory, names, manifest.version);
1416
- });
1417
- /** @internal */
1418
- const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory) {
1419
- const manifest = yield* readVersionedPackageJson(directory);
1420
- if (yield* onNpm({
1421
- directory,
1422
- ...manifest
1423
- })) return yield* Console.log(`${manifest.name}@${manifest.version} is already published`);
1424
- yield* verifyPackage(directory, manifest);
1425
- yield* publishNatives(directory, manifest);
1426
- const tarball = yield* pack(directory);
1427
- return yield* mustSucceed({
1428
- command: "npm",
1429
- args: [
1430
- "publish",
1431
- tarball,
1432
- ...PUBLISH_FLAGS
1433
- ],
1434
- cwd: directory
1435
- });
1436
- }, Effect.scoped);
1437
- // src/features/publish-workspace/model/release.ts
1438
- const ASSETS = "release-assets";
1439
- const revisionOf = Effect.fn("publish.revision")(function* revisionOf(manifest) {
1440
- const head = yield* Config.String("GITHUB_SHA");
1441
- if (!goesToNpm(manifest)) return head;
1442
- const published = yield* provenanceCommit(manifest);
1443
- return Option.getOrElse(published, () => head);
1444
- });
1445
- const tagRevision = Effect.fn("publish.tag")(function* tagRevision(tag, manifest) {
1446
- if (yield* tagged(tag)) return;
1447
- const sha = yield* revisionOf(manifest);
1448
- yield* createTag({
1449
- tag,
1450
- sha
1451
- });
1452
- });
1453
- const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
1454
- const fileSystem = yield* FileSystem.FileSystem;
1455
- const path = yield* Path.Path;
1456
- const folder = path.join(directory, ASSETS);
1457
- if (!(yield* fileSystem.exists(folder))) return [];
1458
- const names = yield* fileSystem.readDirectory(folder, { recursive: true });
1459
- 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)));
1460
- return Array.sort(files, Order.String);
1461
- });
1462
- const LIBRARY_NOTES = [
1463
- "--latest=false",
1464
- "--notes",
1465
- ""
1466
- ];
1467
- const ROOT_NOTES = ["--latest", "--generate-notes"];
1468
- const notesOf = (directory) => {
1469
- if (isRoot(directory)) return ROOT_NOTES;
1470
- return LIBRARY_NOTES;
1471
- };
1472
- const createRelease = Effect.fn("publish.createRelease")(function* createRelease({ directory, manifest }) {
1473
- const tag = tagOf({
1474
- directory,
1475
- ...manifest
1476
- });
1477
- const notes = notesOf(directory);
1478
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1479
- if (yield* succeeds({
1480
- command: "gh",
1481
- args: [
1482
- "release",
1483
- "view",
1484
- tag,
1485
- "--repo",
1486
- repository
1487
- ]
1488
- })) return;
1489
- yield* mustSucceed({
1490
- command: "gh",
1491
- args: [
1492
- "release",
1493
- "create",
1494
- tag,
1495
- "--repo",
1496
- repository,
1497
- "--verify-tag",
1498
- "--title",
1499
- `${releaseName(manifest)} v${manifest.version}`,
1500
- ...notes
1501
- ]
1502
- });
1503
- });
1504
- const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets({ directory, manifest }) {
1505
- const tag = tagOf({
1506
- directory,
1507
- ...manifest
1508
- });
1509
- const files = yield* assetsIn(directory);
1510
- if (Array.isReadonlyArrayEmpty(files) || (yield* releasedWithAssets(tag))) return;
1511
- const repository = yield* Config.String("GITHUB_REPOSITORY");
1512
- yield* createRelease({
1513
- directory,
1514
- manifest
1515
- });
1516
- yield* mustSucceed({
1517
- command: "gh",
1518
- args: [
1519
- "release",
1520
- "upload",
1521
- tag,
1522
- ...files,
1523
- "--repo",
1524
- repository,
1525
- "--clobber"
1526
- ]
1527
- });
1528
- });
1529
- /** @internal */
1530
- const publishRelease = Effect.fn("publish.release")(function* publishRelease(directory) {
1531
- const manifest = yield* readVersionedPackageJson(directory);
1532
- if (!isVersioned(manifest)) {
1533
- yield* Effect.logInfo(`${manifest.name} has no version to publish`);
1534
- return;
1535
- }
1536
- const tag = tagOf({
1537
- directory,
1538
- ...manifest
1539
- });
1540
- yield* Effect.andThen(tagRevision(tag, manifest), backfillTags({
1541
- directory,
1542
- manifest
1543
- }));
1544
- yield* writeOutputs({ tag });
1545
- if (isRoot(directory)) yield* createRelease({
1546
- directory,
1547
- manifest
1548
- });
1549
- yield* uploadAssets({
1550
- directory,
1551
- manifest
1552
- });
1553
- });
1554
- // bin/msch-publish.ts
1555
- const Arguments = Schema.Tuple([Schema.Literals([
1556
- "dispatch",
1557
- "plan",
1558
- "npm",
1559
- "release",
1560
- "compat",
1561
- "compat-plan",
1562
- "consumers"
1563
- ]), Schema.String]);
1564
- const ChangedArguments = Schema.TupleWithRest(Schema.Tuple([Schema.Literal("compat-changed")]), [Schema.String]);
1565
- const taggedError = Schema.TaggedError;
1566
- var UsageError = class extends taggedError()("UsageError", { message: Schema.String }) {};
1567
- const USAGE = "usage: msch-publish <plan|npm|release|compat|compat-plan|consumers> <workspace directory> | msch-publish dispatch <ref> | msch-publish compat-changed [workspace directory...]";
1568
- const steps = {
1569
- dispatch: dispatchPending,
1570
- plan: Effect.fn("plan")(function* plan(directory) {
1571
- return yield* planOf(directory).pipe(Effect.flatMap(writePlan));
1572
- }),
1573
- npm: publishToNpm,
1574
- release: publishRelease,
1575
- compat: checkCompat,
1576
- consumers: Effect.fn("consumers")(function* consumers(directory) {
1577
- return yield* checkConsumers([directory]);
1578
- }),
1579
- "compat-plan": Effect.fn("compat-plan")(function* compatPlan() {
1580
- return yield* writeCompatPlan();
1581
- })
1582
- };
1583
- const publish = Effect.gen(function* publish() {
1584
- const args = yield* (yield* Stdio.Stdio).args;
1585
- const changed = Schema.decodeUnknownOption(ChangedArguments)(args);
1586
- if (Option.isSome(changed)) {
1587
- const [, ...directories] = changed.value;
1588
- return yield* checkChangedCompat(directories);
1589
- }
1590
- const [step, directory] = yield* Schema.decodeUnknownEffect(Arguments)(args).pipe(Effect.mapError(() => UsageError.make({ message: USAGE })));
1591
- return yield* steps[step](directory);
1592
- });
1593
- runCli("msch-publish")(publish);
1594
- export {};
1595
-
1596
- //# sourceMappingURL=publish.mjs.map