@modern-js/utils 3.2.2 → 3.3.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.
@@ -57,6 +57,9 @@ var __webpack_modules__ = {
57
57
  "./route" (module) {
58
58
  module.exports = require("./route.js");
59
59
  },
60
+ "./routeComponentFiles" (module) {
61
+ module.exports = require("./routeComponentFiles.js");
62
+ },
60
63
  "./runtimeExports" (module) {
61
64
  module.exports = require("./runtimeExports.js");
62
65
  },
@@ -205,9 +208,13 @@ var __webpack_exports__ = {};
205
208
  var __rspack_reexport = {};
206
209
  for(const __rspack_import_key in _modulePath__rspack_import_21)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modulePath__rspack_import_21[__rspack_import_key];
207
210
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
208
- var _tsconfig__rspack_import_22 = __webpack_require__("./tsconfig");
211
+ var _routeComponentFiles__rspack_import_22 = __webpack_require__("./routeComponentFiles");
212
+ var __rspack_reexport = {};
213
+ for(const __rspack_import_key in _routeComponentFiles__rspack_import_22)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_routeComponentFiles__rspack_import_22[__rspack_import_key];
214
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
215
+ var _tsconfig__rspack_import_23 = __webpack_require__("./tsconfig");
209
216
  var __rspack_reexport = {};
210
- for(const __rspack_import_key in _tsconfig__rspack_import_22)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tsconfig__rspack_import_22[__rspack_import_key];
217
+ for(const __rspack_import_key in _tsconfig__rspack_import_23)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tsconfig__rspack_import_23[__rspack_import_key];
211
218
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
212
219
  })();
213
220
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ collectRouteComponentFiles: ()=>collectRouteComponentFiles,
41
+ normalizeModulePath: ()=>normalizeModulePath
42
+ });
43
+ const external_node_fs_namespaceObject = require("node:fs");
44
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
45
+ const external_node_path_namespaceObject = require("node:path");
46
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
47
+ const RESOLVE_EXTENSIONS = [
48
+ '.tsx',
49
+ '.ts',
50
+ '.jsx',
51
+ '.js',
52
+ '.mjs',
53
+ '.cjs'
54
+ ];
55
+ function normalizeModulePath(filePath) {
56
+ const absolute = external_node_path_default().resolve(filePath);
57
+ let real = absolute;
58
+ try {
59
+ real = external_node_fs_default().realpathSync.native(absolute);
60
+ } catch {}
61
+ return real.split(external_node_path_default().sep).join('/');
62
+ }
63
+ function resolveRouteComponentFile(component, srcDirectory, srcAlias) {
64
+ const normalizedAlias = srcAlias.replace(/[\\/]+$/, '');
65
+ let candidate;
66
+ if (component === normalizedAlias || component.startsWith(`${normalizedAlias}/`)) {
67
+ const relative = component.slice(normalizedAlias.length).replace(/^\/+/, '');
68
+ candidate = external_node_path_default().resolve(srcDirectory, relative);
69
+ } else {
70
+ if (!external_node_path_default().isAbsolute(component)) return;
71
+ candidate = external_node_path_default().resolve(component);
72
+ }
73
+ if (external_node_path_default().extname(candidate) && external_node_fs_default().existsSync(candidate)) return normalizeModulePath(candidate);
74
+ for (const ext of RESOLVE_EXTENSIONS)if (external_node_fs_default().existsSync(candidate + ext)) return normalizeModulePath(candidate + ext);
75
+ for (const ext of RESOLVE_EXTENSIONS){
76
+ const indexFile = external_node_path_default().join(candidate, `index${ext}`);
77
+ if (external_node_fs_default().existsSync(indexFile)) return normalizeModulePath(indexFile);
78
+ }
79
+ }
80
+ function collectRouteComponentFiles(routes, srcDirectory, srcAlias) {
81
+ const resolvedFiles = new Set();
82
+ const unresolvedSpecifiers = [];
83
+ const walk = (list)=>{
84
+ if (!Array.isArray(list)) return;
85
+ for (const route of list){
86
+ if (route._component) {
87
+ const file = resolveRouteComponentFile(route._component, srcDirectory, srcAlias);
88
+ if (file) resolvedFiles.add(file);
89
+ else unresolvedSpecifiers.push(route._component);
90
+ }
91
+ walk(route.children);
92
+ }
93
+ };
94
+ walk(routes);
95
+ return {
96
+ resolvedFiles,
97
+ unresolvedSpecifiers
98
+ };
99
+ }
100
+ exports.collectRouteComponentFiles = __webpack_exports__.collectRouteComponentFiles;
101
+ exports.normalizeModulePath = __webpack_exports__.normalizeModulePath;
102
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
103
+ "collectRouteComponentFiles",
104
+ "normalizeModulePath"
105
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
106
+ Object.defineProperty(exports, '__esModule', {
107
+ value: true
108
+ });
@@ -20,4 +20,5 @@ export * from "./config.mjs";
20
20
  export * from "./version.mjs";
21
21
  export * from "./route.mjs";
22
22
  export * from "./modulePath.mjs";
23
+ export * from "./routeComponentFiles.mjs";
23
24
  export * from "./tsconfig.mjs";
@@ -0,0 +1,56 @@
1
+ import node_fs from "node:fs";
2
+ import node_path from "node:path";
3
+ const RESOLVE_EXTENSIONS = [
4
+ '.tsx',
5
+ '.ts',
6
+ '.jsx',
7
+ '.js',
8
+ '.mjs',
9
+ '.cjs'
10
+ ];
11
+ function normalizeModulePath(filePath) {
12
+ const absolute = node_path.resolve(filePath);
13
+ let real = absolute;
14
+ try {
15
+ real = node_fs.realpathSync.native(absolute);
16
+ } catch {}
17
+ return real.split(node_path.sep).join('/');
18
+ }
19
+ function resolveRouteComponentFile(component, srcDirectory, srcAlias) {
20
+ const normalizedAlias = srcAlias.replace(/[\\/]+$/, '');
21
+ let candidate;
22
+ if (component === normalizedAlias || component.startsWith(`${normalizedAlias}/`)) {
23
+ const relative = component.slice(normalizedAlias.length).replace(/^\/+/, '');
24
+ candidate = node_path.resolve(srcDirectory, relative);
25
+ } else {
26
+ if (!node_path.isAbsolute(component)) return;
27
+ candidate = node_path.resolve(component);
28
+ }
29
+ if (node_path.extname(candidate) && node_fs.existsSync(candidate)) return normalizeModulePath(candidate);
30
+ for (const ext of RESOLVE_EXTENSIONS)if (node_fs.existsSync(candidate + ext)) return normalizeModulePath(candidate + ext);
31
+ for (const ext of RESOLVE_EXTENSIONS){
32
+ const indexFile = node_path.join(candidate, `index${ext}`);
33
+ if (node_fs.existsSync(indexFile)) return normalizeModulePath(indexFile);
34
+ }
35
+ }
36
+ function collectRouteComponentFiles(routes, srcDirectory, srcAlias) {
37
+ const resolvedFiles = new Set();
38
+ const unresolvedSpecifiers = [];
39
+ const walk = (list)=>{
40
+ if (!Array.isArray(list)) return;
41
+ for (const route of list){
42
+ if (route._component) {
43
+ const file = resolveRouteComponentFile(route._component, srcDirectory, srcAlias);
44
+ if (file) resolvedFiles.add(file);
45
+ else unresolvedSpecifiers.push(route._component);
46
+ }
47
+ walk(route.children);
48
+ }
49
+ };
50
+ walk(routes);
51
+ return {
52
+ resolvedFiles,
53
+ unresolvedSpecifiers
54
+ };
55
+ }
56
+ export { collectRouteComponentFiles, normalizeModulePath };
@@ -21,4 +21,5 @@ export * from "./config.mjs";
21
21
  export * from "./version.mjs";
22
22
  export * from "./route.mjs";
23
23
  export * from "./modulePath.mjs";
24
+ export * from "./routeComponentFiles.mjs";
24
25
  export * from "./tsconfig.mjs";
@@ -0,0 +1,57 @@
1
+ import "node:module";
2
+ import node_fs from "node:fs";
3
+ import node_path from "node:path";
4
+ const RESOLVE_EXTENSIONS = [
5
+ '.tsx',
6
+ '.ts',
7
+ '.jsx',
8
+ '.js',
9
+ '.mjs',
10
+ '.cjs'
11
+ ];
12
+ function normalizeModulePath(filePath) {
13
+ const absolute = node_path.resolve(filePath);
14
+ let real = absolute;
15
+ try {
16
+ real = node_fs.realpathSync.native(absolute);
17
+ } catch {}
18
+ return real.split(node_path.sep).join('/');
19
+ }
20
+ function resolveRouteComponentFile(component, srcDirectory, srcAlias) {
21
+ const normalizedAlias = srcAlias.replace(/[\\/]+$/, '');
22
+ let candidate;
23
+ if (component === normalizedAlias || component.startsWith(`${normalizedAlias}/`)) {
24
+ const relative = component.slice(normalizedAlias.length).replace(/^\/+/, '');
25
+ candidate = node_path.resolve(srcDirectory, relative);
26
+ } else {
27
+ if (!node_path.isAbsolute(component)) return;
28
+ candidate = node_path.resolve(component);
29
+ }
30
+ if (node_path.extname(candidate) && node_fs.existsSync(candidate)) return normalizeModulePath(candidate);
31
+ for (const ext of RESOLVE_EXTENSIONS)if (node_fs.existsSync(candidate + ext)) return normalizeModulePath(candidate + ext);
32
+ for (const ext of RESOLVE_EXTENSIONS){
33
+ const indexFile = node_path.join(candidate, `index${ext}`);
34
+ if (node_fs.existsSync(indexFile)) return normalizeModulePath(indexFile);
35
+ }
36
+ }
37
+ function collectRouteComponentFiles(routes, srcDirectory, srcAlias) {
38
+ const resolvedFiles = new Set();
39
+ const unresolvedSpecifiers = [];
40
+ const walk = (list)=>{
41
+ if (!Array.isArray(list)) return;
42
+ for (const route of list){
43
+ if (route._component) {
44
+ const file = resolveRouteComponentFile(route._component, srcDirectory, srcAlias);
45
+ if (file) resolvedFiles.add(file);
46
+ else unresolvedSpecifiers.push(route._component);
47
+ }
48
+ walk(route.children);
49
+ }
50
+ };
51
+ walk(routes);
52
+ return {
53
+ resolvedFiles,
54
+ unresolvedSpecifiers
55
+ };
56
+ }
57
+ export { collectRouteComponentFiles, normalizeModulePath };
@@ -20,4 +20,5 @@ export * from './config';
20
20
  export * from './version';
21
21
  export * from './route';
22
22
  export * from './modulePath';
23
+ export * from './routeComponentFiles';
23
24
  export * from './tsconfig';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Normalize a path so that route-component collection and `module.resource`
3
+ * comparison use the exact same form: resolve symlinks (best effort), make it
4
+ * absolute, and use POSIX separators. Used on both sides of the `test` match so
5
+ * Windows / symlink / mixed-separator paths still line up.
6
+ */
7
+ export declare function normalizeModulePath(filePath: string): string;
8
+ export type RouteComponentFileCollection = {
9
+ /** Normalized absolute paths of resolved route component files. */
10
+ resolvedFiles: Set<string>;
11
+ /** `_component` specifiers that could not be mapped to a real file. */
12
+ unresolvedSpecifiers: string[];
13
+ };
14
+ /**
15
+ * Per-entry route component files, keyed by entry name. Collected by the router
16
+ * plugin from the FINAL routes and consumed (currently by stream SSR lazy
17
+ * compilation) to force route components eager.
18
+ */
19
+ export type EagerRouteComponentFilesByEntry = Map<string, RouteComponentFileCollection>;
20
+ /**
21
+ * Walk the file-system route tree and collect the normalized absolute file
22
+ * paths of every route component, plus any `_component` specifiers that could
23
+ * not be resolved to a real file.
24
+ */
25
+ export declare function collectRouteComponentFiles(routes: unknown, srcDirectory: string, srcAlias: string): RouteComponentFileCollection;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.2.2",
18
+ "version": "3.3.0",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "module": "./dist/esm/index.mjs",
@@ -142,17 +142,17 @@
142
142
  "rslog": "^1.3.2"
143
143
  },
144
144
  "devDependencies": {
145
- "@rslib/core": "0.21.5",
145
+ "@rslib/core": "0.22.0",
146
146
  "@types/node": "^20",
147
147
  "happy-dom": "^20.9.0",
148
148
  "typescript": "^5",
149
149
  "@modern-js/rslib": "2.68.10",
150
- "@scripts/rstest-config": "2.66.0",
151
- "@modern-js/types": "3.2.2"
150
+ "@modern-js/types": "3.3.0",
151
+ "@scripts/rstest-config": "2.66.0"
152
152
  },
153
153
  "peerDependencies": {
154
- "react": "^19.2.6",
155
- "react-dom": "^19.2.6"
154
+ "react": "^19.2.7",
155
+ "react-dom": "^19.2.7"
156
156
  },
157
157
  "peerDependenciesMeta": {
158
158
  "react": {