tegami 1.0.0-beta.5 → 1.0.2

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.
@@ -1,2 +1,2 @@
1
- import { n as execFailure } from "../error-We7chQVJ.js";
1
+ import { n as execFailure } from "../error-BhMYq9iW.js";
2
2
  export { execFailure };
@@ -1,5 +1,5 @@
1
1
  import { r as formatNpmDistTag } from "./semver-EKJ8yK5U.js";
2
- import { n as execFailure } from "./error-We7chQVJ.js";
2
+ import { n as execFailure } from "./error-BhMYq9iW.js";
3
3
  import { x } from "tinyexec";
4
4
  //#region src/utils/version-request.ts
5
5
  async function hasGitChanges(cwd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tegami",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.2",
4
4
  "description": "Utility for package versioning & publish",
5
5
  "license": "MIT",
6
6
  "author": "Fuma Nama",
@@ -16,11 +16,11 @@
16
16
  ".": "./dist/index.js",
17
17
  "./cli": "./dist/cli/index.js",
18
18
  "./generators/simple": "./dist/generators/simple.js",
19
+ "./plugins/cargo": "./dist/plugins/cargo.js",
19
20
  "./plugins/git": "./dist/plugins/git.js",
20
21
  "./plugins/github": "./dist/plugins/github.js",
21
22
  "./plugins/gitlab": "./dist/plugins/gitlab.js",
22
23
  "./plugins/go": "./dist/plugins/go.js",
23
- "./providers/cargo": "./dist/providers/cargo.js",
24
24
  "./providers/npm": "./dist/providers/npm.js",
25
25
  "./utils": "./dist/utils/index.js",
26
26
  "./package.json": "./package.json"
@@ -1,292 +0,0 @@
1
- import { n as execFailure } from "./error-We7chQVJ.js";
2
- import { n as WorkspacePackage } from "./graph-gThXu8Cz.js";
3
- import { readFile, writeFile } from "node:fs/promises";
4
- import { join, normalize } from "node:path";
5
- import { x } from "tinyexec";
6
- import * as semver$1 from "semver";
7
- import z from "zod";
8
- import initToml, { edit, parse as parse$1 } from "@rainbowatcher/toml-edit-js";
9
- import { glob } from "tinyglobby";
10
- //#region src/providers/cargo/schema.ts
11
- const cargoDependencySchema = z.union([z.string(), z.object({
12
- version: z.string(),
13
- package: z.string().optional(),
14
- path: z.string().optional()
15
- })]);
16
- const cargoTargetConfigSchema = z.object({
17
- dependencies: z.record(z.string(), cargoDependencySchema).optional(),
18
- "dev-dependencies": z.record(z.string(), cargoDependencySchema).optional(),
19
- "build-dependencies": z.record(z.string(), cargoDependencySchema).optional()
20
- });
21
- const cargoPackageSchema = z.object({
22
- name: z.string(),
23
- version: z.string().optional(),
24
- publish: z.boolean().optional()
25
- });
26
- const cargoWorkspaceSchema = z.object({
27
- members: z.array(z.string()).optional(),
28
- exclude: z.array(z.string()).optional(),
29
- package: z.object({ version: z.string().optional() }).optional()
30
- });
31
- const cargoManifestSchema = z.object({
32
- package: cargoPackageSchema,
33
- workspace: cargoWorkspaceSchema.optional(),
34
- dependencies: z.record(z.string(), cargoDependencySchema).optional(),
35
- "dev-dependencies": z.record(z.string(), cargoDependencySchema).optional(),
36
- "build-dependencies": z.record(z.string(), cargoDependencySchema).optional(),
37
- target: z.record(z.string(), cargoTargetConfigSchema).optional()
38
- });
39
- //#endregion
40
- //#region src/providers/cargo.ts
41
- const DEP_FIELDS = [
42
- "dependencies",
43
- "dev-dependencies",
44
- "build-dependencies"
45
- ];
46
- var CargoPackage = class extends WorkspacePackage {
47
- path;
48
- manifest;
49
- content;
50
- workspaceManifest;
51
- manager = "cargo";
52
- constructor(path, manifest, content, workspaceManifest) {
53
- super();
54
- this.path = path;
55
- this.manifest = manifest;
56
- this.content = content;
57
- this.workspaceManifest = workspaceManifest;
58
- }
59
- get name() {
60
- return this.packageInfo.name;
61
- }
62
- get version() {
63
- return this.packageInfo.version ?? this.workspaceVersion;
64
- }
65
- setVersion(version) {
66
- this.packageInfo.version = version;
67
- this.patch("package.version", version);
68
- }
69
- async write() {
70
- await writeFile(join(this.path, "Cargo.toml"), this.content + "\n");
71
- }
72
- patch(path, value) {
73
- this.content = edit(this.content, path, value);
74
- }
75
- get packageInfo() {
76
- return this.manifest.package;
77
- }
78
- get workspaceVersion() {
79
- return this.workspaceManifest?.workspace?.package?.version;
80
- }
81
- };
82
- function cargo({ updateLockFile = true, bumpDep: getBumpDepType } = {}) {
83
- let active = false;
84
- return {
85
- name: "cargo",
86
- enforce: "pre",
87
- async init() {
88
- await initToml();
89
- },
90
- async resolve() {
91
- await discoverCargoPackages(this.cwd, (pkg) => this.graph.add(pkg));
92
- active = this.graph.getPackages().some((pkg) => pkg instanceof CargoPackage);
93
- },
94
- initDraft(plan) {
95
- if (!active) return;
96
- plan.addPolicy(depsPolicy(this, getBumpDepType));
97
- },
98
- async publishPreflight({ pkg }) {
99
- if (!(pkg instanceof CargoPackage)) return;
100
- const wait = [];
101
- for (const { table } of dependencyTables(pkg.manifest, "")) for (const [rawName, dep] of Object.entries(table)) {
102
- if (!dep || typeof dep === "string" || !dep.path) continue;
103
- const id = `cargo:${dep.package ?? rawName}`;
104
- const linked = this.graph.get(id);
105
- if (!linked || !(linked instanceof CargoPackage)) continue;
106
- wait.push(id);
107
- }
108
- return {
109
- shouldPublish: pkg.version !== void 0 && pkg.packageInfo.publish !== false,
110
- wait
111
- };
112
- },
113
- resolvePlanStatus({ plan }) {
114
- return Array.from(plan.packages, async ([id, { preflight }]) => {
115
- if (!preflight.shouldPublish) return;
116
- const pkg = this.graph.get(id);
117
- if (!(pkg instanceof CargoPackage) || !pkg.version) return;
118
- if (!await isPackagePublished(pkg.name, pkg.version)) return "pending";
119
- });
120
- },
121
- async publish({ pkg }) {
122
- if (!(pkg instanceof CargoPackage)) return;
123
- const result = await x("cargo", ["publish"], { nodeOptions: { cwd: pkg.path } });
124
- if (result.exitCode !== 0) {
125
- if (/already exists|already published/i.test(`${result.stdout}\n${result.stderr}`)) return { type: "skipped" };
126
- return {
127
- type: "failed",
128
- error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}.`, result).message
129
- };
130
- }
131
- return { type: "published" };
132
- },
133
- async applyDraft(draft) {
134
- if (!active) return;
135
- const { graph } = this;
136
- const writes = [];
137
- for (const pkg of graph.getPackages()) {
138
- if (!(pkg instanceof CargoPackage)) continue;
139
- const bumped = draft.getPackageDraft(pkg.id)?.bumpVersion(pkg);
140
- if (bumped) pkg.setVersion(bumped);
141
- }
142
- for (const pkg of graph.getPackages()) {
143
- if (!(pkg instanceof CargoPackage)) continue;
144
- for (const { table, path: tablePath } of dependencyTables(pkg.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
145
- const spec = parseSpec(rawSpec);
146
- if (!spec || !semver$1.validRange(spec.version)) continue;
147
- const packageName = spec.package ?? rawName;
148
- const linked = graph.get(`cargo:${packageName}`);
149
- if (!linked || !(linked instanceof CargoPackage)) continue;
150
- if (!linked.version || semver$1.satisfies(linked.version, spec.version)) continue;
151
- let updatedRange;
152
- if (spec.version.startsWith("^")) updatedRange = `^${linked.version}`;
153
- else if (spec.version.startsWith("~")) updatedRange = `~${linked.version}`;
154
- else updatedRange = linked.version;
155
- table[rawName] = spec.setVersion(updatedRange);
156
- pkg.patch(typeof rawSpec === "string" ? `${tablePath}.${rawName}` : `${tablePath}.${rawName}.version`, updatedRange);
157
- }
158
- writes.push(pkg.write());
159
- }
160
- await Promise.all(writes);
161
- },
162
- async applyCliDraft() {
163
- if (!active || !updateLockFile) return;
164
- const result = await x("cargo", ["update", "--workspace"], { nodeOptions: { cwd: this.cwd } });
165
- if (result.exitCode !== 0) throw execFailure("Failed to update Cargo lock file", result);
166
- }
167
- };
168
- }
169
- function depsPolicy({ graph }, getBumpDepType = ({ kind }) => {
170
- switch (kind) {
171
- case "dependencies": return "patch";
172
- case "build-dependencies":
173
- case "dev-dependencies": return false;
174
- }
175
- }) {
176
- return {
177
- id: "cargo:deps",
178
- onUpdate({ pkg, packageDraft: plan }) {
179
- if (!(pkg instanceof CargoPackage)) return;
180
- const group = graph.getPackageGroup(pkg.id);
181
- for (const dependent of graph.getPackages()) {
182
- if (!(dependent instanceof CargoPackage)) continue;
183
- for (const { table, kind } of dependencyTables(dependent.manifest, "")) for (const [rawName, rawSpec] of Object.entries(table)) {
184
- const spec = parseSpec(rawSpec);
185
- if (!spec || !semver$1.validRange(spec.version)) continue;
186
- if (pkg.id !== `cargo:${spec.package ?? rawName}`) continue;
187
- if (group?.options.syncBump && graph.getPackageGroup(dependent.id) === group) continue;
188
- const bumped = plan.bumpVersion(pkg);
189
- if (!bumped || semver$1.satisfies(bumped, spec.version)) continue;
190
- const bumpType = getBumpDepType({
191
- kind,
192
- dependent,
193
- name: pkg.name,
194
- version: spec.version
195
- });
196
- if (bumpType === false) continue;
197
- this.bumpPackage(dependent, {
198
- type: bumpType,
199
- reason: `update dependency "${rawName}"`
200
- });
201
- }
202
- }
203
- }
204
- };
205
- }
206
- async function isPackagePublished(name, version) {
207
- const response = await fetch(`https://crates.io/api/v1/crates/${encodeURIComponent(name)}/${version}`);
208
- if (response.status === 200) return true;
209
- if (response.status === 404) return false;
210
- throw new Error(`Unable to validate ${name}@${version} against crates.io: ${await response.text()}`);
211
- }
212
- async function buildEntry(path) {
213
- try {
214
- const content = await readFile(join(path, "Cargo.toml"), "utf8");
215
- return {
216
- manifest: cargoManifestSchema.parse(parse$1(content)),
217
- content,
218
- path
219
- };
220
- } catch {
221
- return;
222
- }
223
- }
224
- async function discoverCargoPackages(cwd, add) {
225
- const root = await buildEntry(cwd);
226
- if (!root) return;
227
- if (root.manifest.package?.name) add(new CargoPackage(cwd, root.manifest, root.content, root.manifest));
228
- const workspace = root.manifest.workspace;
229
- if (!workspace?.members) return;
230
- const paths = await expandWorkspaceMembers(cwd, workspace.members, workspace.exclude);
231
- const manifests = await Promise.all(paths.map(buildEntry));
232
- for (const entry of manifests) if (entry?.manifest.package?.name) add(new CargoPackage(entry.path, entry.manifest, entry.content, root.manifest));
233
- }
234
- async function expandWorkspaceMembers(cwd, members, exclude = []) {
235
- const paths = members.includes(".") ? [cwd] : [];
236
- const patterns = members.filter((member) => member !== ".");
237
- if (patterns.length > 0) paths.push(...await glob(patterns, {
238
- absolute: true,
239
- cwd,
240
- ignore: ["**/target/**", ...exclude],
241
- onlyDirectories: true,
242
- onlyFiles: false
243
- }));
244
- return paths.map(normalize);
245
- }
246
- function dependencyTables(manifest, prefix) {
247
- const tables = [];
248
- for (const field of DEP_FIELDS) {
249
- const table = manifest[field];
250
- if (table) {
251
- const path = prefix ? `${prefix}.${field}` : field;
252
- tables.push({
253
- kind: field,
254
- table,
255
- path
256
- });
257
- }
258
- }
259
- const target = manifest.target;
260
- if (target) for (const [targetKey, targetConfig] of Object.entries(target)) {
261
- const targetPath = prefix ? `${prefix}.target.${targetKey}` : `target.${targetKey}`;
262
- for (const field of DEP_FIELDS) {
263
- const table = targetConfig[field];
264
- if (table) tables.push({
265
- kind: field,
266
- table,
267
- path: `${targetPath}.${field}`
268
- });
269
- }
270
- }
271
- return tables;
272
- }
273
- function parseSpec(v) {
274
- if (typeof v === "string") return {
275
- version: v,
276
- setVersion(version) {
277
- return version;
278
- }
279
- };
280
- return {
281
- package: v.package,
282
- version: v.version,
283
- setVersion(version) {
284
- return {
285
- ...v,
286
- version
287
- };
288
- }
289
- };
290
- }
291
- //#endregion
292
- export { cargo as n, CargoPackage as t };
@@ -1,371 +0,0 @@
1
- import { i as isNodeError, n as execFailure } from "./error-We7chQVJ.js";
2
- import { n as WorkspacePackage } from "./graph-gThXu8Cz.js";
3
- import { readFile, writeFile } from "node:fs/promises";
4
- import path from "node:path";
5
- import { x } from "tinyexec";
6
- import * as semver$1 from "semver";
7
- import z from "zod";
8
- import { load } from "js-yaml";
9
- import { glob } from "tinyglobby";
10
- import { detect } from "package-manager-detector";
11
- //#region src/providers/npm/schema.ts
12
- const stringRecordSchema = z.record(z.string(), z.string());
13
- const pnpmWorkspaceSchema = z.looseObject({ packages: z.array(z.string()).optional() });
14
- const packageManifestSchema = z.looseObject({
15
- name: z.string(),
16
- version: z.string().optional(),
17
- private: z.boolean().optional(),
18
- publishConfig: z.looseObject({
19
- access: z.enum(["public", "restricted"]).optional(),
20
- registry: z.string().optional(),
21
- tag: z.string().optional()
22
- }).optional(),
23
- scripts: z.record(z.string(), z.string()).optional(),
24
- workspaces: z.array(z.string()).optional(),
25
- dependencies: stringRecordSchema.optional(),
26
- devDependencies: stringRecordSchema.optional(),
27
- peerDependencies: stringRecordSchema.optional(),
28
- optionalDependencies: stringRecordSchema.optional()
29
- });
30
- //#endregion
31
- //#region src/providers/npm.ts
32
- const DEP_FIELDS = [
33
- "dependencies",
34
- "devDependencies",
35
- "peerDependencies",
36
- "optionalDependencies"
37
- ];
38
- var NpmPackage = class extends WorkspacePackage {
39
- path;
40
- manifest;
41
- manager = "npm";
42
- constructor(path, manifest) {
43
- super();
44
- this.path = path;
45
- this.manifest = manifest;
46
- }
47
- get name() {
48
- return this.manifest.name;
49
- }
50
- get version() {
51
- return this.manifest.version;
52
- }
53
- async write() {
54
- await writeFile(path.join(this.path, "package.json"), `${JSON.stringify(this.manifest, null, 2)}\n`);
55
- }
56
- initDraft() {
57
- const defaults = super.initDraft();
58
- defaults.npm = { distTag: this.manifest.publishConfig?.tag };
59
- return defaults;
60
- }
61
- configureDraft(draft, group) {
62
- super.configureDraft(draft, group);
63
- const { distTag = group?.options?.npm?.distTag } = this.getPackageOptions().npm ?? {};
64
- if (distTag) {
65
- draft.npm ??= {};
66
- draft.npm.distTag = distTag;
67
- } else if (draft.prerelease) {
68
- draft.npm ??= {};
69
- draft.npm.distTag ??= draft.prerelease;
70
- }
71
- }
72
- };
73
- function parseDependencySpec(context, dependent, name, range) {
74
- const { graph } = context;
75
- if (range.startsWith("workspace:")) return {
76
- range: range.slice(10),
77
- linked: graph.get(`npm:${name}`),
78
- protocol: "workspace"
79
- };
80
- if (range.startsWith("file:")) {
81
- let target = path.resolve(dependent.path, range.slice(5));
82
- if (path.basename(target) === "package.json") target = path.dirname(target);
83
- return {
84
- protocol: "file",
85
- raw: range,
86
- linked: graph.getPackages().find((pkg) => pkg instanceof NpmPackage && pkg.path === target)
87
- };
88
- }
89
- if (range.startsWith("npm:")) {
90
- const spec = range.slice(4);
91
- const separator = spec.lastIndexOf("@");
92
- if (separator <= 0) return;
93
- const alias = spec.slice(0, separator);
94
- return {
95
- alias,
96
- linked: graph.get(`npm:${alias}`),
97
- range: spec.slice(separator + 1),
98
- protocol: "npm"
99
- };
100
- }
101
- return {
102
- linked: graph.get(`npm:${name}`),
103
- range
104
- };
105
- }
106
- function formatDependencySpec(spec) {
107
- if (spec.protocol === "workspace") return `workspace:${spec.range}`;
108
- if (spec.protocol === "file") return spec.raw;
109
- if (spec.protocol === "npm") return `npm:${spec.alias}@${spec.range}`;
110
- return spec.range;
111
- }
112
- const packageLockSchema = z.object({
113
- id: z.string(),
114
- distTag: z.string().optional()
115
- });
116
- function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = true, bumpDep: getBumpDepType = ({ kind }) => {
117
- switch (kind) {
118
- case "dependencies":
119
- case "optionalDependencies": return "patch";
120
- case "devDependencies": return false;
121
- case "peerDependencies":
122
- if (onBreakPeerDep === "ignore") return false;
123
- return "major";
124
- }
125
- } } = {}) {
126
- let active = false;
127
- let client;
128
- return {
129
- name: "npm",
130
- enforce: "pre",
131
- async init() {
132
- if (defaultClient) client = defaultClient;
133
- else client = (await detect({ cwd: this.cwd }))?.name ?? "npm";
134
- this.npm = { client };
135
- },
136
- async resolve() {
137
- await discoverNpmPackages(this.cwd, (pkg) => this.graph.add(pkg));
138
- active = this.graph.getPackages().some((pkg) => pkg instanceof NpmPackage);
139
- },
140
- async publishPreflight({ pkg }) {
141
- if (!(pkg instanceof NpmPackage)) return;
142
- return { shouldPublish: pkg.version !== void 0 && pkg.manifest.private !== true };
143
- },
144
- resolvePlanStatus({ plan }) {
145
- return Array.from(plan.packages, async ([id, { preflight }]) => {
146
- if (!preflight.shouldPublish) return;
147
- const pkg = this.graph.get(id);
148
- if (!(pkg instanceof NpmPackage) || !pkg.version) return;
149
- if (!await isPackagePublished(pkg.name, pkg.version, pkg.manifest.publishConfig?.registry)) return "pending";
150
- });
151
- },
152
- initPublishLock({ lock, draft }) {
153
- for (const [id, pkg] of draft.getPackageDrafts()) {
154
- if (!pkg.npm) continue;
155
- lock.write("npm:packages", {
156
- id,
157
- distTag: pkg.npm.distTag
158
- });
159
- }
160
- },
161
- initPublishPlan({ lock, plan }) {
162
- let data;
163
- while (data = lock.read("npm:packages")) {
164
- const parsed = packageLockSchema.safeParse(data).data;
165
- if (!parsed) continue;
166
- const packagePlan = plan.packages.get(parsed.id);
167
- if (!packagePlan) continue;
168
- packagePlan.npm = { distTag: parsed.distTag };
169
- }
170
- },
171
- async publish({ pkg, plan }) {
172
- if (!(pkg instanceof NpmPackage)) return;
173
- return publish(client, pkg, plan.packages.get(pkg.id)?.npm?.distTag);
174
- },
175
- initDraft(plan) {
176
- if (!active) return;
177
- plan.addPolicy(depsPolicy(this, getBumpDepType));
178
- },
179
- async applyDraft(draft) {
180
- if (!active) return;
181
- const { graph } = this;
182
- const writes = [];
183
- for (const pkg of graph.getPackages()) {
184
- if (!(pkg instanceof NpmPackage)) continue;
185
- const bumped = draft.getPackageDraft(pkg.id)?.bumpVersion(pkg);
186
- if (bumped) pkg.manifest.version = bumped;
187
- }
188
- for (const pkg of graph.getPackages()) {
189
- if (!(pkg instanceof NpmPackage)) continue;
190
- for (const field of DEP_FIELDS) {
191
- const dependencies = pkg.manifest[field];
192
- if (!dependencies) continue;
193
- for (const [k, v] of Object.entries(dependencies)) {
194
- const spec = parseDependencySpec(this, pkg, k, v);
195
- if (!spec?.linked || spec.protocol === "workspace" || spec.protocol === "file") continue;
196
- if (!semver$1.validRange(spec.range)) continue;
197
- if (!spec.linked.version || semver$1.satisfies(spec.linked.version, spec.range)) continue;
198
- let updatedRange;
199
- const isPeer = field === "peerDependencies";
200
- if (isPeer && onBreakPeerDep === "ignore") continue;
201
- if (isPeer && onBreakPeerDep === "set") updatedRange = spec.linked.version;
202
- 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.`);
203
- else if (spec.range.startsWith("^")) updatedRange = `^${spec.linked.version}`;
204
- else if (spec.range.startsWith("~")) updatedRange = `~${spec.linked.version}`;
205
- else updatedRange = spec.linked.version;
206
- dependencies[k] = formatDependencySpec({
207
- ...spec,
208
- range: updatedRange
209
- });
210
- }
211
- }
212
- writes.push(pkg.write());
213
- }
214
- await Promise.all(writes);
215
- },
216
- async applyCliDraft() {
217
- if (!active || !updateLockFile) return;
218
- let args;
219
- if (client === "npm") args = ["ci"];
220
- else if (client === "yarn") args = ["install", "--immutable"];
221
- else if (client === "bun") args = ["install", "--frozen-lockfile"];
222
- else args = ["install", "--frozen-lockfile"];
223
- const result = await x(client, args, { nodeOptions: { cwd: this.cwd } });
224
- if (result.exitCode !== 0) throw execFailure("Failed to update lockfile.", result);
225
- }
226
- };
227
- }
228
- function depsPolicy(context, getBumpDepType) {
229
- const { graph } = context;
230
- function needsUpdate(spec, target) {
231
- if (spec.linked && spec.protocol === "workspace") switch (spec.range) {
232
- case "":
233
- case "*": return true;
234
- case "^":
235
- case "~": return !semver$1.satisfies(target, `${spec.range}${spec.linked.version}`);
236
- }
237
- if (spec.linked && spec.protocol === "file") return true;
238
- if (spec.protocol === "file" || !semver$1.validRange(spec.range)) return false;
239
- return !semver$1.satisfies(target, spec.range);
240
- }
241
- return {
242
- id: "npm:deps",
243
- onUpdate({ pkg, packageDraft: plan }) {
244
- if (!(pkg instanceof NpmPackage)) return;
245
- const group = graph.getPackageGroup(pkg.id);
246
- for (const dependent of graph.getPackages()) {
247
- if (!(dependent instanceof NpmPackage)) continue;
248
- for (const field of DEP_FIELDS) {
249
- const dependencies = dependent.manifest[field];
250
- if (!dependencies) continue;
251
- for (const [k, v] of Object.entries(dependencies)) {
252
- const spec = parseDependencySpec(context, dependent, k, v);
253
- if (!spec || spec.linked !== pkg) continue;
254
- if (group?.options.syncBump && graph.getPackageGroup(dependent.id) === group) continue;
255
- const bumped = plan.bumpVersion(pkg);
256
- if (!bumped || !needsUpdate(spec, bumped)) continue;
257
- const bumpType = getBumpDepType({
258
- kind: field,
259
- dependent,
260
- spec,
261
- name: k
262
- });
263
- if (bumpType === false) continue;
264
- this.bumpPackage(dependent, {
265
- type: bumpType,
266
- reason: `update dependency "${k}"`
267
- });
268
- }
269
- }
270
- }
271
- }
272
- };
273
- }
274
- async function publish(client, pkg, distTag) {
275
- if (!pkg.version || await isPackagePublished(pkg.name, pkg.version, pkg.manifest.publishConfig?.registry)) return { type: "skipped" };
276
- if (client === "bun") {
277
- for (const script of [
278
- "prepublishOnly",
279
- "prepack",
280
- "prepare"
281
- ]) {
282
- if (!pkg.manifest.scripts?.[script]) continue;
283
- const result = await x("bun", ["run", script], { nodeOptions: { cwd: pkg.path } });
284
- if (result.exitCode === 0) continue;
285
- return {
286
- type: "failed",
287
- error: execFailure(`Failed to run ${script} script for ${pkg.name}@${pkg.version}.`, result).message
288
- };
289
- }
290
- const tarballPath = path.resolve(pkg.path, "pkg.tgz");
291
- const packResult = await x("bun", [
292
- "pm",
293
- "pack",
294
- "--filename",
295
- tarballPath
296
- ], { nodeOptions: { cwd: pkg.path } });
297
- if (packResult.exitCode !== 0) return {
298
- type: "failed",
299
- error: execFailure(`Failed to pack ${pkg.name}@${pkg.version}.`, packResult).message
300
- };
301
- const publishArgs = ["publish", tarballPath];
302
- if (distTag) publishArgs.push("--tag", distTag);
303
- const publishResult = await x("npm", publishArgs, { nodeOptions: { cwd: pkg.path } });
304
- if (publishResult.exitCode !== 0) return {
305
- type: "failed",
306
- error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, publishResult).message
307
- };
308
- return { type: "published" };
309
- }
310
- let command;
311
- const args = ["publish"];
312
- if (distTag) args.push("--tag", distTag);
313
- if (client === "pnpm") {
314
- command = "pnpm";
315
- args.push("--no-git-checks");
316
- } else if (client === "yarn") command = "yarn";
317
- else command = "npm";
318
- const result = await x(command, args, { nodeOptions: { cwd: pkg.path } });
319
- if (result.exitCode !== 0) return {
320
- type: "failed",
321
- error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, result).message
322
- };
323
- return { type: "published" };
324
- }
325
- async function isPackagePublished(name, version, registry = "https://registry.npmjs.org") {
326
- const base = registry.replace(/\/$/, "");
327
- const response = await fetch(`${base}/${name}/${version}`, { headers: { Accept: "application/json" } });
328
- if (response.status === 404) return false;
329
- if (!response.ok) throw new Error(`Unable to validate ${name}@${version} against the npm registry${registry ? ` "${registry}"` : ""}.`);
330
- return true;
331
- }
332
- async function discoverNpmPackages(cwd, add) {
333
- let patterns;
334
- const rootManifest = await readManifest(cwd).catch(() => void 0);
335
- const pnpmPatterns = await readFile(path.join(cwd, "pnpm-workspace.yaml"), "utf8").then((content) => pnpmWorkspaceSchema.parse(load(content) ?? {})).catch((error) => {
336
- if (isNodeError(error) && error.code === "ENOENT") return void 0;
337
- throw error;
338
- });
339
- if (pnpmPatterns) patterns = pnpmPatterns.packages ?? [];
340
- else patterns = rootManifest?.workspaces ?? [];
341
- const candidatePaths = await expandWorkspacePatterns(cwd, patterns);
342
- const manifests = await Promise.all(candidatePaths.map((path) => readManifest(path).then((manifest) => ({
343
- path,
344
- manifest
345
- })).catch(() => void 0)));
346
- if (rootManifest?.name) add(new NpmPackage(cwd, rootManifest));
347
- for (const entry of manifests) {
348
- if (!entry) continue;
349
- add(new NpmPackage(entry.path, entry.manifest));
350
- }
351
- }
352
- async function expandWorkspacePatterns(cwd, patterns) {
353
- if (patterns.length === 0) return [];
354
- return (await glob(patterns, {
355
- absolute: true,
356
- cwd,
357
- ignore: ["**/node_modules/**", "**/dist/**"],
358
- onlyDirectories: true,
359
- onlyFiles: false
360
- })).map((item) => {
361
- return item.endsWith(path.sep) ? item.slice(0, -1) : item;
362
- });
363
- }
364
- async function readManifest(packagePath) {
365
- const content = await readFile(path.join(packagePath, "package.json"), "utf8");
366
- const parsed = JSON.parse(content);
367
- packageManifestSchema.parse(parsed);
368
- return parsed;
369
- }
370
- //#endregion
371
- export { npm as n, NpmPackage as t };
@@ -1,2 +0,0 @@
1
- import { b as cargo, v as CargoPackage, y as CargoPluginOptions } from "../types-C1rEqeM4.js";
2
- export { CargoPackage, CargoPluginOptions, cargo };