@faasjs/load 7.1.0 → 8.0.0-beta.0
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/dist/index.cjs +8 -30
- package/dist/index.d.ts +9 -11
- package/dist/index.mjs +6 -28
- package/package.json +5 -7
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var fs = require('fs');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var deep_merge = require('@faasjs/deep_merge');
|
|
6
|
-
var logger
|
|
6
|
+
var logger = require('@faasjs/logger');
|
|
7
7
|
var jsYaml = require('js-yaml');
|
|
8
8
|
|
|
9
9
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -14,9 +14,9 @@ var Config = class {
|
|
|
14
14
|
origin;
|
|
15
15
|
defaults;
|
|
16
16
|
logger;
|
|
17
|
-
constructor(root, filename,
|
|
18
|
-
this.logger = new logger
|
|
19
|
-
|
|
17
|
+
constructor(root, filename, logger$1) {
|
|
18
|
+
this.logger = new logger.Logger(
|
|
19
|
+
logger$1?.label ? `${logger$1.label}] [config` : "config"
|
|
20
20
|
);
|
|
21
21
|
this.root = root;
|
|
22
22
|
if (!this.root.endsWith(path.sep)) this.root += path.sep;
|
|
@@ -53,9 +53,11 @@ var Config = class {
|
|
|
53
53
|
return this[key] || this.defaults || /* @__PURE__ */ Object.create(null);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
function loadConfig(root, filename, staging,
|
|
57
|
-
return new Config(root, filename,
|
|
56
|
+
function loadConfig(root, filename, staging, logger) {
|
|
57
|
+
return new Config(root, filename, logger).get(staging);
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
// src/load_package.ts
|
|
59
61
|
var _runtime = null;
|
|
60
62
|
function resetRuntime() {
|
|
61
63
|
_runtime = null;
|
|
@@ -67,23 +69,10 @@ function detectNodeRuntime() {
|
|
|
67
69
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) }) !== "undefined") return _runtime = "module";
|
|
68
70
|
throw Error("Unknown runtime");
|
|
69
71
|
}
|
|
70
|
-
var tsxLoaded = null;
|
|
71
|
-
var logger = new logger$1.Logger("loadPackage");
|
|
72
72
|
async function loadPackage(name, defaultNames = "default") {
|
|
73
73
|
const runtime = detectNodeRuntime();
|
|
74
74
|
let module2;
|
|
75
75
|
if (runtime === "module") {
|
|
76
|
-
if (tsxLoaded === null) {
|
|
77
|
-
try {
|
|
78
|
-
await import('tsx');
|
|
79
|
-
tsxLoaded = true;
|
|
80
|
-
} catch (_) {
|
|
81
|
-
tsxLoaded = false;
|
|
82
|
-
logger.warn(
|
|
83
|
-
'Recommend installing the "tsx" package for loading ts/tsx files'
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
76
|
module2 = await import(name);
|
|
88
77
|
if (typeof defaultNames === "string")
|
|
89
78
|
return defaultNames in module2 ? module2[defaultNames] : module2;
|
|
@@ -91,17 +80,6 @@ async function loadPackage(name, defaultNames = "default") {
|
|
|
91
80
|
return module2;
|
|
92
81
|
}
|
|
93
82
|
if (runtime === "commonjs") {
|
|
94
|
-
if (tsxLoaded === null) {
|
|
95
|
-
try {
|
|
96
|
-
globalThis.require("tsx");
|
|
97
|
-
tsxLoaded = true;
|
|
98
|
-
} catch (_) {
|
|
99
|
-
tsxLoaded = false;
|
|
100
|
-
logger.warn(
|
|
101
|
-
'Recommend installing the "tsx" package for loading ts/tsx files'
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
83
|
module2 = globalThis.require(name);
|
|
106
84
|
if (typeof defaultNames === "string")
|
|
107
85
|
return defaultNames in module2 ? module2[defaultNames] : module2;
|
package/dist/index.d.ts
CHANGED
|
@@ -34,25 +34,23 @@ declare function loadFunc<TEvent = any, TContext = any, TResult = any>(root: str
|
|
|
34
34
|
type NodeRuntime = 'commonjs' | 'module';
|
|
35
35
|
declare function resetRuntime(): void;
|
|
36
36
|
/**
|
|
37
|
-
* Detect
|
|
37
|
+
* Detect current JavaScript runtime environment.
|
|
38
38
|
*
|
|
39
|
-
* This function checks for
|
|
40
|
-
* whether
|
|
39
|
+
* This function checks for presence of `import.meta` and `require` to determine
|
|
40
|
+
* whether runtime is using ECMAScript modules (ESM) or CommonJS modules (CJS).
|
|
41
41
|
*
|
|
42
|
-
* @returns {NodeRuntime} - Returns 'module' if
|
|
42
|
+
* @returns {NodeRuntime} - Returns 'module' if runtime is using ECMAScript modules,
|
|
43
43
|
* and 'cjs' if the runtime is using CommonJS modules.
|
|
44
|
-
* @throws {Error} - Throws an error if
|
|
44
|
+
* @throws {Error} - Throws an error if runtime cannot be determined.
|
|
45
45
|
*/
|
|
46
46
|
declare function detectNodeRuntime(): NodeRuntime;
|
|
47
47
|
/**
|
|
48
48
|
* Asynchronously loads a package by its name, supporting both ESM and CommonJS runtimes.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
* @
|
|
54
|
-
* @returns {Promise<T>} A promise that resolves to the loaded module.
|
|
55
|
-
* @throws {Error} If the runtime is unknown.
|
|
50
|
+
* @template T - The type of module to be loaded.
|
|
51
|
+
* @param {string} name - The name of package to load.
|
|
52
|
+
* @returns {Promise<T>} A promise that resolves to loaded module.
|
|
53
|
+
* @throws {Error} If runtime is unknown.
|
|
56
54
|
*
|
|
57
55
|
* @example
|
|
58
56
|
* ```typescript
|
package/dist/index.mjs
CHANGED
|
@@ -11,9 +11,9 @@ var Config = class {
|
|
|
11
11
|
origin;
|
|
12
12
|
defaults;
|
|
13
13
|
logger;
|
|
14
|
-
constructor(root, filename,
|
|
14
|
+
constructor(root, filename, logger) {
|
|
15
15
|
this.logger = new Logger(
|
|
16
|
-
|
|
16
|
+
logger?.label ? `${logger.label}] [config` : "config"
|
|
17
17
|
);
|
|
18
18
|
this.root = root;
|
|
19
19
|
if (!this.root.endsWith(sep)) this.root += sep;
|
|
@@ -50,9 +50,11 @@ var Config = class {
|
|
|
50
50
|
return this[key] || this.defaults || /* @__PURE__ */ Object.create(null);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
function loadConfig(root, filename, staging,
|
|
54
|
-
return new Config(root, filename,
|
|
53
|
+
function loadConfig(root, filename, staging, logger) {
|
|
54
|
+
return new Config(root, filename, logger).get(staging);
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
// src/load_package.ts
|
|
56
58
|
var _runtime = null;
|
|
57
59
|
function resetRuntime() {
|
|
58
60
|
_runtime = null;
|
|
@@ -64,23 +66,10 @@ function detectNodeRuntime() {
|
|
|
64
66
|
if (typeof import.meta !== "undefined") return _runtime = "module";
|
|
65
67
|
throw Error("Unknown runtime");
|
|
66
68
|
}
|
|
67
|
-
var tsxLoaded = null;
|
|
68
|
-
var logger = new Logger("loadPackage");
|
|
69
69
|
async function loadPackage(name, defaultNames = "default") {
|
|
70
70
|
const runtime = detectNodeRuntime();
|
|
71
71
|
let module2;
|
|
72
72
|
if (runtime === "module") {
|
|
73
|
-
if (tsxLoaded === null) {
|
|
74
|
-
try {
|
|
75
|
-
await import('tsx');
|
|
76
|
-
tsxLoaded = true;
|
|
77
|
-
} catch (_) {
|
|
78
|
-
tsxLoaded = false;
|
|
79
|
-
logger.warn(
|
|
80
|
-
'Recommend installing the "tsx" package for loading ts/tsx files'
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
73
|
module2 = await import(name);
|
|
85
74
|
if (typeof defaultNames === "string")
|
|
86
75
|
return defaultNames in module2 ? module2[defaultNames] : module2;
|
|
@@ -88,17 +77,6 @@ async function loadPackage(name, defaultNames = "default") {
|
|
|
88
77
|
return module2;
|
|
89
78
|
}
|
|
90
79
|
if (runtime === "commonjs") {
|
|
91
|
-
if (tsxLoaded === null) {
|
|
92
|
-
try {
|
|
93
|
-
globalThis.require("tsx");
|
|
94
|
-
tsxLoaded = true;
|
|
95
|
-
} catch (_) {
|
|
96
|
-
tsxLoaded = false;
|
|
97
|
-
logger.warn(
|
|
98
|
-
'Recommend installing the "tsx" package for loading ts/tsx files'
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
80
|
module2 = globalThis.require(name);
|
|
103
81
|
if (typeof defaultNames === "string")
|
|
104
82
|
return defaultNames in module2 ? module2[defaultNames] : module2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/load",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v8.0.0-beta.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -31,16 +31,14 @@
|
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"js-yaml": "*",
|
|
34
|
-
"
|
|
35
|
-
"@faasjs/
|
|
36
|
-
"@faasjs/func": ">=7.1.0"
|
|
34
|
+
"@faasjs/deep_merge": ">=v8.0.0-beta.0",
|
|
35
|
+
"@faasjs/func": ">=v8.0.0-beta.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"js-yaml": "*",
|
|
40
|
-
"tsx": "*",
|
|
41
39
|
"@types/js-yaml": "*",
|
|
42
|
-
"@faasjs/deep_merge": ">=
|
|
43
|
-
"@faasjs/func": ">=
|
|
40
|
+
"@faasjs/deep_merge": ">=v8.0.0-beta.0",
|
|
41
|
+
"@faasjs/func": ">=v8.0.0-beta.0"
|
|
44
42
|
},
|
|
45
43
|
"engines": {
|
|
46
44
|
"node": ">=24.0.0",
|