@shrkcrft/core 0.1.0-alpha.7 → 0.1.0-alpha.9
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
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SharkCraft core primitives: Result, AppError, logger, file-system abstraction, path/string/object utils, IDs.
|
|
4
4
|
|
|
5
|
-
Part of [SharkCraft](https://github.com/
|
|
5
|
+
Part of [SharkCraft](https://github.com/sharkcraft/sharkcraft) — a deterministic, local-first toolkit that gives AI coding agents durable project context. See the main repo for documentation, examples, and the `shrk` CLI.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -17,13 +17,5 @@ export interface ISafeImportOptions {
|
|
|
17
17
|
skipExistsCheck?: boolean;
|
|
18
18
|
}
|
|
19
19
|
export declare const DEFAULT_SAFE_IMPORT_TIMEOUT_MS = 8000;
|
|
20
|
-
/**
|
|
21
|
-
* Bun-or-jiti-aware dynamic import. Use this anywhere the engine needs to
|
|
22
|
-
* load a user-authored TypeScript file (config, knowledge, boundaries,
|
|
23
|
-
* pipelines, etc.) from an absolute path. Falls back to native `import()`
|
|
24
|
-
* for `.js` / `.mjs` so library consumers without TypeScript files pay
|
|
25
|
-
* nothing.
|
|
26
|
-
*/
|
|
27
|
-
export declare function importModuleViaLoader<T = Record<string, unknown>>(filePath: string): Promise<T>;
|
|
28
20
|
export declare function safeImport<T = Record<string, unknown>>(filePath: string, options?: ISafeImportOptions): Promise<SafeImportResult<T>>;
|
|
29
21
|
//# sourceMappingURL=safe-import.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-import.d.ts","sourceRoot":"","sources":["../../src/load/safe-import.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,EAAE,EAAE,IAAI,CAAC;IACT,MAAM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AEnD,wBAAsB,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CA+C9B"}
|
package/dist/load/safe-import.js
CHANGED
|
@@ -9,53 +9,6 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
9
9
|
import { existsSync } from 'node:fs';
|
|
10
10
|
import { pathToFileURL } from 'node:url';
|
|
11
11
|
export const DEFAULT_SAFE_IMPORT_TIMEOUT_MS = 8000;
|
|
12
|
-
// Bun reads TypeScript natively. Node does not (Node 22+ has experimental
|
|
13
|
-
// strip-types, but it is gated on a flag). When running on Node, route
|
|
14
|
-
// every `.ts` / `.tsx` / `.mts` / `.cts` import through jiti so dist-mode
|
|
15
|
-
// CLI invocations (`npx shrk …`) can load user-authored TypeScript config
|
|
16
|
-
// files (`sharkcraft.config.ts`, `sharkcraft/boundaries.ts`, etc.).
|
|
17
|
-
const isBun = typeof globalThis.Bun !== 'undefined' &&
|
|
18
|
-
globalThis.Bun?.version !== undefined;
|
|
19
|
-
const TS_FILE_RE = /\.(ts|tsx|mts|cts)$/i;
|
|
20
|
-
let jitiInstance = null;
|
|
21
|
-
let jitiLoadAttempted = false;
|
|
22
|
-
async function getJiti() {
|
|
23
|
-
if (jitiInstance)
|
|
24
|
-
return jitiInstance;
|
|
25
|
-
if (jitiLoadAttempted)
|
|
26
|
-
return null;
|
|
27
|
-
jitiLoadAttempted = true;
|
|
28
|
-
try {
|
|
29
|
-
const mod = (await import('jiti'));
|
|
30
|
-
const factory = mod.createJiti ?? mod.default;
|
|
31
|
-
if (typeof factory !== 'function')
|
|
32
|
-
return null;
|
|
33
|
-
jitiInstance = factory(pathToFileURL(import.meta.url).href, {
|
|
34
|
-
interopDefault: false,
|
|
35
|
-
});
|
|
36
|
-
return jitiInstance;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Bun-or-jiti-aware dynamic import. Use this anywhere the engine needs to
|
|
44
|
-
* load a user-authored TypeScript file (config, knowledge, boundaries,
|
|
45
|
-
* pipelines, etc.) from an absolute path. Falls back to native `import()`
|
|
46
|
-
* for `.js` / `.mjs` so library consumers without TypeScript files pay
|
|
47
|
-
* nothing.
|
|
48
|
-
*/
|
|
49
|
-
export async function importModuleViaLoader(filePath) {
|
|
50
|
-
if (!isBun && TS_FILE_RE.test(filePath)) {
|
|
51
|
-
const jiti = await getJiti();
|
|
52
|
-
if (jiti)
|
|
53
|
-
return (await jiti.import(filePath));
|
|
54
|
-
// Fall through to native import — Node 22+ with --experimental-strip-types
|
|
55
|
-
// can still resolve, otherwise the error surfaces to the caller.
|
|
56
|
-
}
|
|
57
|
-
return (await import(__rewriteRelativeImportExtension(pathToFileURL(filePath).href)));
|
|
58
|
-
}
|
|
59
12
|
export async function safeImport(filePath, options = {}) {
|
|
60
13
|
const timeoutMs = options.timeoutMs ?? DEFAULT_SAFE_IMPORT_TIMEOUT_MS;
|
|
61
14
|
const start = Date.now();
|
|
@@ -83,7 +36,7 @@ export async function safeImport(filePath, options = {}) {
|
|
|
83
36
|
});
|
|
84
37
|
const importPromise = (async () => {
|
|
85
38
|
try {
|
|
86
|
-
const mod = await
|
|
39
|
+
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(filePath).href)));
|
|
87
40
|
return { ok: true, module: mod, elapsedMs: Date.now() - start };
|
|
88
41
|
}
|
|
89
42
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shrkcrft/core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.9",
|
|
4
4
|
"description": "SharkCraft core primitives: Result, AppError, logger, file-system abstraction, path/string/object utils, IDs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SharkCraft contributors",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
],
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/
|
|
24
|
+
"url": "git+https://github.com/sharkcraft/sharkcraft.git",
|
|
25
25
|
"directory": "packages/core"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/
|
|
27
|
+
"homepage": "https://github.com/sharkcraft/sharkcraft",
|
|
28
28
|
"bugs": {
|
|
29
|
-
"url": "https://github.com/
|
|
29
|
+
"url": "https://github.com/sharkcraft/sharkcraft/issues"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
32
32
|
"sharkcraft",
|
|
@@ -43,9 +43,6 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
45
45
|
},
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"jiti": "^2.7.0"
|
|
48
|
-
},
|
|
49
46
|
"publishConfig": {
|
|
50
47
|
"access": "public"
|
|
51
48
|
}
|