@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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Finds the nearest directory at or above `fromDir` that holds a `package.json`.
|
|
3
|
+
*
|
|
4
|
+
* Pass `import.meta.dir` to get the root of the package the caller lives in,
|
|
5
|
+
* from `src/` and `dist/` alike.
|
|
6
|
+
*
|
|
7
|
+
* @param fromDir - Directory to start searching from, e.g. `import.meta.dir`.
|
|
8
|
+
* @returns Path of the package root directory.
|
|
9
|
+
* @throws {Error} When no package.json exists on the way up to the filesystem root.
|
|
10
|
+
*/
|
|
11
|
+
export declare function findPackageRoot(fromDir: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* @brief Finds the nearest directory at or above `fromDir` that holds `marker` as a direct entry.
|
|
14
|
+
*
|
|
15
|
+
* @param fromDir - Directory to start searching from.
|
|
16
|
+
* @param marker - Name of a file or directory to look for, e.g. `.git`.
|
|
17
|
+
* @returns Directory that holds `marker`, or `null` when no ancestor holds it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findUp(fromDir: string, marker: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Finds the root of the git repository that contains `fromDir`.
|
|
22
|
+
*
|
|
23
|
+
* @param fromDir - Directory to start searching from.
|
|
24
|
+
* @returns Root directory of the repository, or `null` outside a repo.
|
|
25
|
+
*/
|
|
26
|
+
export declare function findGitRoot(fromDir: string): string | null;
|
|
27
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQrE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// packages/core/src/utils/paths.ts
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* @brief Finds the nearest directory at or above `fromDir` that holds a `package.json`.
|
|
6
|
+
*
|
|
7
|
+
* Pass `import.meta.dir` to get the root of the package the caller lives in,
|
|
8
|
+
* from `src/` and `dist/` alike.
|
|
9
|
+
*
|
|
10
|
+
* @param fromDir - Directory to start searching from, e.g. `import.meta.dir`.
|
|
11
|
+
* @returns Path of the package root directory.
|
|
12
|
+
* @throws {Error} When no package.json exists on the way up to the filesystem root.
|
|
13
|
+
*/
|
|
14
|
+
export function findPackageRoot(fromDir) {
|
|
15
|
+
let dir = fromDir;
|
|
16
|
+
while (!existsSync(join(dir, "package.json"))) {
|
|
17
|
+
const parent = dirname(dir);
|
|
18
|
+
if (parent === dir)
|
|
19
|
+
throw new Error(`no package.json found above ${fromDir}`);
|
|
20
|
+
dir = parent;
|
|
21
|
+
}
|
|
22
|
+
return dir;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @brief Finds the nearest directory at or above `fromDir` that holds `marker` as a direct entry.
|
|
26
|
+
*
|
|
27
|
+
* @param fromDir - Directory to start searching from.
|
|
28
|
+
* @param marker - Name of a file or directory to look for, e.g. `.git`.
|
|
29
|
+
* @returns Directory that holds `marker`, or `null` when no ancestor holds it.
|
|
30
|
+
*/
|
|
31
|
+
export function findUp(fromDir, marker) {
|
|
32
|
+
let dir = fromDir;
|
|
33
|
+
while (true) {
|
|
34
|
+
if (existsSync(join(dir, marker)))
|
|
35
|
+
return dir;
|
|
36
|
+
const parent = dirname(dir);
|
|
37
|
+
if (parent === dir)
|
|
38
|
+
return null;
|
|
39
|
+
dir = parent;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Finds the root of the git repository that contains `fromDir`.
|
|
44
|
+
*
|
|
45
|
+
* @param fromDir - Directory to start searching from.
|
|
46
|
+
* @returns Root directory of the repository, or `null` outside a repo.
|
|
47
|
+
*/
|
|
48
|
+
export function findGitRoot(fromDir) {
|
|
49
|
+
return findUp(fromDir, ".git");
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,IAAI,GAAG,GAAG,OAAO,CAAC;IAClB,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,OAAO,EAAE,CAAC,CAAC;QAC9E,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,MAAc;IACpD,IAAI,GAAG,GAAG,OAAO,CAAC;IAClB,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAAE,OAAO,GAAG,CAAC;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAChC,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the value a prompt gave back, or exits the process when the user cancelled it.
|
|
3
|
+
*
|
|
4
|
+
* @param result - Value a prompt returned, or the symbol it returns on cancel.
|
|
5
|
+
* @returns The value, unchanged.
|
|
6
|
+
*/
|
|
7
|
+
export declare function guardCancel<T>(result: T | symbol): T;
|
|
8
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/utils/prompt.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAGpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// packages/core/src/utils/prompt.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns the value a prompt gave back, or exits the process when the user cancelled it.
|
|
4
|
+
*
|
|
5
|
+
* @param result - Value a prompt returned, or the symbol it returns on cancel.
|
|
6
|
+
* @returns The value, unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export function guardCancel(result) {
|
|
9
|
+
if (typeof result === "symbol")
|
|
10
|
+
process.exit(0);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/utils/prompt.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAI,MAAkB;IAC/C,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/C,OAAO,MAAW,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Warns on stderr when a newer version of `pkgName` exists on the registry.
|
|
3
|
+
*
|
|
4
|
+
* When the process runs from a stale `bunx <pkg>@latest` cache, that cache
|
|
5
|
+
* directory is removed on exit so the next invocation reinstalls fresh.
|
|
6
|
+
* Checks the registry at most once per hour; no-op when offline or when
|
|
7
|
+
* `G3N_NO_UPDATE_CHECK` is set.
|
|
8
|
+
*
|
|
9
|
+
* @param pkgName - npm package name, e.g. `@g3nomaly/core`.
|
|
10
|
+
* @param currentVersion - Version that is running, e.g. `1.2.3`.
|
|
11
|
+
* @param entryUrl - File URL of the running module, pass `import.meta.url`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function warnIfOutdated(pkgName: string, currentVersion: string, entryUrl: string): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAsGA;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC7G"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// packages/core/src/utils/version.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
const REGISTRY = "https://registry.npmjs.org";
|
|
7
|
+
const CHECK_INTERVAL_MS = 60 * 60 * 1000;
|
|
8
|
+
const FETCH_TIMEOUT_MS = 1500;
|
|
9
|
+
/**
|
|
10
|
+
* Path of the throttle file that records when `pkgName` was last checked.
|
|
11
|
+
*
|
|
12
|
+
* @param pkgName - npm package name, e.g. `@g3nomaly/core`.
|
|
13
|
+
* @returns Path under the OS temporary directory.
|
|
14
|
+
*/
|
|
15
|
+
function throttleFile(pkgName) {
|
|
16
|
+
return path.join(os.tmpdir(), `.g3n-update-${pkgName.replace(/[^a-z0-9-]/gi, "_")}.json`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads the throttle record from `file`.
|
|
20
|
+
*
|
|
21
|
+
* @param file - Path of the throttle file.
|
|
22
|
+
* @returns The stored record, or `null` when the file is missing or malformed.
|
|
23
|
+
*/
|
|
24
|
+
function readState(file) {
|
|
25
|
+
try {
|
|
26
|
+
const raw = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
27
|
+
return typeof raw.checkedAt === "number" && typeof raw.latest === "string" ? raw : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Fetches the newest published version of `pkgName` from the npm registry.
|
|
35
|
+
*
|
|
36
|
+
* @param pkgName - npm package name, e.g. `@g3nomaly/core`.
|
|
37
|
+
* @returns The version string, or `null` when offline, timed out or not found.
|
|
38
|
+
*/
|
|
39
|
+
async function fetchLatest(pkgName) {
|
|
40
|
+
try {
|
|
41
|
+
const res = await fetch(`${REGISTRY}/${pkgName}/latest`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
42
|
+
if (!res.ok)
|
|
43
|
+
return null;
|
|
44
|
+
const data = (await res.json());
|
|
45
|
+
return typeof data.version === "string" ? data.version : null;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Tells whether `latest` is a newer major.minor.patch version than `current`.
|
|
53
|
+
*
|
|
54
|
+
* Pre-release suffixes are ignored.
|
|
55
|
+
*
|
|
56
|
+
* @param current - Version that is running, e.g. `1.2.3`.
|
|
57
|
+
* @param latest - Version the registry reported, e.g. `1.3.0`.
|
|
58
|
+
* @returns `true` when `latest` is newer.
|
|
59
|
+
*/
|
|
60
|
+
function isOutdated(current, latest) {
|
|
61
|
+
const a = current.split("-")[0].split(".").map(Number);
|
|
62
|
+
const b = latest.split("-")[0].split(".").map(Number);
|
|
63
|
+
for (let i = 0; i < 3; i++) {
|
|
64
|
+
if ((b[i] ?? 0) > (a[i] ?? 0))
|
|
65
|
+
return true;
|
|
66
|
+
if ((b[i] ?? 0) < (a[i] ?? 0))
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Finds the root of the `bunx <pkg>@latest` cache directory that `entryUrl` runs from.
|
|
73
|
+
*
|
|
74
|
+
* @param entryUrl - File URL of the running module, pass `import.meta.url`.
|
|
75
|
+
* @returns Path of the cache root, or `null` when the module does not run from such a cache.
|
|
76
|
+
*/
|
|
77
|
+
function bunxLatestCacheRoot(entryUrl) {
|
|
78
|
+
let entryPath;
|
|
79
|
+
try {
|
|
80
|
+
entryPath = fileURLToPath(entryUrl);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const marker = entryPath.indexOf("@latest" + path.sep);
|
|
86
|
+
if (marker === -1 || !entryPath.startsWith(os.tmpdir()) || !entryPath.includes("bunx-"))
|
|
87
|
+
return null;
|
|
88
|
+
return entryPath.slice(0, marker + "@latest".length);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @brief Warns on stderr when a newer version of `pkgName` exists on the registry.
|
|
92
|
+
*
|
|
93
|
+
* When the process runs from a stale `bunx <pkg>@latest` cache, that cache
|
|
94
|
+
* directory is removed on exit so the next invocation reinstalls fresh.
|
|
95
|
+
* Checks the registry at most once per hour; no-op when offline or when
|
|
96
|
+
* `G3N_NO_UPDATE_CHECK` is set.
|
|
97
|
+
*
|
|
98
|
+
* @param pkgName - npm package name, e.g. `@g3nomaly/core`.
|
|
99
|
+
* @param currentVersion - Version that is running, e.g. `1.2.3`.
|
|
100
|
+
* @param entryUrl - File URL of the running module, pass `import.meta.url`.
|
|
101
|
+
*/
|
|
102
|
+
export async function warnIfOutdated(pkgName, currentVersion, entryUrl) {
|
|
103
|
+
if (process.env.G3N_NO_UPDATE_CHECK !== undefined)
|
|
104
|
+
return;
|
|
105
|
+
const file = throttleFile(pkgName);
|
|
106
|
+
const cached = readState(file);
|
|
107
|
+
let latest;
|
|
108
|
+
if (cached !== null && Date.now() - cached.checkedAt < CHECK_INTERVAL_MS) {
|
|
109
|
+
latest = cached.latest;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const fetched = await fetchLatest(pkgName);
|
|
113
|
+
if (fetched === null)
|
|
114
|
+
return;
|
|
115
|
+
latest = fetched;
|
|
116
|
+
try {
|
|
117
|
+
fs.writeFileSync(file, JSON.stringify({ checkedAt: Date.now(), latest }));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// throttle state is best-effort; the warning below still works
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!isOutdated(currentVersion, latest))
|
|
124
|
+
return;
|
|
125
|
+
const cacheRoot = bunxLatestCacheRoot(entryUrl);
|
|
126
|
+
if (cacheRoot !== null) {
|
|
127
|
+
process.once("exit", () => {
|
|
128
|
+
try {
|
|
129
|
+
fs.rmSync(cacheRoot, { recursive: true, force: true });
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// cache dir may already be gone; next run resolves fresh either way
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
console.error(`[g3n] ${pkgName} ${currentVersion} is outdated (latest ${latest}) — stale bunx cache cleared, the next run uses ${latest}.`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
console.error(`[g3n] ${pkgName} ${currentVersion} is outdated (latest ${latest}) — update with: bun install -g ${pkgName}@${latest}`);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAC9C,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACzC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAe9B;;;;;GAKG;AACH,SAAS,YAAY,CAAC,OAAe;IACnC,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,eAAe,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC5F,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CA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 -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g3nomaly/core",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.2",
|
|
4
|
+
"description": "Shared runtime for @g3n packages — hashing, registry, security, config",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./hash": {
|
|
13
|
+
"types": "./dist/hash/index.d.ts",
|
|
14
|
+
"default": "./dist/hash/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./registry": {
|
|
17
|
+
"types": "./dist/registry/index.d.ts",
|
|
18
|
+
"default": "./dist/registry/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./security": {
|
|
21
|
+
"types": "./dist/security/index.d.ts",
|
|
22
|
+
"default": "./dist/security/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./config": {
|
|
25
|
+
"types": "./dist/config/index.d.ts",
|
|
26
|
+
"default": "./dist/config/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./installer": {
|
|
29
|
+
"types": "./dist/installer/index.d.ts",
|
|
30
|
+
"default": "./dist/installer/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./cli": {
|
|
33
|
+
"types": "./dist/cli/index.d.ts",
|
|
34
|
+
"default": "./dist/cli/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./sources": {
|
|
37
|
+
"types": "./dist/sources/index.d.ts",
|
|
38
|
+
"default": "./dist/sources/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./utils": {
|
|
41
|
+
"types": "./dist/utils/index.d.ts",
|
|
42
|
+
"default": "./dist/utils/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "rm -rf dist && tsc --project tsconfig.build.json",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@clack/prompts": "^1.7.0",
|
|
55
|
+
"@tanstack/store": "^0.11.1",
|
|
56
|
+
"chalk": "^6.0.0",
|
|
57
|
+
"zod": "^4.4.3"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/bun": "^1.4.0",
|
|
61
|
+
"typescript": "~7.0.2"
|
|
62
|
+
},
|
|
63
|
+
"license": "Elastic-2.0",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
}
|
|
6
67
|
}
|
package/README.md
DELETED