tegami 0.2.1 → 1.0.0-beta.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/cli/index.d.ts +2 -1
- package/dist/cli/index.js +22 -29
- package/dist/{generate-L7ucD7ic.js → generate-OZFKzXnu.js} +9 -24
- package/dist/generators/simple.d.ts +1 -1
- package/dist/generators/simple.js +1 -1
- package/dist/{graph-DrzluXw8.js → graph-OnX9ncdQ.js} +2 -7
- package/dist/index-B4ehnvrS.d.ts +64 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +27 -26
- package/dist/npm-Q0qvAkIu.js +362 -0
- package/dist/plugins/git.d.ts +1 -1
- package/dist/plugins/github.d.ts +1 -1
- package/dist/plugins/github.js +4 -6
- package/dist/plugins/go.d.ts +51 -0
- package/dist/plugins/go.js +291 -0
- package/dist/providers/cargo.d.ts +1 -1
- package/dist/providers/cargo.js +3 -5
- package/dist/providers/npm.d.ts +1 -1
- package/dist/providers/npm.js +1 -333
- package/dist/{semver-C4vJ4SK8.js → semver-jcIUAvbl.js} +2 -1
- package/dist/{types-DEaKjB3O.d.ts → types-DnCUr2dB.d.ts} +84 -138
- package/package.json +2 -1
- package/dist/schemas-BdUlXfSu.js +0 -27
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { i as isNodeError, n as execFailure } from "../error-DNy8R5ue.js";
|
|
2
|
+
import { n as WorkspacePackage } from "../graph-OnX9ncdQ.js";
|
|
3
|
+
import { relative, resolve } from "node:path";
|
|
4
|
+
import { x } from "tinyexec";
|
|
5
|
+
import * as semver from "semver";
|
|
6
|
+
import z from "zod";
|
|
7
|
+
//#region src/plugins/go.ts
|
|
8
|
+
const goWorkJsonSchema = z.object({ Use: z.array(z.object({
|
|
9
|
+
DiskPath: z.string(),
|
|
10
|
+
ModulePath: z.string().optional()
|
|
11
|
+
})).optional() });
|
|
12
|
+
const goModJsonSchema = z.object({
|
|
13
|
+
Module: z.object({ Path: z.string() }),
|
|
14
|
+
Require: z.array(z.object({
|
|
15
|
+
Path: z.string(),
|
|
16
|
+
Version: z.string().optional()
|
|
17
|
+
})).optional(),
|
|
18
|
+
Replace: z.array(z.object({
|
|
19
|
+
Old: z.object({
|
|
20
|
+
Path: z.string(),
|
|
21
|
+
Version: z.string().optional()
|
|
22
|
+
}),
|
|
23
|
+
New: z.object({
|
|
24
|
+
Path: z.string(),
|
|
25
|
+
Version: z.string().optional()
|
|
26
|
+
})
|
|
27
|
+
})).optional()
|
|
28
|
+
});
|
|
29
|
+
var GoPackage = class extends WorkspacePackage {
|
|
30
|
+
path;
|
|
31
|
+
mod;
|
|
32
|
+
manager = "go";
|
|
33
|
+
versionValue;
|
|
34
|
+
pendingRequires = /* @__PURE__ */ new Map();
|
|
35
|
+
constructor(path, mod, version) {
|
|
36
|
+
super();
|
|
37
|
+
this.path = path;
|
|
38
|
+
this.mod = mod;
|
|
39
|
+
this.versionValue = version;
|
|
40
|
+
}
|
|
41
|
+
get name() {
|
|
42
|
+
return this.mod.module;
|
|
43
|
+
}
|
|
44
|
+
get version() {
|
|
45
|
+
return this.versionValue;
|
|
46
|
+
}
|
|
47
|
+
setVersion(version) {
|
|
48
|
+
this.versionValue = version;
|
|
49
|
+
}
|
|
50
|
+
setRequire(module, version) {
|
|
51
|
+
const formatted = formatGoVersion(version);
|
|
52
|
+
this.mod.requires.set(module, formatted);
|
|
53
|
+
this.pendingRequires.set(module, formatted);
|
|
54
|
+
}
|
|
55
|
+
async write() {
|
|
56
|
+
if (this.pendingRequires.size === 0) return;
|
|
57
|
+
const args = ["mod", "edit"];
|
|
58
|
+
for (const [module, version] of this.pendingRequires) args.push(`-require=${module}@${version}`);
|
|
59
|
+
const result = await x("go", args, { nodeOptions: { cwd: this.path } });
|
|
60
|
+
if (result.exitCode !== 0) throw execFailure(`Failed to update go.mod requires in ${this.path}.`, result);
|
|
61
|
+
this.pendingRequires.clear();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const packageLockSchema = z.object({
|
|
65
|
+
id: z.string(),
|
|
66
|
+
version: z.string()
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Experimental plugin for Golang, the release flow of Golang is pretty special, there's some exceptions for it:
|
|
70
|
+
*
|
|
71
|
+
* - Version is stored in lock file, normally, it should prefer to store versions in a file like `package.json` & `Cargo.toml`, but for Golang, there is no such file.
|
|
72
|
+
* - Publishing is handed to Git plugin, because Golang uses Git tag for publishing.
|
|
73
|
+
*/
|
|
74
|
+
function go({ updateLockFile = true, bumpDep: getBumpDepType } = {}) {
|
|
75
|
+
let active = false;
|
|
76
|
+
return {
|
|
77
|
+
name: "go",
|
|
78
|
+
enforce: "post",
|
|
79
|
+
async resolve() {
|
|
80
|
+
await discoverGoPackages(this.cwd, (pkg) => this.graph.add(pkg));
|
|
81
|
+
active = this.graph.getPackages().some((pkg) => pkg instanceof GoPackage);
|
|
82
|
+
if (active && !this.plugins.some((plugin) => plugin.name === "git")) throw new Error("The go plugin requires the git plugin. Add git() from \"tegami/plugins/git\" to your plugins array.");
|
|
83
|
+
},
|
|
84
|
+
initDraft(plan) {
|
|
85
|
+
if (!active) return;
|
|
86
|
+
plan.addPolicy(depsPolicy(this, getBumpDepType));
|
|
87
|
+
},
|
|
88
|
+
async applyDraft(draft) {
|
|
89
|
+
if (!active) return;
|
|
90
|
+
const { graph } = this;
|
|
91
|
+
const writes = [];
|
|
92
|
+
for (const pkg of graph.getPackages()) {
|
|
93
|
+
if (!(pkg instanceof GoPackage)) continue;
|
|
94
|
+
const plan = draft.getPackageDraft(pkg.id);
|
|
95
|
+
if (plan) pkg.setVersion(plan.bumpVersion(pkg));
|
|
96
|
+
}
|
|
97
|
+
for (const pkg of graph.getPackages()) {
|
|
98
|
+
if (!(pkg instanceof GoPackage)) continue;
|
|
99
|
+
for (const [moduleName, requireVersion] of pkg.mod.requires) {
|
|
100
|
+
const linked = graph.get(`go:${moduleName}`);
|
|
101
|
+
if (!linked || !(linked instanceof GoPackage)) continue;
|
|
102
|
+
if (semver.satisfies(linked.version, stripGoVersion(requireVersion))) continue;
|
|
103
|
+
pkg.setRequire(moduleName, linked.version);
|
|
104
|
+
}
|
|
105
|
+
writes.push(pkg.write());
|
|
106
|
+
}
|
|
107
|
+
await Promise.all(writes);
|
|
108
|
+
},
|
|
109
|
+
initPublishLock({ lock, draft }) {
|
|
110
|
+
if (!active) return;
|
|
111
|
+
for (const [id, packageDraft] of draft.getPackageDrafts()) {
|
|
112
|
+
const pkg = this.graph.get(id);
|
|
113
|
+
if (!(pkg instanceof GoPackage) || !packageDraft.type) continue;
|
|
114
|
+
lock.write("go:packages", {
|
|
115
|
+
id,
|
|
116
|
+
version: pkg.version
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
initPublishPlan({ lock, plan }) {
|
|
121
|
+
if (!active) return;
|
|
122
|
+
let data;
|
|
123
|
+
while (data = lock.read("go:packages")) {
|
|
124
|
+
const parsed = packageLockSchema.safeParse(data).data;
|
|
125
|
+
if (!parsed) continue;
|
|
126
|
+
const pkg = this.graph.get(parsed.id);
|
|
127
|
+
if (pkg instanceof GoPackage) pkg.setVersion(parsed.version);
|
|
128
|
+
}
|
|
129
|
+
for (const [id, packagePlan] of plan.packages) {
|
|
130
|
+
const pkg = this.graph.get(id);
|
|
131
|
+
if (!(pkg instanceof GoPackage)) continue;
|
|
132
|
+
packagePlan.git = { tag: formatGoTag(this.cwd, pkg.path, pkg.version) };
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
async publishPreflight({ pkg }) {
|
|
136
|
+
if (!(pkg instanceof GoPackage)) return;
|
|
137
|
+
const wait = [];
|
|
138
|
+
for (const [moduleName] of pkg.mod.requires) {
|
|
139
|
+
const linked = this.graph.get(`go:${moduleName}`);
|
|
140
|
+
if (linked instanceof GoPackage) wait.push(linked.id);
|
|
141
|
+
}
|
|
142
|
+
for (const replace of pkg.mod.replaces.values()) {
|
|
143
|
+
if (!replace.path) continue;
|
|
144
|
+
const linked = findLocalModule(this.graph, pkg.path, replace.path);
|
|
145
|
+
if (!linked) continue;
|
|
146
|
+
wait.push(linked.id);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
publish: !await isModulePublished(pkg.name, pkg.version),
|
|
150
|
+
wait
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
async publish({ pkg }) {
|
|
154
|
+
if (!(pkg instanceof GoPackage)) return;
|
|
155
|
+
return { type: "published" };
|
|
156
|
+
},
|
|
157
|
+
cli: { async draftApplied() {
|
|
158
|
+
if (!active || !updateLockFile) return;
|
|
159
|
+
if (await listGoWorkUsePaths(this.cwd)) {
|
|
160
|
+
const result = await x("go", ["work", "sync"], { nodeOptions: { cwd: this.cwd } });
|
|
161
|
+
if (result.exitCode !== 0) throw execFailure("Failed to run `go work sync`.", result);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
await Promise.all(this.graph.getPackages().map(async (pkg) => {
|
|
165
|
+
if (!(pkg instanceof GoPackage)) return;
|
|
166
|
+
const result = await x("go", ["mod", "tidy"], { nodeOptions: { cwd: pkg.path } });
|
|
167
|
+
if (result.exitCode !== 0) throw execFailure(`Failed to run \`go mod tidy\` in ${pkg.path}.`, result);
|
|
168
|
+
}));
|
|
169
|
+
} }
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function depsPolicy({ graph }, getBumpDepType = () => "patch") {
|
|
173
|
+
return {
|
|
174
|
+
id: "go:deps",
|
|
175
|
+
onUpdate({ pkg, packageDraft: plan }) {
|
|
176
|
+
if (!(pkg instanceof GoPackage)) return;
|
|
177
|
+
const group = graph.getPackageGroup(pkg.id);
|
|
178
|
+
for (const dependent of graph.getPackages()) {
|
|
179
|
+
if (!(dependent instanceof GoPackage)) continue;
|
|
180
|
+
for (const [moduleName, requireVersion] of dependent.mod.requires) {
|
|
181
|
+
if (pkg.id !== `go:${moduleName}`) continue;
|
|
182
|
+
if (group?.options.syncBump && graph.getPackageGroup(dependent.id) === group) continue;
|
|
183
|
+
if (semver.satisfies(plan.bumpVersion(pkg), stripGoVersion(requireVersion))) continue;
|
|
184
|
+
const bumpType = getBumpDepType?.({
|
|
185
|
+
name: pkg.name,
|
|
186
|
+
dependent,
|
|
187
|
+
version: requireVersion
|
|
188
|
+
});
|
|
189
|
+
if (bumpType === false) continue;
|
|
190
|
+
this.bumpPackage(dependent, {
|
|
191
|
+
type: bumpType,
|
|
192
|
+
reason: `update require "${moduleName}"`
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
async function discoverGoPackages(cwd, add) {
|
|
200
|
+
const modulePaths = await listModulePaths(cwd);
|
|
201
|
+
await Promise.all(modulePaths.map(async (modulePath) => {
|
|
202
|
+
const mod = await readGoMod(modulePath).catch((error) => {
|
|
203
|
+
if (isNodeError(error) && error.code === "ENOENT") return void 0;
|
|
204
|
+
throw error;
|
|
205
|
+
});
|
|
206
|
+
if (!mod) return;
|
|
207
|
+
add(new GoPackage(modulePath, mod, await readLatestVersion(cwd, modulePath)));
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
async function listModulePaths(cwd) {
|
|
211
|
+
const workPaths = await listGoWorkUsePaths(cwd);
|
|
212
|
+
if (workPaths) return workPaths;
|
|
213
|
+
if (await readGoMod(cwd)) return [cwd];
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
async function listGoWorkUsePaths(cwd) {
|
|
217
|
+
const result = await x("go", [
|
|
218
|
+
"work",
|
|
219
|
+
"edit",
|
|
220
|
+
"-json"
|
|
221
|
+
], { nodeOptions: { cwd } });
|
|
222
|
+
if (result.exitCode !== 0) return void 0;
|
|
223
|
+
const data = goWorkJsonSchema.safeParse(JSON.parse(result.stdout)).data;
|
|
224
|
+
if (!data?.Use?.length) return [cwd];
|
|
225
|
+
return data.Use.map((use) => resolve(cwd, use.DiskPath));
|
|
226
|
+
}
|
|
227
|
+
async function readGoMod(path) {
|
|
228
|
+
const result = await x("go", [
|
|
229
|
+
"mod",
|
|
230
|
+
"edit",
|
|
231
|
+
"-json"
|
|
232
|
+
], { nodeOptions: { cwd: path } });
|
|
233
|
+
if (result.exitCode !== 0) return;
|
|
234
|
+
const data = goModJsonSchema.safeParse(JSON.parse(result.stdout)).data;
|
|
235
|
+
if (!data) return;
|
|
236
|
+
const requires = /* @__PURE__ */ new Map();
|
|
237
|
+
for (const req of data.Require ?? []) if (req.Version) requires.set(req.Path, req.Version);
|
|
238
|
+
const replaces = /* @__PURE__ */ new Map();
|
|
239
|
+
for (const rep of data.Replace ?? []) replaces.set(rep.Old.Path, {
|
|
240
|
+
module: rep.New.Path,
|
|
241
|
+
path: rep.New.Version ? void 0 : rep.New.Path,
|
|
242
|
+
version: rep.New.Version
|
|
243
|
+
});
|
|
244
|
+
return {
|
|
245
|
+
module: data.Module.Path,
|
|
246
|
+
requires,
|
|
247
|
+
replaces
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function findLocalModule(graph, modulePath, replacePath) {
|
|
251
|
+
const absolute = resolve(modulePath, replacePath);
|
|
252
|
+
return graph.getPackages().find((pkg) => pkg instanceof GoPackage && pkg.path === absolute);
|
|
253
|
+
}
|
|
254
|
+
async function readLatestVersion(cwd, modulePath) {
|
|
255
|
+
const result = await x("git", [
|
|
256
|
+
"tag",
|
|
257
|
+
"--list",
|
|
258
|
+
formatGoTag(cwd, modulePath, "v*"),
|
|
259
|
+
"--sort=-v:refname"
|
|
260
|
+
], { nodeOptions: { cwd } });
|
|
261
|
+
if (result.exitCode !== 0) return "0.0.0";
|
|
262
|
+
for (const tag of result.stdout.split("\n")) {
|
|
263
|
+
const version = parseTagVersion(tag.trim());
|
|
264
|
+
if (version) return version;
|
|
265
|
+
}
|
|
266
|
+
return "0.0.0";
|
|
267
|
+
}
|
|
268
|
+
function parseTagVersion(tag) {
|
|
269
|
+
const version = stripGoVersion(tag.slice(tag.lastIndexOf("/") + 1));
|
|
270
|
+
if (semver.valid(version)) return version;
|
|
271
|
+
}
|
|
272
|
+
function formatGoTag(cwd, modulePath, version) {
|
|
273
|
+
const relativeDir = relative(cwd, modulePath).replaceAll("\\", "/");
|
|
274
|
+
if (relativeDir === "") return formatGoVersion(version);
|
|
275
|
+
return `${relativeDir}/${formatGoVersion(version)}`;
|
|
276
|
+
}
|
|
277
|
+
function formatGoVersion(version) {
|
|
278
|
+
return version.startsWith("v") ? version : `v${version}`;
|
|
279
|
+
}
|
|
280
|
+
function stripGoVersion(version) {
|
|
281
|
+
return version.startsWith("v") ? version.slice(1) : version;
|
|
282
|
+
}
|
|
283
|
+
async function isModulePublished(module, version) {
|
|
284
|
+
const formatted = formatGoVersion(version);
|
|
285
|
+
const response = await fetch(`https://proxy.golang.org/${encodeURIComponent(module)}/@v/${formatted}.info`);
|
|
286
|
+
if (response.status === 200) return true;
|
|
287
|
+
if (response.status === 404) return false;
|
|
288
|
+
throw new Error(`Unable to validate ${module}@${formatted} against proxy.golang.org: ${await response.text()}`);
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
export { GoPackage, go };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as cargo, h as CargoPluginOptions, m as CargoPackage } from "../types-DnCUr2dB.js";
|
|
2
2
|
export { CargoPackage, CargoPluginOptions, cargo };
|
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-OnX9ncdQ.js";
|
|
3
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { join, normalize } from "node:path";
|
|
5
5
|
import { x } from "tinyexec";
|
|
@@ -147,6 +147,7 @@ function depsPolicy({ graph }, getBumpDepType = ({ kind }) => {
|
|
|
147
147
|
if (semver.satisfies(plan.bumpVersion(pkg), spec.version)) continue;
|
|
148
148
|
const bumpType = getBumpDepType({
|
|
149
149
|
kind,
|
|
150
|
+
dependent,
|
|
150
151
|
name: pkg.name,
|
|
151
152
|
version: spec.version
|
|
152
153
|
});
|
|
@@ -185,10 +186,7 @@ async function discoverCargoPackages(cwd, add) {
|
|
|
185
186
|
for (const entry of manifests) if (entry) addCargoPackage(entry.path, entry.manifest.manifest, entry.manifest.content, root.manifest, add);
|
|
186
187
|
}
|
|
187
188
|
function addCargoPackage(path, manifest, content, workspaceManifest, add) {
|
|
188
|
-
|
|
189
|
-
const workspacePackage = tableValue(workspaceManifest.workspace)?.package;
|
|
190
|
-
if (!packageInfo?.name) return;
|
|
191
|
-
if (!packageInfo.version && !tableValue(workspacePackage)?.version) return;
|
|
189
|
+
if (!tableValue(manifest.package)?.name) return;
|
|
192
190
|
add(new CargoPackage(path, manifest, content, workspaceManifest));
|
|
193
191
|
}
|
|
194
192
|
async function expandWorkspaceMembers(cwd, members, exclude) {
|
package/dist/providers/npm.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as NpmPackage, v as NpmPluginOptions, y as npm } from "../types-DnCUr2dB.js";
|
|
2
2
|
export { NpmPackage, NpmPluginOptions, npm };
|
package/dist/providers/npm.js
CHANGED
|
@@ -1,334 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as packageManifestSchema, r as pnpmWorkspaceSchema } from "../schemas-BdUlXfSu.js";
|
|
3
|
-
import { n as WorkspacePackage } from "../graph-DrzluXw8.js";
|
|
4
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { x } from "tinyexec";
|
|
7
|
-
import * as semver from "semver";
|
|
8
|
-
import z from "zod";
|
|
9
|
-
import { load } from "js-yaml";
|
|
10
|
-
import { glob } from "tinyglobby";
|
|
11
|
-
import { detect } from "package-manager-detector";
|
|
12
|
-
//#region src/providers/npm.ts
|
|
13
|
-
const DEP_FIELDS = [
|
|
14
|
-
"dependencies",
|
|
15
|
-
"devDependencies",
|
|
16
|
-
"peerDependencies",
|
|
17
|
-
"optionalDependencies"
|
|
18
|
-
];
|
|
19
|
-
var NpmPackage = class extends WorkspacePackage {
|
|
20
|
-
path;
|
|
21
|
-
manifest;
|
|
22
|
-
manager = "npm";
|
|
23
|
-
constructor(path, manifest) {
|
|
24
|
-
super();
|
|
25
|
-
this.path = path;
|
|
26
|
-
this.manifest = manifest;
|
|
27
|
-
}
|
|
28
|
-
get name() {
|
|
29
|
-
return this.manifest.name;
|
|
30
|
-
}
|
|
31
|
-
get version() {
|
|
32
|
-
return this.manifest.version ?? "0.0.0";
|
|
33
|
-
}
|
|
34
|
-
async write() {
|
|
35
|
-
await writeFile(path.join(this.path, "package.json"), `${JSON.stringify(this.manifest, null, 2)}\n`);
|
|
36
|
-
}
|
|
37
|
-
initDraft() {
|
|
38
|
-
const defaults = super.initDraft();
|
|
39
|
-
if (this.manifest.publishConfig?.tag) {
|
|
40
|
-
defaults.npm ??= {};
|
|
41
|
-
defaults.npm.distTag ??= this.manifest.publishConfig.tag;
|
|
42
|
-
}
|
|
43
|
-
return defaults;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function parseDependencySpec(context, dependent, name, range) {
|
|
47
|
-
const { graph } = context;
|
|
48
|
-
if (range.startsWith("workspace:")) return {
|
|
49
|
-
range: range.slice(10),
|
|
50
|
-
linked: graph.get(`npm:${name}`),
|
|
51
|
-
protocol: "workspace"
|
|
52
|
-
};
|
|
53
|
-
if (range.startsWith("file:")) {
|
|
54
|
-
let target = path.resolve(dependent.path, range.slice(5));
|
|
55
|
-
if (path.basename(target) === "package.json") target = path.dirname(target);
|
|
56
|
-
return {
|
|
57
|
-
protocol: "file",
|
|
58
|
-
raw: range,
|
|
59
|
-
linked: graph.getPackages().find((pkg) => pkg instanceof NpmPackage && pkg.path === target)
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (range.startsWith("npm:")) {
|
|
63
|
-
const spec = range.slice(4);
|
|
64
|
-
const separator = spec.lastIndexOf("@");
|
|
65
|
-
if (separator <= 0) return;
|
|
66
|
-
const alias = spec.slice(0, separator);
|
|
67
|
-
return {
|
|
68
|
-
alias,
|
|
69
|
-
linked: graph.get(`npm:${alias}`),
|
|
70
|
-
range: spec.slice(separator + 1),
|
|
71
|
-
protocol: "npm"
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
linked: graph.get(`npm:${name}`),
|
|
76
|
-
range
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function formatDependencySpec(spec) {
|
|
80
|
-
if (spec.protocol === "workspace") return `workspace:${spec.range}`;
|
|
81
|
-
if (spec.protocol === "file") return spec.raw;
|
|
82
|
-
if (spec.protocol === "npm") return `npm:${spec.alias}@${spec.range}`;
|
|
83
|
-
return spec.range;
|
|
84
|
-
}
|
|
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 }) => {
|
|
90
|
-
switch (kind) {
|
|
91
|
-
case "dependencies":
|
|
92
|
-
case "optionalDependencies": return "patch";
|
|
93
|
-
case "devDependencies": return false;
|
|
94
|
-
case "peerDependencies":
|
|
95
|
-
if (onBreakPeerDep === "ignore") return false;
|
|
96
|
-
return "major";
|
|
97
|
-
}
|
|
98
|
-
} } = {}) {
|
|
99
|
-
let active = false;
|
|
100
|
-
let client;
|
|
101
|
-
return {
|
|
102
|
-
name: "npm",
|
|
103
|
-
enforce: "pre",
|
|
104
|
-
async init() {
|
|
105
|
-
if (defaultClient) client = defaultClient;
|
|
106
|
-
else client = (await detect({ cwd: this.cwd }))?.name ?? "npm";
|
|
107
|
-
this.npm = { client };
|
|
108
|
-
},
|
|
109
|
-
async resolve() {
|
|
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
|
-
return { publish: pkg.manifest.private !== true && !await isPackagePublished(pkg) };
|
|
116
|
-
},
|
|
117
|
-
initPublishLock({ lock, draft }) {
|
|
118
|
-
for (const [id, pkg] of draft.getPackageDrafts()) {
|
|
119
|
-
if (!pkg.npm) continue;
|
|
120
|
-
lock.write("npm:packages", {
|
|
121
|
-
id,
|
|
122
|
-
distTag: pkg.npm.distTag
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
initPublishPlan({ lock, plan }) {
|
|
127
|
-
let data;
|
|
128
|
-
while (data = lock.read("npm:packages")) {
|
|
129
|
-
const parsed = packageLockSchema.safeParse(data).data;
|
|
130
|
-
if (!parsed) continue;
|
|
131
|
-
const packagePlan = plan.packages.get(parsed.id);
|
|
132
|
-
if (!packagePlan) continue;
|
|
133
|
-
packagePlan.npm = { distTag: parsed.distTag };
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
async publish({ pkg, plan }) {
|
|
137
|
-
if (!(pkg instanceof NpmPackage)) return;
|
|
138
|
-
return publish(client, pkg, plan.packages.get(pkg.id)?.npm?.distTag);
|
|
139
|
-
},
|
|
140
|
-
initDraft(plan) {
|
|
141
|
-
if (!active) return;
|
|
142
|
-
plan.addPolicy(depsPolicy(this, getBumpDepType));
|
|
143
|
-
},
|
|
144
|
-
async applyDraft(draft) {
|
|
145
|
-
if (!active) return;
|
|
146
|
-
const { graph } = this;
|
|
147
|
-
const writes = [];
|
|
148
|
-
for (const pkg of graph.getPackages()) {
|
|
149
|
-
if (!(pkg instanceof NpmPackage)) continue;
|
|
150
|
-
const plan = draft.getPackageDraft(pkg.id);
|
|
151
|
-
if (plan) pkg.manifest.version = plan.bumpVersion(pkg);
|
|
152
|
-
}
|
|
153
|
-
for (const pkg of graph.getPackages()) {
|
|
154
|
-
if (!(pkg instanceof NpmPackage)) continue;
|
|
155
|
-
for (const field of DEP_FIELDS) {
|
|
156
|
-
const dependencies = pkg.manifest[field];
|
|
157
|
-
if (!dependencies) continue;
|
|
158
|
-
for (const [k, v] of Object.entries(dependencies)) {
|
|
159
|
-
const spec = parseDependencySpec(this, pkg, k, v);
|
|
160
|
-
if (!spec?.linked || spec.protocol === "workspace" || spec.protocol === "file") continue;
|
|
161
|
-
if (!semver.validRange(spec.range)) continue;
|
|
162
|
-
if (semver.satisfies(spec.linked.version, spec.range)) continue;
|
|
163
|
-
let updatedRange;
|
|
164
|
-
const isPeer = field === "peerDependencies";
|
|
165
|
-
if (isPeer && onBreakPeerDep === "ignore") continue;
|
|
166
|
-
else if (isPeer && onBreakPeerDep === "set") updatedRange = spec.linked.version;
|
|
167
|
-
else if (isPeer && onBreakPeerDep === "error") throw new Error(`[Tegami] the version of "${spec.linked.name}" is beyond its peer dependency constraint "${v}" in package "${pkg.name}", please update the constraint to satisfy.`);
|
|
168
|
-
else if (spec.range.startsWith("^")) updatedRange = `^${spec.linked.version}`;
|
|
169
|
-
else if (spec.range.startsWith("~")) updatedRange = `~${spec.linked.version}`;
|
|
170
|
-
else updatedRange = spec.linked.version;
|
|
171
|
-
dependencies[k] = formatDependencySpec({
|
|
172
|
-
...spec,
|
|
173
|
-
range: updatedRange
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
writes.push(pkg.write());
|
|
178
|
-
}
|
|
179
|
-
await Promise.all(writes);
|
|
180
|
-
},
|
|
181
|
-
cli: { async draftApplied() {
|
|
182
|
-
if (!active || !updateLockFile) return;
|
|
183
|
-
let args;
|
|
184
|
-
if (client === "npm") args = ["ci"];
|
|
185
|
-
else if (client === "yarn") args = ["install", "--immutable"];
|
|
186
|
-
else if (client === "bun") args = ["install", "--frozen-lockfile"];
|
|
187
|
-
else args = ["install", "--frozen-lockfile"];
|
|
188
|
-
const result = await x(client, args, { nodeOptions: { cwd: this.cwd } });
|
|
189
|
-
if (result.exitCode !== 0) throw execFailure("Failed to update lockfile.", result);
|
|
190
|
-
} }
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function depsPolicy(context, getBumpDepType) {
|
|
194
|
-
const { graph } = context;
|
|
195
|
-
function needsUpdate(spec, target) {
|
|
196
|
-
if (spec.linked && spec.protocol === "workspace") switch (spec.range) {
|
|
197
|
-
case "":
|
|
198
|
-
case "*": return true;
|
|
199
|
-
case "^":
|
|
200
|
-
case "~": return !semver.satisfies(target, `${spec.range}${spec.linked.version}`);
|
|
201
|
-
}
|
|
202
|
-
if (spec.linked && spec.protocol === "file") return true;
|
|
203
|
-
if (spec.protocol === "file" || !semver.validRange(spec.range)) return false;
|
|
204
|
-
return !semver.satisfies(target, spec.range);
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
id: "npm:deps",
|
|
208
|
-
onUpdate({ pkg, packageDraft: plan }) {
|
|
209
|
-
if (!(pkg instanceof NpmPackage)) return;
|
|
210
|
-
const group = graph.getPackageGroup(pkg.id);
|
|
211
|
-
for (const dependent of graph.getPackages()) {
|
|
212
|
-
if (!(dependent instanceof NpmPackage)) continue;
|
|
213
|
-
for (const field of DEP_FIELDS) {
|
|
214
|
-
const dependencies = dependent.manifest[field];
|
|
215
|
-
if (!dependencies) continue;
|
|
216
|
-
for (const [k, v] of Object.entries(dependencies)) {
|
|
217
|
-
const spec = parseDependencySpec(context, dependent, k, v);
|
|
218
|
-
if (!spec || spec.linked !== pkg) continue;
|
|
219
|
-
if (group?.options.syncBump && graph.getPackageGroup(dependent.id) === group) continue;
|
|
220
|
-
if (!needsUpdate(spec, plan.bumpVersion(pkg))) continue;
|
|
221
|
-
const bumpType = getBumpDepType({
|
|
222
|
-
kind: field,
|
|
223
|
-
spec,
|
|
224
|
-
name: k
|
|
225
|
-
});
|
|
226
|
-
if (bumpType === false) continue;
|
|
227
|
-
this.bumpPackage(dependent, {
|
|
228
|
-
type: bumpType,
|
|
229
|
-
reason: `update dependency "${k}"`
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
async function publish(client, pkg, distTag) {
|
|
238
|
-
if (client === "bun") {
|
|
239
|
-
for (const script of [
|
|
240
|
-
"prepublishOnly",
|
|
241
|
-
"prepack",
|
|
242
|
-
"prepare"
|
|
243
|
-
]) {
|
|
244
|
-
if (!pkg.manifest.scripts?.[script]) continue;
|
|
245
|
-
const result = await x("bun", ["run", script], { nodeOptions: { cwd: pkg.path } });
|
|
246
|
-
if (result.exitCode === 0) continue;
|
|
247
|
-
return {
|
|
248
|
-
type: "failed",
|
|
249
|
-
error: execFailure(`Failed to run ${script} script for ${pkg.name}@${pkg.version}.`, result).message
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
const tarballPath = path.resolve(pkg.path, "pkg.tgz");
|
|
253
|
-
const packResult = await x("bun", [
|
|
254
|
-
"pm",
|
|
255
|
-
"pack",
|
|
256
|
-
"--filename",
|
|
257
|
-
tarballPath
|
|
258
|
-
], { nodeOptions: { cwd: pkg.path } });
|
|
259
|
-
if (packResult.exitCode !== 0) return {
|
|
260
|
-
type: "failed",
|
|
261
|
-
error: execFailure(`Failed to pack ${pkg.name}@${pkg.version}.`, packResult).message
|
|
262
|
-
};
|
|
263
|
-
const publishArgs = ["publish", tarballPath];
|
|
264
|
-
if (distTag) publishArgs.push("--tag", distTag);
|
|
265
|
-
const publishResult = await x("npm", publishArgs, { nodeOptions: { cwd: pkg.path } });
|
|
266
|
-
if (publishResult.exitCode !== 0) return {
|
|
267
|
-
type: "failed",
|
|
268
|
-
error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, publishResult).message
|
|
269
|
-
};
|
|
270
|
-
return { type: "published" };
|
|
271
|
-
}
|
|
272
|
-
let command;
|
|
273
|
-
const args = ["publish"];
|
|
274
|
-
if (distTag) args.push("--tag", distTag);
|
|
275
|
-
if (client === "pnpm") {
|
|
276
|
-
command = "pnpm";
|
|
277
|
-
args.push("--no-git-checks");
|
|
278
|
-
} else if (client === "yarn") command = "yarn";
|
|
279
|
-
else command = "npm";
|
|
280
|
-
const result = await x(command, args, { nodeOptions: { cwd: pkg.path } });
|
|
281
|
-
if (result.exitCode !== 0) return {
|
|
282
|
-
type: "failed",
|
|
283
|
-
error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, result).message
|
|
284
|
-
};
|
|
285
|
-
return { type: "published" };
|
|
286
|
-
}
|
|
287
|
-
async function isPackagePublished(pkg) {
|
|
288
|
-
const registry = pkg.manifest.publishConfig?.registry ?? "https://registry.npmjs.org";
|
|
289
|
-
const base = registry.replace(/\/$/, "");
|
|
290
|
-
const response = await fetch(`${base}/${pkg.name}/${pkg.version}`, { headers: { Accept: "application/json" } });
|
|
291
|
-
if (response.status === 404) return false;
|
|
292
|
-
if (!response.ok) throw new Error(`Unable to validate ${pkg.name}@${pkg.version} against the npm registry${registry ? ` "${registry}"` : ""}.`);
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
async function discoverNpmPackages(cwd, add) {
|
|
296
|
-
let patterns;
|
|
297
|
-
const rootManifest = await readManifest(cwd).catch(() => void 0);
|
|
298
|
-
const pnpmPatterns = await readFile(path.join(cwd, "pnpm-workspace.yaml"), "utf8").then((content) => pnpmWorkspaceSchema.parse(load(content) ?? {})).catch((error) => {
|
|
299
|
-
if (isNodeError(error) && error.code === "ENOENT") return void 0;
|
|
300
|
-
throw error;
|
|
301
|
-
});
|
|
302
|
-
if (pnpmPatterns) patterns = pnpmPatterns.packages ?? [];
|
|
303
|
-
else patterns = rootManifest?.workspaces ?? [];
|
|
304
|
-
const candidatePaths = await expandWorkspacePatterns(cwd, patterns);
|
|
305
|
-
const manifests = await Promise.all(candidatePaths.map((path) => readManifest(path).then((manifest) => ({
|
|
306
|
-
path,
|
|
307
|
-
manifest
|
|
308
|
-
})).catch(() => void 0)));
|
|
309
|
-
if (rootManifest?.version) add(new NpmPackage(cwd, rootManifest));
|
|
310
|
-
for (const entry of manifests) {
|
|
311
|
-
if (!entry?.manifest.version) continue;
|
|
312
|
-
add(new NpmPackage(entry.path, entry.manifest));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async function expandWorkspacePatterns(cwd, patterns) {
|
|
316
|
-
if (patterns.length === 0) return [];
|
|
317
|
-
return (await glob(patterns, {
|
|
318
|
-
absolute: true,
|
|
319
|
-
cwd,
|
|
320
|
-
ignore: ["**/node_modules/**", "**/dist/**"],
|
|
321
|
-
onlyDirectories: true,
|
|
322
|
-
onlyFiles: false
|
|
323
|
-
})).map((item) => {
|
|
324
|
-
return item.endsWith(path.sep) ? item.slice(0, -1) : item;
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
async function readManifest(packagePath) {
|
|
328
|
-
const content = await readFile(path.join(packagePath, "package.json"), "utf8");
|
|
329
|
-
const parsed = JSON.parse(content);
|
|
330
|
-
packageManifestSchema.parse(parsed);
|
|
331
|
-
return parsed;
|
|
332
|
-
}
|
|
333
|
-
//#endregion
|
|
1
|
+
import { n as npm, t as NpmPackage } from "../npm-Q0qvAkIu.js";
|
|
334
2
|
export { NpmPackage, npm };
|
|
@@ -33,7 +33,8 @@ function bumpVersion(version, type, prerelease) {
|
|
|
33
33
|
const parsed = parse(version);
|
|
34
34
|
if (!parsed) next = null;
|
|
35
35
|
else if (prerelease) {
|
|
36
|
-
if (parsed.prerelease[0] === prerelease
|
|
36
|
+
if (parsed.prerelease[0] === prerelease) next = type ? inc(parsed, "prerelease", prerelease) : version;
|
|
37
|
+
else if (parsed.prerelease[0]) next = inc(parsed, "prerelease", prerelease);
|
|
37
38
|
else if (type) next = inc(parsed, PRE[type], prerelease);
|
|
38
39
|
} else if (type) next = inc(parsed, type);
|
|
39
40
|
else if (parsed.prerelease.length > 0) next = inc(parsed, "release");
|