@bonvoy/plugin-npm 0.1.0 → 0.1.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.
- package/dist/index.d.mts +10 -2
- package/dist/index.mjs +33 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { BonvoyPlugin } from "@bonvoy/core";
|
|
2
2
|
|
|
3
|
+
//#region src/operations.d.ts
|
|
4
|
+
interface NpmOperations {
|
|
5
|
+
publish(args: string[], cwd: string): Promise<void>;
|
|
6
|
+
view(pkg: string, version: string): Promise<string | null>;
|
|
7
|
+
}
|
|
8
|
+
declare const defaultNpmOperations: NpmOperations;
|
|
9
|
+
//#endregion
|
|
3
10
|
//#region src/npm.d.ts
|
|
4
11
|
interface NpmPluginConfig {
|
|
5
12
|
registry?: string;
|
|
@@ -11,7 +18,8 @@ interface NpmPluginConfig {
|
|
|
11
18
|
declare class NpmPlugin implements BonvoyPlugin {
|
|
12
19
|
name: string;
|
|
13
20
|
private config;
|
|
14
|
-
|
|
21
|
+
private ops;
|
|
22
|
+
constructor(config?: NpmPluginConfig, ops?: NpmOperations);
|
|
15
23
|
apply(bonvoy: {
|
|
16
24
|
hooks: {
|
|
17
25
|
publish: any;
|
|
@@ -22,5 +30,5 @@ declare class NpmPlugin implements BonvoyPlugin {
|
|
|
22
30
|
private isAlreadyPublished;
|
|
23
31
|
}
|
|
24
32
|
//#endregion
|
|
25
|
-
export { type NpmPluginConfig, NpmPlugin as default };
|
|
33
|
+
export { type NpmOperations, type NpmPluginConfig, NpmPlugin as default, defaultNpmOperations };
|
|
26
34
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
import { execa } from "execa";
|
|
2
2
|
|
|
3
|
+
//#region src/operations.ts
|
|
4
|
+
const defaultNpmOperations = {
|
|
5
|
+
async publish(args, cwd) {
|
|
6
|
+
await execa("npm", ["publish", ...args], {
|
|
7
|
+
cwd,
|
|
8
|
+
stdio: "inherit"
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
async view(pkg, version) {
|
|
12
|
+
try {
|
|
13
|
+
return (await execa("npm", [
|
|
14
|
+
"view",
|
|
15
|
+
`${pkg}@${version}`,
|
|
16
|
+
"version"
|
|
17
|
+
], { stdio: "pipe" })).stdout.trim() || null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
3
25
|
//#region src/npm.ts
|
|
4
26
|
var NpmPlugin = class {
|
|
5
27
|
name = "npm";
|
|
6
28
|
config;
|
|
7
|
-
|
|
29
|
+
ops;
|
|
30
|
+
constructor(config = {}, ops) {
|
|
8
31
|
this.config = {
|
|
9
32
|
registry: config.registry ?? "https://registry.npmjs.org",
|
|
10
33
|
access: config.access ?? "public",
|
|
@@ -12,9 +35,14 @@ var NpmPlugin = class {
|
|
|
12
35
|
skipExisting: config.skipExisting ?? true,
|
|
13
36
|
provenance: config.provenance ?? true
|
|
14
37
|
};
|
|
38
|
+
this.ops = ops ?? defaultNpmOperations;
|
|
15
39
|
}
|
|
16
40
|
apply(bonvoy) {
|
|
17
41
|
bonvoy.hooks.publish.tapPromise(this.name, async (context) => {
|
|
42
|
+
if (context.isDryRun) {
|
|
43
|
+
console.log("🔍 [dry-run] Would publish packages to npm");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
18
46
|
await this.publishPackages(context);
|
|
19
47
|
});
|
|
20
48
|
}
|
|
@@ -29,30 +57,19 @@ var NpmPlugin = class {
|
|
|
29
57
|
}
|
|
30
58
|
}
|
|
31
59
|
async publishPackage(pkg) {
|
|
32
|
-
const args = [
|
|
60
|
+
const args = [];
|
|
33
61
|
if (this.config.dryRun) args.push("--dry-run");
|
|
34
62
|
args.push("--access", this.config.access);
|
|
35
63
|
if (this.config.provenance) args.push("--provenance");
|
|
36
64
|
if (this.config.registry !== "https://registry.npmjs.org") args.push("--registry", this.config.registry);
|
|
37
65
|
console.log(`Publishing ${pkg.name}@${pkg.version}...`);
|
|
38
|
-
await
|
|
39
|
-
cwd: pkg.path,
|
|
40
|
-
stdio: "inherit"
|
|
41
|
-
});
|
|
66
|
+
await this.ops.publish(args, pkg.path);
|
|
42
67
|
}
|
|
43
68
|
async isAlreadyPublished(pkg) {
|
|
44
|
-
|
|
45
|
-
return (await execa("npm", [
|
|
46
|
-
"view",
|
|
47
|
-
`${pkg.name}@${pkg.version}`,
|
|
48
|
-
"version"
|
|
49
|
-
], { stdio: "pipe" })).stdout.trim() === pkg.version;
|
|
50
|
-
} catch {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
69
|
+
return await this.ops.view(pkg.name, pkg.version) === pkg.version;
|
|
53
70
|
}
|
|
54
71
|
};
|
|
55
72
|
|
|
56
73
|
//#endregion
|
|
57
|
-
export { NpmPlugin as default };
|
|
74
|
+
export { NpmPlugin as default, defaultNpmOperations };
|
|
58
75
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/npm.ts"],"sourcesContent":["import type { BonvoyPlugin, PublishContext } from '@bonvoy/core';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/operations.ts","../src/npm.ts"],"sourcesContent":["import { execa } from 'execa';\n\nexport interface NpmOperations {\n publish(args: string[], cwd: string): Promise<void>;\n view(pkg: string, version: string): Promise<string | null>;\n}\n\nexport const defaultNpmOperations: NpmOperations = {\n async publish(args, cwd) {\n await execa('npm', ['publish', ...args], { cwd, stdio: 'inherit' });\n },\n\n async view(pkg, version) {\n try {\n const result = await execa('npm', ['view', `${pkg}@${version}`, 'version'], {\n stdio: 'pipe',\n });\n return result.stdout.trim() || null;\n } catch {\n return null;\n }\n },\n};\n","import type { BonvoyPlugin, PublishContext } from '@bonvoy/core';\n\nimport { defaultNpmOperations, type NpmOperations } from './operations.js';\n\nexport interface NpmPluginConfig {\n registry?: string;\n access?: 'public' | 'restricted';\n dryRun?: boolean;\n skipExisting?: boolean;\n provenance?: boolean;\n}\n\nexport default class NpmPlugin implements BonvoyPlugin {\n name = 'npm';\n\n private config: Required<NpmPluginConfig>;\n private ops: NpmOperations;\n\n constructor(config: NpmPluginConfig = {}, ops?: NpmOperations) {\n this.config = {\n registry: config.registry ?? 'https://registry.npmjs.org',\n access: config.access ?? 'public',\n dryRun: config.dryRun ?? false,\n skipExisting: config.skipExisting ?? true,\n provenance: config.provenance ?? true,\n };\n this.ops = ops ?? defaultNpmOperations;\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Hook types are complex and vary by implementation\n apply(bonvoy: { hooks: { publish: any } }): void {\n bonvoy.hooks.publish.tapPromise(this.name, async (context: PublishContext) => {\n if (context.isDryRun) {\n console.log('🔍 [dry-run] Would publish packages to npm');\n return;\n }\n await this.publishPackages(context);\n });\n }\n\n private async publishPackages(context: PublishContext): Promise<void> {\n const { packages } = context;\n\n for (const pkg of packages) {\n if (this.config.skipExisting && (await this.isAlreadyPublished(pkg))) {\n console.log(`Skipping ${pkg.name}@${pkg.version} - already published`);\n continue;\n }\n\n await this.publishPackage(pkg);\n }\n }\n\n private async publishPackage(pkg: {\n name: string;\n version: string;\n path: string;\n }): Promise<void> {\n const args: string[] = [];\n\n if (this.config.dryRun) {\n args.push('--dry-run');\n }\n\n args.push('--access', this.config.access);\n\n if (this.config.provenance) {\n args.push('--provenance');\n }\n\n if (this.config.registry !== 'https://registry.npmjs.org') {\n args.push('--registry', this.config.registry);\n }\n\n console.log(`Publishing ${pkg.name}@${pkg.version}...`);\n\n await this.ops.publish(args, pkg.path);\n }\n\n private async isAlreadyPublished(pkg: { name: string; version: string }): Promise<boolean> {\n const version = await this.ops.view(pkg.name, pkg.version);\n return version === pkg.version;\n }\n}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AAO,OAAO;AAEzC,MAAI,KAAK,OAAO,WACd,MAAK,KAAK,eAAe;AAG3B,MAAI,KAAK,OAAO,aAAa,6BAC3B,MAAK,KAAK,cAAc,KAAK,OAAO,SAAS;AAG/C,UAAQ,IAAI,cAAc,IAAI,KAAK,GAAG,IAAI,QAAQ,KAAK;AAEvD,QAAM,KAAK,IAAI,QAAQ,MAAM,IAAI,KAAK;;CAGxC,MAAc,mBAAmB,KAA0D;AAEzF,SADgB,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,IAAI,QAAQ,KACvC,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonvoy/plugin-npm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "npm publishing plugin for bonvoy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bonvoy",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
".": "./dist/index.mjs",
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
31
|
-
"types": "./dist/index.d.mts",
|
|
32
31
|
"files": [
|
|
33
32
|
"dist"
|
|
34
33
|
],
|