@docusaurus/utils 3.10.1-canary-6615 → 3.10.1-canary-6616
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/lib/moduleUtils.d.ts +3 -1
- package/lib/moduleUtils.d.ts.map +1 -1
- package/lib/moduleUtils.js +25 -14
- package/lib/moduleUtils.js.map +1 -1
- package/package.json +6 -6
- package/src/moduleUtils.ts +35 -14
package/lib/moduleUtils.d.ts
CHANGED
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
export declare function loadFreshModule(modulePath: string
|
|
7
|
+
export declare function loadFreshModule(modulePath: string, options?: {
|
|
8
|
+
default?: true;
|
|
9
|
+
}): Promise<unknown>;
|
|
8
10
|
//# sourceMappingURL=moduleUtils.d.ts.map
|
package/lib/moduleUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moduleUtils.d.ts","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"moduleUtils.d.ts","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB,GACA,OAAO,CAAC,OAAO,CAAC,CA+BlB"}
|
package/lib/moduleUtils.js
CHANGED
|
@@ -8,29 +8,40 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.loadFreshModule = loadFreshModule;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const jiti_1 = tslib_1.__importDefault(require("jiti"));
|
|
12
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const jiti_1 = require("jiti");
|
|
13
|
+
const DEBUG = false;
|
|
14
|
+
const jiti = (0, jiti_1.createJiti)(__filename, {
|
|
15
|
+
// Transpilation cache, can be safely enabled
|
|
16
|
+
fsCache: true,
|
|
17
|
+
// Bypass Node.js runtime require cache for hot reloads
|
|
18
|
+
moduleCache: false,
|
|
19
|
+
interopDefault: true,
|
|
20
|
+
debug: DEBUG,
|
|
21
|
+
});
|
|
13
22
|
/*
|
|
14
23
|
jiti is able to load ESM, CJS, JSON, TS modules
|
|
15
24
|
*/
|
|
16
|
-
async function loadFreshModule(modulePath) {
|
|
25
|
+
async function loadFreshModule(modulePath, options) {
|
|
17
26
|
if (typeof modulePath !== 'string') {
|
|
18
27
|
throw new Error(logger_1.default.interpolate `Invalid module path of type "name=${typeof modulePath}" with value "name=${modulePath}"`);
|
|
19
28
|
}
|
|
20
29
|
try {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
cache: true,
|
|
24
|
-
// Bypass Node.js runtime require cache
|
|
25
|
-
// Same as "import-fresh" package we used previously
|
|
26
|
-
requireCache: false,
|
|
27
|
-
// Only take into consideration the default export
|
|
28
|
-
// For now we don't need named exports
|
|
29
|
-
// This also helps normalize return value for both CJS/ESM/TS modules
|
|
30
|
-
interopDefault: true,
|
|
31
|
-
// debug: true,
|
|
30
|
+
const module = await jiti.import(modulePath, {
|
|
31
|
+
default: options?.default,
|
|
32
32
|
});
|
|
33
|
-
|
|
33
|
+
if (DEBUG) {
|
|
34
|
+
console.log('Jiti module loaded', {
|
|
35
|
+
modulePath,
|
|
36
|
+
options,
|
|
37
|
+
type: typeof module,
|
|
38
|
+
keys: module && typeof module === 'object'
|
|
39
|
+
? Object.keys(module)
|
|
40
|
+
: undefined,
|
|
41
|
+
module,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return module;
|
|
34
45
|
}
|
|
35
46
|
catch (error) {
|
|
36
47
|
throw new Error(logger_1.default.interpolate `Docusaurus could not load module at path path=${modulePath}`, { cause: error });
|
package/lib/moduleUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moduleUtils.js","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"moduleUtils.js","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAoBH,0CAoCC;;AAtDD,wEAAwC;AACxC,+BAAgC;AAEhC,MAAM,KAAK,GAAG,KAAK,CAAC;AAEpB,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC,UAAU,EAAE;IAClC,6CAA6C;IAC7C,OAAO,EAAE,IAAI;IACb,uDAAuD;IACvD,WAAW,EAAE,KAAK;IAElB,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,KAAK;CACb,CAAC,CAAC;AAEH;;GAEG;AACI,KAAK,UAAU,eAAe,CACnC,UAAkB,EAClB,OAEC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,gBAAM,CAAC,WAAW,CAAA,qCAAqC,OAAO,UAAU,sBAAsB,UAAU,GAAG,CAC5G,CAAC;IACJ,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC3C,OAAO,EAAE,OAAO,EAAE,OAAO;SAC1B,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE;gBAChC,UAAU;gBACV,OAAO;gBACP,IAAI,EAAE,OAAO,MAAM;gBACnB,IAAI,EACF,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;oBAClC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;oBACrB,CAAC,CAAC,SAAS;gBACf,MAAM;aACP,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,gBAAM,CAAC,WAAW,CAAA,iDAAiD,UAAU,EAAE,EAC/E,EAAC,KAAK,EAAE,KAAK,EAAC,CACf,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "3.10.1-canary-
|
|
3
|
+
"version": "3.10.1-canary-6616",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "3.10.1-canary-
|
|
22
|
-
"@docusaurus/types": "3.10.1-canary-
|
|
23
|
-
"@docusaurus/utils-common": "3.10.1-canary-
|
|
21
|
+
"@docusaurus/logger": "3.10.1-canary-6616",
|
|
22
|
+
"@docusaurus/types": "3.10.1-canary-6616",
|
|
23
|
+
"@docusaurus/utils-common": "3.10.1-canary-6616",
|
|
24
24
|
"escape-string-regexp": "^4.0.0",
|
|
25
25
|
"execa": "^5.1.1",
|
|
26
26
|
"file-loader": "^6.2.0",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"github-slugger": "^1.5.0",
|
|
29
29
|
"globby": "^11.1.0",
|
|
30
30
|
"gray-matter": "^4.0.3",
|
|
31
|
-
"jiti": "^
|
|
31
|
+
"jiti": "^2.7.0",
|
|
32
32
|
"js-yaml": "^4.1.0",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"micromatch": "^4.0.5",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"dedent": "^0.7.0",
|
|
52
52
|
"tmp-promise": "^3.0.3"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "dbee2f840c422aa17fa8dd47665cbe3a8a04f788"
|
|
55
55
|
}
|
package/src/moduleUtils.ts
CHANGED
|
@@ -5,33 +5,54 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import jiti from 'jiti';
|
|
9
8
|
import logger from '@docusaurus/logger';
|
|
9
|
+
import {createJiti} from 'jiti';
|
|
10
|
+
|
|
11
|
+
const DEBUG = false;
|
|
12
|
+
|
|
13
|
+
const jiti = createJiti(__filename, {
|
|
14
|
+
// Transpilation cache, can be safely enabled
|
|
15
|
+
fsCache: true,
|
|
16
|
+
// Bypass Node.js runtime require cache for hot reloads
|
|
17
|
+
moduleCache: false,
|
|
18
|
+
|
|
19
|
+
interopDefault: true,
|
|
20
|
+
debug: DEBUG,
|
|
21
|
+
});
|
|
10
22
|
|
|
11
23
|
/*
|
|
12
24
|
jiti is able to load ESM, CJS, JSON, TS modules
|
|
13
25
|
*/
|
|
14
|
-
export async function loadFreshModule(
|
|
26
|
+
export async function loadFreshModule(
|
|
27
|
+
modulePath: string,
|
|
28
|
+
options?: {
|
|
29
|
+
default?: true; // Use this when only the default export matters
|
|
30
|
+
},
|
|
31
|
+
): Promise<unknown> {
|
|
15
32
|
if (typeof modulePath !== 'string') {
|
|
16
33
|
throw new Error(
|
|
17
34
|
logger.interpolate`Invalid module path of type "name=${typeof modulePath}" with value "name=${modulePath}"`,
|
|
18
35
|
);
|
|
19
36
|
}
|
|
20
37
|
try {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
cache: true,
|
|
24
|
-
// Bypass Node.js runtime require cache
|
|
25
|
-
// Same as "import-fresh" package we used previously
|
|
26
|
-
requireCache: false,
|
|
27
|
-
// Only take into consideration the default export
|
|
28
|
-
// For now we don't need named exports
|
|
29
|
-
// This also helps normalize return value for both CJS/ESM/TS modules
|
|
30
|
-
interopDefault: true,
|
|
31
|
-
// debug: true,
|
|
38
|
+
const module = await jiti.import(modulePath, {
|
|
39
|
+
default: options?.default,
|
|
32
40
|
});
|
|
33
41
|
|
|
34
|
-
|
|
42
|
+
if (DEBUG) {
|
|
43
|
+
console.log('Jiti module loaded', {
|
|
44
|
+
modulePath,
|
|
45
|
+
options,
|
|
46
|
+
type: typeof module,
|
|
47
|
+
keys:
|
|
48
|
+
module && typeof module === 'object'
|
|
49
|
+
? Object.keys(module)
|
|
50
|
+
: undefined,
|
|
51
|
+
module,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return module;
|
|
35
56
|
} catch (error) {
|
|
36
57
|
throw new Error(
|
|
37
58
|
logger.interpolate`Docusaurus could not load module at path path=${modulePath}`,
|