@g3nomaly/core 0.3.0 → 0.3.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.
- package/LICENSE +95 -0
- package/dist/cli/commands/add.d.ts +37 -0
- package/dist/cli/commands/add.d.ts.map +1 -0
- package/dist/cli/commands/add.js +99 -0
- package/dist/cli/commands/add.js.map +1 -0
- package/dist/cli/commands/conflict.d.ts +52 -0
- package/dist/cli/commands/conflict.d.ts.map +1 -0
- package/dist/cli/commands/conflict.js +88 -0
- package/dist/cli/commands/conflict.js.map +1 -0
- package/dist/cli/commands/installFromSources.d.ts +78 -0
- package/dist/cli/commands/installFromSources.d.ts.map +1 -0
- package/dist/cli/commands/installFromSources.js +187 -0
- package/dist/cli/commands/installFromSources.js.map +1 -0
- package/dist/cli/commands/ls.d.ts +26 -0
- package/dist/cli/commands/ls.d.ts.map +1 -0
- package/dist/cli/commands/ls.js +85 -0
- package/dist/cli/commands/ls.js.map +1 -0
- package/dist/cli/commands/remove.d.ts +19 -0
- package/dist/cli/commands/remove.d.ts.map +1 -0
- package/dist/cli/commands/remove.js +123 -0
- package/dist/cli/commands/remove.js.map +1 -0
- package/dist/cli/commands/sources.d.ts +69 -0
- package/dist/cli/commands/sources.d.ts.map +1 -0
- package/dist/cli/commands/sources.js +103 -0
- package/dist/cli/commands/sources.js.map +1 -0
- package/dist/cli/commands/update.d.ts +17 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +110 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/dialogue.d.ts +126 -0
- package/dist/cli/dialogue.d.ts.map +1 -0
- package/dist/cli/dialogue.js +156 -0
- package/dist/cli/dialogue.js.map +1 -0
- package/dist/cli/index.d.ts +19 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +16 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/installDialogues.d.ts +23 -0
- package/dist/cli/installDialogues.d.ts.map +1 -0
- package/dist/cli/installDialogues.js +89 -0
- package/dist/cli/installDialogues.js.map +1 -0
- package/dist/cli/pick.d.ts +23 -0
- package/dist/cli/pick.d.ts.map +1 -0
- package/dist/cli/pick.js +44 -0
- package/dist/cli/pick.js.map +1 -0
- package/dist/cli/report.d.ts +58 -0
- package/dist/cli/report.d.ts.map +1 -0
- package/dist/cli/report.js +92 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/theme.d.ts +27 -0
- package/dist/cli/theme.d.ts.map +1 -0
- package/dist/cli/theme.js +29 -0
- package/dist/cli/theme.js.map +1 -0
- package/dist/cli/types.d.ts +96 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config/config.d.ts +55 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +107 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +182 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +51 -0
- package/dist/config/types.js.map +1 -0
- package/dist/hash/hash.d.ts +23 -0
- package/dist/hash/hash.d.ts.map +1 -0
- package/dist/hash/hash.js +43 -0
- package/dist/hash/hash.js.map +1 -0
- package/dist/hash/index.d.ts +2 -0
- package/dist/hash/index.d.ts.map +1 -0
- package/dist/hash/index.js +3 -0
- package/dist/hash/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/installer/classify.d.ts +33 -0
- package/dist/installer/classify.d.ts.map +1 -0
- package/dist/installer/classify.js +82 -0
- package/dist/installer/classify.js.map +1 -0
- package/dist/installer/files.d.ts +19 -0
- package/dist/installer/files.d.ts.map +1 -0
- package/dist/installer/files.js +23 -0
- package/dist/installer/files.js.map +1 -0
- package/dist/installer/index.d.ts +19 -0
- package/dist/installer/index.d.ts.map +1 -0
- package/dist/installer/index.js +14 -0
- package/dist/installer/index.js.map +1 -0
- package/dist/installer/install.d.ts +25 -0
- package/dist/installer/install.d.ts.map +1 -0
- package/dist/installer/install.js +74 -0
- package/dist/installer/install.js.map +1 -0
- package/dist/installer/io.d.ts +9 -0
- package/dist/installer/io.d.ts.map +1 -0
- package/dist/installer/io.js +23 -0
- package/dist/installer/io.js.map +1 -0
- package/dist/installer/manifest.d.ts +69 -0
- package/dist/installer/manifest.d.ts.map +1 -0
- package/dist/installer/manifest.js +70 -0
- package/dist/installer/manifest.js.map +1 -0
- package/dist/installer/manifestSources.d.ts +32 -0
- package/dist/installer/manifestSources.d.ts.map +1 -0
- package/dist/installer/manifestSources.js +50 -0
- package/dist/installer/manifestSources.js.map +1 -0
- package/dist/installer/marketplace.d.ts +46 -0
- package/dist/installer/marketplace.d.ts.map +1 -0
- package/dist/installer/marketplace.js +72 -0
- package/dist/installer/marketplace.js.map +1 -0
- package/dist/installer/origin.d.ts +59 -0
- package/dist/installer/origin.d.ts.map +1 -0
- package/dist/installer/origin.js +29 -0
- package/dist/installer/origin.js.map +1 -0
- package/dist/installer/remove.d.ts +26 -0
- package/dist/installer/remove.d.ts.map +1 -0
- package/dist/installer/remove.js +49 -0
- package/dist/installer/remove.js.map +1 -0
- package/dist/installer/resolve.d.ts +127 -0
- package/dist/installer/resolve.d.ts.map +1 -0
- package/dist/installer/resolve.js +251 -0
- package/dist/installer/resolve.js.map +1 -0
- package/dist/installer/sourceRegistry.d.ts +96 -0
- package/dist/installer/sourceRegistry.d.ts.map +1 -0
- package/dist/installer/sourceRegistry.js +86 -0
- package/dist/installer/sourceRegistry.js.map +1 -0
- package/dist/installer/types.d.ts +133 -0
- package/dist/installer/types.d.ts.map +1 -0
- package/dist/installer/types.js +31 -0
- package/dist/installer/types.js.map +1 -0
- package/dist/registry/index.d.ts +8 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +9 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/registry.handlers.d.ts +16 -0
- package/dist/registry/registry.handlers.d.ts.map +1 -0
- package/dist/registry/registry.handlers.js +13 -0
- package/dist/registry/registry.handlers.js.map +1 -0
- package/dist/registry/registry.io.d.ts +38 -0
- package/dist/registry/registry.io.d.ts.map +1 -0
- package/dist/registry/registry.io.js +101 -0
- package/dist/registry/registry.io.js.map +1 -0
- package/dist/registry/registry.mutations.d.ts +19 -0
- package/dist/registry/registry.mutations.d.ts.map +1 -0
- package/dist/registry/registry.mutations.js +29 -0
- package/dist/registry/registry.mutations.js.map +1 -0
- package/dist/registry/registry.selectors.d.ts +68 -0
- package/dist/registry/registry.selectors.d.ts.map +1 -0
- package/dist/registry/registry.selectors.js +91 -0
- package/dist/registry/registry.selectors.js.map +1 -0
- package/dist/registry/registry.store.d.ts +47 -0
- package/dist/registry/registry.store.d.ts.map +1 -0
- package/dist/registry/registry.store.js +36 -0
- package/dist/registry/registry.store.js.map +1 -0
- package/dist/registry/registry.template.d.ts +29 -0
- package/dist/registry/registry.template.d.ts.map +1 -0
- package/dist/registry/registry.template.js +70 -0
- package/dist/registry/registry.template.js.map +1 -0
- package/dist/registry/types.d.ts +47 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +35 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +3 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/securityParser.d.ts +15 -0
- package/dist/security/securityParser.d.ts.map +1 -0
- package/dist/security/securityParser.js +79 -0
- package/dist/security/securityParser.js.map +1 -0
- package/dist/security/securityWorker.d.ts +19 -0
- package/dist/security/securityWorker.d.ts.map +1 -0
- package/dist/security/securityWorker.js +137 -0
- package/dist/security/securityWorker.js.map +1 -0
- package/dist/sources/checkout.d.ts +20 -0
- package/dist/sources/checkout.d.ts.map +1 -0
- package/dist/sources/checkout.js +33 -0
- package/dist/sources/checkout.js.map +1 -0
- package/dist/sources/git.d.ts +11 -0
- package/dist/sources/git.d.ts.map +1 -0
- package/dist/sources/git.js +24 -0
- package/dist/sources/git.js.map +1 -0
- package/dist/sources/index.d.ts +5 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +6 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/local.d.ts +12 -0
- package/dist/sources/local.d.ts.map +1 -0
- package/dist/sources/local.js +22 -0
- package/dist/sources/local.js.map +1 -0
- package/dist/sources/npm.d.ts +16 -0
- package/dist/sources/npm.d.ts.map +1 -0
- package/dist/sources/npm.js +162 -0
- package/dist/sources/npm.js.map +1 -0
- package/dist/sources/packageJson.d.ts +3 -0
- package/dist/sources/packageJson.d.ts.map +1 -0
- package/dist/sources/packageJson.js +13 -0
- package/dist/sources/packageJson.js.map +1 -0
- package/dist/sources/parse.d.ts +42 -0
- package/dist/sources/parse.d.ts.map +1 -0
- package/dist/sources/parse.js +114 -0
- package/dist/sources/parse.js.map +1 -0
- package/dist/sources/process.d.ts +21 -0
- package/dist/sources/process.d.ts.map +1 -0
- package/dist/sources/process.js +46 -0
- package/dist/sources/process.js.map +1 -0
- package/dist/sources/register.d.ts +31 -0
- package/dist/sources/register.d.ts.map +1 -0
- package/dist/sources/register.js +52 -0
- package/dist/sources/register.js.map +1 -0
- package/dist/sources/types.d.ts +108 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +53 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +11 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge.d.ts +12 -0
- package/dist/utils/merge.d.ts.map +1 -0
- package/dist/utils/merge.js +28 -0
- package/dist/utils/merge.js.map +1 -0
- package/dist/utils/packageMeta.d.ts +26 -0
- package/dist/utils/packageMeta.d.ts.map +1 -0
- package/dist/utils/packageMeta.js +24 -0
- package/dist/utils/packageMeta.js.map +1 -0
- package/dist/utils/paths.d.ts +27 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +51 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/prompt.d.ts +8 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +13 -0
- package/dist/utils/prompt.js.map +1 -0
- package/dist/utils/version.d.ts +14 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +140 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +64 -3
- package/README.md +0 -3
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// packages/core/src/security/securityWorker.ts
|
|
3
|
+
const worker = self;
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Deep object sanitiser
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
const MAX_DEPTH = 20;
|
|
8
|
+
const MAX_KEYS = 1_000;
|
|
9
|
+
const MAX_STRLEN = 100_000;
|
|
10
|
+
let totalKeys = 0;
|
|
11
|
+
/**
|
|
12
|
+
* @brief Copies evaluated sandbox data into plain values, rejecting anything that can carry code, memory or stacks.
|
|
13
|
+
*
|
|
14
|
+
* Getters and setters are dropped without running them.
|
|
15
|
+
*
|
|
16
|
+
* @param value - Value to copy. Usually the result of the sandbox evaluation.
|
|
17
|
+
* @param depth - Current nesting depth, starting at 0.
|
|
18
|
+
* @returns Plain copy of `value`.
|
|
19
|
+
* @throws {Error} When the value nests too deep, has too many keys, is a function, symbol, RegExp, buffer, error,
|
|
20
|
+
* promise or non-plain object, or is a string that is too long or looks like a stack trace.
|
|
21
|
+
*/
|
|
22
|
+
function sanitise(value, depth = 0) {
|
|
23
|
+
if (depth > MAX_DEPTH) {
|
|
24
|
+
throw new Error(`Object exceeds maximum nesting depth (${MAX_DEPTH})`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "function") {
|
|
27
|
+
throw new Error("Functions are not allowed in meta objects");
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === "symbol") {
|
|
30
|
+
throw new Error("Symbols are not allowed in meta objects");
|
|
31
|
+
}
|
|
32
|
+
const tag = Object.prototype.toString.call(value);
|
|
33
|
+
if (tag === "[object RegExp]") {
|
|
34
|
+
throw new Error("RegExp values are not allowed (potential ReDoS)");
|
|
35
|
+
}
|
|
36
|
+
if (tag === "[object ArrayBuffer]" ||
|
|
37
|
+
tag === "[object SharedArrayBuffer]" ||
|
|
38
|
+
ArrayBuffer.isView(value)) {
|
|
39
|
+
throw new Error("ArrayBuffer / TypedArray values are not allowed");
|
|
40
|
+
}
|
|
41
|
+
if (tag === "[object Error]" || value instanceof Error) {
|
|
42
|
+
throw new Error("Error objects are not allowed (potential stack leakage)");
|
|
43
|
+
}
|
|
44
|
+
if (tag === "[object Promise]") {
|
|
45
|
+
throw new Error("Promise values are not allowed");
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
if (++totalKeys > MAX_KEYS)
|
|
49
|
+
throw new Error("Object exceeds maximum key/element count");
|
|
50
|
+
return value.map((item) => sanitise(item, depth + 1));
|
|
51
|
+
}
|
|
52
|
+
if (value !== null && typeof value === "object") {
|
|
53
|
+
if (tag !== "[object Object]") {
|
|
54
|
+
throw new Error(`Non-plain objects are not allowed (tag: ${tag})`);
|
|
55
|
+
}
|
|
56
|
+
const out = {};
|
|
57
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
58
|
+
for (const key of Object.keys(descriptors)) {
|
|
59
|
+
if (++totalKeys > MAX_KEYS)
|
|
60
|
+
throw new Error("Object exceeds maximum key/element count");
|
|
61
|
+
const desc = descriptors[key];
|
|
62
|
+
if (desc.get || desc.set) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
out[key] = sanitise(value[key], depth + 1);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
if (typeof value === "string") {
|
|
70
|
+
if (value.length > MAX_STRLEN) {
|
|
71
|
+
throw new Error(`String value exceeds maximum length (${MAX_STRLEN})`);
|
|
72
|
+
}
|
|
73
|
+
// A stack frame line starts with four spaces and "at ".
|
|
74
|
+
if (/\n {4}at /.test(value)) {
|
|
75
|
+
throw new Error("String value appears to contain a stack trace");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// Resource-limit stubs injected into the sandbox
|
|
82
|
+
//
|
|
83
|
+
// IIFEs run during object construction, before sanitise() sees the result, so the
|
|
84
|
+
// builtins they can allocate or match with are stubbed to throw at the call.
|
|
85
|
+
// Object literals cannot be stubbed; loops that build them are rejected by
|
|
86
|
+
// static analysis in securityParser.ts.
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
const SANDBOX_PREAMBLE = `
|
|
89
|
+
"use strict";
|
|
90
|
+
|
|
91
|
+
const process = undefined;
|
|
92
|
+
const global = undefined;
|
|
93
|
+
const globalThis = Object.create(null); // isolated dummy — writes succeed but go nowhere
|
|
94
|
+
const module = undefined;
|
|
95
|
+
const require = undefined;
|
|
96
|
+
const __dirname = undefined;
|
|
97
|
+
const __filename = undefined;
|
|
98
|
+
const importScripts = undefined;
|
|
99
|
+
const Function = undefined;
|
|
100
|
+
const Reflect = undefined;
|
|
101
|
+
const Proxy = undefined;
|
|
102
|
+
|
|
103
|
+
// Stub ArrayBuffer — catches IIFE allocation bombs before they run.
|
|
104
|
+
const ArrayBuffer = function() {
|
|
105
|
+
throw new RangeError("ArrayBuffer construction is not allowed in meta files");
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Stub RegExp constructor — catches IIFE regex bombs constructed via
|
|
109
|
+
// new RegExp(...) or RegExp(...). Regex *literals* are a different path
|
|
110
|
+
// (they don't call the RegExp constructor at parse time) but executing
|
|
111
|
+
// .match()/.exec() on them still goes through the engine's regex executor.
|
|
112
|
+
// The Worker timeout is the backstop for literal-based regex bombs.
|
|
113
|
+
const RegExp = function() {
|
|
114
|
+
throw new Error("RegExp construction is not allowed in meta files");
|
|
115
|
+
};
|
|
116
|
+
`;
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Message handler
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
worker.onmessage = (event) => {
|
|
121
|
+
const { objectString } = event.data;
|
|
122
|
+
try {
|
|
123
|
+
const sandbox = new Function(`
|
|
124
|
+
${SANDBOX_PREAMBLE}
|
|
125
|
+
return (${objectString});
|
|
126
|
+
`);
|
|
127
|
+
totalKeys = 0;
|
|
128
|
+
const rawData = sandbox();
|
|
129
|
+
const pureData = sanitise(rawData);
|
|
130
|
+
worker.postMessage({ success: true, data: pureData });
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const safeMessage = (error?.message ?? String(error)).split("\n")[0];
|
|
134
|
+
worker.postMessage({ success: false, error: safeMessage });
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=securityWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"securityWorker.js","sourceRoot":"","sources":["../../src/security/securityWorker.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,MAAM,MAAM,GAAG,IAA6C,CAAC;AAE7D,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E,MAAM,SAAS,GAAI,EAAE,CAAC;AACtB,MAAM,QAAQ,GAAK,KAAK,CAAC;AACzB,MAAM,UAAU,GAAG,OAAO,CAAC;AAC3B,IAAM,SAAS,GAAI,CAAC,CAAC;AAErB;;;;;;;;;;GAUG;AACH,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IACzC,IAAI,K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8E;AAE9E,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BxB,CAAC;AAEF,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E,MAAM,CAAC,SAAS,GAAG,CAAC,KAAmB,EAAE,EAAE;IACzC,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC;IAEpC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC;QACzB,gBAAgB;gBACR,YAAY;KACvB,CAAC,CAAC;QAEH,SAAS,GAAG,CAAC,CAAC;QACd,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEnC,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SourceCheckout, SourceSpec } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Resolves a source to a folder holding its files: a shallow clone for git, an installed or downloaded package for npm, the folder itself for local.
|
|
4
|
+
*
|
|
5
|
+
* @param source - Name and spec of the source to check out.
|
|
6
|
+
* @param projectRoot - Absolute project root. Local paths and the `node_modules` lookup start there.
|
|
7
|
+
* @returns Checkout of the source's folder.
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkoutSource(source: {
|
|
10
|
+
name: string;
|
|
11
|
+
spec: SourceSpec;
|
|
12
|
+
}, projectRoot: string): Promise<SourceCheckout>;
|
|
13
|
+
/**
|
|
14
|
+
* @brief Names where a source comes from, in one line.
|
|
15
|
+
*
|
|
16
|
+
* @param spec - Spec to describe.
|
|
17
|
+
* @returns Text such as `git https://github.com/me/skills.git#main`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function describeSource(spec: SourceSpec): string;
|
|
20
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/sources/checkout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAO7H;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAMvD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// packages/core/src/sources/checkout.ts
|
|
2
|
+
import { checkoutGit } from "./git";
|
|
3
|
+
import { checkoutLocal } from "./local";
|
|
4
|
+
import { checkoutNpm } from "./npm";
|
|
5
|
+
/**
|
|
6
|
+
* @brief Resolves a source to a folder holding its files: a shallow clone for git, an installed or downloaded package for npm, the folder itself for local.
|
|
7
|
+
*
|
|
8
|
+
* @param source - Name and spec of the source to check out.
|
|
9
|
+
* @param projectRoot - Absolute project root. Local paths and the `node_modules` lookup start there.
|
|
10
|
+
* @returns Checkout of the source's folder.
|
|
11
|
+
*/
|
|
12
|
+
export async function checkoutSource(source, projectRoot) {
|
|
13
|
+
const { name, spec } = source;
|
|
14
|
+
switch (spec.kind) {
|
|
15
|
+
case "git": return checkoutGit(name, spec);
|
|
16
|
+
case "npm": return checkoutNpm(name, spec, projectRoot);
|
|
17
|
+
case "local": return checkoutLocal(name, spec, projectRoot);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief Names where a source comes from, in one line.
|
|
22
|
+
*
|
|
23
|
+
* @param spec - Spec to describe.
|
|
24
|
+
* @returns Text such as `git https://github.com/me/skills.git#main`.
|
|
25
|
+
*/
|
|
26
|
+
export function describeSource(spec) {
|
|
27
|
+
switch (spec.kind) {
|
|
28
|
+
case "git": return `git ${spec.url}${spec.ref === undefined ? "" : `#${spec.ref}`}`;
|
|
29
|
+
case "npm": return `npm ${spec.package}${spec.version === undefined ? "" : `@${spec.version}`}`;
|
|
30
|
+
case "local": return `local ${spec.path}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/sources/checkout.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGpC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAA0C,EAAE,WAAmB;IAClG,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAC9B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,KAAK,EAAI,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7C,KAAK,KAAK,EAAI,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAC1D,KAAK,OAAO,EAAE,OAAO,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,KAAK,EAAI,OAAO,OAAO,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QACtF,KAAK,KAAK,EAAI,OAAO,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAClG,KAAK,OAAO,EAAE,OAAO,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GitSourceSpec, SourceCheckout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Shallow-clones a git source into a temporary folder, at its `ref` when set and at the default branch otherwise.
|
|
4
|
+
*
|
|
5
|
+
* @param name - Name of the source.
|
|
6
|
+
* @param spec - Git spec with the URL and optional ref.
|
|
7
|
+
* @returns Checkout with the commit the clone resolved to.
|
|
8
|
+
* @throws {Error} When the clone fails, e.g. an unknown ref or an unreachable host.
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkoutGit(name: string, spec: GitSourceSpec): Promise<SourceCheckout>;
|
|
11
|
+
//# sourceMappingURL=git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/sources/git.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAW5F"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// packages/core/src/sources/git.ts
|
|
2
|
+
import { createTempDir, removeDir, runCommand } from "./process";
|
|
3
|
+
/**
|
|
4
|
+
* @brief Shallow-clones a git source into a temporary folder, at its `ref` when set and at the default branch otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @param name - Name of the source.
|
|
7
|
+
* @param spec - Git spec with the URL and optional ref.
|
|
8
|
+
* @returns Checkout with the commit the clone resolved to.
|
|
9
|
+
* @throws {Error} When the clone fails, e.g. an unknown ref or an unreachable host.
|
|
10
|
+
*/
|
|
11
|
+
export async function checkoutGit(name, spec) {
|
|
12
|
+
const dir = createTempDir("git");
|
|
13
|
+
try {
|
|
14
|
+
const ref = spec.ref === undefined ? [] : ["--branch", spec.ref];
|
|
15
|
+
await runCommand(["git", "clone", "--depth", "1", "--quiet", ...ref, "--", spec.url, dir]);
|
|
16
|
+
const commit = await runCommand(["git", "rev-parse", "HEAD"], dir);
|
|
17
|
+
return { name, spec, dir, commit, dispose: () => removeDir(dir) };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
removeDir(dir);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/sources/git.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGjE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,IAAmB;IACjE,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjE,MAAM,UAAU,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC3F,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;QACnE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,GAAG,CAAC,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export { parseSourceSpec, defaultSourceName, anchorLocalSpec } from "./parse";
|
|
3
|
+
export { listSources, addSource, removeSource } from "./register";
|
|
4
|
+
export { checkoutSource, describeSource } from "./checkout";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sources/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// packages/core/src/sources/index.ts
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export { parseSourceSpec, defaultSourceName, anchorLocalSpec } from "./parse";
|
|
4
|
+
export { listSources, addSource, removeSource } from "./register";
|
|
5
|
+
export { checkoutSource, describeSource } from "./checkout";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sources/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LocalSourceSpec, SourceCheckout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Resolves a local source to its folder. Nothing is copied, so `dispose` is a no-op.
|
|
4
|
+
*
|
|
5
|
+
* @param name - Name of the source.
|
|
6
|
+
* @param spec - Local spec with the folder path.
|
|
7
|
+
* @param projectRoot - Absolute path a relative `spec.path` is resolved against.
|
|
8
|
+
* @returns Checkout whose version is read from the folder's package.json, if any.
|
|
9
|
+
* @throws {Error} When the folder does not exist.
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkoutLocal(name: string, spec: LocalSourceSpec, projectRoot: string): SourceCheckout;
|
|
12
|
+
//# 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;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAMtG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
* @brief Resolves a local source to its folder. Nothing is copied, so `dispose` is a no-op.
|
|
8
|
+
*
|
|
9
|
+
* @param name - Name of the source.
|
|
10
|
+
* @param spec - Local spec with the folder path.
|
|
11
|
+
* @param projectRoot - Absolute path a relative `spec.path` is resolved against.
|
|
12
|
+
* @returns Checkout whose version is read from the folder's package.json, if any.
|
|
13
|
+
* @throws {Error} When the folder does not exist.
|
|
14
|
+
*/
|
|
15
|
+
export function checkoutLocal(name, spec, projectRoot) {
|
|
16
|
+
const dir = path.resolve(projectRoot, expandHome(spec.path));
|
|
17
|
+
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
|
18
|
+
throw new Error(`${dir} is not a folder`);
|
|
19
|
+
}
|
|
20
|
+
return { name, spec, dir, version: readPackageVersion(dir), dispose: () => { } };
|
|
21
|
+
}
|
|
22
|
+
//# 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;;;;;;;;GAQG;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,16 @@
|
|
|
1
|
+
import type { NpmSourceSpec, SourceCheckout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Resolves an npm source to a folder.
|
|
4
|
+
*
|
|
5
|
+
* A copy in `node_modules` at or above the project root is read in place when it satisfies `spec.version`
|
|
6
|
+
* (any copy does when no version is set). Otherwise the package tarball is downloaded from the registry
|
|
7
|
+
* in `npm_config_registry`, checked against its integrity hash and unpacked into a temporary folder.
|
|
8
|
+
*
|
|
9
|
+
* @param name - Name of the source.
|
|
10
|
+
* @param spec - npm spec with the package name and optional version.
|
|
11
|
+
* @param projectRoot - Absolute folder the `node_modules` lookup starts from.
|
|
12
|
+
* @returns Checkout of the package folder.
|
|
13
|
+
* @throws {Error} When the registry has no matching version or the download fails its integrity check.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkoutNpm(name: string, spec: NpmSourceSpec, projectRoot: string): Promise<SourceCheckout>;
|
|
16
|
+
//# 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;AAsB7D;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAMjH"}
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
* @brief Resolves an npm source to a folder.
|
|
23
|
+
*
|
|
24
|
+
* A copy in `node_modules` at or above the project root is read in place when it satisfies `spec.version`
|
|
25
|
+
* (any copy does when no version is set). Otherwise the package tarball is downloaded from the registry
|
|
26
|
+
* in `npm_config_registry`, checked against its integrity hash and unpacked into a temporary folder.
|
|
27
|
+
*
|
|
28
|
+
* @param name - Name of the source.
|
|
29
|
+
* @param spec - npm spec with the package name and optional version.
|
|
30
|
+
* @param projectRoot - Absolute folder the `node_modules` lookup starts from.
|
|
31
|
+
* @returns Checkout of the package folder.
|
|
32
|
+
* @throws {Error} When the registry has no matching version or the download fails its integrity check.
|
|
33
|
+
*/
|
|
34
|
+
export async function checkoutNpm(name, spec, projectRoot) {
|
|
35
|
+
const installed = findInstalled(projectRoot, spec.package);
|
|
36
|
+
if (installed !== null && accepts(installed.version, spec.version)) {
|
|
37
|
+
return { name, spec, dir: installed.dir, version: installed.version, dispose: () => { } };
|
|
38
|
+
}
|
|
39
|
+
return downloadFromRegistry(name, spec);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @brief Finds the nearest installed copy of a package, at or above a folder.
|
|
43
|
+
*
|
|
44
|
+
* @param fromDir - Absolute folder the search starts from.
|
|
45
|
+
* @param pkg - Package name, e.g. `@g3nomaly/g3n-skills`.
|
|
46
|
+
* @returns Real path and version of `node_modules/<pkg>`, or `null` when no copy exists.
|
|
47
|
+
*/
|
|
48
|
+
function findInstalled(fromDir, pkg) {
|
|
49
|
+
let dir = fromDir;
|
|
50
|
+
while (true) {
|
|
51
|
+
const candidate = path.join(dir, "node_modules", pkg);
|
|
52
|
+
if (fs.existsSync(path.join(candidate, "package.json"))) {
|
|
53
|
+
const real = fs.realpathSync(candidate);
|
|
54
|
+
return { dir: real, version: readPackageVersion(real) };
|
|
55
|
+
}
|
|
56
|
+
const parent = path.dirname(dir);
|
|
57
|
+
if (parent === dir)
|
|
58
|
+
return null;
|
|
59
|
+
dir = parent;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @brief Checks whether an installed version satisfies the requested range.
|
|
64
|
+
*
|
|
65
|
+
* @param installed - Installed version, `undefined` when unknown.
|
|
66
|
+
* @param requested - Semver range or dist-tag. `undefined` accepts any copy.
|
|
67
|
+
* @returns `true` when the installed copy can be used.
|
|
68
|
+
*/
|
|
69
|
+
function accepts(installed, requested) {
|
|
70
|
+
if (requested === undefined)
|
|
71
|
+
return true;
|
|
72
|
+
return installed !== undefined && Bun.semver.satisfies(installed, requested);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @brief Reads the registry base URL from the environment.
|
|
76
|
+
*
|
|
77
|
+
* @returns The URL from `npm_config_registry`, with a trailing slash. npmjs.org when unset.
|
|
78
|
+
*/
|
|
79
|
+
function registryUrl() {
|
|
80
|
+
const env = RegistryEnvSchema.parse(process.env);
|
|
81
|
+
const url = env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY ?? DEFAULT_REGISTRY;
|
|
82
|
+
return url.endsWith("/") ? url : `${url}/`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @brief Downloads the version `spec` asks for, checks it against its integrity hash and unpacks it into a temporary folder.
|
|
86
|
+
*
|
|
87
|
+
* @param name - Name of the source.
|
|
88
|
+
* @param spec - npm spec with the package name and optional version.
|
|
89
|
+
* @returns Checkout whose `dispose` removes the temporary folder.
|
|
90
|
+
* @throws {Error} When the registry has no matching version, a download fails or the hash does not match.
|
|
91
|
+
*/
|
|
92
|
+
async function downloadFromRegistry(name, spec) {
|
|
93
|
+
const packumentUrl = registryUrl() + spec.package.replace("/", "%2f");
|
|
94
|
+
const response = await fetch(packumentUrl);
|
|
95
|
+
if (!response.ok)
|
|
96
|
+
throw new Error(`${spec.package} — registry answered ${response.status} for ${packumentUrl}`);
|
|
97
|
+
const packument = PackumentSchema.parse(await response.json());
|
|
98
|
+
const version = pickVersion(packument, spec.version);
|
|
99
|
+
if (version === undefined)
|
|
100
|
+
throw new Error(`${spec.package} has no version matching "${spec.version ?? "latest"}"`);
|
|
101
|
+
const dist = packument.versions[version]?.dist;
|
|
102
|
+
if (dist === undefined)
|
|
103
|
+
throw new Error(`${spec.package}@${version} is missing from the registry`);
|
|
104
|
+
const tarball = await fetch(dist.tarball);
|
|
105
|
+
if (!tarball.ok)
|
|
106
|
+
throw new Error(`${spec.package}@${version} — tarball download answered ${tarball.status}`);
|
|
107
|
+
const bytes = new Uint8Array(await tarball.arrayBuffer());
|
|
108
|
+
if (dist.integrity !== undefined)
|
|
109
|
+
verifyIntegrity(bytes, dist.integrity, `${spec.package}@${version}`);
|
|
110
|
+
const dir = createTempDir("npm");
|
|
111
|
+
try {
|
|
112
|
+
const archive = path.join(dir, "..", `${path.basename(dir)}.tgz`);
|
|
113
|
+
fs.writeFileSync(archive, bytes);
|
|
114
|
+
try {
|
|
115
|
+
await runCommand(["tar", "-xzf", archive, "-C", dir, "--strip-components=1"]);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
fs.rmSync(archive, { force: true });
|
|
119
|
+
}
|
|
120
|
+
return { name, spec, dir, version, dispose: () => removeDir(dir) };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
removeDir(dir);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @brief Picks the version to download: a dist-tag, an exact version, or the highest version in a range.
|
|
129
|
+
*
|
|
130
|
+
* @param packument - Registry metadata of the package.
|
|
131
|
+
* @param requested - Dist-tag, exact version or semver range. `latest` when `undefined`.
|
|
132
|
+
* @returns The chosen version, or `undefined` when none matches.
|
|
133
|
+
*/
|
|
134
|
+
function pickVersion(packument, requested) {
|
|
135
|
+
const wanted = requested ?? "latest";
|
|
136
|
+
const tagged = packument["dist-tags"][wanted];
|
|
137
|
+
if (tagged !== undefined)
|
|
138
|
+
return tagged;
|
|
139
|
+
if (packument.versions[wanted] !== undefined)
|
|
140
|
+
return wanted;
|
|
141
|
+
return Object.keys(packument.versions)
|
|
142
|
+
.filter((v) => Bun.semver.satisfies(v, wanted))
|
|
143
|
+
.sort((a, b) => Bun.semver.order(b, a))[0];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @brief Checks downloaded bytes against an SRI integrity string.
|
|
147
|
+
*
|
|
148
|
+
* @param bytes - Downloaded tarball.
|
|
149
|
+
* @param integrity - SRI string such as `sha512-<base64>`.
|
|
150
|
+
* @param label - Package and version, used in error messages, e.g. `pkg@1.0.0`.
|
|
151
|
+
* @throws {Error} When the algorithm is unsupported or the hash does not match.
|
|
152
|
+
*/
|
|
153
|
+
function verifyIntegrity(bytes, integrity, label) {
|
|
154
|
+
const [algorithm, expected] = integrity.split(" ")[0]?.split("-", 2) ?? [];
|
|
155
|
+
if (algorithm !== "sha512" && algorithm !== "sha256" && algorithm !== "sha1") {
|
|
156
|
+
throw new Error(`${label} — unsupported integrity algorithm "${algorithm ?? ""}"`);
|
|
157
|
+
}
|
|
158
|
+
const actual = new Bun.CryptoHasher(algorithm).update(bytes).digest("base64");
|
|
159
|
+
if (actual !== expected)
|
|
160
|
+
throw new Error(`${label} — tarball does not match its integrity hash`);
|
|
161
|
+
}
|
|
162
|
+
//# 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,EAAE;CACxC,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IACzD,QAAQ,EAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC;QACzC,IAAI,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C,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 @@
|
|
|
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,42 @@
|
|
|
1
|
+
import type { SourceSpec } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Reads a source as typed on the command line.
|
|
4
|
+
*
|
|
5
|
+
* `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs are git repositories,
|
|
6
|
+
* `local:<path>` and paths starting with `.`, `/` or `~` are local folders, and `owner/repo` is a GitHub repository.
|
|
7
|
+
*
|
|
8
|
+
* @param input - Text as typed, e.g. `npm:@g3nomaly/g3n-skills@^1`, `git@github.com:me/skills.git`, `./my-skills`.
|
|
9
|
+
* @param options - `ref` pins a git source to a branch or tag.
|
|
10
|
+
* @returns The spec for the first form the input matches.
|
|
11
|
+
* @throws {Error} 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
|
+
* @brief Derives the name a source registers under when none is given: the repository name for git,
|
|
18
|
+
* the package name without its scope for npm, the folder name for local.
|
|
19
|
+
*
|
|
20
|
+
* @param spec - Spec to derive the name from.
|
|
21
|
+
* @returns A valid source name, e.g. `skills` for `git@github.com:g3nomaly/skills.git`.
|
|
22
|
+
* @throws {Error} When no name can be derived. The caller must then ask for one.
|
|
23
|
+
*/
|
|
24
|
+
export declare function defaultSourceName(spec: SourceSpec): string;
|
|
25
|
+
/**
|
|
26
|
+
* @brief Replaces a leading `~` with the home folder.
|
|
27
|
+
*
|
|
28
|
+
* @param localPath - Path that may start with `~`.
|
|
29
|
+
* @returns The path with the home folder in place of `~`. Any other path is returned unchanged.
|
|
30
|
+
*/
|
|
31
|
+
export declare function expandHome(localPath: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* @brief Stores a local path the way it is read back: relative to the project root, or absolute when the
|
|
34
|
+
* manifest is shared by every project (a user scope). Other kinds are returned unchanged.
|
|
35
|
+
*
|
|
36
|
+
* @param spec - Spec to anchor. Only `local` specs change.
|
|
37
|
+
* @param cwd - Absolute folder the path was typed in.
|
|
38
|
+
* @param projectRoot - Absolute project root, or `null` to store the path absolute.
|
|
39
|
+
* @returns The spec with its path anchored.
|
|
40
|
+
*/
|
|
41
|
+
export declare function anchorLocalSpec(spec: SourceSpec, cwd: string, projectRoot: string | null): SourceSpec;
|
|
42
|
+
//# 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;AA0CD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAW1D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAIrG"}
|