tegami 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-D-jf_8xY.js +116 -0
- package/dist/cli/index.d.ts +4 -4
- package/dist/cli/index.js +124 -133
- package/dist/{checks-Cwz-Ezkq.js → generate-BMlrn-2e.js} +18 -106
- package/dist/generators/simple.d.ts +1 -1
- package/dist/generators/simple.js +3 -3
- package/dist/{graph-DLKPUXSD.js → graph-DrzluXw8.js} +17 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +317 -210
- package/dist/plugins/git.d.ts +1 -1
- package/dist/plugins/git.js +47 -35
- package/dist/plugins/github.d.ts +28 -15
- package/dist/plugins/github.js +158 -142
- package/dist/providers/cargo.d.ts +2 -2
- package/dist/providers/cargo.js +86 -100
- package/dist/providers/npm.d.ts +2 -2
- package/dist/providers/npm.js +132 -129
- package/dist/schemas-B7N6EE2k.js +26 -0
- package/dist/{types-BXk2fMqa.d.ts → types-CurHqnWl.d.ts} +199 -226
- package/package.json +6 -7
- package/dist/schemas-CurBAaW5.js +0 -42
package/dist/providers/cargo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as isNodeError, n as execFailure } from "../error-DNy8R5ue.js";
|
|
2
|
-
import { n as WorkspacePackage } from "../graph-
|
|
2
|
+
import { n as WorkspacePackage } from "../graph-DrzluXw8.js";
|
|
3
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { join, normalize } from "node:path";
|
|
5
5
|
import { x } from "tinyexec";
|
|
@@ -31,17 +31,12 @@ var CargoPackage = class extends WorkspacePackage {
|
|
|
31
31
|
get version() {
|
|
32
32
|
return stringValue(this.packageInfo.version) ?? this.workspaceVersion ?? "0.0.0";
|
|
33
33
|
}
|
|
34
|
-
initPlan() {
|
|
35
|
-
const defaults = super.initPlan();
|
|
36
|
-
defaults.publish ??= this.packageInfo.publish !== false;
|
|
37
|
-
return defaults;
|
|
38
|
-
}
|
|
39
34
|
setVersion(version) {
|
|
40
35
|
this.packageInfo.version = version;
|
|
41
36
|
this.patch("package.version", version);
|
|
42
37
|
}
|
|
43
38
|
async write() {
|
|
44
|
-
await writeFile(join(this.path, "Cargo.toml"), this.content);
|
|
39
|
+
await writeFile(join(this.path, "Cargo.toml"), this.content + "\n");
|
|
45
40
|
}
|
|
46
41
|
patch(path, value) {
|
|
47
42
|
this.content = edit(this.content, path, value);
|
|
@@ -54,85 +49,8 @@ var CargoPackage = class extends WorkspacePackage {
|
|
|
54
49
|
return stringValue(tableValue(tableValue(this.workspaceManifest?.workspace)?.package)?.version);
|
|
55
50
|
}
|
|
56
51
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
id = "cargo";
|
|
60
|
-
#versionMap = /* @__PURE__ */ new Map();
|
|
61
|
-
constructor(graph) {
|
|
62
|
-
this.graph = graph;
|
|
63
|
-
}
|
|
64
|
-
supports(pkg) {
|
|
65
|
-
return pkg instanceof CargoPackage;
|
|
66
|
-
}
|
|
67
|
-
async isPackagePublished(pkg) {
|
|
68
|
-
const cacheKey = `${pkg.id}@${pkg.version}`;
|
|
69
|
-
let info = this.#versionMap.get(cacheKey);
|
|
70
|
-
if (!info) {
|
|
71
|
-
info = fetch(`https://crates.io/api/v1/crates/${encodeURIComponent(pkg.name)}/${pkg.version}`).then(async (response) => {
|
|
72
|
-
if (response.status === 200) return true;
|
|
73
|
-
if (response.status === 404) return false;
|
|
74
|
-
throw new Error(`Unable to validate ${pkg.name}@${pkg.version} against crates.io: ${await response.text()}`);
|
|
75
|
-
});
|
|
76
|
-
this.#versionMap.set(cacheKey, info);
|
|
77
|
-
}
|
|
78
|
-
return info;
|
|
79
|
-
}
|
|
80
|
-
publishPreflight(pkg, { store }) {
|
|
81
|
-
const wait = [];
|
|
82
|
-
for (const { table } of dependencyTables(pkg.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
|
|
83
|
-
if (!isTableValue(rawSpec) || typeof rawSpec.path !== "string") continue;
|
|
84
|
-
const id = `cargo:${stringValue(rawSpec.package) ?? rawName}`;
|
|
85
|
-
if (!store.packages[id]?.publish) continue;
|
|
86
|
-
const linked = this.graph.get(id);
|
|
87
|
-
if (!linked || !(linked instanceof CargoPackage)) continue;
|
|
88
|
-
wait.push(id);
|
|
89
|
-
}
|
|
90
|
-
return { wait };
|
|
91
|
-
}
|
|
92
|
-
async publish(pkg, _env) {
|
|
93
|
-
const result = await x("cargo", ["publish"], { nodeOptions: { cwd: pkg.path } });
|
|
94
|
-
if (result.exitCode !== 0) throw execFailure(`Failed to publish ${pkg.name}@${pkg.version}.`, result);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
function cargo({ updateLockFile = false, bumpDep: getBumpDepType = ({ kind }) => {
|
|
98
|
-
switch (kind) {
|
|
99
|
-
case "dependencies": return "patch";
|
|
100
|
-
case "build-dependencies":
|
|
101
|
-
case "dev-dependencies": return false;
|
|
102
|
-
}
|
|
103
|
-
} } = {}) {
|
|
104
|
-
function updateRange(range, next) {
|
|
105
|
-
if (!semver.validRange(range)) return false;
|
|
106
|
-
if (new semver.Range(range).test(next)) return false;
|
|
107
|
-
return next;
|
|
108
|
-
}
|
|
109
|
-
function depsPolicy({ graph }) {
|
|
110
|
-
return {
|
|
111
|
-
id: "cargo:deps",
|
|
112
|
-
onUpdate({ pkg, plan }) {
|
|
113
|
-
for (const other of graph.getPackages()) {
|
|
114
|
-
if (!(other instanceof CargoPackage)) continue;
|
|
115
|
-
for (const { table, kind } of dependencyTables(other.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
|
|
116
|
-
const spec = parseSpec(rawSpec);
|
|
117
|
-
if (!spec) continue;
|
|
118
|
-
const packageName = spec.package ?? rawName;
|
|
119
|
-
if (pkg.id !== `cargo:${packageName}`) continue;
|
|
120
|
-
if (updateRange(spec.version, plan.bumpVersion(pkg)) === false) continue;
|
|
121
|
-
const bumpType = getBumpDepType({
|
|
122
|
-
kind,
|
|
123
|
-
name: packageName,
|
|
124
|
-
version: spec.version
|
|
125
|
-
});
|
|
126
|
-
if (bumpType === false) continue;
|
|
127
|
-
this.bumpPackage(other, {
|
|
128
|
-
type: bumpType,
|
|
129
|
-
reason: `update dependency "${rawName}"`
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
52
|
+
function cargo({ updateLockFile = true, bumpDep: getBumpDepType } = {}) {
|
|
53
|
+
let active = false;
|
|
136
54
|
return {
|
|
137
55
|
name: "cargo",
|
|
138
56
|
enforce: "pre",
|
|
@@ -141,45 +59,113 @@ function cargo({ updateLockFile = false, bumpDep: getBumpDepType = ({ kind }) =>
|
|
|
141
59
|
},
|
|
142
60
|
async resolve() {
|
|
143
61
|
await discoverCargoPackages(this.cwd, (pkg) => this.graph.add(pkg));
|
|
62
|
+
active = this.graph.getPackages().some((pkg) => pkg instanceof CargoPackage);
|
|
144
63
|
},
|
|
145
|
-
|
|
146
|
-
|
|
64
|
+
initDraft(plan) {
|
|
65
|
+
if (!active) return;
|
|
66
|
+
plan.addPolicy(depsPolicy(this, getBumpDepType));
|
|
147
67
|
},
|
|
148
|
-
|
|
149
|
-
|
|
68
|
+
async publishPreflight({ pkg }) {
|
|
69
|
+
if (!(pkg instanceof CargoPackage)) return;
|
|
70
|
+
const wait = [];
|
|
71
|
+
for (const { table } of dependencyTables(pkg.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
|
|
72
|
+
if (!isTableValue(rawSpec) || typeof rawSpec.path !== "string") continue;
|
|
73
|
+
const id = `cargo:${stringValue(rawSpec.package) ?? rawName}`;
|
|
74
|
+
const linked = this.graph.get(id);
|
|
75
|
+
if (!linked || !(linked instanceof CargoPackage)) continue;
|
|
76
|
+
wait.push(id);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
publish: pkg.packageInfo.publish !== false && !await isPackagePublished(pkg.name, pkg.version),
|
|
80
|
+
wait
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
async publish({ pkg }) {
|
|
84
|
+
if (!(pkg instanceof CargoPackage)) return;
|
|
85
|
+
const result = await x("cargo", ["publish"], { nodeOptions: { cwd: pkg.path } });
|
|
86
|
+
if (result.exitCode !== 0) return {
|
|
87
|
+
type: "failed",
|
|
88
|
+
error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}.`, result).message
|
|
89
|
+
};
|
|
90
|
+
return { type: "published" };
|
|
150
91
|
},
|
|
151
|
-
async
|
|
92
|
+
async applyDraft(draft) {
|
|
93
|
+
if (!active) return;
|
|
152
94
|
const { graph } = this;
|
|
153
95
|
const writes = [];
|
|
154
96
|
for (const pkg of graph.getPackages()) {
|
|
155
97
|
if (!(pkg instanceof CargoPackage)) continue;
|
|
156
|
-
const plan = draft.
|
|
98
|
+
const plan = draft.getPackageDraft(pkg.id);
|
|
157
99
|
if (plan) pkg.setVersion(plan.bumpVersion(pkg));
|
|
158
100
|
}
|
|
159
101
|
for (const pkg of graph.getPackages()) {
|
|
160
102
|
if (!(pkg instanceof CargoPackage)) continue;
|
|
161
103
|
for (const { table, path: tablePath } of dependencyTables(pkg.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
|
|
162
104
|
const spec = parseSpec(rawSpec);
|
|
163
|
-
if (!spec) continue;
|
|
105
|
+
if (!spec || !semver.validRange(spec.version)) continue;
|
|
164
106
|
const packageName = spec.package ?? rawName;
|
|
165
107
|
const linked = graph.get(`cargo:${packageName}`);
|
|
166
108
|
if (!linked || !(linked instanceof CargoPackage)) continue;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
109
|
+
if (semver.satisfies(linked.version, spec.version)) continue;
|
|
110
|
+
let updatedRange;
|
|
111
|
+
if (spec.version.startsWith("^")) updatedRange = `^${linked.version}`;
|
|
112
|
+
else if (spec.version.startsWith("~")) updatedRange = `~${linked.version}`;
|
|
113
|
+
else updatedRange = linked.version;
|
|
114
|
+
table[rawName] = spec.setVersion(updatedRange);
|
|
115
|
+
pkg.patch(typeof rawSpec === "string" ? `${tablePath}.${rawName}` : `${tablePath}.${rawName}.version`, updatedRange);
|
|
171
116
|
}
|
|
172
117
|
writes.push(pkg.write());
|
|
173
118
|
}
|
|
174
119
|
await Promise.all(writes);
|
|
175
120
|
},
|
|
176
|
-
cli: { async
|
|
177
|
-
if (!updateLockFile) return;
|
|
121
|
+
cli: { async draftApplied() {
|
|
122
|
+
if (!active || !updateLockFile) return;
|
|
178
123
|
const result = await x("cargo", ["update", "--workspace"], { nodeOptions: { cwd: this.cwd } });
|
|
179
124
|
if (result.exitCode !== 0) throw execFailure("Failed to update Cargo lock file", result);
|
|
180
125
|
} }
|
|
181
126
|
};
|
|
182
127
|
}
|
|
128
|
+
function depsPolicy({ graph }, getBumpDepType = ({ kind }) => {
|
|
129
|
+
switch (kind) {
|
|
130
|
+
case "dependencies": return "patch";
|
|
131
|
+
case "build-dependencies":
|
|
132
|
+
case "dev-dependencies": return false;
|
|
133
|
+
}
|
|
134
|
+
}) {
|
|
135
|
+
return {
|
|
136
|
+
id: "cargo:deps",
|
|
137
|
+
onUpdate({ pkg, packageDraft: plan }) {
|
|
138
|
+
if (!(pkg instanceof CargoPackage)) return;
|
|
139
|
+
const group = graph.getPackageGroup(pkg.id);
|
|
140
|
+
for (const dependent of graph.getPackages()) {
|
|
141
|
+
if (!(dependent instanceof CargoPackage)) continue;
|
|
142
|
+
for (const { table, kind } of dependencyTables(dependent.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
|
|
143
|
+
const spec = parseSpec(rawSpec);
|
|
144
|
+
if (!spec || !semver.validRange(spec.version)) continue;
|
|
145
|
+
if (pkg.id !== `cargo:${spec.package ?? rawName}`) continue;
|
|
146
|
+
if (group?.options.syncBump && graph.getPackageGroup(dependent.id) === group) continue;
|
|
147
|
+
if (semver.satisfies(plan.bumpVersion(pkg), spec.version)) continue;
|
|
148
|
+
const bumpType = getBumpDepType({
|
|
149
|
+
kind,
|
|
150
|
+
name: pkg.name,
|
|
151
|
+
version: spec.version
|
|
152
|
+
});
|
|
153
|
+
if (bumpType === false) continue;
|
|
154
|
+
this.bumpPackage(dependent, {
|
|
155
|
+
type: bumpType,
|
|
156
|
+
reason: `update dependency "${rawName}"`
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async function isPackagePublished(name, version) {
|
|
164
|
+
const response = await fetch(`https://crates.io/api/v1/crates/${encodeURIComponent(name)}/${version}`);
|
|
165
|
+
if (response.status === 200) return true;
|
|
166
|
+
if (response.status === 404) return false;
|
|
167
|
+
throw new Error(`Unable to validate ${name}@${version} against crates.io: ${await response.text()}`);
|
|
168
|
+
}
|
|
183
169
|
async function discoverCargoPackages(cwd, add) {
|
|
184
170
|
const root = await readCargoManifest(cwd).catch((error) => {
|
|
185
171
|
if (isNodeError(error) && error.code === "ENOENT") return void 0;
|
|
@@ -282,4 +268,4 @@ function stringValue(value) {
|
|
|
282
268
|
return typeof value === "string" ? value : void 0;
|
|
283
269
|
}
|
|
284
270
|
//#endregion
|
|
285
|
-
export { CargoPackage,
|
|
271
|
+
export { CargoPackage, cargo };
|
package/dist/providers/npm.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { NpmPackage, NpmPluginOptions,
|
|
1
|
+
import { f as NpmPackage, m as npm, p as NpmPluginOptions } from "../types-CurHqnWl.js";
|
|
2
|
+
export { NpmPackage, NpmPluginOptions, npm };
|
package/dist/providers/npm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { i as isNodeError, n as execFailure } from "../error-DNy8R5ue.js";
|
|
2
|
-
import {
|
|
3
|
-
import { n as WorkspacePackage } from "../graph-
|
|
2
|
+
import { n as packageManifestSchema, r as pnpmWorkspaceSchema } from "../schemas-B7N6EE2k.js";
|
|
3
|
+
import { n as WorkspacePackage } from "../graph-DrzluXw8.js";
|
|
4
4
|
import { readFile, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { x } from "tinyexec";
|
|
7
7
|
import * as semver from "semver";
|
|
8
|
+
import z from "zod";
|
|
8
9
|
import { load } from "js-yaml";
|
|
9
10
|
import { glob } from "tinyglobby";
|
|
10
11
|
import { detect } from "package-manager-detector";
|
|
@@ -33,9 +34,8 @@ var NpmPackage = class extends WorkspacePackage {
|
|
|
33
34
|
async write() {
|
|
34
35
|
await writeFile(path.join(this.path, "package.json"), `${JSON.stringify(this.manifest, null, 2)}\n`);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
const defaults = super.
|
|
38
|
-
defaults.publish ??= this.manifest.private !== true;
|
|
37
|
+
initDraft() {
|
|
38
|
+
const defaults = super.initDraft();
|
|
39
39
|
if (this.manifest.publishConfig?.tag) {
|
|
40
40
|
defaults.npm ??= {};
|
|
41
41
|
defaults.npm.distTag ??= this.manifest.publishConfig.tag;
|
|
@@ -43,74 +43,6 @@ var NpmPackage = class extends WorkspacePackage {
|
|
|
43
43
|
return defaults;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
var NpmRegistryClient = class {
|
|
47
|
-
cwd;
|
|
48
|
-
client;
|
|
49
|
-
id = "npm";
|
|
50
|
-
#versionMap = /* @__PURE__ */ new Map();
|
|
51
|
-
constructor(cwd, client, _graph) {
|
|
52
|
-
this.cwd = cwd;
|
|
53
|
-
this.client = client;
|
|
54
|
-
}
|
|
55
|
-
supports(pkg) {
|
|
56
|
-
return pkg instanceof NpmPackage;
|
|
57
|
-
}
|
|
58
|
-
async isPackagePublished(pkg) {
|
|
59
|
-
const cacheKey = `${pkg.id}@${pkg.version}`;
|
|
60
|
-
let info = this.#versionMap.get(cacheKey);
|
|
61
|
-
if (!info) {
|
|
62
|
-
const run = async () => {
|
|
63
|
-
const registry = pkg.manifest.publishConfig?.registry;
|
|
64
|
-
const args = [
|
|
65
|
-
"view",
|
|
66
|
-
`${pkg.name}@${pkg.version}`,
|
|
67
|
-
"version",
|
|
68
|
-
"--json"
|
|
69
|
-
];
|
|
70
|
-
if (registry) args.push("--registry", registry);
|
|
71
|
-
const result = await x(this.client === "pnpm" ? "pnpm" : "npm", args, { nodeOptions: { cwd: this.cwd } });
|
|
72
|
-
if (result.exitCode === 0) return true;
|
|
73
|
-
if (isMissingRegistryEntry(result.stderr) || isMissingRegistryEntry(result.stdout)) return false;
|
|
74
|
-
throw execFailure(`Unable to validate ${pkg.name}@${pkg.version} against the npm registry${registry ? ` "${registry}"` : ""}.`, result);
|
|
75
|
-
};
|
|
76
|
-
info = run();
|
|
77
|
-
this.#versionMap.set(cacheKey, info);
|
|
78
|
-
}
|
|
79
|
-
return info;
|
|
80
|
-
}
|
|
81
|
-
async publish(pkg, { packageStore }) {
|
|
82
|
-
const distTag = packageStore.npm?.distTag;
|
|
83
|
-
if (this.client === "bun") {
|
|
84
|
-
const tarballPath = path.resolve(pkg.path, "pkg.tgz");
|
|
85
|
-
const packResult = await x("bun", [
|
|
86
|
-
"pm",
|
|
87
|
-
"pack",
|
|
88
|
-
"--filename",
|
|
89
|
-
tarballPath
|
|
90
|
-
], { nodeOptions: { cwd: pkg.path } });
|
|
91
|
-
if (packResult.exitCode !== 0) throw execFailure(`Failed to pack ${pkg.name}@${pkg.version}.`, packResult);
|
|
92
|
-
const publishArgs = ["publish", tarballPath];
|
|
93
|
-
if (distTag) publishArgs.push("--tag", distTag);
|
|
94
|
-
const publishResult = await x("npm", publishArgs, { nodeOptions: { cwd: pkg.path } });
|
|
95
|
-
if (publishResult.exitCode !== 0) throw execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, publishResult);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const args = ["publish"];
|
|
99
|
-
if (distTag) args.push("--tag", distTag);
|
|
100
|
-
let client;
|
|
101
|
-
if (this.client === "pnpm") {
|
|
102
|
-
client = "pnpm";
|
|
103
|
-
args.push("--no-git-checks");
|
|
104
|
-
} else if (this.client === "yarn") client = "yarn";
|
|
105
|
-
else client = "npm";
|
|
106
|
-
const result = await x(client, args, { nodeOptions: { cwd: pkg.path } });
|
|
107
|
-
if (result.exitCode !== 0) throw execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, result);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
function isMissingRegistryEntry(output) {
|
|
111
|
-
const normalized = output.toLowerCase();
|
|
112
|
-
return normalized.includes("e404") || normalized.includes("404") || normalized.includes("no match") || normalized.includes("no matching version") || normalized.includes("not found");
|
|
113
|
-
}
|
|
114
46
|
function parseDependencySpec(context, dependent, name, range) {
|
|
115
47
|
const { graph } = context;
|
|
116
48
|
if (range.startsWith("workspace:")) return {
|
|
@@ -150,7 +82,11 @@ function formatDependencySpec(spec) {
|
|
|
150
82
|
if (spec.protocol === "npm") return `npm:${spec.alias}@${spec.range}`;
|
|
151
83
|
return spec.range;
|
|
152
84
|
}
|
|
153
|
-
|
|
85
|
+
const packageLockSchema = z.object({
|
|
86
|
+
id: z.string(),
|
|
87
|
+
distTag: z.string().optional()
|
|
88
|
+
});
|
|
89
|
+
function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = true, bumpDep: getBumpDepType = ({ kind }) => {
|
|
154
90
|
switch (kind) {
|
|
155
91
|
case "dependencies":
|
|
156
92
|
case "optionalDependencies": return "patch";
|
|
@@ -160,53 +96,8 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = f
|
|
|
160
96
|
return "major";
|
|
161
97
|
}
|
|
162
98
|
} } = {}) {
|
|
99
|
+
let active = false;
|
|
163
100
|
let client;
|
|
164
|
-
function depsPolicy(context) {
|
|
165
|
-
const { graph } = context;
|
|
166
|
-
function needsUpdate(dependent, spec, target) {
|
|
167
|
-
if (spec.linked) {
|
|
168
|
-
const group = graph.getPackageGroup(dependent.id);
|
|
169
|
-
if (group?.options.syncBump && graph.getPackageGroup(spec.linked.id) === group) return false;
|
|
170
|
-
if (spec.protocol === "workspace") switch (spec.range) {
|
|
171
|
-
case "":
|
|
172
|
-
case "*": return true;
|
|
173
|
-
case "^":
|
|
174
|
-
case "~": return !semver.satisfies(target, `${spec.range}${spec.linked.version}`);
|
|
175
|
-
}
|
|
176
|
-
if (spec.protocol === "file") return true;
|
|
177
|
-
}
|
|
178
|
-
if (spec.protocol === "file" || !semver.validRange(spec.range)) return false;
|
|
179
|
-
return !semver.satisfies(target, spec.range);
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
id: "npm:deps",
|
|
183
|
-
onUpdate({ pkg, plan }) {
|
|
184
|
-
if (!(pkg instanceof NpmPackage)) return;
|
|
185
|
-
for (const dependent of graph.getPackages()) {
|
|
186
|
-
if (!(dependent instanceof NpmPackage)) continue;
|
|
187
|
-
for (const field of DEP_FIELDS) {
|
|
188
|
-
const dependencies = dependent.manifest[field];
|
|
189
|
-
if (!dependencies) continue;
|
|
190
|
-
for (const [k, v] of Object.entries(dependencies)) {
|
|
191
|
-
const spec = parseDependencySpec(context, dependent, k, v);
|
|
192
|
-
if (!spec || spec.linked !== pkg) continue;
|
|
193
|
-
if (!needsUpdate(dependent, spec, plan.bumpVersion(pkg))) continue;
|
|
194
|
-
const bumpType = getBumpDepType({
|
|
195
|
-
kind: field,
|
|
196
|
-
spec,
|
|
197
|
-
name: k
|
|
198
|
-
});
|
|
199
|
-
if (bumpType === false) continue;
|
|
200
|
-
this.bumpPackage(dependent, {
|
|
201
|
-
type: bumpType,
|
|
202
|
-
reason: `update dependency "${k}"`
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
101
|
return {
|
|
211
102
|
name: "npm",
|
|
212
103
|
enforce: "pre",
|
|
@@ -217,19 +108,87 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = f
|
|
|
217
108
|
},
|
|
218
109
|
async resolve() {
|
|
219
110
|
await discoverNpmPackages(this.cwd, (pkg) => this.graph.add(pkg));
|
|
111
|
+
active = this.graph.getPackages().some((pkg) => pkg instanceof NpmPackage);
|
|
112
|
+
},
|
|
113
|
+
async publishPreflight({ pkg }) {
|
|
114
|
+
if (!(pkg instanceof NpmPackage)) return;
|
|
115
|
+
if (pkg.manifest.private === true) return { publish: false };
|
|
116
|
+
const registry = pkg.manifest.publishConfig?.registry;
|
|
117
|
+
const base = (registry ?? "https://registry.npmjs.org").replace(/\/$/, "");
|
|
118
|
+
const response = await fetch(`${base}/${pkg.name}/${pkg.version}`, { headers: { Accept: "application/json" } });
|
|
119
|
+
if (response.status === 404) return { publish: true };
|
|
120
|
+
if (!response.ok) throw new Error(`Unable to validate ${pkg.name}@${pkg.version} against the npm registry${registry ? ` "${registry}"` : ""}.`);
|
|
121
|
+
return { publish: false };
|
|
122
|
+
},
|
|
123
|
+
initPublishLock({ lock, draft }) {
|
|
124
|
+
for (const [id, pkg] of draft.getPackageDrafts()) {
|
|
125
|
+
if (!pkg.npm) continue;
|
|
126
|
+
lock.write("npm:packages", {
|
|
127
|
+
id,
|
|
128
|
+
distTag: pkg.npm.distTag
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
initPublishPlan({ lock, plan }) {
|
|
133
|
+
let data;
|
|
134
|
+
while (data = lock.read("npm:packages")) {
|
|
135
|
+
const parsed = packageLockSchema.safeParse(data).data;
|
|
136
|
+
if (!parsed) continue;
|
|
137
|
+
const packagePlan = plan.packages.get(parsed.id);
|
|
138
|
+
if (!packagePlan) continue;
|
|
139
|
+
packagePlan.npm = { distTag: parsed.distTag };
|
|
140
|
+
}
|
|
220
141
|
},
|
|
221
|
-
|
|
222
|
-
|
|
142
|
+
async publish({ pkg, plan }) {
|
|
143
|
+
if (!(pkg instanceof NpmPackage)) return;
|
|
144
|
+
const distTag = plan.packages.get(pkg.id).npm?.distTag;
|
|
145
|
+
if (client === "bun") {
|
|
146
|
+
const tarballPath = path.resolve(pkg.path, "pkg.tgz");
|
|
147
|
+
const packResult = await x("bun", [
|
|
148
|
+
"pm",
|
|
149
|
+
"pack",
|
|
150
|
+
"--filename",
|
|
151
|
+
tarballPath
|
|
152
|
+
], { nodeOptions: { cwd: pkg.path } });
|
|
153
|
+
if (packResult.exitCode !== 0) return {
|
|
154
|
+
type: "failed",
|
|
155
|
+
error: execFailure(`Failed to pack ${pkg.name}@${pkg.version}.`, packResult).message
|
|
156
|
+
};
|
|
157
|
+
const publishArgs = ["publish", tarballPath];
|
|
158
|
+
if (distTag) publishArgs.push("--tag", distTag);
|
|
159
|
+
const publishResult = await x("npm", publishArgs, { nodeOptions: { cwd: pkg.path } });
|
|
160
|
+
if (publishResult.exitCode !== 0) return {
|
|
161
|
+
type: "failed",
|
|
162
|
+
error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, publishResult).message
|
|
163
|
+
};
|
|
164
|
+
return { type: "published" };
|
|
165
|
+
}
|
|
166
|
+
let command;
|
|
167
|
+
const args = ["publish"];
|
|
168
|
+
if (distTag) args.push("--tag", distTag);
|
|
169
|
+
if (client === "pnpm") {
|
|
170
|
+
command = "pnpm";
|
|
171
|
+
args.push("--no-git-checks");
|
|
172
|
+
} else if (client === "yarn") command = "yarn";
|
|
173
|
+
else command = "npm";
|
|
174
|
+
const result = await x(command, args, { nodeOptions: { cwd: pkg.path } });
|
|
175
|
+
if (result.exitCode !== 0) return {
|
|
176
|
+
type: "failed",
|
|
177
|
+
error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, result).message
|
|
178
|
+
};
|
|
179
|
+
return { type: "published" };
|
|
223
180
|
},
|
|
224
|
-
|
|
225
|
-
|
|
181
|
+
initDraft(plan) {
|
|
182
|
+
if (!active) return;
|
|
183
|
+
plan.addPolicy(depsPolicy(this, getBumpDepType));
|
|
226
184
|
},
|
|
227
|
-
async
|
|
185
|
+
async applyDraft(draft) {
|
|
186
|
+
if (!active) return;
|
|
228
187
|
const { graph } = this;
|
|
229
188
|
const writes = [];
|
|
230
189
|
for (const pkg of graph.getPackages()) {
|
|
231
190
|
if (!(pkg instanceof NpmPackage)) continue;
|
|
232
|
-
const plan = draft.
|
|
191
|
+
const plan = draft.getPackageDraft(pkg.id);
|
|
233
192
|
if (plan) pkg.manifest.version = plan.bumpVersion(pkg);
|
|
234
193
|
}
|
|
235
194
|
for (const pkg of graph.getPackages()) {
|
|
@@ -260,8 +219,8 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = f
|
|
|
260
219
|
}
|
|
261
220
|
await Promise.all(writes);
|
|
262
221
|
},
|
|
263
|
-
cli: { async
|
|
264
|
-
if (!updateLockFile) return;
|
|
222
|
+
cli: { async draftApplied() {
|
|
223
|
+
if (!active || !updateLockFile) return;
|
|
265
224
|
let args;
|
|
266
225
|
if (client === "npm") args = ["ci"];
|
|
267
226
|
else if (client === "yarn") args = ["install", "--immutable"];
|
|
@@ -272,6 +231,50 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = f
|
|
|
272
231
|
} }
|
|
273
232
|
};
|
|
274
233
|
}
|
|
234
|
+
function depsPolicy(context, getBumpDepType) {
|
|
235
|
+
const { graph } = context;
|
|
236
|
+
function needsUpdate(spec, target) {
|
|
237
|
+
if (spec.linked && spec.protocol === "workspace") switch (spec.range) {
|
|
238
|
+
case "":
|
|
239
|
+
case "*": return true;
|
|
240
|
+
case "^":
|
|
241
|
+
case "~": return !semver.satisfies(target, `${spec.range}${spec.linked.version}`);
|
|
242
|
+
}
|
|
243
|
+
if (spec.linked && spec.protocol === "file") return true;
|
|
244
|
+
if (spec.protocol === "file" || !semver.validRange(spec.range)) return false;
|
|
245
|
+
return !semver.satisfies(target, spec.range);
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
id: "npm:deps",
|
|
249
|
+
onUpdate({ pkg, packageDraft: plan }) {
|
|
250
|
+
if (!(pkg instanceof NpmPackage)) return;
|
|
251
|
+
const group = graph.getPackageGroup(pkg.id);
|
|
252
|
+
for (const dependent of graph.getPackages()) {
|
|
253
|
+
if (!(dependent instanceof NpmPackage)) continue;
|
|
254
|
+
for (const field of DEP_FIELDS) {
|
|
255
|
+
const dependencies = dependent.manifest[field];
|
|
256
|
+
if (!dependencies) continue;
|
|
257
|
+
for (const [k, v] of Object.entries(dependencies)) {
|
|
258
|
+
const spec = parseDependencySpec(context, dependent, k, v);
|
|
259
|
+
if (!spec || spec.linked !== pkg) continue;
|
|
260
|
+
if (group?.options.syncBump && graph.getPackageGroup(dependent.id) === group) continue;
|
|
261
|
+
if (!needsUpdate(spec, plan.bumpVersion(pkg))) continue;
|
|
262
|
+
const bumpType = getBumpDepType({
|
|
263
|
+
kind: field,
|
|
264
|
+
spec,
|
|
265
|
+
name: k
|
|
266
|
+
});
|
|
267
|
+
if (bumpType === false) continue;
|
|
268
|
+
this.bumpPackage(dependent, {
|
|
269
|
+
type: bumpType,
|
|
270
|
+
reason: `update dependency "${k}"`
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
275
278
|
async function discoverNpmPackages(cwd, add) {
|
|
276
279
|
let patterns;
|
|
277
280
|
const rootManifest = await readManifest(cwd).catch(() => void 0);
|
|
@@ -311,4 +314,4 @@ async function readManifest(packagePath) {
|
|
|
311
314
|
return parsed;
|
|
312
315
|
}
|
|
313
316
|
//#endregion
|
|
314
|
-
export { NpmPackage,
|
|
317
|
+
export { NpmPackage, npm };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z as z$1 } from "zod";
|
|
2
|
+
//#region src/schemas.ts
|
|
3
|
+
const stringRecordSchema = z$1.record(z$1.string(), z$1.string());
|
|
4
|
+
const bumpTypeSchema = z$1.enum([
|
|
5
|
+
"major",
|
|
6
|
+
"minor",
|
|
7
|
+
"patch"
|
|
8
|
+
]);
|
|
9
|
+
const pnpmWorkspaceSchema = z$1.looseObject({ packages: z$1.array(z$1.string()).optional() });
|
|
10
|
+
const packageManifestSchema = z$1.looseObject({
|
|
11
|
+
name: z$1.string(),
|
|
12
|
+
version: z$1.string().optional(),
|
|
13
|
+
private: z$1.boolean().optional(),
|
|
14
|
+
publishConfig: z$1.looseObject({
|
|
15
|
+
access: z$1.enum(["public", "restricted"]).optional(),
|
|
16
|
+
registry: z$1.string().optional(),
|
|
17
|
+
tag: z$1.string().optional()
|
|
18
|
+
}).optional(),
|
|
19
|
+
workspaces: z$1.array(z$1.string()).optional(),
|
|
20
|
+
dependencies: stringRecordSchema.optional(),
|
|
21
|
+
devDependencies: stringRecordSchema.optional(),
|
|
22
|
+
peerDependencies: stringRecordSchema.optional(),
|
|
23
|
+
optionalDependencies: stringRecordSchema.optional()
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { packageManifestSchema as n, pnpmWorkspaceSchema as r, bumpTypeSchema as t };
|