@modern-js/utils 2.60.2 → 2.60.3
Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/cli/require.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
19
|
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
var require_exports = {};
|
20
30
|
__export(require_exports, {
|
@@ -22,6 +32,7 @@ __export(require_exports, {
|
|
22
32
|
compatibleRequire: () => compatibleRequire,
|
23
33
|
deleteRequireCache: () => deleteRequireCache,
|
24
34
|
dynamicImport: () => dynamicImport,
|
35
|
+
loadFromProject: () => loadFromProject,
|
25
36
|
requireExistModule: () => requireExistModule,
|
26
37
|
tryResolve: () => tryResolve
|
27
38
|
});
|
@@ -29,6 +40,7 @@ module.exports = __toCommonJS(require_exports);
|
|
29
40
|
var import_node_path = require("node:path");
|
30
41
|
var import_node_url = require("node:url");
|
31
42
|
var import_fs = require("./fs");
|
43
|
+
const import_meta = {};
|
32
44
|
async function compatibleRequire(path, interop = true) {
|
33
45
|
if (path.endsWith(".json")) {
|
34
46
|
return require(path);
|
@@ -47,6 +59,35 @@ async function compatibleRequire(path, interop = true) {
|
|
47
59
|
}
|
48
60
|
return interop && (requiredModule === null || requiredModule === void 0 ? void 0 : requiredModule.__esModule) ? requiredModule.default : requiredModule;
|
49
61
|
}
|
62
|
+
async function loadFromProject(moduleName, appDir) {
|
63
|
+
let requiredModule;
|
64
|
+
const paths = [
|
65
|
+
appDir,
|
66
|
+
process.cwd()
|
67
|
+
];
|
68
|
+
try {
|
69
|
+
if (typeof require !== "undefined") {
|
70
|
+
const modulePath = require.resolve(moduleName, {
|
71
|
+
paths
|
72
|
+
});
|
73
|
+
requiredModule = require(modulePath);
|
74
|
+
} else {
|
75
|
+
const { createRequire } = await import("node:module");
|
76
|
+
const require1 = createRequire(import_meta.url);
|
77
|
+
const modulePath = require1.resolve(moduleName, {
|
78
|
+
paths
|
79
|
+
});
|
80
|
+
const moduleUrl = (0, import_node_url.pathToFileURL)(modulePath).href;
|
81
|
+
requiredModule = await import(moduleUrl);
|
82
|
+
}
|
83
|
+
return requiredModule.default || requiredModule;
|
84
|
+
} catch (error) {
|
85
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
86
|
+
throw new Error(`Cannot find module ${moduleName}.`);
|
87
|
+
}
|
88
|
+
throw error;
|
89
|
+
}
|
90
|
+
}
|
50
91
|
const dynamicImport = new Function("modulePath", "return import(modulePath)");
|
51
92
|
const requireExistModule = async (filename, opt) => {
|
52
93
|
const final = {
|
@@ -99,6 +140,7 @@ const tryResolve = (name, resolvePath) => {
|
|
99
140
|
compatibleRequire,
|
100
141
|
deleteRequireCache,
|
101
142
|
dynamicImport,
|
143
|
+
loadFromProject,
|
102
144
|
requireExistModule,
|
103
145
|
tryResolve
|
104
146
|
});
|
package/dist/esm/cli/require.js
CHANGED
@@ -70,6 +70,79 @@ function _compatibleRequire() {
|
|
70
70
|
});
|
71
71
|
return _compatibleRequire.apply(this, arguments);
|
72
72
|
}
|
73
|
+
function loadFromProject(moduleName, appDir) {
|
74
|
+
return _loadFromProject.apply(this, arguments);
|
75
|
+
}
|
76
|
+
function _loadFromProject() {
|
77
|
+
_loadFromProject = _async_to_generator(function(moduleName, appDir) {
|
78
|
+
var requiredModule, paths, modulePath, createRequire, _$require, modulePath1, moduleUrl, error;
|
79
|
+
return _ts_generator(this, function(_state) {
|
80
|
+
switch (_state.label) {
|
81
|
+
case 0:
|
82
|
+
paths = [
|
83
|
+
appDir,
|
84
|
+
process.cwd()
|
85
|
+
];
|
86
|
+
_state.label = 1;
|
87
|
+
case 1:
|
88
|
+
_state.trys.push([
|
89
|
+
1,
|
90
|
+
6,
|
91
|
+
,
|
92
|
+
7
|
93
|
+
]);
|
94
|
+
if (!(typeof require !== "undefined"))
|
95
|
+
return [
|
96
|
+
3,
|
97
|
+
2
|
98
|
+
];
|
99
|
+
modulePath = require.resolve(moduleName, {
|
100
|
+
paths
|
101
|
+
});
|
102
|
+
requiredModule = require(modulePath);
|
103
|
+
return [
|
104
|
+
3,
|
105
|
+
5
|
106
|
+
];
|
107
|
+
case 2:
|
108
|
+
return [
|
109
|
+
4,
|
110
|
+
import("node:module")
|
111
|
+
];
|
112
|
+
case 3:
|
113
|
+
createRequire = _state.sent().createRequire;
|
114
|
+
_$require = createRequire(import.meta.url);
|
115
|
+
modulePath1 = _$require.resolve(moduleName, {
|
116
|
+
paths
|
117
|
+
});
|
118
|
+
moduleUrl = pathToFileURL(modulePath1).href;
|
119
|
+
return [
|
120
|
+
4,
|
121
|
+
import(moduleUrl)
|
122
|
+
];
|
123
|
+
case 4:
|
124
|
+
requiredModule = _state.sent();
|
125
|
+
_state.label = 5;
|
126
|
+
case 5:
|
127
|
+
return [
|
128
|
+
2,
|
129
|
+
requiredModule.default || requiredModule
|
130
|
+
];
|
131
|
+
case 6:
|
132
|
+
error = _state.sent();
|
133
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
134
|
+
throw new Error("Cannot find module ".concat(moduleName, "."));
|
135
|
+
}
|
136
|
+
throw error;
|
137
|
+
case 7:
|
138
|
+
return [
|
139
|
+
2
|
140
|
+
];
|
141
|
+
}
|
142
|
+
});
|
143
|
+
});
|
144
|
+
return _loadFromProject.apply(this, arguments);
|
145
|
+
}
|
73
146
|
var dynamicImport = new Function("modulePath", "return import(modulePath)");
|
74
147
|
var requireExistModule = function() {
|
75
148
|
var _ref = _async_to_generator(function(filename, opt) {
|
@@ -138,6 +211,7 @@ export {
|
|
138
211
|
compatibleRequire,
|
139
212
|
deleteRequireCache,
|
140
213
|
dynamicImport,
|
214
|
+
loadFromProject,
|
141
215
|
requireExistModule,
|
142
216
|
tryResolve
|
143
217
|
};
|
@@ -1,3 +1,4 @@
|
|
1
|
+
const import_meta = {};
|
1
2
|
import { isAbsolute } from "node:path";
|
2
3
|
import { pathToFileURL } from "node:url";
|
3
4
|
import { findExists } from "./fs";
|
@@ -19,6 +20,35 @@ async function compatibleRequire(path, interop = true) {
|
|
19
20
|
}
|
20
21
|
return interop && (requiredModule === null || requiredModule === void 0 ? void 0 : requiredModule.__esModule) ? requiredModule.default : requiredModule;
|
21
22
|
}
|
23
|
+
async function loadFromProject(moduleName, appDir) {
|
24
|
+
let requiredModule;
|
25
|
+
const paths = [
|
26
|
+
appDir,
|
27
|
+
process.cwd()
|
28
|
+
];
|
29
|
+
try {
|
30
|
+
if (typeof require !== "undefined") {
|
31
|
+
const modulePath = require.resolve(moduleName, {
|
32
|
+
paths
|
33
|
+
});
|
34
|
+
requiredModule = require(modulePath);
|
35
|
+
} else {
|
36
|
+
const { createRequire } = await import("node:module");
|
37
|
+
const require1 = createRequire(import_meta.url);
|
38
|
+
const modulePath = require1.resolve(moduleName, {
|
39
|
+
paths
|
40
|
+
});
|
41
|
+
const moduleUrl = pathToFileURL(modulePath).href;
|
42
|
+
requiredModule = await import(moduleUrl);
|
43
|
+
}
|
44
|
+
return requiredModule.default || requiredModule;
|
45
|
+
} catch (error) {
|
46
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
47
|
+
throw new Error(`Cannot find module ${moduleName}.`);
|
48
|
+
}
|
49
|
+
throw error;
|
50
|
+
}
|
51
|
+
}
|
22
52
|
const dynamicImport = new Function("modulePath", "return import(modulePath)");
|
23
53
|
const requireExistModule = async (filename, opt) => {
|
24
54
|
const final = {
|
@@ -70,6 +100,7 @@ export {
|
|
70
100
|
compatibleRequire,
|
71
101
|
deleteRequireCache,
|
72
102
|
dynamicImport,
|
103
|
+
loadFromProject,
|
73
104
|
requireExistModule,
|
74
105
|
tryResolve
|
75
106
|
};
|
@@ -4,6 +4,7 @@
|
|
4
4
|
* @returns module export object.
|
5
5
|
*/
|
6
6
|
export declare function compatibleRequire(path: string, interop?: boolean): Promise<any>;
|
7
|
+
export declare function loadFromProject(moduleName: string, appDir: string): Promise<any>;
|
7
8
|
export declare const dynamicImport: Function;
|
8
9
|
export declare const requireExistModule: (filename: string, opt?: {
|
9
10
|
extensions?: string[];
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.60.
|
18
|
+
"version": "2.60.3",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -161,10 +161,10 @@
|
|
161
161
|
"@types/node": "^14",
|
162
162
|
"jest": "^29",
|
163
163
|
"typescript": "^5",
|
164
|
-
"webpack": "^5.
|
165
|
-
"@modern-js/types": "2.60.
|
166
|
-
"@scripts/jest-config": "2.60.
|
167
|
-
"@scripts/build": "2.60.
|
164
|
+
"webpack": "^5.95.0",
|
165
|
+
"@modern-js/types": "2.60.3",
|
166
|
+
"@scripts/jest-config": "2.60.3",
|
167
|
+
"@scripts/build": "2.60.3"
|
168
168
|
},
|
169
169
|
"sideEffects": false,
|
170
170
|
"scripts": {
|