@r_masseater/msch 0.53.1 → 0.57.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/README.md +18 -18
- package/dist/app-B22Gq0no.mjs +2120 -0
- package/dist/app-B22Gq0no.mjs.map +1 -0
- package/dist/cargo-inputs.d.mts +1 -1
- package/dist/cargo-inputs.mjs +4 -9
- package/dist/cargo-inputs.mjs.map +1 -1
- package/dist/changed.mjs +90 -19
- package/dist/changed.mjs.map +1 -1
- package/dist/{check-upstream-exits-DYxWDyHC.mjs → check-upstream-exits-DsBS7bui.mjs} +2 -2
- package/dist/check-upstream-exits-DsBS7bui.mjs.map +1 -0
- package/dist/cli.mjs +469 -385
- package/dist/cli.mjs.map +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +3 -3
- package/dist/config.mjs.map +1 -1
- package/dist/credential-broker-D8sFyowJ.mjs +105 -0
- package/dist/credential-broker-D8sFyowJ.mjs.map +1 -0
- package/dist/decision-rules.d.mts +1 -1
- package/dist/decision-rules.mjs +1 -1
- package/dist/{define-lint-preset-CecEvjVf.mjs → define-lint-preset-DeLIlDuA.mjs} +8 -643
- package/dist/define-lint-preset-DeLIlDuA.mjs.map +1 -0
- package/dist/{dependencies-DCJv7YcW.mjs → dependencies-CbvZost8.mjs} +11 -7
- package/dist/dependencies-CbvZost8.mjs.map +1 -0
- package/dist/exits.mjs +4 -5
- package/dist/exits.mjs.map +1 -1
- package/dist/{index-B2X8WhBt.d.mts → index-Cwnhs7VE.d.mts} +5 -51
- package/dist/library.d.mts +18 -0
- package/dist/library.mjs +28 -0
- package/dist/library.mjs.map +1 -0
- package/dist/lint-rules.mjs +353 -110
- package/dist/lint-rules.mjs.map +1 -1
- package/dist/lint.d.mts +2 -2
- package/dist/lint.mjs +1 -1
- package/dist/locked-inputs-DMSoGCa-.mjs +20 -0
- package/dist/locked-inputs-DMSoGCa-.mjs.map +1 -0
- package/dist/locked-inputs.d.mts +2 -3
- package/dist/locked-inputs.mjs +1 -20
- package/dist/oxlint.mjs +29 -14
- package/dist/oxlint.mjs.map +1 -1
- package/dist/{package-LeBO9czg.mjs → package-DZbqpZfs.mjs} +6 -6
- package/dist/package-DZbqpZfs.mjs.map +1 -0
- package/dist/{problem-CzOlOb5f.mjs → problem-Q4Zyi4PR.mjs} +10 -6
- package/dist/problem-Q4Zyi4PR.mjs.map +1 -0
- package/dist/{project-C4uzq7_4.mjs → project-CIY_lNiT.mjs} +36 -14
- package/dist/project-CIY_lNiT.mjs.map +1 -0
- package/dist/publish.mjs +629 -305
- package/dist/publish.mjs.map +1 -1
- package/dist/runtime-LT40e_l3.mjs +28 -0
- package/dist/runtime-LT40e_l3.mjs.map +1 -0
- package/dist/{syntax-3AJkpCcs.mjs → syntax-BNRNY74H.mjs} +13 -4
- package/dist/syntax-BNRNY74H.mjs.map +1 -0
- package/dist/wake.d.mts +1 -0
- package/dist/wake.mjs +25 -0
- package/dist/wake.mjs.map +1 -0
- package/dist/workspace-settings.mjs +5 -5
- package/dist/workspace-settings.mjs.map +1 -1
- package/package.json +48 -41
- package/skills/{publishing → msch-publishing}/SKILL.md +10 -2
- package/skills/{repository-config → msch-repository-config}/SKILL.md +5 -2
- package/skills/{workspace-settings → msch-workspace-settings}/SKILL.md +4 -3
- package/dist/check-upstream-exits-DYxWDyHC.mjs.map +0 -1
- package/dist/define-lint-preset-CecEvjVf.mjs.map +0 -1
- package/dist/dependencies-DCJv7YcW.mjs.map +0 -1
- package/dist/locked-inputs.mjs.map +0 -1
- package/dist/package-LeBO9czg.mjs.map +0 -1
- package/dist/problem-CzOlOb5f.mjs.map +0 -1
- package/dist/project-C4uzq7_4.mjs.map +0 -1
- package/dist/runtime-DFsdNYI0.mjs +0 -29
- package/dist/runtime-DFsdNYI0.mjs.map +0 -1
- package/dist/syntax-3AJkpCcs.mjs.map +0 -1
package/dist/publish.mjs
CHANGED
|
@@ -1,189 +1,124 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as runCli } from "./runtime-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { t as runCli } from "./runtime-LT40e_l3.mjs";
|
|
3
|
+
import { a as mustSucceed, i as writeOutputs, n as actionsOidcToken, o as outputOf, r as mask, s as succeeds, t as BROKER } from "./credential-broker-D8sFyowJ.mjs";
|
|
4
|
+
import { Array, Config, Console, Effect, FileSystem, Option, Order, Path, Predicate, Record, Schema, Stdio, String as String$1, pipe } from "effect";
|
|
5
5
|
import semver from "semver";
|
|
6
6
|
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
7
7
|
import { Base64 } from "effect/encoding";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const requestTo = Effect.fn("requestTo")(function* requestTo(method, path) {
|
|
16
|
-
const repository = yield* Config.String("GITHUB_REPOSITORY");
|
|
17
|
-
const token = yield* Config.Redacted("GH_TOKEN").pipe(Config.orElse(() => Config.Redacted("GITHUB_TOKEN")));
|
|
18
|
-
return HttpClientRequest.make(method)(`${API}/repos/${repository}/${path}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)), HttpClientRequest.setHeaders(HEADERS));
|
|
19
|
-
});
|
|
20
|
-
const execute = Effect.fn("execute")(function* execute(request) {
|
|
21
|
-
const response = yield* (yield* HttpClient.HttpClient).execute(request);
|
|
22
|
-
return yield* HttpClientResponse.filterStatusOk(response);
|
|
23
|
-
});
|
|
24
|
-
Effect.fn("withBody")(function* withBody(method, path, body) {
|
|
25
|
-
const request = yield* requestTo(method, path);
|
|
26
|
-
const filled = yield* HttpClientRequest.bodyJson(request, body);
|
|
27
|
-
return yield* execute(filled);
|
|
28
|
-
});
|
|
29
|
-
// ../github-workflow/src/shared/lib/process.ts
|
|
30
|
-
const SUCCESS = 0;
|
|
31
|
-
const taggedError$3 = Schema.TaggedError;
|
|
32
|
-
var CommandFailed = class extends taggedError$3()("CommandFailed", { message: Schema.String }) {};
|
|
33
|
-
const failed = ({ command, args }) => CommandFailed.make({ message: `${command} ${Array.join(args, " ")} failed` });
|
|
34
|
-
const exitCodeOf = Effect.fn("exitCodeOf")(function* exitCodeOf({ command, args, env, cwd }) {
|
|
35
|
-
return yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(command, args, {
|
|
36
|
-
cwd,
|
|
37
|
-
env,
|
|
38
|
-
extendEnv: true,
|
|
39
|
-
stdin: "ignore",
|
|
40
|
-
stdout: "inherit",
|
|
41
|
-
stderr: "inherit"
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
44
|
-
const succeedsWith = (command) => exitCodeOf(command).pipe(Effect.map((code) => code === SUCCESS));
|
|
45
|
-
const mustSucceedWith = (command) => succeedsWith(command).pipe(Effect.filterOrFail((passed) => passed, () => failed(command)), Effect.asVoid);
|
|
46
|
-
const collected = Effect.fn("collected")(function* collected({ command, args, env, cwd }) {
|
|
47
|
-
const handle = yield* ChildProcess.make(command, args, {
|
|
48
|
-
cwd,
|
|
49
|
-
env,
|
|
50
|
-
extendEnv: true,
|
|
51
|
-
stdin: "ignore",
|
|
52
|
-
stderr: "inherit"
|
|
53
|
-
});
|
|
54
|
-
const [output, code] = yield* Effect.all([handle.stdout.pipe(Stream.decodeText(), Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
|
|
55
|
-
return {
|
|
56
|
-
output,
|
|
57
|
-
code
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
const outputWith = (command) => collected(command).pipe(Effect.scoped, Effect.filterOrFail(({ code }) => code === SUCCESS, () => failed(command)), Effect.map(({ output }) => String.trim(output)));
|
|
61
|
-
/** @internal */
|
|
62
|
-
const succeeds = succeedsWith;
|
|
63
|
-
/** @internal */
|
|
64
|
-
const mustSucceed = mustSucceedWith;
|
|
65
|
-
/** @internal */
|
|
66
|
-
const outputOf = outputWith;
|
|
67
|
-
// ../github-workflow/src/shared/lib/workflow.ts
|
|
68
|
-
const taggedError$2 = Schema.TaggedError;
|
|
69
|
-
var WorkflowFailed = class extends taggedError$2()("WorkflowFailed", { message: Schema.String }) {};
|
|
70
|
-
const appendTo = (variable, entries) => Effect.gen(function* appended() {
|
|
71
|
-
const path = yield* Config.String(variable);
|
|
72
|
-
const fs = yield* FileSystem.FileSystem;
|
|
73
|
-
const lines = pipe(Record.toEntries(entries), Array.map(([name, value]) => `${name}=${value}\n`), Array.join(""));
|
|
74
|
-
yield* fs.writeFileString(path, lines, { flag: "a" });
|
|
75
|
-
});
|
|
76
|
-
const outputsOf = (outputs) => appendTo("GITHUB_OUTPUT", outputs);
|
|
8
|
+
import { arch, platform } from "node:os";
|
|
9
|
+
// src/features/publish-workspace/model/compat-manifest.ts
|
|
10
|
+
const PACKAGE_JSON_EXPORT = "./package.json";
|
|
11
|
+
const PATTERN$1 = "*";
|
|
12
|
+
const ROOT_EXPORT = ".";
|
|
13
|
+
const UNVERSIONED$2 = "0.0.0";
|
|
14
|
+
const VITE = "vite";
|
|
77
15
|
/** @internal */
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
yield* Console.log(`::error::${message}`);
|
|
82
|
-
return yield* WorkflowFailed.make({ message });
|
|
83
|
-
});
|
|
84
|
-
// src/features/publish-workspace/model/broker.ts
|
|
85
|
-
const BROKER = "https://credentials.masseater.dev/";
|
|
86
|
-
const AUDIENCE = "masseater-dev-credential-broker";
|
|
87
|
-
const IdToken = Schema.Struct({ value: Schema.String });
|
|
88
|
-
const Issued = Schema.Record(Schema.String, Schema.Unknown);
|
|
89
|
-
const oidcToken = Effect.fn("publish.oidc")(function* oidcToken(requestUrl, requestToken) {
|
|
90
|
-
const client = yield* HttpClient.HttpClient;
|
|
91
|
-
const request = HttpClientRequest.get(`${requestUrl}&audience=${AUDIENCE}`).pipe(HttpClientRequest.bearerToken(Redacted.value(requestToken)));
|
|
92
|
-
const response = yield* HttpClient.filterStatusOk(client).execute(request);
|
|
93
|
-
const { value } = yield* HttpClientResponse.schemaBodyJson(IdToken)(response);
|
|
94
|
-
yield* mask(value);
|
|
95
|
-
return value;
|
|
96
|
-
});
|
|
97
|
-
const issued = Effect.fn("publish.issued")(function* issued(oidc, { kind, field }) {
|
|
98
|
-
const client = yield* HttpClient.HttpClient;
|
|
99
|
-
const request = HttpClientRequest.post(`${BROKER}?only=${kind}`).pipe(HttpClientRequest.bearerToken(oidc));
|
|
100
|
-
const response = yield* HttpClient.filterStatusOk(client).execute(request);
|
|
101
|
-
const body = yield* HttpClientResponse.schemaBodyJson(Issued)(response);
|
|
102
|
-
const token = Option.filter(Option.fromNullishOr(body[field]), (value) => typeof value === "string" && value !== "");
|
|
103
|
-
yield* Effect.forEach(Option.toArray(token), mask, {
|
|
104
|
-
concurrency: 1,
|
|
105
|
-
discard: true
|
|
106
|
-
});
|
|
107
|
-
return token;
|
|
108
|
-
});
|
|
16
|
+
const VITE_PLUS = "vite-plus";
|
|
17
|
+
const TYPES = "types";
|
|
18
|
+
const taggedError$3 = Schema.TaggedError;
|
|
109
19
|
/** @internal */
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
// src/features/publish-workspace/model/manifest.ts
|
|
117
|
-
const MANIFEST_FILE$1 = "package.json";
|
|
118
|
-
const SCOPE = /^@[^/]+\//u;
|
|
119
|
-
const UNVERSIONED$1 = "0.0.0";
|
|
120
|
-
const ROOT = ".";
|
|
121
|
-
const Native = Schema.Struct({
|
|
20
|
+
var IncompatiblePackage = class extends taggedError$3()("IncompatiblePackage", { message: Schema.String }) {};
|
|
21
|
+
const Declared = Schema.Record(Schema.String, Schema.String);
|
|
22
|
+
const VitePlusManifestJson = Schema.fromJsonString(Schema.Struct({ dependencies: Schema.optionalKey(Declared) }));
|
|
23
|
+
const Bin = Schema.Union([Schema.String, Declared]);
|
|
24
|
+
const Native$1 = Schema.Struct({
|
|
122
25
|
binary: Schema.String,
|
|
123
26
|
targets: Schema.Array(Schema.String)
|
|
124
27
|
});
|
|
125
|
-
const
|
|
28
|
+
const Engines = Schema.Struct({ node: Schema.optionalKey(Schema.String) });
|
|
29
|
+
const PublishConfig$1 = Schema.Struct({
|
|
30
|
+
exports: Schema.optionalKey(Schema.Unknown),
|
|
31
|
+
bin: Schema.optionalKey(Bin)
|
|
32
|
+
});
|
|
33
|
+
/** @internal */
|
|
34
|
+
const CompatManifestJson = Schema.fromJsonString(Schema.Struct({
|
|
126
35
|
name: Schema.String,
|
|
127
36
|
version: Schema.String,
|
|
128
37
|
private: Schema.optionalKey(Schema.Boolean),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
38
|
+
native: Schema.optionalKey(Native$1),
|
|
39
|
+
exports: Schema.optionalKey(Schema.Unknown),
|
|
40
|
+
bin: Schema.optionalKey(Bin),
|
|
41
|
+
dependencies: Schema.optionalKey(Declared),
|
|
42
|
+
optionalDependencies: Schema.optionalKey(Declared),
|
|
43
|
+
engines: Schema.optionalKey(Engines),
|
|
44
|
+
peerDependencies: Schema.optionalKey(Declared),
|
|
45
|
+
publishConfig: Schema.optionalKey(PublishConfig$1)
|
|
46
|
+
}));
|
|
47
|
+
const lowestOf = (range) => pipe(Option.fromNullishOr(semver.validRange(range)), Option.flatMap(() => Option.fromNullishOr(semver.minVersion(range))), Option.map(({ version }) => version));
|
|
48
|
+
const floorOf = (version) => {
|
|
49
|
+
if (semver.prerelease(version) !== null) return version;
|
|
50
|
+
return `~${String(semver.major(version))}.${String(semver.minor(version))}.0`;
|
|
51
|
+
};
|
|
52
|
+
const pinnedPeer = ([name, range]) => Option.match(lowestOf(range), {
|
|
53
|
+
onNone: () => [],
|
|
54
|
+
onSome: (version) => {
|
|
55
|
+
if (version === UNVERSIONED$2) return [[name, range]];
|
|
56
|
+
return [[name, floorOf(version)]];
|
|
57
|
+
}
|
|
139
58
|
});
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const tagOf = ({ directory, name, version }) => {
|
|
146
|
-
if (isRoot(directory)) return `v${version}`;
|
|
147
|
-
return `${releaseName({ name })}-v${version}`;
|
|
59
|
+
const floorPeers = (peers) => pipe(Record.toEntries(peers), Array.flatMap(pinnedPeer), Record.fromEntries);
|
|
60
|
+
const nodeFloorOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.engines), Option.flatMap(({ node }) => Option.fromUndefinedOr(node)), Option.flatMap(lowestOf));
|
|
61
|
+
const withoutViteOfVitePlus = (peers) => {
|
|
62
|
+
if (Record.has(peers, "vite-plus")) return Record.remove(peers, VITE);
|
|
63
|
+
return peers;
|
|
148
64
|
};
|
|
149
65
|
/** @internal */
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
66
|
+
const viteAliasOf = (vitePlusManifest) => pipe(Schema.decodeOption(VitePlusManifestJson)(vitePlusManifest), Option.flatMapNullishOr(({ dependencies }) => dependencies), Option.flatMap(Record.get(VITE)), Option.map((spec) => `${VITE}@${spec}`));
|
|
67
|
+
const casesOf = (manifest, floor) => {
|
|
68
|
+
const declared = withoutViteOfVitePlus(manifest.peerDependencies ?? {});
|
|
69
|
+
return [{
|
|
70
|
+
label: "floor",
|
|
71
|
+
node: floorOf(floor),
|
|
72
|
+
peers: floorPeers(declared)
|
|
73
|
+
}, {
|
|
74
|
+
label: "latest",
|
|
75
|
+
node: `^${String(semver.major(floor))}`,
|
|
76
|
+
peers: declared
|
|
77
|
+
}];
|
|
78
|
+
};
|
|
158
79
|
/** @internal */
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
cwd: directory
|
|
80
|
+
const compatCasesOf = (manifest) => pipe(nodeFloorOf(manifest), Option.match({
|
|
81
|
+
onNone: () => [],
|
|
82
|
+
onSome: (floor) => casesOf(manifest, floor)
|
|
83
|
+
}));
|
|
84
|
+
const isTypesOnly = (target) => Option.match(target, {
|
|
85
|
+
onNone: () => false,
|
|
86
|
+
onSome: (value) => Predicate.isReadonlyObject(value) && pipe(Record.keys(value), Array.every((key) => key === TYPES))
|
|
167
87
|
});
|
|
168
|
-
const
|
|
88
|
+
const subpathsOf = (exports) => {
|
|
89
|
+
if (Predicate.isString(exports)) return [ROOT_EXPORT];
|
|
90
|
+
if (Predicate.isReadonlyObject(exports)) {
|
|
91
|
+
const keys = Record.keys(exports);
|
|
92
|
+
if (pipe(keys, Array.every(String$1.startsWith(ROOT_EXPORT)))) return pipe(keys, Array.filter((key) => key !== PACKAGE_JSON_EXPORT && !String$1.includes(PATTERN$1)(key)), Array.filter((key) => !isTypesOnly(Record.get(exports, key))));
|
|
93
|
+
return [ROOT_EXPORT];
|
|
94
|
+
}
|
|
95
|
+
return [];
|
|
96
|
+
};
|
|
97
|
+
const specifierOf = (name, subpath) => {
|
|
98
|
+
if (subpath === ROOT_EXPORT) return name;
|
|
99
|
+
return `${name}${String$1.replace(ROOT_EXPORT, "")(subpath)}`;
|
|
100
|
+
};
|
|
101
|
+
const binFilesOf = (bin) => {
|
|
102
|
+
if (Predicate.isUndefined(bin)) return [];
|
|
103
|
+
if (Predicate.isString(bin)) return [bin];
|
|
104
|
+
return Record.values(bin);
|
|
105
|
+
};
|
|
169
106
|
/** @internal */
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
107
|
+
const smokeTargetsOf = (manifest) => {
|
|
108
|
+
const published = Option.fromUndefinedOr(manifest.publishConfig);
|
|
109
|
+
const exports = pipe(published, Option.flatMap(({ exports: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.exports));
|
|
110
|
+
const bin = pipe(published, Option.flatMap(({ bin: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.bin));
|
|
111
|
+
return {
|
|
112
|
+
imports: pipe(subpathsOf(exports), Array.map((subpath) => specifierOf(manifest.name, subpath))),
|
|
113
|
+
bins: binFilesOf(bin)
|
|
114
|
+
};
|
|
176
115
|
};
|
|
177
116
|
/** @internal */
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}))), { concurrency: READ_CONCURRENCY });
|
|
184
|
-
const internal = pipe(siblings, Array.filter((sibling) => Array.contains(wanted, sibling.name) && goesToNpm(sibling)));
|
|
185
|
-
const missing = yield* Effect.filter(internal, (sibling) => onNpm(sibling).pipe(Effect.map((published) => !published)), { concurrency: READ_CONCURRENCY });
|
|
186
|
-
yield* failWhenMissing(missing, manifest);
|
|
117
|
+
const compatManifestIn = Effect.fn("compat.manifestIn")(function* compatManifestIn(directory) {
|
|
118
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
119
|
+
const path = yield* Path.Path;
|
|
120
|
+
const text = yield* fileSystem.readFileString(path.join(directory, "package.json"));
|
|
121
|
+
return yield* Schema.decodeEffect(CompatManifestJson)(text);
|
|
187
122
|
});
|
|
188
123
|
// src/features/publish-workspace/model/platforms.ts
|
|
189
124
|
const RUNNERS = {
|
|
@@ -214,7 +149,7 @@ const buildsOf = (tasks) => runnersFor(tasks, BUILD);
|
|
|
214
149
|
/** @internal */
|
|
215
150
|
const checksOf = (tasks) => runnersFor(tasks, CHECK);
|
|
216
151
|
/** @internal */
|
|
217
|
-
const nativeTargetsOf = (targets) => pipe(targets, Array.flatMap((target) => pipe(Array.head(String.split(target, "-")), Option.flatMap((platform) => Record.get(NODE_PLATFORMS, platform)), Option.map((os) => ({
|
|
152
|
+
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) => ({
|
|
218
153
|
target,
|
|
219
154
|
runner: RUNNERS[os]
|
|
220
155
|
})), Option.toArray)));
|
|
@@ -226,7 +161,7 @@ const libcOf = (parts) => pipe(Array.get(parts, ABI_INDEX), Option.flatMap((abi)
|
|
|
226
161
|
const nativeFileOf = ({ binary, target }) => `${binary}.${target}.node`;
|
|
227
162
|
/** @internal */
|
|
228
163
|
const nativeFields = (native) => {
|
|
229
|
-
const parts = String.split(native.target, "-");
|
|
164
|
+
const parts = String$1.split(native.target, "-");
|
|
230
165
|
const file = nativeFileOf(native);
|
|
231
166
|
return {
|
|
232
167
|
name: `${native.name}-${native.target}`,
|
|
@@ -240,6 +175,42 @@ const nativeFields = (native) => {
|
|
|
240
175
|
};
|
|
241
176
|
/** @internal */
|
|
242
177
|
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`;
|
|
178
|
+
// src/features/publish-workspace/model/native-package.ts
|
|
179
|
+
const NPM_DIR = "npm";
|
|
180
|
+
const NATIVE_DIR = "native";
|
|
181
|
+
const MANIFEST_FILE$4 = "package.json";
|
|
182
|
+
const KEPT_FIELDS = [
|
|
183
|
+
"license",
|
|
184
|
+
"repository",
|
|
185
|
+
"homepage",
|
|
186
|
+
"bugs",
|
|
187
|
+
"engines"
|
|
188
|
+
];
|
|
189
|
+
/** @internal */
|
|
190
|
+
const PackageJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
|
|
191
|
+
const keptFields = Effect.fn("publish.keptFields")(function* keptFields(directory) {
|
|
192
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
193
|
+
const path = yield* Path.Path;
|
|
194
|
+
const text = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE$4));
|
|
195
|
+
const raw = yield* Schema.decodeEffect(PackageJson)(text);
|
|
196
|
+
return pipe(raw, Record.filter((_value, key) => Array.contains(KEPT_FIELDS, key)));
|
|
197
|
+
});
|
|
198
|
+
/** @internal */
|
|
199
|
+
const writeNative = Effect.fn("publish.writeNative")(function* writeNative(directory, native) {
|
|
200
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
201
|
+
const path = yield* Path.Path;
|
|
202
|
+
const kept = yield* keptFields(directory);
|
|
203
|
+
const target = path.resolve(directory, NPM_DIR, native.target);
|
|
204
|
+
const file = nativeFileOf(native);
|
|
205
|
+
yield* fileSystem.makeDirectory(target, { recursive: true });
|
|
206
|
+
yield* fileSystem.copyFile(path.join(directory, NATIVE_DIR, file), path.join(target, file));
|
|
207
|
+
const text = yield* Schema.encodeEffect(PackageJson)({
|
|
208
|
+
...kept,
|
|
209
|
+
...nativeFields(native)
|
|
210
|
+
});
|
|
211
|
+
yield* Effect.all([fileSystem.writeFileString(path.join(target, MANIFEST_FILE$4), text), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
|
|
212
|
+
return target;
|
|
213
|
+
});
|
|
243
214
|
// src/features/publish-workspace/model/widened-ranges.ts
|
|
244
215
|
const HOOK_FILE = "widen-ranges.mjs";
|
|
245
216
|
/** @internal */
|
|
@@ -263,163 +234,346 @@ const widenRangesEnv = Effect.fn("publish.widenRanges")(function* widenRangesEnv
|
|
|
263
234
|
yield* fileSystem.writeFileString(hook, WIDEN_RANGES);
|
|
264
235
|
return { pnpm_config_pnpmfile: hook };
|
|
265
236
|
});
|
|
266
|
-
// src/features/publish-workspace/model/
|
|
237
|
+
// src/features/publish-workspace/model/pack.ts
|
|
267
238
|
const TARBALL = "package.tgz";
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
]
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
name: Schema.String,
|
|
286
|
-
version: Schema.String
|
|
287
|
-
}));
|
|
288
|
-
const authEnv = Effect.fn("publish.authEnv")(function* authEnv() {
|
|
289
|
-
const token = yield* brokerCredential({
|
|
290
|
-
kind: "npm",
|
|
291
|
-
field: "npmToken"
|
|
239
|
+
/** @internal */
|
|
240
|
+
const pack = Effect.fn("publish.pack")(function* pack(directory) {
|
|
241
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
242
|
+
const path = yield* Path.Path;
|
|
243
|
+
const temporary = yield* fileSystem.makeTempDirectoryScoped();
|
|
244
|
+
const tarball = path.join(temporary, TARBALL);
|
|
245
|
+
const env = yield* widenRangesEnv(temporary);
|
|
246
|
+
yield* mustSucceed({
|
|
247
|
+
command: "vp",
|
|
248
|
+
args: [
|
|
249
|
+
"pm",
|
|
250
|
+
"pack",
|
|
251
|
+
"--out",
|
|
252
|
+
tarball
|
|
253
|
+
],
|
|
254
|
+
env,
|
|
255
|
+
cwd: directory
|
|
292
256
|
});
|
|
293
|
-
return
|
|
294
|
-
|
|
295
|
-
|
|
257
|
+
return tarball;
|
|
258
|
+
});
|
|
259
|
+
// src/features/publish-workspace/model/compat-native.ts
|
|
260
|
+
const HOST_PREFIX = `${platform()}-${arch()}-`;
|
|
261
|
+
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) => ({
|
|
262
|
+
directory,
|
|
263
|
+
manifest,
|
|
264
|
+
binary,
|
|
265
|
+
target
|
|
266
|
+
})))));
|
|
267
|
+
const packedNative = Effect.fn("compat.packedNative")(function* packedNative({ directory, manifest, binary, target }) {
|
|
268
|
+
const written = yield* writeNative(directory, {
|
|
269
|
+
name: manifest.name,
|
|
270
|
+
version: manifest.version,
|
|
271
|
+
binary,
|
|
272
|
+
target
|
|
296
273
|
});
|
|
274
|
+
const tarball = yield* pack(written);
|
|
275
|
+
return [[`${manifest.name}-${target}`, tarball]];
|
|
297
276
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
277
|
+
/** @internal */
|
|
278
|
+
const nativeTarballs = Effect.fn("compat.native")(function* nativeTarballs(directory, manifest) {
|
|
279
|
+
const none = [];
|
|
280
|
+
return yield* pipe(builtOf(directory, manifest), Option.match({
|
|
281
|
+
onNone: () => Effect.succeed(none),
|
|
282
|
+
onSome: packedNative
|
|
283
|
+
}));
|
|
284
|
+
});
|
|
285
|
+
// src/features/publish-workspace/model/compat-workspace.ts
|
|
286
|
+
const dependencyNamesOf = (manifest) => pipe([
|
|
287
|
+
manifest.dependencies,
|
|
288
|
+
manifest.peerDependencies,
|
|
289
|
+
manifest.optionalDependencies
|
|
290
|
+
], Array.flatMap((declared) => Record.keys(declared ?? {})));
|
|
291
|
+
const closureOf = (known, names, seen) => {
|
|
292
|
+
const [name, ...rest] = names;
|
|
293
|
+
if (Predicate.isUndefined(name)) return seen;
|
|
294
|
+
const found = Record.get(known, name);
|
|
295
|
+
const reached = pipe(seen, Array.some((item) => item.manifest.name === name));
|
|
296
|
+
if (Option.isNone(found) || reached) return closureOf(known, rest, seen);
|
|
297
|
+
const inner = closureOf(known, dependencyNamesOf(found.value.manifest), [...seen, found.value]);
|
|
298
|
+
return closureOf(known, rest, inner);
|
|
299
|
+
};
|
|
300
|
+
const workspacesBeside = Effect.fn("compat.workspaces")(function* workspacesBeside(directory) {
|
|
301
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
302
|
+
const path = yield* Path.Path;
|
|
303
|
+
const parent = path.dirname(path.resolve(directory));
|
|
304
|
+
const entries = yield* fileSystem.readDirectory(parent);
|
|
305
|
+
const found = yield* Effect.forEach(entries, (entry) => compatManifestIn(path.join(parent, entry)).pipe(Effect.map((manifest) => [{
|
|
306
|
+
directory: path.join(parent, entry),
|
|
307
|
+
manifest
|
|
308
|
+
}]), Effect.orElseSucceed(() => [])), { concurrency: 1 });
|
|
309
|
+
return pipe(Array.flatten(found), Array.map((workspace) => [workspace.manifest.name, workspace]), Record.fromEntries);
|
|
310
|
+
});
|
|
311
|
+
const builtTarball = Effect.fn("compat.pack")(function* builtTarball(directory) {
|
|
312
|
+
yield* mustSucceed({
|
|
305
313
|
command: "vp",
|
|
306
|
-
args: ["run",
|
|
314
|
+
args: ["run", "build"],
|
|
307
315
|
cwd: directory
|
|
308
|
-
}), {
|
|
309
|
-
concurrency: 1,
|
|
310
|
-
discard: true
|
|
311
316
|
});
|
|
317
|
+
return yield* pack(directory);
|
|
312
318
|
});
|
|
313
|
-
const
|
|
314
|
-
const
|
|
319
|
+
const tarballsOf = Effect.fn("compat.tarballs")(function* tarballsOf({ directory, manifest }) {
|
|
320
|
+
const tarball = yield* builtTarball(directory);
|
|
321
|
+
const natives = yield* nativeTarballs(directory, manifest);
|
|
322
|
+
return [...[[manifest.name, tarball]], ...natives];
|
|
323
|
+
});
|
|
324
|
+
/** @internal */
|
|
325
|
+
const workspaceTarballs = Effect.fn("compat.local")(function* workspaceTarballs(directory, manifest) {
|
|
326
|
+
const known = yield* workspacesBeside(directory);
|
|
327
|
+
const reached = closureOf(known, dependencyNamesOf(manifest), [{
|
|
328
|
+
directory,
|
|
329
|
+
manifest
|
|
330
|
+
}]);
|
|
331
|
+
const packed = yield* Effect.forEach(reached, tarballsOf, { concurrency: 1 });
|
|
332
|
+
return Record.fromEntries(Array.flatten(packed));
|
|
333
|
+
});
|
|
334
|
+
// src/features/publish-workspace/model/compat.ts
|
|
335
|
+
const MANIFEST_FILE$3 = "package.json";
|
|
336
|
+
const INSTALL_FLAGS = ["--no-audit", "--no-fund"];
|
|
337
|
+
const LOAD_FAILURE = String.raw`/ERR_(MODULE_NOT_FOUND|PACKAGE_|INVALID_PACKAGE|UNKNOWN_FILE|UNSUPPORTED_DIR|REQUIRE_ESM)|SyntaxError/u`;
|
|
338
|
+
const IMPORT_ONLY = "await import(process.argv[1])";
|
|
339
|
+
const SPAWN_CHECKED = `import { spawnSync } from "node:child_process"; const { stderr } = spawnSync(process.execPath, process.argv.slice(1), { encoding: "utf8", stdio: ["ignore", "ignore", "pipe"], timeout: 60000 }); if (${LOAD_FAILURE}.test(stderr)) { process.stderr.write(stderr); process.exit(1); }`;
|
|
340
|
+
const Versions$1 = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
|
|
341
|
+
const ConsumerJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
|
|
342
|
+
const installedNode = Effect.fn("compat.node")(function* installedNode(directory, range) {
|
|
315
343
|
const path = yield* Path.Path;
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
|
|
344
|
+
yield* (yield* FileSystem.FileSystem).makeDirectory(directory, { recursive: true });
|
|
345
|
+
const listed = yield* outputOf({
|
|
346
|
+
command: "npm",
|
|
347
|
+
args: [
|
|
348
|
+
"view",
|
|
349
|
+
"node",
|
|
350
|
+
"versions",
|
|
351
|
+
"--json"
|
|
352
|
+
],
|
|
353
|
+
cwd: directory
|
|
354
|
+
});
|
|
355
|
+
const versions = yield* Schema.decodeEffect(Versions$1)(listed);
|
|
356
|
+
const version = yield* Effect.fromOption(Option.fromNullishOr(semver.maxSatisfying([...versions], range))).pipe(Effect.mapError(() => IncompatiblePackage.make({ message: `No Node.js release satisfies ${range}` })));
|
|
357
|
+
yield* mustSucceed({
|
|
358
|
+
command: "npm",
|
|
359
|
+
args: [
|
|
360
|
+
"install",
|
|
361
|
+
...INSTALL_FLAGS,
|
|
362
|
+
`node@${version}`
|
|
363
|
+
],
|
|
364
|
+
cwd: directory
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
version,
|
|
368
|
+
binary: path.join(directory, "node_modules", "node", "bin", "node")
|
|
369
|
+
};
|
|
319
370
|
});
|
|
320
|
-
const
|
|
371
|
+
const fileEntries = (tarballs) => pipe(Record.toEntries(tarballs), Array.map(([name, file]) => [name, `file:${file}`]));
|
|
372
|
+
const siblingOverrides = (tarballs) => pipe(Record.keys(tarballs), Array.map((sibling) => [sibling, `$${sibling}`]));
|
|
373
|
+
const consumerJson = Effect.fn("compat.json")(function* consumerJson({ peers, tarballs }) {
|
|
374
|
+
const dependencies = Record.fromEntries([...Record.toEntries(peers), ...fileEntries(tarballs)]);
|
|
375
|
+
return yield* Schema.encodeEffect(ConsumerJson)({
|
|
376
|
+
private: true,
|
|
377
|
+
type: "module",
|
|
378
|
+
dependencies,
|
|
379
|
+
overrides: Record.fromEntries(siblingOverrides(tarballs))
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
const withViteOfVitePlus = Effect.fn("compat.vite")(function* withViteOfVitePlus(directory) {
|
|
321
383
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
322
384
|
const path = yield* Path.Path;
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
385
|
+
const text = yield* fileSystem.readFileString(path.join(directory, "node_modules", VITE_PLUS, MANIFEST_FILE$3));
|
|
386
|
+
yield* Option.match(viteAliasOf(text), {
|
|
387
|
+
onNone: () => Effect.void,
|
|
388
|
+
onSome: (alias) => mustSucceed({
|
|
389
|
+
command: "npm",
|
|
390
|
+
args: [
|
|
391
|
+
"install",
|
|
392
|
+
"--ignore-scripts",
|
|
393
|
+
"--force",
|
|
394
|
+
...INSTALL_FLAGS,
|
|
395
|
+
alias
|
|
396
|
+
],
|
|
397
|
+
cwd: directory
|
|
398
|
+
})
|
|
331
399
|
});
|
|
332
|
-
yield* Effect.all([fileSystem.writeFileString(path.join(target, MANIFEST_FILE), text), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
|
|
333
|
-
return target;
|
|
334
400
|
});
|
|
335
|
-
const
|
|
401
|
+
const installedConsumer = Effect.fn("compat.consumer")(function* installedConsumer(root, consumer) {
|
|
336
402
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
337
403
|
const path = yield* Path.Path;
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
version
|
|
343
|
-
})) {
|
|
344
|
-
yield* Console.log(`${name}@${version} is already published, skipping`);
|
|
345
|
-
return name;
|
|
346
|
-
}
|
|
404
|
+
const directory = path.join(root, "consumer");
|
|
405
|
+
yield* fileSystem.makeDirectory(directory, { recursive: true });
|
|
406
|
+
const text = yield* consumerJson(consumer);
|
|
407
|
+
yield* fileSystem.writeFileString(path.join(directory, MANIFEST_FILE$3), text);
|
|
347
408
|
yield* mustSucceed({
|
|
348
409
|
command: "npm",
|
|
349
410
|
args: [
|
|
350
|
-
"
|
|
351
|
-
"
|
|
352
|
-
...
|
|
411
|
+
"install",
|
|
412
|
+
"--ignore-scripts",
|
|
413
|
+
...INSTALL_FLAGS
|
|
353
414
|
],
|
|
354
|
-
|
|
355
|
-
cwd: target
|
|
415
|
+
cwd: directory
|
|
356
416
|
});
|
|
357
|
-
|
|
417
|
+
if (Record.has(consumer.peers, "vite-plus")) yield* withViteOfVitePlus(directory);
|
|
418
|
+
return directory;
|
|
358
419
|
});
|
|
359
|
-
const
|
|
420
|
+
const loadsCleanly = ({ runtime, consumer, args }) => mustSucceed({
|
|
421
|
+
command: runtime,
|
|
422
|
+
args: [
|
|
423
|
+
"--input-type=module",
|
|
424
|
+
"-e",
|
|
425
|
+
SPAWN_CHECKED,
|
|
426
|
+
"--",
|
|
427
|
+
...args
|
|
428
|
+
],
|
|
429
|
+
cwd: consumer
|
|
430
|
+
});
|
|
431
|
+
const smoke = Effect.fn("compat.smoke")(function* smoke(manifest, runtime, consumer) {
|
|
432
|
+
const path = yield* Path.Path;
|
|
433
|
+
const { imports, bins } = smokeTargetsOf(manifest);
|
|
434
|
+
const importer = [
|
|
435
|
+
"--input-type=module",
|
|
436
|
+
"-e",
|
|
437
|
+
IMPORT_ONLY
|
|
438
|
+
];
|
|
439
|
+
yield* Effect.forEach(imports, (specifier) => loadsCleanly({
|
|
440
|
+
runtime,
|
|
441
|
+
consumer,
|
|
442
|
+
args: [...importer, specifier]
|
|
443
|
+
}), {
|
|
444
|
+
concurrency: 1,
|
|
445
|
+
discard: true
|
|
446
|
+
});
|
|
447
|
+
yield* Effect.forEach(bins, (file) => loadsCleanly({
|
|
448
|
+
runtime,
|
|
449
|
+
consumer,
|
|
450
|
+
args: [path.join(consumer, "node_modules", manifest.name, file), "--help"]
|
|
451
|
+
}), {
|
|
452
|
+
concurrency: 1,
|
|
453
|
+
discard: true
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
const runCase = Effect.fn("compat.case")(function* runCase({ manifest, tarballs, compat }) {
|
|
360
457
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
458
|
+
const path = yield* Path.Path;
|
|
459
|
+
const root = yield* fileSystem.makeTempDirectoryScoped();
|
|
460
|
+
const runtime = yield* installedNode(path.join(root, "runtime"), compat.node);
|
|
461
|
+
const consumer = yield* installedConsumer(root, {
|
|
462
|
+
peers: compat.peers,
|
|
463
|
+
tarballs
|
|
367
464
|
});
|
|
368
|
-
|
|
465
|
+
const peers = pipe(Record.toEntries(compat.peers), Array.map(([name, range]) => `${name}@${range}`), Array.join(", "));
|
|
466
|
+
yield* Console.log(`${manifest.name} ${compat.label}: Node.js ${runtime.version}, peers ${peers}`);
|
|
467
|
+
yield* smoke(manifest, runtime.binary, consumer);
|
|
468
|
+
}, Effect.scoped);
|
|
469
|
+
/** @internal */
|
|
470
|
+
const checkCompat = Effect.fn("publish.compat")(function* checkCompat(directory) {
|
|
471
|
+
const manifest = yield* compatManifestIn(directory);
|
|
472
|
+
const cases = compatCasesOf(manifest);
|
|
473
|
+
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` });
|
|
474
|
+
const tarballs = yield* workspaceTarballs(directory, manifest);
|
|
475
|
+
return yield* Effect.forEach(cases, (compat) => runCase({
|
|
476
|
+
manifest,
|
|
477
|
+
tarballs,
|
|
478
|
+
compat
|
|
479
|
+
}), {
|
|
480
|
+
concurrency: 1,
|
|
481
|
+
discard: true
|
|
482
|
+
});
|
|
483
|
+
}, Effect.scoped);
|
|
484
|
+
// src/features/publish-workspace/model/manifest.ts
|
|
485
|
+
const MANIFEST_FILE$2 = "package.json";
|
|
486
|
+
const SCOPE = /^@[^/]+\//u;
|
|
487
|
+
const UNVERSIONED$1 = "0.0.0";
|
|
488
|
+
const ROOT = ".";
|
|
489
|
+
const Native = Schema.Struct({
|
|
490
|
+
binary: Schema.String,
|
|
491
|
+
targets: Schema.Array(Schema.String)
|
|
369
492
|
});
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
target
|
|
378
|
-
}), { concurrency: 1 });
|
|
379
|
-
const names = yield* Effect.forEach(written, (target) => publishNative(target, env), { concurrency: 1 });
|
|
380
|
-
yield* addOptionalDependencies(directory, names, manifest.version);
|
|
493
|
+
const ManifestSchema = Schema.Struct({
|
|
494
|
+
name: Schema.String,
|
|
495
|
+
version: Schema.String,
|
|
496
|
+
private: Schema.optionalKey(Schema.Boolean),
|
|
497
|
+
dependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
498
|
+
native: Schema.optionalKey(Native),
|
|
499
|
+
"size-limit": Schema.optionalKey(Schema.Unknown)
|
|
381
500
|
});
|
|
382
|
-
|
|
501
|
+
/** @internal */
|
|
502
|
+
const manifestIn = Effect.fn("publish.manifest")(function* manifestIn(directory) {
|
|
383
503
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
384
504
|
const path = yield* Path.Path;
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
const env = yield* widenRangesEnv(temporary);
|
|
388
|
-
yield* mustSucceed({
|
|
389
|
-
command: "vp",
|
|
390
|
-
args: [
|
|
391
|
-
"pm",
|
|
392
|
-
"pack",
|
|
393
|
-
"--out",
|
|
394
|
-
tarball
|
|
395
|
-
],
|
|
396
|
-
env,
|
|
397
|
-
cwd: directory
|
|
398
|
-
});
|
|
399
|
-
return tarball;
|
|
505
|
+
const text = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE$2));
|
|
506
|
+
return yield* Schema.decodeEffect(Schema.fromJsonString(ManifestSchema))(text);
|
|
400
507
|
});
|
|
401
508
|
/** @internal */
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
509
|
+
const releaseName = ({ name }) => String$1.replace(SCOPE, "")(name);
|
|
510
|
+
/** @internal */
|
|
511
|
+
const isRoot = (directory) => directory === ROOT;
|
|
512
|
+
/** @internal */
|
|
513
|
+
const tagOf = ({ directory, name, version }) => {
|
|
514
|
+
if (isRoot(directory)) return `v${version}`;
|
|
515
|
+
return `${releaseName({ name })}-v${version}`;
|
|
516
|
+
};
|
|
517
|
+
/** @internal */
|
|
518
|
+
const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
|
|
519
|
+
/** @internal */
|
|
520
|
+
const isVersioned = ({ version }) => version !== UNVERSIONED$1;
|
|
521
|
+
/** @internal */
|
|
522
|
+
const goesToNpm = (manifest) => !pipe(Option.fromUndefinedOr(manifest.private), Option.getOrElse(() => false));
|
|
523
|
+
// src/features/publish-workspace/model/dependencies.ts
|
|
524
|
+
const WORKSPACE_PROTOCOL = "workspace:";
|
|
525
|
+
const READ_CONCURRENCY = 8;
|
|
526
|
+
/** @internal */
|
|
527
|
+
const onNpm = ({ directory, name, version }) => succeeds({
|
|
528
|
+
command: "npm",
|
|
529
|
+
args: [
|
|
530
|
+
"view",
|
|
531
|
+
`${name}@${version}`,
|
|
532
|
+
"version"
|
|
533
|
+
],
|
|
534
|
+
cwd: directory
|
|
535
|
+
});
|
|
536
|
+
const taggedError$2 = Schema.TaggedError;
|
|
537
|
+
/** @internal */
|
|
538
|
+
var UnpublishedDependencies = class extends taggedError$2()("UnpublishedDependencies", { message: Schema.String }) {};
|
|
539
|
+
const workspaceDependencies = (manifest) => pipe(Option.fromUndefinedOr(manifest.dependencies), Option.map((dependencies) => pipe(dependencies, Record.filter(String$1.startsWith(WORKSPACE_PROTOCOL)), Record.keys)), Option.getOrElse(() => []));
|
|
540
|
+
const failWhenMissing = (missing, manifest) => {
|
|
541
|
+
if (Array.isReadonlyArrayEmpty(missing)) return Effect.void;
|
|
542
|
+
const names = pipe(missing, Array.map(({ directory, name, version }) => `${name}@${version} (${directory})`), Array.join(", "));
|
|
543
|
+
return Effect.fail(UnpublishedDependencies.make({ message: `${manifest.name} depends on versions that are not on npm yet. Publish them first: ${names}` }));
|
|
544
|
+
};
|
|
545
|
+
/** @internal */
|
|
546
|
+
const requirePublishedDependencies = Effect.fn("publish.dependencies")(function* requirePublishedDependencies({ manifest, workspaces }) {
|
|
547
|
+
const wanted = workspaceDependencies(manifest);
|
|
548
|
+
const siblings = yield* Effect.forEach(workspaces, (directory) => manifestIn(directory).pipe(Effect.map((found) => ({
|
|
405
549
|
directory,
|
|
406
|
-
...
|
|
407
|
-
}))
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
yield*
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
550
|
+
...found
|
|
551
|
+
}))), { concurrency: READ_CONCURRENCY });
|
|
552
|
+
const internal = pipe(siblings, Array.filter((sibling) => Array.contains(wanted, sibling.name) && goesToNpm(sibling)));
|
|
553
|
+
const missing = yield* Effect.filter(internal, (sibling) => onNpm(sibling).pipe(Effect.map((published) => !published)), { concurrency: READ_CONCURRENCY });
|
|
554
|
+
yield* failWhenMissing(missing, manifest);
|
|
555
|
+
});
|
|
556
|
+
// src/features/publish-workspace/model/broker.ts
|
|
557
|
+
const Issued = Schema.Record(Schema.String, Schema.Unknown);
|
|
558
|
+
const issued = Effect.fn("publish.issued")(function* issued(oidc, { kind, field }) {
|
|
559
|
+
const client = yield* HttpClient.HttpClient;
|
|
560
|
+
const request = HttpClientRequest.post(`${BROKER}?only=${kind}`).pipe(HttpClientRequest.bearerToken(oidc));
|
|
561
|
+
const response = yield* HttpClient.filterStatusOk(client).execute(request);
|
|
562
|
+
const body = yield* HttpClientResponse.schemaBodyJson(Issued)(response);
|
|
563
|
+
const token = Option.filter(Option.fromNullishOr(body[field]), (value) => typeof value === "string" && value !== "");
|
|
564
|
+
yield* Effect.forEach(Option.toArray(token), mask, {
|
|
565
|
+
concurrency: 1,
|
|
566
|
+
discard: true
|
|
421
567
|
});
|
|
422
|
-
|
|
568
|
+
return token;
|
|
569
|
+
});
|
|
570
|
+
/** @internal */
|
|
571
|
+
const brokerCredential = Effect.fn("publish.brokerCredential")(function* brokerCredential(credential) {
|
|
572
|
+
return yield* actionsOidcToken.pipe(Effect.flatMap(Option.match({
|
|
573
|
+
onNone: () => Effect.succeedNone,
|
|
574
|
+
onSome: (oidc) => issued(oidc, credential)
|
|
575
|
+
})), Effect.tapError(() => Console.log(`The credential broker gave no ${credential.field}`)), Effect.orElseSucceed(() => Option.none()));
|
|
576
|
+
});
|
|
423
577
|
// src/features/publish-workspace/model/provenance.ts
|
|
424
578
|
const ATTESTATIONS = "https://registry.npmjs.org/-/npm/v1/attestations/";
|
|
425
579
|
const SLSA = /slsa\.dev\/provenance/u;
|
|
@@ -439,7 +593,7 @@ const commitOf = (payload) => pipe(Base64.decodeString(payload), Effect.fromResu
|
|
|
439
593
|
/** @internal */
|
|
440
594
|
const provenanceCommit = Effect.fn("publish.provenanceCommit")(function* provenanceCommit({ name, version }) {
|
|
441
595
|
const client = yield* HttpClient.HttpClient;
|
|
442
|
-
const url = `${ATTESTATIONS}${String.replace("/", "%2f")(name)}@${version}`;
|
|
596
|
+
const url = `${ATTESTATIONS}${String$1.replace("/", "%2f")(name)}@${version}`;
|
|
443
597
|
const found = yield* HttpClient.filterStatusOk(client).get(url).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Attestations)), Effect.map(({ attestations }) => Array.findFirst(attestations, ({ predicateType }) => SLSA.test(predicateType))), Effect.orElseSucceed(() => Option.none()));
|
|
444
598
|
if (Option.isNone(found)) return Option.none();
|
|
445
599
|
return yield* commitOf(found.value.bundle.dsseEnvelope.payload);
|
|
@@ -447,7 +601,7 @@ const provenanceCommit = Effect.fn("publish.provenanceCommit")(function* provena
|
|
|
447
601
|
// src/features/publish-workspace/model/tags.ts
|
|
448
602
|
const UNVERSIONED = "0.0.0";
|
|
449
603
|
const LOOKUP_CONCURRENCY = 4;
|
|
450
|
-
const Versions = Schema.
|
|
604
|
+
const Versions = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
|
|
451
605
|
/** @internal */
|
|
452
606
|
const tagged = Effect.fn("publish.tagged")(function* tagged(tag) {
|
|
453
607
|
const repository = yield* Config.String("GITHUB_REPOSITORY");
|
|
@@ -571,11 +725,13 @@ const PlanSchema = Schema.Struct({
|
|
|
571
725
|
hook: Schema.Boolean
|
|
572
726
|
});
|
|
573
727
|
const AssetCount = Schema.fromJsonString(Schema.Finite);
|
|
728
|
+
/** @internal */
|
|
574
729
|
const graphTasks = outputOf({
|
|
575
730
|
command: "vp",
|
|
576
731
|
args: ["run", "--json"]
|
|
577
732
|
}).pipe(Effect.flatMap(Schema.decodeEffect(TaskGraph)), Effect.map(({ tasks }) => Record.values(tasks)));
|
|
578
733
|
const tasksIn = (tasks, directory) => pipe(tasks, Array.filter((task) => task.package === directory), Array.map(({ name }) => name));
|
|
734
|
+
/** @internal */
|
|
579
735
|
const workspacesOf = (tasks) => pipe(tasks, Array.map((task) => task.package), Array.dedupe);
|
|
580
736
|
const allTagged = Effect.fn("publish.allTagged")(function* allTagged(directory, manifest) {
|
|
581
737
|
if (!isVersioned(manifest)) return true;
|
|
@@ -589,7 +745,7 @@ const allTagged = Effect.fn("publish.allTagged")(function* allTagged(directory,
|
|
|
589
745
|
});
|
|
590
746
|
return current && Array.isReadonlyArrayEmpty(older);
|
|
591
747
|
});
|
|
592
|
-
const workspaceOf = (directory) => Path.Path.pipe(Effect.map((path) => String.replace(TRAILING_SLASH, "")(path.normalize(directory))));
|
|
748
|
+
const workspaceOf = (directory) => Path.Path.pipe(Effect.map((path) => String$1.replace(TRAILING_SLASH, "")(path.normalize(directory))));
|
|
593
749
|
/** @internal */
|
|
594
750
|
const released = Effect.fn("publish.released")(function* released(tag) {
|
|
595
751
|
const repository = yield* Config.String("GITHUB_REPOSITORY");
|
|
@@ -683,6 +839,163 @@ const writePlan = Effect.fn("publish.writePlan")(function* writePlan(plan) {
|
|
|
683
839
|
yield* Effect.logInfo(encoded);
|
|
684
840
|
yield* writeOutputs({ plan: encoded });
|
|
685
841
|
});
|
|
842
|
+
// src/features/publish-workspace/model/compat-plan.ts
|
|
843
|
+
const Directories = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
|
|
844
|
+
const isChecked = Effect.fn("compat.isChecked")(function* isChecked(directory) {
|
|
845
|
+
const manifest = yield* compatManifestIn(directory);
|
|
846
|
+
return goesToNpm(manifest) && !Array.isReadonlyArrayEmpty(compatCasesOf(manifest));
|
|
847
|
+
});
|
|
848
|
+
/** @internal */
|
|
849
|
+
const writeCompatPlan = Effect.fn("publish.compatPlan")(function* writeCompatPlan() {
|
|
850
|
+
const graph = yield* graphTasks;
|
|
851
|
+
const checked = yield* Effect.filter(workspacesOf(graph), isChecked, { concurrency: 1 });
|
|
852
|
+
const encoded = yield* Schema.encodeEffect(Directories)(checked);
|
|
853
|
+
yield* Effect.logInfo(encoded);
|
|
854
|
+
yield* writeOutputs({ directories: encoded });
|
|
855
|
+
});
|
|
856
|
+
// src/features/publish-workspace/model/export-targets.ts
|
|
857
|
+
const PATTERN = "*";
|
|
858
|
+
const MANIFEST_FILE$1 = "package.json";
|
|
859
|
+
const taggedError$1 = Schema.TaggedError;
|
|
860
|
+
/** @internal */
|
|
861
|
+
var MissingExportTargets = class extends taggedError$1()("MissingExportTargets", { message: Schema.String }) {};
|
|
862
|
+
const AnyExports = Schema.optionalKey(Schema.Unknown);
|
|
863
|
+
const PublishConfig = Schema.Struct({ exports: AnyExports });
|
|
864
|
+
const PublishedExports = Schema.fromJsonString(Schema.Struct({
|
|
865
|
+
exports: AnyExports,
|
|
866
|
+
publishConfig: Schema.optionalKey(PublishConfig)
|
|
867
|
+
}));
|
|
868
|
+
const singleTarget = (target) => {
|
|
869
|
+
if (String$1.includes(PATTERN)(target)) return [];
|
|
870
|
+
return [target];
|
|
871
|
+
};
|
|
872
|
+
/** @internal */
|
|
873
|
+
const exportTargetsOf = (exports) => {
|
|
874
|
+
if (Predicate.isString(exports)) return singleTarget(exports);
|
|
875
|
+
if (Array.isArray(exports)) return pipe(exports, Array.flatMap((entry) => exportTargetsOf(entry)));
|
|
876
|
+
if (Predicate.isReadonlyObject(exports)) return pipe(Record.values(exports), Array.flatMap((entry) => exportTargetsOf(entry)));
|
|
877
|
+
return [];
|
|
878
|
+
};
|
|
879
|
+
const publishedExportsOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.publishConfig), Option.flatMap((config) => Option.fromUndefinedOr(config.exports)), Option.orElse(() => Option.fromUndefinedOr(manifest.exports)), Option.getOrUndefined);
|
|
880
|
+
const missingMessage = (missing) => `The published exports point to files the build did not write: ${Array.join(missing, ", ")}`;
|
|
881
|
+
/** @internal */
|
|
882
|
+
const checkExportTargets = Effect.fn("publish.checkExportTargets")(function* checkExportTargets(directory) {
|
|
883
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
884
|
+
const path = yield* Path.Path;
|
|
885
|
+
const manifest = yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE$1)).pipe(Effect.flatMap(Schema.decodeEffect(PublishedExports)));
|
|
886
|
+
const missing = yield* Effect.filter(exportTargetsOf(publishedExportsOf(manifest)), (target) => Effect.map(fileSystem.exists(path.join(directory, target)), (found) => !found));
|
|
887
|
+
return yield* pipe(missing, Array.match({
|
|
888
|
+
onEmpty: () => Effect.void,
|
|
889
|
+
onNonEmpty: (list) => Effect.fail(MissingExportTargets.make({ message: missingMessage(list) }))
|
|
890
|
+
}));
|
|
891
|
+
});
|
|
892
|
+
// src/features/publish-workspace/model/npm.ts
|
|
893
|
+
const MANIFEST_FILE = "package.json";
|
|
894
|
+
const PUBLISH_FLAGS = [
|
|
895
|
+
"--provenance",
|
|
896
|
+
"--access",
|
|
897
|
+
"public"
|
|
898
|
+
];
|
|
899
|
+
const PlatformManifest = Schema.fromJsonString(Schema.Struct({
|
|
900
|
+
name: Schema.String,
|
|
901
|
+
version: Schema.String
|
|
902
|
+
}));
|
|
903
|
+
const authEnv = Effect.fn("publish.authEnv")(function* authEnv() {
|
|
904
|
+
const token = yield* brokerCredential({
|
|
905
|
+
kind: "npm",
|
|
906
|
+
field: "npmToken"
|
|
907
|
+
});
|
|
908
|
+
return Option.match(token, {
|
|
909
|
+
onNone: () => ({}),
|
|
910
|
+
onSome: (value) => ({ NODE_AUTH_TOKEN: value })
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
const verifyPackage = Effect.fn("publish.verify")(function* verifyPackage(directory, manifest) {
|
|
914
|
+
const tasks = [
|
|
915
|
+
"build",
|
|
916
|
+
"test",
|
|
917
|
+
...pipe(Option.fromUndefinedOr(manifest["size-limit"]), Option.map(() => "size"), Option.toArray)
|
|
918
|
+
];
|
|
919
|
+
yield* Effect.forEach(tasks, (task) => mustSucceed({
|
|
920
|
+
command: "vp",
|
|
921
|
+
args: ["run", task],
|
|
922
|
+
cwd: directory
|
|
923
|
+
}), {
|
|
924
|
+
concurrency: 1,
|
|
925
|
+
discard: true
|
|
926
|
+
});
|
|
927
|
+
yield* checkExportTargets(directory);
|
|
928
|
+
yield* checkCompat(directory);
|
|
929
|
+
});
|
|
930
|
+
const publishNative = Effect.fn("publish.publishNative")(function* publishNative(target, env) {
|
|
931
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
932
|
+
const path = yield* Path.Path;
|
|
933
|
+
const { name, version } = yield* fileSystem.readFileString(path.join(target, MANIFEST_FILE)).pipe(Effect.flatMap(Schema.decodeEffect(PlatformManifest)));
|
|
934
|
+
if (yield* onNpm({
|
|
935
|
+
directory: target,
|
|
936
|
+
name,
|
|
937
|
+
version
|
|
938
|
+
})) {
|
|
939
|
+
yield* Console.log(`${name}@${version} is already published, skipping`);
|
|
940
|
+
return name;
|
|
941
|
+
}
|
|
942
|
+
yield* mustSucceed({
|
|
943
|
+
command: "npm",
|
|
944
|
+
args: [
|
|
945
|
+
"publish",
|
|
946
|
+
".",
|
|
947
|
+
...PUBLISH_FLAGS
|
|
948
|
+
],
|
|
949
|
+
env,
|
|
950
|
+
cwd: target
|
|
951
|
+
});
|
|
952
|
+
return name;
|
|
953
|
+
});
|
|
954
|
+
const addOptionalDependencies = Effect.fn("publish.optionalDependencies")(function* addOptionalDependencies(directory, names, version) {
|
|
955
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
956
|
+
const file = (yield* Path.Path).join(directory, MANIFEST_FILE);
|
|
957
|
+
const manifest = yield* fileSystem.readFileString(file).pipe(Effect.flatMap(Schema.decodeEffect(PackageJson)));
|
|
958
|
+
const optionalDependencies = pipe(names, Array.map((name) => [name, version]), Record.fromEntries);
|
|
959
|
+
const updated = yield* Schema.encodeEffect(PackageJson)({
|
|
960
|
+
...manifest,
|
|
961
|
+
optionalDependencies
|
|
962
|
+
});
|
|
963
|
+
yield* fileSystem.writeFileString(file, updated);
|
|
964
|
+
});
|
|
965
|
+
const publishNatives = Effect.fn("publish.publishNatives")(function* publishNatives(directory, manifest, env) {
|
|
966
|
+
if (Predicate.isUndefined(manifest.native)) return;
|
|
967
|
+
const { binary, targets } = manifest.native;
|
|
968
|
+
const written = yield* Effect.forEach(targets, (target) => writeNative(directory, {
|
|
969
|
+
name: manifest.name,
|
|
970
|
+
version: manifest.version,
|
|
971
|
+
binary,
|
|
972
|
+
target
|
|
973
|
+
}), { concurrency: 1 });
|
|
974
|
+
const names = yield* Effect.forEach(written, (target) => publishNative(target, env), { concurrency: 1 });
|
|
975
|
+
yield* addOptionalDependencies(directory, names, manifest.version);
|
|
976
|
+
});
|
|
977
|
+
/** @internal */
|
|
978
|
+
const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory) {
|
|
979
|
+
const manifest = yield* manifestIn(directory);
|
|
980
|
+
if (yield* onNpm({
|
|
981
|
+
directory,
|
|
982
|
+
...manifest
|
|
983
|
+
})) return yield* Console.log(`${manifest.name}@${manifest.version} is already published`);
|
|
984
|
+
yield* verifyPackage(directory, manifest);
|
|
985
|
+
const env = yield* authEnv();
|
|
986
|
+
yield* publishNatives(directory, manifest, env);
|
|
987
|
+
const tarball = yield* pack(directory);
|
|
988
|
+
return yield* mustSucceed({
|
|
989
|
+
command: "npm",
|
|
990
|
+
args: [
|
|
991
|
+
"publish",
|
|
992
|
+
tarball,
|
|
993
|
+
...PUBLISH_FLAGS
|
|
994
|
+
],
|
|
995
|
+
env,
|
|
996
|
+
cwd: directory
|
|
997
|
+
});
|
|
998
|
+
}, Effect.scoped);
|
|
686
999
|
// src/features/publish-workspace/model/release.ts
|
|
687
1000
|
const ASSETS = "release-assets";
|
|
688
1001
|
const revisionOf = Effect.fn("publish.revision")(function* revisionOf(manifest) {
|
|
@@ -801,20 +1114,31 @@ const publishRelease = Effect.fn("publish.release")(function* publishRelease(dir
|
|
|
801
1114
|
});
|
|
802
1115
|
});
|
|
803
1116
|
// bin/msch-publish.ts
|
|
804
|
-
const Arguments = Schema.
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
1117
|
+
const Arguments = Schema.Tuple([Schema.Literals([
|
|
1118
|
+
"plan",
|
|
1119
|
+
"npm",
|
|
1120
|
+
"release",
|
|
1121
|
+
"compat",
|
|
1122
|
+
"compat-plan"
|
|
1123
|
+
]), Schema.String]);
|
|
809
1124
|
const taggedError = Schema.TaggedError;
|
|
810
1125
|
var UsageError = class extends taggedError()("UsageError", { message: Schema.String }) {};
|
|
811
|
-
const USAGE = "usage: msch-publish <plan|npm|release> <workspace directory>";
|
|
1126
|
+
const USAGE = "usage: msch-publish <plan|npm|release|compat|compat-plan> <workspace directory>";
|
|
1127
|
+
const steps = {
|
|
1128
|
+
plan: Effect.fn("plan")(function* plan(directory) {
|
|
1129
|
+
return yield* planOf(directory).pipe(Effect.flatMap(writePlan));
|
|
1130
|
+
}),
|
|
1131
|
+
npm: publishToNpm,
|
|
1132
|
+
release: publishRelease,
|
|
1133
|
+
compat: checkCompat,
|
|
1134
|
+
"compat-plan": Effect.fn("compat-plan")(function* compatPlan() {
|
|
1135
|
+
return yield* writeCompatPlan();
|
|
1136
|
+
})
|
|
1137
|
+
};
|
|
812
1138
|
const publish = Effect.gen(function* publish() {
|
|
813
1139
|
const args = yield* (yield* Stdio.Stdio).args;
|
|
814
1140
|
const [step, directory] = yield* Schema.decodeUnknownEffect(Arguments)(args).pipe(Effect.mapError(() => UsageError.make({ message: USAGE })));
|
|
815
|
-
|
|
816
|
-
if (step === "npm") return yield* publishToNpm(directory);
|
|
817
|
-
return yield* publishRelease(directory);
|
|
1141
|
+
return yield* steps[step](directory);
|
|
818
1142
|
});
|
|
819
1143
|
runCli(publish);
|
|
820
1144
|
export {};
|