@modern-js/utils 2.60.1 → 2.60.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/cli/index.js +3 -3
- package/dist/cjs/cli/require.js +42 -0
- package/dist/cjs/cli/route.js +23 -2
- package/dist/esm/cli/index.js +1 -1
- package/dist/esm/cli/require.js +74 -0
- package/dist/esm/cli/route.js +21 -1
- package/dist/esm-node/cli/index.js +1 -1
- package/dist/esm-node/cli/require.js +31 -0
- package/dist/esm-node/cli/route.js +21 -1
- package/dist/types/cli/index.d.ts +1 -1
- package/dist/types/cli/require.d.ts +1 -0
- package/dist/types/cli/route.d.ts +1 -0
- package/package.json +5 -5
package/dist/cjs/cli/index.js
CHANGED
@@ -36,8 +36,8 @@ __reExport(cli_exports, require("./runtimeExports"), module.exports);
|
|
36
36
|
__reExport(cli_exports, require("./watch"), module.exports);
|
37
37
|
__reExport(cli_exports, require("./config"), module.exports);
|
38
38
|
__reExport(cli_exports, require("./action"), module.exports);
|
39
|
-
__reExport(cli_exports, require("./route"), module.exports);
|
40
39
|
__reExport(cli_exports, require("./version"), module.exports);
|
40
|
+
__reExport(cli_exports, require("./route"), module.exports);
|
41
41
|
// Annotate the CommonJS export names for ESM import in node:
|
42
42
|
0 && (module.exports = {
|
43
43
|
...require("./constants"),
|
@@ -61,6 +61,6 @@ __reExport(cli_exports, require("./version"), module.exports);
|
|
61
61
|
...require("./watch"),
|
62
62
|
...require("./config"),
|
63
63
|
...require("./action"),
|
64
|
-
...require("./
|
65
|
-
...require("./
|
64
|
+
...require("./version"),
|
65
|
+
...require("./route")
|
66
66
|
});
|
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/cjs/cli/route.js
CHANGED
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
19
19
|
var route_exports = {};
|
20
20
|
__export(route_exports, {
|
21
21
|
filterRoutesForServer: () => filterRoutesForServer,
|
22
|
-
filterRoutesLoader: () => filterRoutesLoader
|
22
|
+
filterRoutesLoader: () => filterRoutesLoader,
|
23
|
+
markRoutes: () => markRoutes
|
23
24
|
});
|
24
25
|
module.exports = __toCommonJS(route_exports);
|
25
26
|
var import_compiled = require("../compiled");
|
@@ -58,8 +59,28 @@ function filterRoutesLoader(routes) {
|
|
58
59
|
}).filter((route) => route !== null);
|
59
60
|
return newRoutes;
|
60
61
|
}
|
62
|
+
function markRoutes(routes, routeIds) {
|
63
|
+
return routes.map((route) => {
|
64
|
+
if (route.type !== "nested") {
|
65
|
+
return route;
|
66
|
+
}
|
67
|
+
if (route.children && route.children.length > 0) {
|
68
|
+
route.children = markRoutes(route.children, routeIds);
|
69
|
+
}
|
70
|
+
if (route.children && route.children.length > 0) {
|
71
|
+
route.inValidSSRRoute = route.children.every((child) => {
|
72
|
+
var _child_inValidSSRRoute;
|
73
|
+
return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
|
74
|
+
});
|
75
|
+
} else if (route.id) {
|
76
|
+
route.inValidSSRRoute = !routeIds.includes(route.id);
|
77
|
+
}
|
78
|
+
return route;
|
79
|
+
});
|
80
|
+
}
|
61
81
|
// Annotate the CommonJS export names for ESM import in node:
|
62
82
|
0 && (module.exports = {
|
63
83
|
filterRoutesForServer,
|
64
|
-
filterRoutesLoader
|
84
|
+
filterRoutesLoader,
|
85
|
+
markRoutes
|
65
86
|
});
|
package/dist/esm/cli/index.js
CHANGED
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
|
};
|
package/dist/esm/cli/route.js
CHANGED
@@ -38,7 +38,27 @@ function filterRoutesLoader(routes) {
|
|
38
38
|
});
|
39
39
|
return newRoutes;
|
40
40
|
}
|
41
|
+
function markRoutes(routes, routeIds) {
|
42
|
+
return routes.map(function(route) {
|
43
|
+
if (route.type !== "nested") {
|
44
|
+
return route;
|
45
|
+
}
|
46
|
+
if (route.children && route.children.length > 0) {
|
47
|
+
route.children = markRoutes(route.children, routeIds);
|
48
|
+
}
|
49
|
+
if (route.children && route.children.length > 0) {
|
50
|
+
route.inValidSSRRoute = route.children.every(function(child) {
|
51
|
+
var _child_inValidSSRRoute;
|
52
|
+
return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
|
53
|
+
});
|
54
|
+
} else if (route.id) {
|
55
|
+
route.inValidSSRRoute = !routeIds.includes(route.id);
|
56
|
+
}
|
57
|
+
return route;
|
58
|
+
});
|
59
|
+
}
|
41
60
|
export {
|
42
61
|
filterRoutesForServer,
|
43
|
-
filterRoutesLoader
|
62
|
+
filterRoutesLoader,
|
63
|
+
markRoutes
|
44
64
|
};
|
@@ -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
|
};
|
@@ -34,7 +34,27 @@ function filterRoutesLoader(routes) {
|
|
34
34
|
}).filter((route) => route !== null);
|
35
35
|
return newRoutes;
|
36
36
|
}
|
37
|
+
function markRoutes(routes, routeIds) {
|
38
|
+
return routes.map((route) => {
|
39
|
+
if (route.type !== "nested") {
|
40
|
+
return route;
|
41
|
+
}
|
42
|
+
if (route.children && route.children.length > 0) {
|
43
|
+
route.children = markRoutes(route.children, routeIds);
|
44
|
+
}
|
45
|
+
if (route.children && route.children.length > 0) {
|
46
|
+
route.inValidSSRRoute = route.children.every((child) => {
|
47
|
+
var _child_inValidSSRRoute;
|
48
|
+
return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
|
49
|
+
});
|
50
|
+
} else if (route.id) {
|
51
|
+
route.inValidSSRRoute = !routeIds.includes(route.id);
|
52
|
+
}
|
53
|
+
return route;
|
54
|
+
});
|
55
|
+
}
|
37
56
|
export {
|
38
57
|
filterRoutesForServer,
|
39
|
-
filterRoutesLoader
|
58
|
+
filterRoutesLoader,
|
59
|
+
markRoutes
|
40
60
|
};
|
@@ -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[];
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
|
2
2
|
export declare function filterRoutesForServer(routes: (NestedRouteForCli | PageRoute)[]): (NestedRouteForCli | PageRoute)[];
|
3
3
|
export declare function filterRoutesLoader(routes: (NestedRouteForCli | PageRoute)[]): (NestedRouteForCli | PageRoute)[];
|
4
|
+
export declare function markRoutes(routes: (NestedRouteForCli | PageRoute)[], routeIds: string[]): (NestedRouteForCli | PageRoute)[];
|
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/
|
167
|
-
"@scripts/
|
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": {
|