tegami 1.0.0-beta.5 → 1.0.1

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,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 };
@@ -1,2 +0,0 @@
1
- import { n as cargo, t as CargoPackage } from "../cargo-hlZX2akE.js";
2
- export { CargoPackage, cargo };