@kb-labs/marketplace-npm 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/README.md +75 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @product-name/package-name
|
|
2
|
+
|
|
3
|
+
Baseline library package inside KB Labs Product Template.
|
|
4
|
+
|
|
5
|
+
## Vision & Purpose
|
|
6
|
+
|
|
7
|
+
**@product-name/package-name** is a minimal example library shipped with `kb-labs-product-template`.
|
|
8
|
+
It shows how a typical package is structured (source, tests, types) and is intended to be **renamed or removed** when creating a real product.
|
|
9
|
+
|
|
10
|
+
### Core Goals
|
|
11
|
+
|
|
12
|
+
- Demonstrate the standard KB Labs package layout (src/types/tests/build tooling)
|
|
13
|
+
- Provide a simple, testable function (`hello`) as a starting point
|
|
14
|
+
- Act as a safe playground for verifying DevKit configs (tsup, Vitest, ESLint)
|
|
15
|
+
|
|
16
|
+
## Package Status
|
|
17
|
+
|
|
18
|
+
- **Version**: 0.1.0
|
|
19
|
+
- **Stage**: Template / Example
|
|
20
|
+
- **Status**: Not for Production ⚠️
|
|
21
|
+
|
|
22
|
+
## Architecture
|
|
23
|
+
|
|
24
|
+
### Structure
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
packages/package-name/
|
|
28
|
+
├── src/
|
|
29
|
+
│ ├── index.ts # Public entrypoint
|
|
30
|
+
│ └── types/ # Shared types and re-exports
|
|
31
|
+
│ ├── types.ts
|
|
32
|
+
│ └── index.ts
|
|
33
|
+
├── index.test.ts # Vitest example
|
|
34
|
+
└── tsup.config.ts # Build configuration
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The default implementation is intentionally tiny:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
export const hello = (name = 'KB Labs') => `Hello, ${name}!`;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Dependencies
|
|
44
|
+
|
|
45
|
+
### Runtime
|
|
46
|
+
|
|
47
|
+
None by default — this is a pure TypeScript example.
|
|
48
|
+
|
|
49
|
+
### Development
|
|
50
|
+
|
|
51
|
+
- `@kb-labs/devkit`: shared TS/ESLint/Vitest/TSUP presets
|
|
52
|
+
- `tsup`, `vitest`, `tsx`, `typescript`
|
|
53
|
+
|
|
54
|
+
## Scripts
|
|
55
|
+
|
|
56
|
+
From the `kb-labs-product-template` root:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pnpm --filter @product-name/package-name build
|
|
60
|
+
pnpm --filter @product-name/package-name test
|
|
61
|
+
pnpm --filter @product-name/package-name lint
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## How to Adapt for a Real Package
|
|
65
|
+
|
|
66
|
+
When using the product template for your own project:
|
|
67
|
+
|
|
68
|
+
1. Rename the package in `package.json` (e.g. `@kb-labs/my-product-core`).
|
|
69
|
+
2. Replace the `hello` function with your actual public API.
|
|
70
|
+
3. Update tests in `index.test.ts` to cover real behaviour.
|
|
71
|
+
4. Adjust `types/` to expose the correct public types.
|
|
72
|
+
|
|
73
|
+
This package is meant as a scaffold only; don’t ship it as-is to production.
|
|
74
|
+
|
|
75
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PackageSource, ResolvedPackage, InstalledPackage } from '@kb-labs/marketplace-contracts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module @kb-labs/marketplace-npm/npm-source
|
|
5
|
+
* pnpm-based PackageSource implementation.
|
|
6
|
+
* This is the ONLY place in the marketplace codebase that calls pnpm.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare class NpmPackageSource implements PackageSource {
|
|
10
|
+
resolve(spec: string): Promise<ResolvedPackage>;
|
|
11
|
+
install(pkg: ResolvedPackage, root: string, opts?: {
|
|
12
|
+
dev?: boolean;
|
|
13
|
+
}): Promise<InstalledPackage>;
|
|
14
|
+
remove(packageId: string, root: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { NpmPackageSource };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs/promises';
|
|
4
|
+
import * as crypto from 'crypto';
|
|
5
|
+
|
|
6
|
+
// src/npm-source.ts
|
|
7
|
+
var NpmPackageSource = class {
|
|
8
|
+
async resolve(spec) {
|
|
9
|
+
const id = extractPackageName(spec);
|
|
10
|
+
if (!id) {
|
|
11
|
+
throw new Error(`Invalid package spec: ${spec}`);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
id,
|
|
15
|
+
version: extractVersion(spec) ?? "latest",
|
|
16
|
+
integrity: "",
|
|
17
|
+
// computed after install
|
|
18
|
+
source: "marketplace"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async install(pkg, root, opts) {
|
|
22
|
+
const spec = pkg.version === "latest" ? pkg.id : `${pkg.id}@${pkg.version}`;
|
|
23
|
+
const args = ["add", spec];
|
|
24
|
+
if (opts?.dev) {
|
|
25
|
+
args.push("--save-dev");
|
|
26
|
+
}
|
|
27
|
+
await execa("pnpm", args, { cwd: root, timeout: 5 * 60 * 1e3 });
|
|
28
|
+
const packageRoot = path.join(root, "node_modules", pkg.id);
|
|
29
|
+
let version = pkg.version;
|
|
30
|
+
try {
|
|
31
|
+
const pkgJson = JSON.parse(await fs.readFile(path.join(packageRoot, "package.json"), "utf-8"));
|
|
32
|
+
version = pkgJson.version ?? version;
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
const integrity = await computeIntegrity(packageRoot);
|
|
36
|
+
return {
|
|
37
|
+
id: pkg.id,
|
|
38
|
+
version,
|
|
39
|
+
packageRoot,
|
|
40
|
+
integrity
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async remove(packageId, root) {
|
|
44
|
+
await execa("pnpm", ["remove", packageId], { cwd: root, timeout: 2 * 60 * 1e3 });
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function extractPackageName(spec) {
|
|
48
|
+
if (!spec || spec.startsWith(".") || spec.startsWith("/")) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (spec.startsWith("@")) {
|
|
52
|
+
const slashIndex = spec.indexOf("/");
|
|
53
|
+
if (slashIndex === -1) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const versionSep2 = spec.lastIndexOf("@");
|
|
57
|
+
return versionSep2 > slashIndex ? spec.slice(0, versionSep2) : spec;
|
|
58
|
+
}
|
|
59
|
+
const versionSep = spec.indexOf("@");
|
|
60
|
+
return versionSep > 0 ? spec.slice(0, versionSep) : spec;
|
|
61
|
+
}
|
|
62
|
+
function extractVersion(spec) {
|
|
63
|
+
if (spec.startsWith("@")) {
|
|
64
|
+
const slashIndex = spec.indexOf("/");
|
|
65
|
+
const lastAt = spec.lastIndexOf("@");
|
|
66
|
+
return lastAt > slashIndex ? spec.slice(lastAt + 1) : null;
|
|
67
|
+
}
|
|
68
|
+
const atIndex = spec.indexOf("@");
|
|
69
|
+
return atIndex > 0 ? spec.slice(atIndex + 1) : null;
|
|
70
|
+
}
|
|
71
|
+
async function computeIntegrity(packageRoot) {
|
|
72
|
+
try {
|
|
73
|
+
const content = await fs.readFile(path.join(packageRoot, "package.json"));
|
|
74
|
+
const hash = crypto.createHash("sha256").update(content).digest("base64");
|
|
75
|
+
return `sha256-${hash}`;
|
|
76
|
+
} catch {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { NpmPackageSource };
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/npm-source.ts"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AAM,CAAA,EAAG,UAAU,CAAA,GAAI,IAAA;AACtD;AAEA,SAAS,eAAe,IAAA,EAA6B;AACnD,EAAA,IAAI,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,EAAG;AACxB,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,OAAA,CAAQ,GAAG,CAAA;AACnC,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,WAAA,CAAY,GAAG,CAAA;AACnC,IAAA,OAAO,SAAS,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,GAAI,IAAA;AAAA,EACxD;AACA,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,OAAA,CAAQ,GAAG,CAAA;AAChC,EAAA,OAAO,UAAU,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,OAAA,GAAU,CAAC,CAAA,GAAI,IAAA;AACjD;AAEA,eAAe,iBAAiB,WAAA,EAAsC;AACpE,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,MAAS,EAAA,CAAA,QAAA,CAAc,IAAA,CAAA,IAAA,CAAK,WAAA,EAAa,cAAc,CAAC,CAAA;AACxE,IAAA,MAAM,IAAA,GAAc,kBAAW,QAAQ,CAAA,CAAE,OAAO,OAAO,CAAA,CAAE,OAAO,QAAQ,CAAA;AACxE,IAAA,OAAO,UAAU,IAAI,CAAA,CAAA;AAAA,EACvB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["/**\n * @module @kb-labs/marketplace-npm/npm-source\n * pnpm-based PackageSource implementation.\n * This is the ONLY place in the marketplace codebase that calls pnpm.\n */\n\nimport { execa } from 'execa';\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport * as crypto from 'node:crypto';\nimport type {\n PackageSource,\n ResolvedPackage,\n InstalledPackage,\n} from '@kb-labs/marketplace-contracts';\n\nexport class NpmPackageSource implements PackageSource {\n async resolve(spec: string): Promise<ResolvedPackage> {\n const id = extractPackageName(spec);\n if (!id) {\n throw new Error(`Invalid package spec: ${spec}`);\n }\n\n return {\n id,\n version: extractVersion(spec) ?? 'latest',\n integrity: '', // computed after install\n source: 'marketplace',\n };\n }\n\n async install(\n pkg: ResolvedPackage,\n root: string,\n opts?: { dev?: boolean },\n ): Promise<InstalledPackage> {\n const spec = pkg.version === 'latest' ? pkg.id : `${pkg.id}@${pkg.version}`;\n const args = ['add', spec];\n if (opts?.dev) {args.push('--save-dev');}\n\n await execa('pnpm', args, { cwd: root, timeout: 5 * 60 * 1000 });\n\n const packageRoot = path.join(root, 'node_modules', pkg.id);\n\n // Read actual installed version\n let version = pkg.version;\n try {\n const pkgJson = JSON.parse(await fs.readFile(path.join(packageRoot, 'package.json'), 'utf-8'));\n version = pkgJson.version ?? version;\n } catch { /* use spec version */ }\n\n // Compute integrity\n const integrity = await computeIntegrity(packageRoot);\n\n return {\n id: pkg.id,\n version,\n packageRoot,\n integrity,\n };\n }\n\n async remove(packageId: string, root: string): Promise<void> {\n await execa('pnpm', ['remove', packageId], { cwd: root, timeout: 2 * 60 * 1000 });\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction extractPackageName(spec: string): string | null {\n if (!spec || spec.startsWith('.') || spec.startsWith('/')) {return null;}\n\n if (spec.startsWith('@')) {\n const slashIndex = spec.indexOf('/');\n if (slashIndex === -1) {return null;}\n const versionSep = spec.lastIndexOf('@');\n return versionSep > slashIndex ? spec.slice(0, versionSep) : spec;\n }\n\n const versionSep = spec.indexOf('@');\n return versionSep > 0 ? spec.slice(0, versionSep) : spec;\n}\n\nfunction extractVersion(spec: string): string | null {\n if (spec.startsWith('@')) {\n const slashIndex = spec.indexOf('/');\n const lastAt = spec.lastIndexOf('@');\n return lastAt > slashIndex ? spec.slice(lastAt + 1) : null;\n }\n const atIndex = spec.indexOf('@');\n return atIndex > 0 ? spec.slice(atIndex + 1) : null;\n}\n\nasync function computeIntegrity(packageRoot: string): Promise<string> {\n try {\n const content = await fs.readFile(path.join(packageRoot, 'package.json'));\n const hash = crypto.createHash('sha256').update(content).digest('base64');\n return `sha256-${hash}`;\n } catch {\n return '';\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kb-labs/marketplace-npm",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "npm/pnpm package source for KB Labs marketplace",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rimraf dist",
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
25
|
+
"lint": "eslint .",
|
|
26
|
+
"lint:fix": "eslint . --fix",
|
|
27
|
+
"test": "vitest run --passWithNoTests -c ../../vitest.config.ts",
|
|
28
|
+
"test:watch": "vitest -c ../../vitest.config.ts"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@kb-labs/marketplace-contracts": "^0.1.1",
|
|
32
|
+
"execa": "^9.5.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.5.0",
|
|
36
|
+
"vitest": "^3.2.4",
|
|
37
|
+
"@kb-labs/devkit": "link:../../../../infra/kb-labs-devkit"
|
|
38
|
+
}
|
|
39
|
+
}
|