@g3nomaly/core 0.3.0 → 0.3.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.
Files changed (243) hide show
  1. package/LICENSE +95 -0
  2. package/dist/cli/commands/add.d.ts +17 -0
  3. package/dist/cli/commands/add.d.ts.map +1 -0
  4. package/dist/cli/commands/add.js +76 -0
  5. package/dist/cli/commands/add.js.map +1 -0
  6. package/dist/cli/commands/installFromSources.d.ts +49 -0
  7. package/dist/cli/commands/installFromSources.d.ts.map +1 -0
  8. package/dist/cli/commands/installFromSources.js +138 -0
  9. package/dist/cli/commands/installFromSources.js.map +1 -0
  10. package/dist/cli/commands/ls.d.ts +16 -0
  11. package/dist/cli/commands/ls.d.ts.map +1 -0
  12. package/dist/cli/commands/ls.js +65 -0
  13. package/dist/cli/commands/ls.js.map +1 -0
  14. package/dist/cli/commands/remove.d.ts +13 -0
  15. package/dist/cli/commands/remove.d.ts.map +1 -0
  16. package/dist/cli/commands/remove.js +109 -0
  17. package/dist/cli/commands/remove.js.map +1 -0
  18. package/dist/cli/commands/sources.d.ts +45 -0
  19. package/dist/cli/commands/sources.d.ts.map +1 -0
  20. package/dist/cli/commands/sources.js +89 -0
  21. package/dist/cli/commands/sources.js.map +1 -0
  22. package/dist/cli/commands/update.d.ts +10 -0
  23. package/dist/cli/commands/update.d.ts.map +1 -0
  24. package/dist/cli/commands/update.js +92 -0
  25. package/dist/cli/commands/update.js.map +1 -0
  26. package/dist/cli/dialogue.d.ts +74 -0
  27. package/dist/cli/dialogue.d.ts.map +1 -0
  28. package/dist/cli/dialogue.js +117 -0
  29. package/dist/cli/dialogue.js.map +1 -0
  30. package/dist/cli/index.d.ts +19 -0
  31. package/dist/cli/index.d.ts.map +1 -0
  32. package/dist/cli/index.js +16 -0
  33. package/dist/cli/index.js.map +1 -0
  34. package/dist/cli/installDialogues.d.ts +15 -0
  35. package/dist/cli/installDialogues.d.ts.map +1 -0
  36. package/dist/cli/installDialogues.js +72 -0
  37. package/dist/cli/installDialogues.js.map +1 -0
  38. package/dist/cli/pick.d.ts +14 -0
  39. package/dist/cli/pick.d.ts.map +1 -0
  40. package/dist/cli/pick.js +35 -0
  41. package/dist/cli/pick.js.map +1 -0
  42. package/dist/cli/report.d.ts +34 -0
  43. package/dist/cli/report.d.ts.map +1 -0
  44. package/dist/cli/report.js +71 -0
  45. package/dist/cli/report.js.map +1 -0
  46. package/dist/cli/theme.d.ts +23 -0
  47. package/dist/cli/theme.d.ts.map +1 -0
  48. package/dist/cli/theme.js +25 -0
  49. package/dist/cli/theme.js.map +1 -0
  50. package/dist/cli/types.d.ts +45 -0
  51. package/dist/cli/types.d.ts.map +1 -0
  52. package/dist/cli/types.js +2 -0
  53. package/dist/cli/types.js.map +1 -0
  54. package/dist/config/config.d.ts +30 -0
  55. package/dist/config/config.d.ts.map +1 -0
  56. package/dist/config/config.js +77 -0
  57. package/dist/config/config.js.map +1 -0
  58. package/dist/config/index.d.ts +4 -0
  59. package/dist/config/index.d.ts.map +1 -0
  60. package/dist/config/index.js +3 -0
  61. package/dist/config/index.js.map +1 -0
  62. package/dist/config/types.d.ts +124 -0
  63. package/dist/config/types.d.ts.map +1 -0
  64. package/dist/config/types.js +61 -0
  65. package/dist/config/types.js.map +1 -0
  66. package/dist/hash/hash.d.ts +25 -0
  67. package/dist/hash/hash.d.ts.map +1 -0
  68. package/dist/hash/hash.js +44 -0
  69. package/dist/hash/hash.js.map +1 -0
  70. package/dist/hash/index.d.ts +2 -0
  71. package/dist/hash/index.d.ts.map +1 -0
  72. package/dist/hash/index.js +2 -0
  73. package/dist/hash/index.js.map +1 -0
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.js +2 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/installer/classify.d.ts +7 -0
  79. package/dist/installer/classify.d.ts.map +1 -0
  80. package/dist/installer/classify.js +47 -0
  81. package/dist/installer/classify.js.map +1 -0
  82. package/dist/installer/files.d.ts +15 -0
  83. package/dist/installer/files.d.ts.map +1 -0
  84. package/dist/installer/files.js +22 -0
  85. package/dist/installer/files.js.map +1 -0
  86. package/dist/installer/index.d.ts +19 -0
  87. package/dist/installer/index.d.ts.map +1 -0
  88. package/dist/installer/index.js +14 -0
  89. package/dist/installer/index.js.map +1 -0
  90. package/dist/installer/install.d.ts +13 -0
  91. package/dist/installer/install.d.ts.map +1 -0
  92. package/dist/installer/install.js +61 -0
  93. package/dist/installer/install.js.map +1 -0
  94. package/dist/installer/io.d.ts +4 -0
  95. package/dist/installer/io.d.ts.map +1 -0
  96. package/dist/installer/io.js +18 -0
  97. package/dist/installer/io.js.map +1 -0
  98. package/dist/installer/manifest.d.ts +59 -0
  99. package/dist/installer/manifest.d.ts.map +1 -0
  100. package/dist/installer/manifest.js +60 -0
  101. package/dist/installer/manifest.js.map +1 -0
  102. package/dist/installer/manifestSources.d.ts +21 -0
  103. package/dist/installer/manifestSources.d.ts.map +1 -0
  104. package/dist/installer/manifestSources.js +39 -0
  105. package/dist/installer/manifestSources.js.map +1 -0
  106. package/dist/installer/marketplace.d.ts +34 -0
  107. package/dist/installer/marketplace.d.ts.map +1 -0
  108. package/dist/installer/marketplace.js +64 -0
  109. package/dist/installer/marketplace.js.map +1 -0
  110. package/dist/installer/origin.d.ts +43 -0
  111. package/dist/installer/origin.d.ts.map +1 -0
  112. package/dist/installer/origin.js +22 -0
  113. package/dist/installer/origin.js.map +1 -0
  114. package/dist/installer/remove.d.ts +14 -0
  115. package/dist/installer/remove.d.ts.map +1 -0
  116. package/dist/installer/remove.js +37 -0
  117. package/dist/installer/remove.js.map +1 -0
  118. package/dist/installer/resolve.d.ts +78 -0
  119. package/dist/installer/resolve.d.ts.map +1 -0
  120. package/dist/installer/resolve.js +184 -0
  121. package/dist/installer/resolve.js.map +1 -0
  122. package/dist/installer/sourceRegistry.d.ts +59 -0
  123. package/dist/installer/sourceRegistry.d.ts.map +1 -0
  124. package/dist/installer/sourceRegistry.js +71 -0
  125. package/dist/installer/sourceRegistry.js.map +1 -0
  126. package/dist/installer/types.d.ts +80 -0
  127. package/dist/installer/types.d.ts.map +1 -0
  128. package/dist/installer/types.js +21 -0
  129. package/dist/installer/types.js.map +1 -0
  130. package/dist/registry/index.d.ts +12 -0
  131. package/dist/registry/index.d.ts.map +1 -0
  132. package/dist/registry/index.js +12 -0
  133. package/dist/registry/index.js.map +1 -0
  134. package/dist/registry/registry.handlers.d.ts +9 -0
  135. package/dist/registry/registry.handlers.d.ts.map +1 -0
  136. package/dist/registry/registry.handlers.js +13 -0
  137. package/dist/registry/registry.handlers.js.map +1 -0
  138. package/dist/registry/registry.io.d.ts +22 -0
  139. package/dist/registry/registry.io.d.ts.map +1 -0
  140. package/dist/registry/registry.io.js +78 -0
  141. package/dist/registry/registry.io.js.map +1 -0
  142. package/dist/registry/registry.mutations.d.ts +12 -0
  143. package/dist/registry/registry.mutations.d.ts.map +1 -0
  144. package/dist/registry/registry.mutations.js +22 -0
  145. package/dist/registry/registry.mutations.js.map +1 -0
  146. package/dist/registry/registry.selectors.d.ts +38 -0
  147. package/dist/registry/registry.selectors.d.ts.map +1 -0
  148. package/dist/registry/registry.selectors.js +61 -0
  149. package/dist/registry/registry.selectors.js.map +1 -0
  150. package/dist/registry/registry.store.d.ts +34 -0
  151. package/dist/registry/registry.store.d.ts.map +1 -0
  152. package/dist/registry/registry.store.js +27 -0
  153. package/dist/registry/registry.store.js.map +1 -0
  154. package/dist/registry/registry.template.d.ts +23 -0
  155. package/dist/registry/registry.template.d.ts.map +1 -0
  156. package/dist/registry/registry.template.js +63 -0
  157. package/dist/registry/registry.template.js.map +1 -0
  158. package/dist/registry/types.d.ts +33 -0
  159. package/dist/registry/types.d.ts.map +1 -0
  160. package/dist/registry/types.js +25 -0
  161. package/dist/registry/types.js.map +1 -0
  162. package/dist/security/index.d.ts +2 -0
  163. package/dist/security/index.d.ts.map +1 -0
  164. package/dist/security/index.js +2 -0
  165. package/dist/security/index.js.map +1 -0
  166. package/dist/security/securityParser.d.ts +14 -0
  167. package/dist/security/securityParser.d.ts.map +1 -0
  168. package/dist/security/securityParser.js +89 -0
  169. package/dist/security/securityParser.js.map +1 -0
  170. package/dist/security/securityWorker.d.ts +8 -0
  171. package/dist/security/securityWorker.d.ts.map +1 -0
  172. package/dist/security/securityWorker.js +158 -0
  173. package/dist/security/securityWorker.js.map +1 -0
  174. package/dist/sources/checkout.d.ts +14 -0
  175. package/dist/sources/checkout.d.ts.map +1 -0
  176. package/dist/sources/checkout.js +27 -0
  177. package/dist/sources/checkout.js.map +1 -0
  178. package/dist/sources/git.d.ts +9 -0
  179. package/dist/sources/git.d.ts.map +1 -0
  180. package/dist/sources/git.js +22 -0
  181. package/dist/sources/git.js.map +1 -0
  182. package/dist/sources/index.d.ts +5 -0
  183. package/dist/sources/index.d.ts.map +1 -0
  184. package/dist/sources/index.js +6 -0
  185. package/dist/sources/index.js.map +1 -0
  186. package/dist/sources/local.d.ts +10 -0
  187. package/dist/sources/local.d.ts.map +1 -0
  188. package/dist/sources/local.js +20 -0
  189. package/dist/sources/local.js.map +1 -0
  190. package/dist/sources/npm.d.ts +13 -0
  191. package/dist/sources/npm.d.ts.map +1 -0
  192. package/dist/sources/npm.js +128 -0
  193. package/dist/sources/npm.js.map +1 -0
  194. package/dist/sources/packageJson.d.ts +3 -0
  195. package/dist/sources/packageJson.d.ts.map +1 -0
  196. package/dist/sources/packageJson.js +13 -0
  197. package/dist/sources/packageJson.js.map +1 -0
  198. package/dist/sources/parse.d.ts +34 -0
  199. package/dist/sources/parse.d.ts.map +1 -0
  200. package/dist/sources/parse.js +92 -0
  201. package/dist/sources/parse.js.map +1 -0
  202. package/dist/sources/process.d.ts +18 -0
  203. package/dist/sources/process.d.ts.map +1 -0
  204. package/dist/sources/process.js +43 -0
  205. package/dist/sources/process.js.map +1 -0
  206. package/dist/sources/register.d.ts +16 -0
  207. package/dist/sources/register.d.ts.map +1 -0
  208. package/dist/sources/register.js +37 -0
  209. package/dist/sources/register.js.map +1 -0
  210. package/dist/sources/types.d.ts +73 -0
  211. package/dist/sources/types.d.ts.map +1 -0
  212. package/dist/sources/types.js +36 -0
  213. package/dist/sources/types.js.map +1 -0
  214. package/dist/utils/errors.d.ts +3 -0
  215. package/dist/utils/errors.d.ts.map +1 -0
  216. package/dist/utils/errors.js +6 -0
  217. package/dist/utils/errors.js.map +1 -0
  218. package/dist/utils/index.d.ts +7 -0
  219. package/dist/utils/index.d.ts.map +1 -0
  220. package/dist/utils/index.js +7 -0
  221. package/dist/utils/index.js.map +1 -0
  222. package/dist/utils/merge.d.ts +6 -0
  223. package/dist/utils/merge.d.ts.map +1 -0
  224. package/dist/utils/merge.js +21 -0
  225. package/dist/utils/merge.js.map +1 -0
  226. package/dist/utils/packageMeta.d.ts +12 -0
  227. package/dist/utils/packageMeta.d.ts.map +1 -0
  228. package/dist/utils/packageMeta.js +20 -0
  229. package/dist/utils/packageMeta.js.map +1 -0
  230. package/dist/utils/paths.d.ts +16 -0
  231. package/dist/utils/paths.d.ts.map +1 -0
  232. package/dist/utils/paths.js +40 -0
  233. package/dist/utils/paths.js.map +1 -0
  234. package/dist/utils/prompt.d.ts +3 -0
  235. package/dist/utils/prompt.d.ts.map +1 -0
  236. package/dist/utils/prompt.js +8 -0
  237. package/dist/utils/prompt.js.map +1 -0
  238. package/dist/utils/version.d.ts +9 -0
  239. package/dist/utils/version.d.ts.map +1 -0
  240. package/dist/utils/version.js +103 -0
  241. package/dist/utils/version.js.map +1 -0
  242. package/package.json +64 -3
  243. package/README.md +0 -3
@@ -0,0 +1,10 @@
1
+ import type { LocalSourceSpec, SourceCheckout } from "./types";
2
+ /**
3
+ * Resolves a local source to its folder. Nothing is copied, so `dispose` is a
4
+ * no-op and the version is the one in the folder's package.json, if any.
5
+ *
6
+ * @param projectRoot - Absolute path a relative `spec.path` is resolved against
7
+ * @throws when the folder does not exist
8
+ */
9
+ export declare function checkoutLocal(name: string, spec: LocalSourceSpec, projectRoot: string): SourceCheckout;
10
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/sources/local.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAMtG"}
@@ -0,0 +1,20 @@
1
+ // packages/core/src/sources/local.ts
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { expandHome } from "./parse";
5
+ import { readPackageVersion } from "./packageJson";
6
+ /**
7
+ * Resolves a local source to its folder. Nothing is copied, so `dispose` is a
8
+ * no-op and the version is the one in the folder's package.json, if any.
9
+ *
10
+ * @param projectRoot - Absolute path a relative `spec.path` is resolved against
11
+ * @throws when the folder does not exist
12
+ */
13
+ export function checkoutLocal(name, spec, projectRoot) {
14
+ const dir = path.resolve(projectRoot, expandHome(spec.path));
15
+ if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
16
+ throw new Error(`${dir} is not a folder`);
17
+ }
18
+ return { name, spec, dir, version: readPackageVersion(dir), dispose: () => { } };
19
+ }
20
+ //# sourceMappingURL=local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/sources/local.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,IAAqB,EAAE,WAAmB;IACpF,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,kBAAkB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;AAClF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { NpmSourceSpec, SourceCheckout } from "./types";
2
+ /**
3
+ * Resolves an npm source to a folder. A copy in `node_modules` at or above the
4
+ * project root is read in place when it satisfies `spec.version` (any copy
5
+ * does when no version is set). Otherwise the package tarball is downloaded
6
+ * from the registry in `npm_config_registry`, checked against its integrity
7
+ * hash and unpacked into a temporary folder.
8
+ *
9
+ * @param projectRoot - Absolute folder the `node_modules` lookup starts from
10
+ * @throws when the registry has no matching version or the download fails its integrity check
11
+ */
12
+ export declare function checkoutNpm(name: string, spec: NpmSourceSpec, projectRoot: string): Promise<SourceCheckout>;
13
+ //# sourceMappingURL=npm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm.d.ts","sourceRoot":"","sources":["../../src/sources/npm.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAqB7D;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAMjH"}
@@ -0,0 +1,128 @@
1
+ // packages/core/src/sources/npm.ts
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { z } from "zod";
5
+ import { readPackageVersion } from "./packageJson";
6
+ import { createTempDir, removeDir, runCommand } from "./process";
7
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org/";
8
+ const RegistryEnvSchema = z.object({
9
+ npm_config_registry: z.url().optional(),
10
+ NPM_CONFIG_REGISTRY: z.url().optional(),
11
+ });
12
+ const PackumentSchema = z.object({
13
+ "dist-tags": z.record(z.string(), z.string()).default({}),
14
+ versions: z.record(z.string(), z.object({
15
+ dist: z.object({
16
+ tarball: z.url(),
17
+ integrity: z.string().optional(),
18
+ }),
19
+ })).default({}),
20
+ });
21
+ /**
22
+ * Resolves an npm source to a folder. A copy in `node_modules` at or above the
23
+ * project root is read in place when it satisfies `spec.version` (any copy
24
+ * does when no version is set). Otherwise the package tarball is downloaded
25
+ * from the registry in `npm_config_registry`, checked against its integrity
26
+ * hash and unpacked into a temporary folder.
27
+ *
28
+ * @param projectRoot - Absolute folder the `node_modules` lookup starts from
29
+ * @throws when the registry has no matching version or the download fails its integrity check
30
+ */
31
+ export async function checkoutNpm(name, spec, projectRoot) {
32
+ const installed = findInstalled(projectRoot, spec.package);
33
+ if (installed !== null && accepts(installed.version, spec.version)) {
34
+ return { name, spec, dir: installed.dir, version: installed.version, dispose: () => { } };
35
+ }
36
+ return downloadFromRegistry(name, spec);
37
+ }
38
+ /** Real path and version of the nearest `node_modules/<pkg>` at or above `fromDir`, or `null`. */
39
+ function findInstalled(fromDir, pkg) {
40
+ let dir = fromDir;
41
+ while (true) {
42
+ const candidate = path.join(dir, "node_modules", pkg);
43
+ if (fs.existsSync(path.join(candidate, "package.json"))) {
44
+ const real = fs.realpathSync(candidate);
45
+ return { dir: real, version: readPackageVersion(real) };
46
+ }
47
+ const parent = path.dirname(dir);
48
+ if (parent === dir)
49
+ return null;
50
+ dir = parent;
51
+ }
52
+ }
53
+ /** Whether an installed version satisfies the requested range; no range accepts any copy. */
54
+ function accepts(installed, requested) {
55
+ if (requested === undefined)
56
+ return true;
57
+ return installed !== undefined && Bun.semver.satisfies(installed, requested);
58
+ }
59
+ /** Registry base URL from `npm_config_registry`, with a trailing slash; npmjs.org when unset. */
60
+ function registryUrl() {
61
+ const env = RegistryEnvSchema.parse(process.env);
62
+ const url = env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY ?? DEFAULT_REGISTRY;
63
+ return url.endsWith("/") ? url : `${url}/`;
64
+ }
65
+ /**
66
+ * Downloads the version `spec` asks for, checks it against its integrity hash
67
+ * and unpacks it into a temporary folder that `dispose` removes.
68
+ *
69
+ * @throws when the registry has no matching version, a download fails or the hash does not match
70
+ */
71
+ async function downloadFromRegistry(name, spec) {
72
+ const packumentUrl = registryUrl() + spec.package.replace("/", "%2f");
73
+ const response = await fetch(packumentUrl);
74
+ if (!response.ok)
75
+ throw new Error(`${spec.package} — registry answered ${response.status} for ${packumentUrl}`);
76
+ const packument = PackumentSchema.parse(await response.json());
77
+ const version = pickVersion(packument, spec.version);
78
+ if (version === undefined)
79
+ throw new Error(`${spec.package} has no version matching "${spec.version ?? "latest"}"`);
80
+ const dist = packument.versions[version]?.dist;
81
+ if (dist === undefined)
82
+ throw new Error(`${spec.package}@${version} is missing from the registry`);
83
+ const tarball = await fetch(dist.tarball);
84
+ if (!tarball.ok)
85
+ throw new Error(`${spec.package}@${version} — tarball download answered ${tarball.status}`);
86
+ const bytes = new Uint8Array(await tarball.arrayBuffer());
87
+ if (dist.integrity !== undefined)
88
+ verifyIntegrity(bytes, dist.integrity, `${spec.package}@${version}`);
89
+ const dir = createTempDir("npm");
90
+ try {
91
+ const archive = path.join(dir, "..", `${path.basename(dir)}.tgz`);
92
+ fs.writeFileSync(archive, bytes);
93
+ try {
94
+ await runCommand(["tar", "-xzf", archive, "-C", dir, "--strip-components=1"]);
95
+ }
96
+ finally {
97
+ fs.rmSync(archive, { force: true });
98
+ }
99
+ return { name, spec, dir, version, dispose: () => removeDir(dir) };
100
+ }
101
+ catch (error) {
102
+ removeDir(dir);
103
+ throw error;
104
+ }
105
+ }
106
+ /** The dist-tag, the exact version, or the highest version in the range; `latest` when nothing is asked. */
107
+ function pickVersion(packument, requested) {
108
+ const wanted = requested ?? "latest";
109
+ const tagged = packument["dist-tags"][wanted];
110
+ if (tagged !== undefined)
111
+ return tagged;
112
+ if (packument.versions[wanted] !== undefined)
113
+ return wanted;
114
+ return Object.keys(packument.versions)
115
+ .filter((v) => Bun.semver.satisfies(v, wanted))
116
+ .sort((a, b) => Bun.semver.order(b, a))[0];
117
+ }
118
+ /** Checks an SRI string such as `sha512-<base64>` against the downloaded bytes. */
119
+ function verifyIntegrity(bytes, integrity, label) {
120
+ const [algorithm, expected] = integrity.split(" ")[0]?.split("-", 2) ?? [];
121
+ if (algorithm !== "sha512" && algorithm !== "sha256" && algorithm !== "sha1") {
122
+ throw new Error(`${label} — unsupported integrity algorithm "${algorithm ?? ""}"`);
123
+ }
124
+ const actual = new Bun.CryptoHasher(algorithm).update(bytes).digest("base64");
125
+ if (actual !== expected)
126
+ throw new Error(`${label} — tarball does not match its integrity hash`);
127
+ }
128
+ //# sourceMappingURL=npm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm.js","sourceRoot":"","sources":["../../src/sources/npm.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGjE,MAAM,gBAAgB,GAAG,6BAA6B,CAAC;AAEvD,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,mBAAmB,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACvC,mBAAmB,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAA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E,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,mFAAmF;AACnF,SAAS,eAAe,CAAC,KAAiB,EAAE,SAAiB,EAAE,KAAa;IAC1E,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3E,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;QAC7E,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,uCAAuC,SAAS,IAAI,EAAE,GAAG,CAAC,CAAC;IACrF,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC9E,IAAI,MAAM,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,8CAA8C,CAAC,CAAC;AACnG,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** `version` from `<dir>/package.json`, or `undefined` when the file or the field is missing. */
2
+ export declare function readPackageVersion(dir: string): string | undefined;
3
+ //# sourceMappingURL=packageJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageJson.d.ts","sourceRoot":"","sources":["../../src/sources/packageJson.ts"],"names":[],"mappings":"AAOA,iGAAiG;AACjG,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIlE"}
@@ -0,0 +1,13 @@
1
+ // packages/core/src/sources/packageJson.ts
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { z } from "zod";
5
+ const PackageVersionSchema = z.object({ version: z.string().min(1).optional() });
6
+ /** `version` from `<dir>/package.json`, or `undefined` when the file or the field is missing. */
7
+ export function readPackageVersion(dir) {
8
+ const file = path.join(dir, "package.json");
9
+ if (!fs.existsSync(file))
10
+ return undefined;
11
+ return PackageVersionSchema.parse(JSON.parse(fs.readFileSync(file, "utf8"))).version;
12
+ }
13
+ //# sourceMappingURL=packageJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageJson.js","sourceRoot":"","sources":["../../src/sources/packageJson.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAEjF,iGAAiG;AACjG,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC5C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACvF,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { SourceSpec } from "./types";
2
+ /**
3
+ * Reads a source as typed on the command line.
4
+ *
5
+ * `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs
6
+ * are git repositories, `local:<path>` and paths starting with `.`, `/` or `~`
7
+ * are local folders, and `owner/repo` is a GitHub repository.
8
+ *
9
+ * @param input - e.g. `npm:@g3nomaly/g3n-skills@^1`, `git@github.com:me/skills.git`, `./my-skills`
10
+ * @param options - `ref` pins a git source to a branch or tag
11
+ * @throws when the input matches no form, or `ref` is given for a source that is not git
12
+ */
13
+ export declare function parseSourceSpec(input: string, options?: {
14
+ ref?: string;
15
+ }): SourceSpec;
16
+ /**
17
+ * Name a source registers under when none is given: the repository name for
18
+ * git, the package name without its scope for npm, the folder name for local.
19
+ *
20
+ * @returns a valid source name, e.g. `skills` for `git@github.com:g3nomaly/skills.git`
21
+ */
22
+ export declare function defaultSourceName(spec: SourceSpec): string;
23
+ /** `~/x` with the home folder in place of `~`; any other path unchanged. */
24
+ export declare function expandHome(localPath: string): string;
25
+ /**
26
+ * Stores a local path the way it is read back: relative to the project root,
27
+ * or absolute when the manifest is shared by every project (a user scope).
28
+ * Other kinds are returned unchanged.
29
+ *
30
+ * @param cwd - Absolute folder the path was typed in
31
+ * @param projectRoot - Absolute project root, or `null` to store the path absolute
32
+ */
33
+ export declare function anchorLocalSpec(spec: SourceSpec, cwd: string, projectRoot: string | null): SourceSpec;
34
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/sources/parse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAM1C;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,UAAU,CAOzF;AA4BD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAW1D;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAIrG"}
@@ -0,0 +1,92 @@
1
+ // packages/core/src/sources/parse.ts
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { GIT_URL, GitSourceSpecSchema, LocalSourceSpecSchema, NpmSourceSpecSchema } from "./types";
5
+ const NPM_PREFIX = "npm:";
6
+ const LOCAL_PREFIX = "local:";
7
+ const GITHUB_SHORTHAND = /^[\w.-]+\/[\w.-]+$/;
8
+ /**
9
+ * Reads a source as typed on the command line.
10
+ *
11
+ * `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs
12
+ * are git repositories, `local:<path>` and paths starting with `.`, `/` or `~`
13
+ * are local folders, and `owner/repo` is a GitHub repository.
14
+ *
15
+ * @param input - e.g. `npm:@g3nomaly/g3n-skills@^1`, `git@github.com:me/skills.git`, `./my-skills`
16
+ * @param options - `ref` pins a git source to a branch or tag
17
+ * @throws when the input matches no form, or `ref` is given for a source that is not git
18
+ */
19
+ export function parseSourceSpec(input, options = {}) {
20
+ const value = input.trim();
21
+ const spec = specFor(value, options.ref);
22
+ if (options.ref !== undefined && spec.kind !== "git") {
23
+ throw new Error(`--ref applies to git sources only, "${value}" is ${spec.kind}`);
24
+ }
25
+ return spec;
26
+ }
27
+ /** The spec for one trimmed input, by the first form it matches; `ref` goes onto git specs. */
28
+ function specFor(value, ref) {
29
+ if (value.startsWith(NPM_PREFIX))
30
+ return npmSpec(value.slice(NPM_PREFIX.length));
31
+ if (value.startsWith(LOCAL_PREFIX))
32
+ return LocalSourceSpecSchema.parse({ kind: "local", path: value.slice(LOCAL_PREFIX.length) });
33
+ if (GIT_URL.test(value))
34
+ return GitSourceSpecSchema.parse({ kind: "git", url: value, ref });
35
+ if (value.startsWith(".") || value.startsWith("~") || path.isAbsolute(value)) {
36
+ return LocalSourceSpecSchema.parse({ kind: "local", path: value });
37
+ }
38
+ if (value.startsWith("@"))
39
+ return npmSpec(value);
40
+ if (GITHUB_SHORTHAND.test(value)) {
41
+ return GitSourceSpecSchema.parse({ kind: "git", url: `https://github.com/${value.replace(/\.git$/, "")}.git`, ref });
42
+ }
43
+ throw new Error(`"${value}" is not a source: use a git URL, owner/repo, npm:<package>, @scope/package or a local path`);
44
+ }
45
+ /** `pkg`, `pkg@1.2.0`, `@scope/pkg@^1` — the version follows the last `@` that is not the scope's. */
46
+ function npmSpec(value) {
47
+ const at = value.lastIndexOf("@");
48
+ const hasVersion = at > 0;
49
+ return NpmSourceSpecSchema.parse({
50
+ kind: "npm",
51
+ package: hasVersion ? value.slice(0, at) : value,
52
+ version: hasVersion ? value.slice(at + 1) : undefined,
53
+ });
54
+ }
55
+ /**
56
+ * Name a source registers under when none is given: the repository name for
57
+ * git, the package name without its scope for npm, the folder name for local.
58
+ *
59
+ * @returns a valid source name, e.g. `skills` for `git@github.com:g3nomaly/skills.git`
60
+ */
61
+ export function defaultSourceName(spec) {
62
+ const raw = (() => {
63
+ switch (spec.kind) {
64
+ case "git": return spec.url.replace(/\/+$/, "").split(/[/:]/).pop()?.replace(/\.git$/, "") ?? "";
65
+ case "npm": return spec.package.split("/").pop() ?? spec.package;
66
+ case "local": return path.basename(path.resolve(spec.path));
67
+ }
68
+ })();
69
+ const name = raw.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "");
70
+ if (name === "")
71
+ throw new Error("could not derive a name for the source, pass one with --name");
72
+ return name;
73
+ }
74
+ /** `~/x` with the home folder in place of `~`; any other path unchanged. */
75
+ export function expandHome(localPath) {
76
+ return localPath.startsWith("~") ? path.join(os.homedir(), localPath.slice(1)) : localPath;
77
+ }
78
+ /**
79
+ * Stores a local path the way it is read back: relative to the project root,
80
+ * or absolute when the manifest is shared by every project (a user scope).
81
+ * Other kinds are returned unchanged.
82
+ *
83
+ * @param cwd - Absolute folder the path was typed in
84
+ * @param projectRoot - Absolute project root, or `null` to store the path absolute
85
+ */
86
+ export function anchorLocalSpec(spec, cwd, projectRoot) {
87
+ if (spec.kind !== "local")
88
+ return spec;
89
+ const absolute = path.resolve(cwd, expandHome(spec.path));
90
+ return { kind: "local", path: projectRoot === null ? absolute : path.relative(projectRoot, absolute) || "." };
91
+ }
92
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/sources/parse.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnG,MAAM,UAAU,GAAK,MAAM,CAAC;AAC5B,MAAM,YAAY,GAAG,QAAQ,CAAC;AAC9B,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,OAAO,GAAqB,EAAE;IAC3E,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+FAA+F;AAC/F,SAAS,OAAO,CAAC,KAAa,EAAE,GAAuB;IACrD,IAAI,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,IAAI,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC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C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,GAAW,EAAE,WAA0B;IACvF,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC;AAChH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Runs a command to completion and returns its trimmed stdout. Prompts are
3
+ * switched off for git, so a private repository fails instead of hanging.
4
+ *
5
+ * @throws with the command's stderr when it exits non-zero
6
+ */
7
+ export declare function runCommand(argv: string[], cwd?: string): Promise<string>;
8
+ /**
9
+ * Creates an empty temporary folder that is also removed at process exit, so
10
+ * a command that bails out early leaves nothing behind.
11
+ *
12
+ * @param label - Part of the folder name, e.g. `git` gives `/tmp/g3n-source-git-XXXXXX`
13
+ * @returns absolute path of the folder
14
+ */
15
+ export declare function createTempDir(label: string): string;
16
+ /** Deletes a folder and everything in it; a missing folder is not an error. */
17
+ export declare function removeDir(dir: string): void;
18
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/sources/process.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAc9E;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE3C"}
@@ -0,0 +1,43 @@
1
+ // packages/core/src/sources/process.ts
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ /**
6
+ * Runs a command to completion and returns its trimmed stdout. Prompts are
7
+ * switched off for git, so a private repository fails instead of hanging.
8
+ *
9
+ * @throws with the command's stderr when it exits non-zero
10
+ */
11
+ export async function runCommand(argv, cwd) {
12
+ const proc = Bun.spawn(argv, {
13
+ cwd,
14
+ stdout: "pipe",
15
+ stderr: "pipe",
16
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
17
+ });
18
+ const [stdout, stderr, exitCode] = await Promise.all([
19
+ new Response(proc.stdout).text(),
20
+ new Response(proc.stderr).text(),
21
+ proc.exited,
22
+ ]);
23
+ if (exitCode !== 0)
24
+ throw new Error(stderr.trim() !== "" ? stderr.trim() : `${argv.slice(0, 2).join(" ")} exited with ${exitCode}`);
25
+ return stdout.trim();
26
+ }
27
+ /**
28
+ * Creates an empty temporary folder that is also removed at process exit, so
29
+ * a command that bails out early leaves nothing behind.
30
+ *
31
+ * @param label - Part of the folder name, e.g. `git` gives `/tmp/g3n-source-git-XXXXXX`
32
+ * @returns absolute path of the folder
33
+ */
34
+ export function createTempDir(label) {
35
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), `g3n-source-${label}-`));
36
+ process.once("exit", () => removeDir(dir));
37
+ return dir;
38
+ }
39
+ /** Deletes a folder and everything in it; a missing folder is not an error. */
40
+ export function removeDir(dir) {
41
+ fs.rmSync(dir, { recursive: true, force: true });
42
+ }
43
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.js","sourceRo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AC,CAAC;IAC3E,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { RegisteredSource, SourceRecord, SourceSpec } from "./types";
2
+ /** Built-in sources first, then the registered ones, each group sorted by name. */
3
+ export declare function listSources(record: SourceRecord, builtins: SourceRecord): RegisteredSource[];
4
+ /**
5
+ * Returns `record` with `spec` registered under `name`.
6
+ *
7
+ * @throws when the name is invalid, belongs to a built-in source, or is already registered
8
+ */
9
+ export declare function addSource(record: SourceRecord, name: string, spec: SourceSpec, builtins: SourceRecord): SourceRecord;
10
+ /**
11
+ * Returns `record` without the source registered under `name`.
12
+ *
13
+ * @throws when `name` is a built-in source or is not registered
14
+ */
15
+ export declare function removeSource(record: SourceRecord, name: string, builtins: SourceRecord): SourceRecord;
16
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/sources/register.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1E,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,GAAG,gBAAgB,EAAE,CAM5F;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,GAAG,YAAY,CAKpH;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,YAAY,CAKrG"}
@@ -0,0 +1,37 @@
1
+ // packages/core/src/sources/register.ts
2
+ import { SourceNameSchema, SourceSpecSchema } from "./types";
3
+ /** Built-in sources first, then the registered ones, each group sorted by name. */
4
+ export function listSources(record, builtins) {
5
+ const sorted = (r) => Object.entries(r).sort(([a], [b]) => a.localeCompare(b));
6
+ return [
7
+ ...sorted(builtins).map(([name, spec]) => ({ name, spec, builtin: true })),
8
+ ...sorted(record).filter(([name]) => builtins[name] === undefined).map(([name, spec]) => ({ name, spec, builtin: false })),
9
+ ];
10
+ }
11
+ /**
12
+ * Returns `record` with `spec` registered under `name`.
13
+ *
14
+ * @throws when the name is invalid, belongs to a built-in source, or is already registered
15
+ */
16
+ export function addSource(record, name, spec, builtins) {
17
+ const valid = SourceNameSchema.parse(name);
18
+ if (builtins[valid] !== undefined)
19
+ throw new Error(`"${valid}" is a built-in source and is always registered`);
20
+ if (record[valid] !== undefined)
21
+ throw new Error(`a source named "${valid}" is already registered`);
22
+ return { ...record, [valid]: SourceSpecSchema.parse(spec) };
23
+ }
24
+ /**
25
+ * Returns `record` without the source registered under `name`.
26
+ *
27
+ * @throws when `name` is a built-in source or is not registered
28
+ */
29
+ export function removeSource(record, name, builtins) {
30
+ if (builtins[name] !== undefined)
31
+ throw new Error(`"${name}" is a built-in source and cannot be removed`);
32
+ if (record[name] === undefined)
33
+ throw new Error(`no source named "${name}" is registered`);
34
+ const { [name]: _removed, ...rest } = record;
35
+ return rest;
36
+ }
37
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/sources/register.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG7D,mFAAmF;AACnF,MAAM,UAAU,W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AI,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB,EAAE,IAAY,EAAE,QAAsB;IACrF,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,8CAA8C,CAAC,CAAC;IAC1G,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,iBAAiB,CAAC,CAAC;IAC3F,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { z } from "zod";
2
+ /** Clone URLs `git` accepts without a prompt: https://, ssh://, git://, file:// or scp-style `git@host:path`. */
3
+ export declare const GIT_URL: RegExp;
4
+ /** npm package names, scoped or not, e.g. `@g3nomaly/g3n-skills`. */
5
+ export declare const NPM_PACKAGE: RegExp;
6
+ /** Name a source is registered under, e.g. `g3n-skills`. */
7
+ export declare const SourceNameSchema: z.ZodString;
8
+ export declare const GitSourceSpecSchema: z.ZodObject<{
9
+ kind: z.ZodLiteral<"git">;
10
+ url: z.ZodString;
11
+ ref: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>;
13
+ export declare const NpmSourceSpecSchema: z.ZodObject<{
14
+ kind: z.ZodLiteral<"npm">;
15
+ package: z.ZodString;
16
+ version: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strip>;
18
+ export declare const LocalSourceSpecSchema: z.ZodObject<{
19
+ kind: z.ZodLiteral<"local">;
20
+ path: z.ZodString;
21
+ }, z.core.$strip>;
22
+ /** Where a source's files come from. */
23
+ export declare const SourceSpecSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ kind: z.ZodLiteral<"git">;
25
+ url: z.ZodString;
26
+ ref: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ kind: z.ZodLiteral<"npm">;
29
+ package: z.ZodString;
30
+ version: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strip>, z.ZodObject<{
32
+ kind: z.ZodLiteral<"local">;
33
+ path: z.ZodString;
34
+ }, z.core.$strip>], "kind">;
35
+ /** Registered sources by name, as an installer manifest stores them under its `sources` key. */
36
+ export declare const SourceRecordSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
37
+ kind: z.ZodLiteral<"git">;
38
+ url: z.ZodString;
39
+ ref: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ kind: z.ZodLiteral<"npm">;
42
+ package: z.ZodString;
43
+ version: z.ZodOptional<z.ZodString>;
44
+ }, z.core.$strip>, z.ZodObject<{
45
+ kind: z.ZodLiteral<"local">;
46
+ path: z.ZodString;
47
+ }, z.core.$strip>], "kind">>;
48
+ export type GitSourceSpec = z.infer<typeof GitSourceSpecSchema>;
49
+ export type NpmSourceSpec = z.infer<typeof NpmSourceSpecSchema>;
50
+ export type LocalSourceSpec = z.infer<typeof LocalSourceSpecSchema>;
51
+ export type SourceSpec = z.infer<typeof SourceSpecSchema>;
52
+ export type SourceRecord = z.infer<typeof SourceRecordSchema>;
53
+ /** One source an installer can read from, either built into its code or registered by the user. */
54
+ export interface RegisteredSource {
55
+ name: string;
56
+ spec: SourceSpec;
57
+ /** Built into the installer: always listed, never removable */
58
+ builtin: boolean;
59
+ }
60
+ /** A source resolved to a folder on disk. Call `dispose` once its files have been read. */
61
+ export interface SourceCheckout {
62
+ name: string;
63
+ spec: SourceSpec;
64
+ /** Absolute root of the source's files */
65
+ dir: string;
66
+ /** Commit the git clone resolved to; absent for npm and local sources */
67
+ commit?: string;
68
+ /** Package version for npm sources, or the `version` in a local source's package.json */
69
+ version?: string;
70
+ /** Removes a temporary checkout; a no-op for folders the checkout did not create */
71
+ dispose: () => void;
72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jB,IAAI,EAAM,UAAU,CAAC;IACrB,0CAA0C;IAC1C,GAAG,EAAO,MAAM,CAAC;IACjB,yEAAyE;IACzE,MAAM,CAAC,EAAG,MAAM,CAAC;IACjB,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,OAAO,EAAG,MAAM,IAAI,CAAC;CACtB"}
@@ -0,0 +1,36 @@
1
+ // packages/core/src/sources/types.ts
2
+ import { z } from "zod";
3
+ /** Clone URLs `git` accepts without a prompt: https://, ssh://, git://, file:// or scp-style `git@host:path`. */
4
+ export const GIT_URL = /^(https?:\/\/|ssh:\/\/|git:\/\/|file:\/\/|git@)\S+$/;
5
+ /** npm package names, scoped or not, e.g. `@g3nomaly/g3n-skills`. */
6
+ export const NPM_PACKAGE = /^(@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
7
+ /** Name a source is registered under, e.g. `g3n-skills`. */
8
+ export const SourceNameSchema = z
9
+ .string()
10
+ .regex(/^[a-z0-9][a-z0-9._-]*$/, "use lowercase letters, digits, `.`, `_` and `-`, starting with a letter or digit");
11
+ export const GitSourceSpecSchema = z.object({
12
+ kind: z.literal("git"),
13
+ url: z.string().regex(GIT_URL, "is not a git URL (https://, ssh://, git://, file:// or git@)"),
14
+ /** Branch or tag to check out; the default branch when absent */
15
+ ref: z.string().min(1).optional(),
16
+ });
17
+ export const NpmSourceSpecSchema = z.object({
18
+ kind: z.literal("npm"),
19
+ package: z.string().regex(NPM_PACKAGE, "is not an npm package name"),
20
+ /** Exact version, semver range or dist-tag; absent accepts any installed copy, else `latest` */
21
+ version: z.string().min(1).optional(),
22
+ });
23
+ export const LocalSourceSpecSchema = z.object({
24
+ kind: z.literal("local"),
25
+ /** Folder holding the source, absolute or relative to the project root */
26
+ path: z.string().min(1),
27
+ });
28
+ /** Where a source's files come from. */
29
+ export const SourceSpecSchema = z.discriminatedUnion("kind", [
30
+ GitSourceSpecSchema,
31
+ NpmSourceSpecSchema,
32
+ LocalSourceSpecSchema,
33
+ ]);
34
+ /** Registered sources by name, as an installer manifest stores them under its `sources` key. */
35
+ export const SourceRecordSchema = z.record(SourceNameSchema, SourceSpecSchema);
36
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sources/types.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,iHAAiH;AACjH,MAAM,CAAC,MAAM,OAAO,GAAG,qDAAqD,CAAC;AAE7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,WAAW,GAAG,oDAAoD,CAAC;AAEhF,4DAA4D;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,EAAE;KACR,KAAK,CAAC,wBAAwB,EAAE,kFAAkF,CAAC,CAAC;AAEvH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACtB,GAAG,EAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,8DAA8D,CAAC;IAC/F,iEAAiE;IACjE,GAAG,EAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACnC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACpE,gGAAgG;IAChG,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,0EAA0E;IAC1E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACxB,CAAC,CAAC;AAEH,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC3D,mBAAmB;IACnB,mBAAmB;IACnB,qBAAqB;CACtB,CAAC,CAAC;AAEH,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The message of a thrown value, whether or not it is an `Error`. */
2
+ export declare function errorMessage(error: unknown): string;
3
+ //# sourceMappingURL=errors.d.ts.map