@g3nomaly/core 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -0
- package/dist/cli/commands/add.d.ts +24 -4
- package/dist/cli/commands/add.d.ts.map +1 -1
- package/dist/cli/commands/add.js +37 -14
- package/dist/cli/commands/add.js.map +1 -1
- 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 +42 -13
- package/dist/cli/commands/installFromSources.d.ts.map +1 -1
- package/dist/cli/commands/installFromSources.js +68 -19
- package/dist/cli/commands/installFromSources.js.map +1 -1
- package/dist/cli/commands/ls.d.ts +13 -3
- package/dist/cli/commands/ls.d.ts.map +1 -1
- package/dist/cli/commands/ls.js +26 -6
- package/dist/cli/commands/ls.js.map +1 -1
- package/dist/cli/commands/remove.d.ts +7 -1
- package/dist/cli/commands/remove.d.ts.map +1 -1
- package/dist/cli/commands/remove.js +15 -1
- package/dist/cli/commands/remove.js.map +1 -1
- package/dist/cli/commands/sources.d.ts +34 -10
- package/dist/cli/commands/sources.d.ts.map +1 -1
- package/dist/cli/commands/sources.js +17 -3
- package/dist/cli/commands/sources.js.map +1 -1
- package/dist/cli/commands/update.d.ts +11 -4
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +32 -14
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/dialogue.d.ts +65 -13
- package/dist/cli/dialogue.d.ts.map +1 -1
- package/dist/cli/dialogue.js +46 -7
- package/dist/cli/dialogue.js.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/installDialogues.d.ts +11 -3
- package/dist/cli/installDialogues.d.ts.map +1 -1
- package/dist/cli/installDialogues.js +22 -5
- package/dist/cli/installDialogues.js.map +1 -1
- package/dist/cli/pick.d.ts +11 -2
- package/dist/cli/pick.d.ts.map +1 -1
- package/dist/cli/pick.js +11 -2
- package/dist/cli/pick.js.map +1 -1
- package/dist/cli/report.d.ts +32 -8
- package/dist/cli/report.d.ts.map +1 -1
- package/dist/cli/report.js +26 -5
- package/dist/cli/report.js.map +1 -1
- package/dist/cli/theme.d.ts +4 -0
- package/dist/cli/theme.d.ts.map +1 -1
- package/dist/cli/theme.js +4 -0
- package/dist/cli/theme.js.map +1 -1
- package/dist/cli/types.d.ts +56 -5
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/config/config.d.ts +32 -7
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +37 -7
- package/dist/config/config.js.map +1 -1
- package/dist/config/types.d.ts +58 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +0 -10
- package/dist/config/types.js.map +1 -1
- package/dist/hash/hash.d.ts +6 -8
- package/dist/hash/hash.d.ts.map +1 -1
- package/dist/hash/hash.js +7 -8
- package/dist/hash/hash.js.map +1 -1
- package/dist/hash/index.d.ts.map +1 -1
- package/dist/hash/index.js +1 -0
- package/dist/hash/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/installer/classify.d.ts +27 -1
- package/dist/installer/classify.d.ts.map +1 -1
- package/dist/installer/classify.js +36 -1
- package/dist/installer/classify.js.map +1 -1
- package/dist/installer/files.d.ts +10 -6
- package/dist/installer/files.d.ts.map +1 -1
- package/dist/installer/files.js +4 -3
- package/dist/installer/files.js.map +1 -1
- package/dist/installer/index.d.ts +1 -1
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +1 -1
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/install.d.ts +18 -6
- package/dist/installer/install.d.ts.map +1 -1
- package/dist/installer/install.js +20 -7
- package/dist/installer/install.js.map +1 -1
- package/dist/installer/io.d.ts +6 -1
- package/dist/installer/io.d.ts.map +1 -1
- package/dist/installer/io.js +6 -1
- package/dist/installer/io.js.map +1 -1
- package/dist/installer/manifest.d.ts +29 -19
- package/dist/installer/manifest.d.ts.map +1 -1
- package/dist/installer/manifest.js +20 -10
- package/dist/installer/manifest.js.map +1 -1
- package/dist/installer/manifestSources.d.ts +18 -7
- package/dist/installer/manifestSources.d.ts.map +1 -1
- package/dist/installer/manifestSources.js +18 -7
- package/dist/installer/manifestSources.js.map +1 -1
- package/dist/installer/marketplace.d.ts +24 -12
- package/dist/installer/marketplace.d.ts.map +1 -1
- package/dist/installer/marketplace.js +18 -10
- package/dist/installer/marketplace.js.map +1 -1
- package/dist/installer/origin.d.ts +23 -7
- package/dist/installer/origin.d.ts.map +1 -1
- package/dist/installer/origin.js +14 -7
- package/dist/installer/origin.js.map +1 -1
- package/dist/installer/remove.d.ts +17 -5
- package/dist/installer/remove.d.ts.map +1 -1
- package/dist/installer/remove.js +17 -5
- package/dist/installer/remove.js.map +1 -1
- package/dist/installer/resolve.d.ts +80 -31
- package/dist/installer/resolve.d.ts.map +1 -1
- package/dist/installer/resolve.js +96 -29
- package/dist/installer/resolve.js.map +1 -1
- package/dist/installer/sourceRegistry.d.ts +59 -22
- package/dist/installer/sourceRegistry.d.ts.map +1 -1
- package/dist/installer/sourceRegistry.js +25 -10
- package/dist/installer/sourceRegistry.js.map +1 -1
- package/dist/installer/types.d.ts +72 -19
- package/dist/installer/types.d.ts.map +1 -1
- package/dist/installer/types.js +18 -8
- package/dist/installer/types.js.map +1 -1
- package/dist/registry/index.d.ts +0 -4
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -4
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/registry.handlers.d.ts +7 -0
- package/dist/registry/registry.handlers.d.ts.map +1 -1
- package/dist/registry/registry.handlers.js.map +1 -1
- package/dist/registry/registry.io.d.ts +23 -7
- package/dist/registry/registry.io.d.ts.map +1 -1
- package/dist/registry/registry.io.js +37 -14
- package/dist/registry/registry.io.js.map +1 -1
- package/dist/registry/registry.mutations.d.ts +10 -3
- package/dist/registry/registry.mutations.d.ts.map +1 -1
- package/dist/registry/registry.mutations.js +10 -3
- package/dist/registry/registry.mutations.js.map +1 -1
- package/dist/registry/registry.selectors.d.ts +41 -11
- package/dist/registry/registry.selectors.d.ts.map +1 -1
- package/dist/registry/registry.selectors.js +41 -11
- package/dist/registry/registry.selectors.js.map +1 -1
- package/dist/registry/registry.store.d.ts +22 -9
- package/dist/registry/registry.store.d.ts.map +1 -1
- package/dist/registry/registry.store.js +12 -3
- package/dist/registry/registry.store.js.map +1 -1
- package/dist/registry/registry.template.d.ts +12 -6
- package/dist/registry/registry.template.d.ts.map +1 -1
- package/dist/registry/registry.template.js +13 -6
- package/dist/registry/registry.template.js.map +1 -1
- package/dist/registry/types.d.ts +17 -3
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry/types.js +16 -6
- package/dist/registry/types.js.map +1 -1
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/dist/security/securityParser.d.ts +9 -8
- package/dist/security/securityParser.d.ts.map +1 -1
- package/dist/security/securityParser.js +12 -22
- package/dist/security/securityParser.js.map +1 -1
- package/dist/security/securityWorker.d.ts +11 -0
- package/dist/security/securityWorker.d.ts.map +1 -1
- package/dist/security/securityWorker.js +17 -38
- package/dist/security/securityWorker.js.map +1 -1
- package/dist/sources/checkout.d.ts +10 -4
- package/dist/sources/checkout.d.ts.map +1 -1
- package/dist/sources/checkout.js +10 -4
- package/dist/sources/checkout.js.map +1 -1
- package/dist/sources/git.d.ts +5 -3
- package/dist/sources/git.d.ts.map +1 -1
- package/dist/sources/git.js +5 -3
- package/dist/sources/git.js.map +1 -1
- package/dist/sources/local.d.ts +6 -4
- package/dist/sources/local.d.ts.map +1 -1
- package/dist/sources/local.js +6 -4
- package/dist/sources/local.js.map +1 -1
- package/dist/sources/npm.d.ts +10 -7
- package/dist/sources/npm.d.ts.map +1 -1
- package/dist/sources/npm.js +49 -15
- package/dist/sources/npm.js.map +1 -1
- package/dist/sources/parse.d.ts +24 -16
- package/dist/sources/parse.d.ts.map +1 -1
- package/dist/sources/parse.js +40 -18
- package/dist/sources/parse.js.map +1 -1
- package/dist/sources/process.d.ts +10 -7
- package/dist/sources/process.d.ts.map +1 -1
- package/dist/sources/process.js +10 -7
- package/dist/sources/process.js.map +1 -1
- package/dist/sources/register.d.ts +20 -5
- package/dist/sources/register.d.ts.map +1 -1
- package/dist/sources/register.js +20 -5
- package/dist/sources/register.js.map +1 -1
- package/dist/sources/types.d.ts +43 -8
- package/dist/sources/types.d.ts.map +1 -1
- package/dist/sources/types.js +21 -4
- package/dist/sources/types.js.map +1 -1
- package/dist/utils/errors.d.ts +6 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +6 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/merge.d.ts +8 -2
- package/dist/utils/merge.d.ts.map +1 -1
- package/dist/utils/merge.js +9 -2
- package/dist/utils/merge.js.map +1 -1
- package/dist/utils/packageMeta.d.ts +16 -2
- package/dist/utils/packageMeta.d.ts.map +1 -1
- package/dist/utils/packageMeta.js +6 -2
- package/dist/utils/packageMeta.js.map +1 -1
- package/dist/utils/paths.d.ts +16 -5
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +16 -5
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/prompt.d.ts +6 -1
- package/dist/utils/prompt.d.ts.map +1 -1
- package/dist/utils/prompt.js +6 -1
- package/dist/utils/prompt.js.map +1 -1
- package/dist/utils/version.d.ts +7 -2
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +40 -3
- package/dist/utils/version.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// packages/core/src/security/securityWorker.ts
|
|
2
3
|
const worker = self;
|
|
3
4
|
// ---------------------------------------------------------------------------
|
|
4
5
|
// Deep object sanitiser
|
|
@@ -7,6 +8,17 @@ const MAX_DEPTH = 20;
|
|
|
7
8
|
const MAX_KEYS = 1_000;
|
|
8
9
|
const MAX_STRLEN = 100_000;
|
|
9
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
|
+
*/
|
|
10
22
|
function sanitise(value, depth = 0) {
|
|
11
23
|
if (depth > MAX_DEPTH) {
|
|
12
24
|
throw new Error(`Object exceeds maximum nesting depth (${MAX_DEPTH})`);
|
|
@@ -48,8 +60,6 @@ function sanitise(value, depth = 0) {
|
|
|
48
60
|
throw new Error("Object exceeds maximum key/element count");
|
|
49
61
|
const desc = descriptors[key];
|
|
50
62
|
if (desc.get || desc.set) {
|
|
51
|
-
// Silently skip getter/setter properties — the getter-side-effect test
|
|
52
|
-
// expects a clean resolve and verifies the side effect did not happen.
|
|
53
63
|
continue;
|
|
54
64
|
}
|
|
55
65
|
out[key] = sanitise(value[key], depth + 1);
|
|
@@ -60,9 +70,7 @@ function sanitise(value, depth = 0) {
|
|
|
60
70
|
if (value.length > MAX_STRLEN) {
|
|
61
71
|
throw new Error(`String value exceeds maximum length (${MAX_STRLEN})`);
|
|
62
72
|
}
|
|
63
|
-
//
|
|
64
|
-
// error-stack.meta.ts catches an Error and returns e.stack as a plain
|
|
65
|
-
// string — detectable by the " at " stack frame marker.
|
|
73
|
+
// A stack frame line starts with four spaces and "at ".
|
|
66
74
|
if (/\n {4}at /.test(value)) {
|
|
67
75
|
throw new Error("String value appears to contain a stack trace");
|
|
68
76
|
}
|
|
@@ -72,39 +80,10 @@ function sanitise(value, depth = 0) {
|
|
|
72
80
|
// ---------------------------------------------------------------------------
|
|
73
81
|
// Resource-limit stubs injected into the sandbox
|
|
74
82
|
//
|
|
75
|
-
// IIFEs run during object construction, before
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
// regex-bomb.meta.ts → /(a+)+$/.exec(str) — stubbed via RegExp
|
|
80
|
-
// deep-object.meta.ts → 100k nested { nested: obj } literals
|
|
81
|
-
// Object literals bypass the Object() constructor so
|
|
82
|
-
// they cannot be intercepted via a stub. Instead we
|
|
83
|
-
// cap total object allocations with a counter in the
|
|
84
|
-
// Object stub for `new Object()` / `Object.assign`
|
|
85
|
-
// style calls, AND we rely on the IIFE loop itself
|
|
86
|
-
// being detectable via a loop-iteration counter.
|
|
87
|
-
//
|
|
88
|
-
// The loop counter trick: we inject a global __iterCount variable into the
|
|
89
|
-
// sandbox and wrap the sandbox body so that — via a Proxy on the iteration
|
|
90
|
-
// variable — we detect runaway loops. However, this is complex and fragile.
|
|
91
|
-
//
|
|
92
|
-
// Simpler reliable approach for deep-object: the fixture runs a for-loop
|
|
93
|
-
// 100,000 times. We shadow the Number constructor and use a Proxy on the
|
|
94
|
-
// iteration space? No — object literals are truly uninterceptable at the
|
|
95
|
-
// VM level without a custom realm.
|
|
96
|
-
//
|
|
97
|
-
// Pragmatic solution: raise a hard iteration budget by injecting a
|
|
98
|
-
// __checkBudget() call... but we can't inject into the transpiled fixture.
|
|
99
|
-
//
|
|
100
|
-
// FINAL approach: use a SharedArrayBuffer + Atomics watchdog from the
|
|
101
|
-
// parent thread to measure wall-clock time inside the worker, and terminate
|
|
102
|
-
// if the IIFE phase takes too long. Since we already have a Worker timeout,
|
|
103
|
-
// the deep-object IIFE completing in 6ms means it's genuinely fast — the
|
|
104
|
-
// nesting is built but immediately discarded and the string is returned.
|
|
105
|
-
//
|
|
106
|
-
// The ONLY reliable fix for deep-object is to reject the *input source* via
|
|
107
|
-
// static analysis in securityParser.ts before it reaches the worker.
|
|
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.
|
|
108
87
|
// ---------------------------------------------------------------------------
|
|
109
88
|
const SANDBOX_PREAMBLE = `
|
|
110
89
|
"use strict";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"securityWorker.js","sourceRoot":"","sources":["../../src/security/securityWorker.ts"],"names":[],"mappings":";AAAA,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,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IACzC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,yCAAyC,SAAS,GAAG,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAElD,IAAI,GAAG,KAAK,iBAAiB,EAAE,CA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AK,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"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import type { SourceCheckout, SourceSpec } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
* Resolves a source to a folder holding its files: a shallow clone for git,
|
|
4
|
-
* an installed or downloaded package for npm, the folder itself for local.
|
|
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.
|
|
5
4
|
*
|
|
6
|
-
* @param
|
|
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.
|
|
7
8
|
*/
|
|
8
9
|
export declare function checkoutSource(source: {
|
|
9
10
|
name: string;
|
|
10
11
|
spec: SourceSpec;
|
|
11
12
|
}, projectRoot: string): Promise<SourceCheckout>;
|
|
12
|
-
/**
|
|
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
|
+
*/
|
|
13
19
|
export declare function describeSource(spec: SourceSpec): string;
|
|
14
20
|
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -1 +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
|
|
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"}
|
package/dist/sources/checkout.js
CHANGED
|
@@ -3,10 +3,11 @@ import { checkoutGit } from "./git";
|
|
|
3
3
|
import { checkoutLocal } from "./local";
|
|
4
4
|
import { checkoutNpm } from "./npm";
|
|
5
5
|
/**
|
|
6
|
-
* Resolves a source to a folder holding its files: a shallow clone for git,
|
|
7
|
-
* an installed or downloaded package for npm, the folder itself for local.
|
|
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.
|
|
8
7
|
*
|
|
9
|
-
* @param
|
|
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.
|
|
10
11
|
*/
|
|
11
12
|
export async function checkoutSource(source, projectRoot) {
|
|
12
13
|
const { name, spec } = source;
|
|
@@ -16,7 +17,12 @@ export async function checkoutSource(source, projectRoot) {
|
|
|
16
17
|
case "local": return checkoutLocal(name, spec, projectRoot);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
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
|
+
*/
|
|
20
26
|
export function describeSource(spec) {
|
|
21
27
|
switch (spec.kind) {
|
|
22
28
|
case "git": return `git ${spec.url}${spec.ref === undefined ? "" : `#${spec.ref}`}`;
|
|
@@ -1 +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
|
|
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"}
|
package/dist/sources/git.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { GitSourceSpec, SourceCheckout } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
* Shallow-clones a git source into a temporary folder, at its `ref` when set
|
|
4
|
-
* and at the default branch otherwise, and resolves the commit it landed on.
|
|
3
|
+
* @brief Shallow-clones a git source into a temporary folder, at its `ref` when set and at the default branch otherwise.
|
|
5
4
|
*
|
|
6
|
-
* @
|
|
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.
|
|
7
9
|
*/
|
|
8
10
|
export declare function checkoutGit(name: string, spec: GitSourceSpec): Promise<SourceCheckout>;
|
|
9
11
|
//# sourceMappingURL=git.d.ts.map
|
|
@@ -1 +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
|
|
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"}
|
package/dist/sources/git.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// packages/core/src/sources/git.ts
|
|
2
2
|
import { createTempDir, removeDir, runCommand } from "./process";
|
|
3
3
|
/**
|
|
4
|
-
* Shallow-clones a git source into a temporary folder, at its `ref` when set
|
|
5
|
-
* and at the default branch otherwise, and resolves the commit it landed on.
|
|
4
|
+
* @brief Shallow-clones a git source into a temporary folder, at its `ref` when set and at the default branch otherwise.
|
|
6
5
|
*
|
|
7
|
-
* @
|
|
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.
|
|
8
10
|
*/
|
|
9
11
|
export async function checkoutGit(name, spec) {
|
|
10
12
|
const dir = createTempDir("git");
|
package/dist/sources/git.js.map
CHANGED
|
@@ -1 +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
|
|
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"}
|
package/dist/sources/local.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { LocalSourceSpec, SourceCheckout } from "./types";
|
|
2
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.
|
|
3
|
+
* @brief Resolves a local source to its folder. Nothing is copied, so `dispose` is a no-op.
|
|
5
4
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
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.
|
|
8
10
|
*/
|
|
9
11
|
export declare function checkoutLocal(name: string, spec: LocalSourceSpec, projectRoot: string): SourceCheckout;
|
|
10
12
|
//# sourceMappingURL=local.d.ts.map
|
|
@@ -1 +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
|
|
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"}
|
package/dist/sources/local.js
CHANGED
|
@@ -4,11 +4,13 @@ import path from "node:path";
|
|
|
4
4
|
import { expandHome } from "./parse";
|
|
5
5
|
import { readPackageVersion } from "./packageJson";
|
|
6
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.
|
|
7
|
+
* @brief Resolves a local source to its folder. Nothing is copied, so `dispose` is a no-op.
|
|
9
8
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
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.
|
|
12
14
|
*/
|
|
13
15
|
export function checkoutLocal(name, spec, projectRoot) {
|
|
14
16
|
const dir = path.resolve(projectRoot, expandHome(spec.path));
|
|
@@ -1 +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
|
|
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"}
|
package/dist/sources/npm.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { NpmSourceSpec, SourceCheckout } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
* Resolves an npm source to a folder.
|
|
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.
|
|
3
|
+
* @brief Resolves an npm source to a folder.
|
|
8
4
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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.
|
|
11
14
|
*/
|
|
12
15
|
export declare function checkoutNpm(name: string, spec: NpmSourceSpec, projectRoot: string): Promise<SourceCheckout>;
|
|
13
16
|
//# sourceMappingURL=npm.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
package/dist/sources/npm.js
CHANGED
|
@@ -19,14 +19,17 @@ const PackumentSchema = z.object({
|
|
|
19
19
|
})).default({}),
|
|
20
20
|
});
|
|
21
21
|
/**
|
|
22
|
-
* Resolves an npm source to a folder.
|
|
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.
|
|
22
|
+
* @brief Resolves an npm source to a folder.
|
|
27
23
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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.
|
|
30
33
|
*/
|
|
31
34
|
export async function checkoutNpm(name, spec, projectRoot) {
|
|
32
35
|
const installed = findInstalled(projectRoot, spec.package);
|
|
@@ -35,7 +38,13 @@ export async function checkoutNpm(name, spec, projectRoot) {
|
|
|
35
38
|
}
|
|
36
39
|
return downloadFromRegistry(name, spec);
|
|
37
40
|
}
|
|
38
|
-
/**
|
|
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
|
+
*/
|
|
39
48
|
function findInstalled(fromDir, pkg) {
|
|
40
49
|
let dir = fromDir;
|
|
41
50
|
while (true) {
|
|
@@ -50,23 +59,35 @@ function findInstalled(fromDir, pkg) {
|
|
|
50
59
|
dir = parent;
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
|
-
/**
|
|
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
|
+
*/
|
|
54
69
|
function accepts(installed, requested) {
|
|
55
70
|
if (requested === undefined)
|
|
56
71
|
return true;
|
|
57
72
|
return installed !== undefined && Bun.semver.satisfies(installed, requested);
|
|
58
73
|
}
|
|
59
|
-
/**
|
|
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
|
+
*/
|
|
60
79
|
function registryUrl() {
|
|
61
80
|
const env = RegistryEnvSchema.parse(process.env);
|
|
62
81
|
const url = env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY ?? DEFAULT_REGISTRY;
|
|
63
82
|
return url.endsWith("/") ? url : `${url}/`;
|
|
64
83
|
}
|
|
65
84
|
/**
|
|
66
|
-
* Downloads the version `spec` asks for, checks it against its integrity hash
|
|
67
|
-
* and unpacks it into a temporary folder that `dispose` removes.
|
|
85
|
+
* @brief Downloads the version `spec` asks for, checks it against its integrity hash and unpacks it into a temporary folder.
|
|
68
86
|
*
|
|
69
|
-
* @
|
|
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.
|
|
70
91
|
*/
|
|
71
92
|
async function downloadFromRegistry(name, spec) {
|
|
72
93
|
const packumentUrl = registryUrl() + spec.package.replace("/", "%2f");
|
|
@@ -103,7 +124,13 @@ async function downloadFromRegistry(name, spec) {
|
|
|
103
124
|
throw error;
|
|
104
125
|
}
|
|
105
126
|
}
|
|
106
|
-
/**
|
|
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
|
+
*/
|
|
107
134
|
function pickVersion(packument, requested) {
|
|
108
135
|
const wanted = requested ?? "latest";
|
|
109
136
|
const tagged = packument["dist-tags"][wanted];
|
|
@@ -115,7 +142,14 @@ function pickVersion(packument, requested) {
|
|
|
115
142
|
.filter((v) => Bun.semver.satisfies(v, wanted))
|
|
116
143
|
.sort((a, b) => Bun.semver.order(b, a))[0];
|
|
117
144
|
}
|
|
118
|
-
/**
|
|
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
|
+
*/
|
|
119
153
|
function verifyIntegrity(bytes, integrity, label) {
|
|
120
154
|
const [algorithm, expected] = integrity.split(" ")[0]?.split("-", 2) ?? [];
|
|
121
155
|
if (algorithm !== "sha512" && algorithm !== "sha256" && algorithm !== "sha1") {
|
package/dist/sources/npm.js.map
CHANGED
|
@@ -1 +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,C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C;SAC9C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,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"}
|
package/dist/sources/parse.d.ts
CHANGED
|
@@ -1,34 +1,42 @@
|
|
|
1
1
|
import type { SourceSpec } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
* Reads a source as typed on the command line.
|
|
3
|
+
* @brief Reads a source as typed on the command line.
|
|
4
4
|
*
|
|
5
|
-
* `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs
|
|
6
|
-
*
|
|
7
|
-
* are local folders, and `owner/repo` is a GitHub repository.
|
|
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.
|
|
8
7
|
*
|
|
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
|
-
* @
|
|
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
12
|
*/
|
|
13
13
|
export declare function parseSourceSpec(input: string, options?: {
|
|
14
14
|
ref?: string;
|
|
15
15
|
}): SourceSpec;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
19
|
*
|
|
20
|
-
* @
|
|
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.
|
|
21
23
|
*/
|
|
22
24
|
export declare function defaultSourceName(spec: SourceSpec): string;
|
|
23
|
-
/**
|
|
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
|
+
*/
|
|
24
31
|
export declare function expandHome(localPath: string): string;
|
|
25
32
|
/**
|
|
26
|
-
* Stores a local path the way it is read back: relative to the project root,
|
|
27
|
-
*
|
|
28
|
-
* Other kinds are returned unchanged.
|
|
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.
|
|
29
35
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
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.
|
|
32
40
|
*/
|
|
33
41
|
export declare function anchorLocalSpec(spec: SourceSpec, cwd: string, projectRoot: string | null): SourceSpec;
|
|
34
42
|
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
package/dist/sources/parse.js
CHANGED
|
@@ -6,15 +6,15 @@ const NPM_PREFIX = "npm:";
|
|
|
6
6
|
const LOCAL_PREFIX = "local:";
|
|
7
7
|
const GITHUB_SHORTHAND = /^[\w.-]+\/[\w.-]+$/;
|
|
8
8
|
/**
|
|
9
|
-
* Reads a source as typed on the command line.
|
|
9
|
+
* @brief Reads a source as typed on the command line.
|
|
10
10
|
*
|
|
11
|
-
* `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs
|
|
12
|
-
*
|
|
13
|
-
* are local folders, and `owner/repo` is a GitHub repository.
|
|
11
|
+
* `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs are git repositories,
|
|
12
|
+
* `local:<path>` and paths starting with `.`, `/` or `~` are local folders, and `owner/repo` is a GitHub repository.
|
|
14
13
|
*
|
|
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
|
-
* @
|
|
14
|
+
* @param input - Text as typed, e.g. `npm:@g3nomaly/g3n-skills@^1`, `git@github.com:me/skills.git`, `./my-skills`.
|
|
15
|
+
* @param options - `ref` pins a git source to a branch or tag.
|
|
16
|
+
* @returns The spec for the first form the input matches.
|
|
17
|
+
* @throws {Error} When the input matches no form, or `ref` is given for a source that is not git.
|
|
18
18
|
*/
|
|
19
19
|
export function parseSourceSpec(input, options = {}) {
|
|
20
20
|
const value = input.trim();
|
|
@@ -24,7 +24,14 @@ export function parseSourceSpec(input, options = {}) {
|
|
|
24
24
|
}
|
|
25
25
|
return spec;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* @brief Builds the spec for one trimmed input, by the first form it matches.
|
|
29
|
+
*
|
|
30
|
+
* @param value - Trimmed input.
|
|
31
|
+
* @param ref - Branch or tag for a git spec. Ignored for other kinds.
|
|
32
|
+
* @returns The spec.
|
|
33
|
+
* @throws {Error} When the input matches no form.
|
|
34
|
+
*/
|
|
28
35
|
function specFor(value, ref) {
|
|
29
36
|
if (value.startsWith(NPM_PREFIX))
|
|
30
37
|
return npmSpec(value.slice(NPM_PREFIX.length));
|
|
@@ -42,7 +49,14 @@ function specFor(value, ref) {
|
|
|
42
49
|
}
|
|
43
50
|
throw new Error(`"${value}" is not a source: use a git URL, owner/repo, npm:<package>, @scope/package or a local path`);
|
|
44
51
|
}
|
|
45
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* @brief Builds an npm spec from `pkg`, `pkg@1.2.0` or `@scope/pkg@^1`.
|
|
54
|
+
*
|
|
55
|
+
* The version follows the last `@` that is not the scope's.
|
|
56
|
+
*
|
|
57
|
+
* @param value - Package text, with an optional version.
|
|
58
|
+
* @returns The npm spec.
|
|
59
|
+
*/
|
|
46
60
|
function npmSpec(value) {
|
|
47
61
|
const at = value.lastIndexOf("@");
|
|
48
62
|
const hasVersion = at > 0;
|
|
@@ -53,10 +67,12 @@ function npmSpec(value) {
|
|
|
53
67
|
});
|
|
54
68
|
}
|
|
55
69
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
70
|
+
* @brief Derives the name a source registers under when none is given: the repository name for git,
|
|
71
|
+
* the package name without its scope for npm, the folder name for local.
|
|
58
72
|
*
|
|
59
|
-
* @
|
|
73
|
+
* @param spec - Spec to derive the name from.
|
|
74
|
+
* @returns A valid source name, e.g. `skills` for `git@github.com:g3nomaly/skills.git`.
|
|
75
|
+
* @throws {Error} When no name can be derived. The caller must then ask for one.
|
|
60
76
|
*/
|
|
61
77
|
export function defaultSourceName(spec) {
|
|
62
78
|
const raw = (() => {
|
|
@@ -71,17 +87,23 @@ export function defaultSourceName(spec) {
|
|
|
71
87
|
throw new Error("could not derive a name for the source, pass one with --name");
|
|
72
88
|
return name;
|
|
73
89
|
}
|
|
74
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* @brief Replaces a leading `~` with the home folder.
|
|
92
|
+
*
|
|
93
|
+
* @param localPath - Path that may start with `~`.
|
|
94
|
+
* @returns The path with the home folder in place of `~`. Any other path is returned unchanged.
|
|
95
|
+
*/
|
|
75
96
|
export function expandHome(localPath) {
|
|
76
97
|
return localPath.startsWith("~") ? path.join(os.homedir(), localPath.slice(1)) : localPath;
|
|
77
98
|
}
|
|
78
99
|
/**
|
|
79
|
-
* Stores a local path the way it is read back: relative to the project root,
|
|
80
|
-
*
|
|
81
|
-
* Other kinds are returned unchanged.
|
|
100
|
+
* @brief Stores a local path the way it is read back: relative to the project root, or absolute when the
|
|
101
|
+
* manifest is shared by every project (a user scope). Other kinds are returned unchanged.
|
|
82
102
|
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
103
|
+
* @param spec - Spec to anchor. Only `local` specs change.
|
|
104
|
+
* @param cwd - Absolute folder the path was typed in.
|
|
105
|
+
* @param projectRoot - Absolute project root, or `null` to store the path absolute.
|
|
106
|
+
* @returns The spec with its path anchored.
|
|
85
107
|
*/
|
|
86
108
|
export function anchorLocalSpec(spec, cwd, projectRoot) {
|
|
87
109
|
if (spec.kind !== "local")
|