@modern-js/utils 2.22.1-alpha.0 → 2.22.1-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/cli/constants/index.js +4 -0
- package/dist/cjs/runtime-node/index.js +2 -0
- package/dist/cjs/runtime-node/nestedRoutes.js +28 -0
- package/dist/cjs/universal/constants.js +4 -0
- package/dist/esm/cli/constants/index.js +1 -0
- package/dist/esm/runtime-node/index.js +1 -0
- package/dist/esm/runtime-node/nestedRoutes.js +18 -0
- package/dist/esm/universal/constants.js +1 -0
- package/dist/types/cli/constants/index.d.ts +4 -0
- package/dist/types/runtime-node/index.d.ts +2 -1
- package/dist/types/runtime-node/nestedRoutes.d.ts +3 -0
- package/dist/types/universal/constants.d.ts +5 -1
- package/package.json +10 -1
@@ -13,6 +13,9 @@ _export(exports, {
|
|
13
13
|
ROUTE_SPEC_FILE: function() {
|
14
14
|
return ROUTE_SPEC_FILE;
|
15
15
|
},
|
16
|
+
NESTED_ROUTE_SPEC_FILE: function() {
|
17
|
+
return NESTED_ROUTE_SPEC_FILE;
|
18
|
+
},
|
16
19
|
MAIN_ENTRY_NAME: function() {
|
17
20
|
return MAIN_ENTRY_NAME;
|
18
21
|
},
|
@@ -107,6 +110,7 @@ _export(exports, {
|
|
107
110
|
const _export_star = require("@swc/helpers/_/_export_star");
|
108
111
|
_export_star._(require("./chainId"), exports);
|
109
112
|
const ROUTE_SPEC_FILE = "route.json";
|
113
|
+
const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
|
110
114
|
const MAIN_ENTRY_NAME = "main";
|
111
115
|
const SERVER_BUNDLE_DIRECTORY = "bundles";
|
112
116
|
const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
|
@@ -20,6 +20,8 @@ _export(exports, {
|
|
20
20
|
return _serialize.serializeJson;
|
21
21
|
}
|
22
22
|
});
|
23
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
23
24
|
const _storage = require("./storage");
|
24
25
|
const _serialize = require("./serialize");
|
26
|
+
_export_star._(require("./nestedRoutes"), exports);
|
25
27
|
const { run, useContext: useHeaders } = (0, _storage.createStorage)();
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "matchEntry", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return matchEntry;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
function sortByUrlPath(entries) {
|
12
|
+
entries.sort(function(a, b) {
|
13
|
+
const length1 = a.urlPath.length;
|
14
|
+
const length2 = b.urlPath.length;
|
15
|
+
if (length1 < length2) {
|
16
|
+
return 1;
|
17
|
+
}
|
18
|
+
if (length1 > length2) {
|
19
|
+
return -1;
|
20
|
+
}
|
21
|
+
return 0;
|
22
|
+
});
|
23
|
+
return entries;
|
24
|
+
}
|
25
|
+
const matchEntry = (pathname, entries) => {
|
26
|
+
sortByUrlPath(entries);
|
27
|
+
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
28
|
+
};
|
@@ -15,7 +15,11 @@ _export(exports, {
|
|
15
15
|
},
|
16
16
|
HMR_SOCK_PATH: function() {
|
17
17
|
return HMR_SOCK_PATH;
|
18
|
+
},
|
19
|
+
HTML_CHUNKSMAP_SEPARATOR: function() {
|
20
|
+
return HTML_CHUNKSMAP_SEPARATOR;
|
18
21
|
}
|
19
22
|
});
|
20
23
|
const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
|
21
24
|
const HMR_SOCK_PATH = "/webpack-hmr";
|
25
|
+
const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
|
@@ -0,0 +1,18 @@
|
|
1
|
+
function sortByUrlPath(entries) {
|
2
|
+
entries.sort(function(a, b) {
|
3
|
+
const length1 = a.urlPath.length;
|
4
|
+
const length2 = b.urlPath.length;
|
5
|
+
if (length1 < length2) {
|
6
|
+
return 1;
|
7
|
+
}
|
8
|
+
if (length1 > length2) {
|
9
|
+
return -1;
|
10
|
+
}
|
11
|
+
return 0;
|
12
|
+
});
|
13
|
+
return entries;
|
14
|
+
}
|
15
|
+
export const matchEntry = (pathname, entries) => {
|
16
|
+
sortByUrlPath(entries);
|
17
|
+
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
18
|
+
};
|
@@ -3,6 +3,10 @@ import { InternalPlugins } from '@modern-js/types';
|
|
3
3
|
* route specification file
|
4
4
|
*/
|
5
5
|
export declare const ROUTE_SPEC_FILE = "route.json";
|
6
|
+
/**
|
7
|
+
* Front-end routing metadata
|
8
|
+
*/
|
9
|
+
export declare const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
|
6
10
|
/**
|
7
11
|
* main entry name
|
8
12
|
*/
|
@@ -5,4 +5,5 @@
|
|
5
5
|
import type { IncomingHttpHeaders } from 'http';
|
6
6
|
declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
|
7
7
|
export { run, useHeaders };
|
8
|
-
export { serializeJson } from './serialize';
|
8
|
+
export { serializeJson } from './serialize';
|
9
|
+
export * from './nestedRoutes';
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { ModernServerContext, ServerRoute } from '@modern-js/types';
|
2
|
+
export type ServerContext = Pick<ModernServerContext, 'logger' | 'req' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
|
3
|
+
export declare const matchEntry: (pathname: string, entries: ServerRoute[]) => ServerRoute | undefined;
|
@@ -5,4 +5,8 @@ export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
|
|
5
5
|
/**
|
6
6
|
* hmr socket connect path
|
7
7
|
*/
|
8
|
-
export declare const HMR_SOCK_PATH = "/webpack-hmr";
|
8
|
+
export declare const HMR_SOCK_PATH = "/webpack-hmr";
|
9
|
+
/**
|
10
|
+
* html placeholder
|
11
|
+
*/
|
12
|
+
export declare const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.22.1-alpha.
|
18
|
+
"version": "2.22.1-alpha.2",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -36,41 +36,50 @@
|
|
36
36
|
},
|
37
37
|
"./runtime/router": {
|
38
38
|
"types": "./dist/types/runtime/router.d.ts",
|
39
|
+
"require": "./dist/cjs/runtime/router.js",
|
39
40
|
"default": "./dist/esm/runtime/router.js"
|
40
41
|
},
|
41
42
|
"./runtime/remix-router": {
|
42
43
|
"types": "./dist/types/runtime/remixRouter.d.ts",
|
44
|
+
"require": "./dist/cjs/runtime/remixRouter.js",
|
43
45
|
"default": "./dist/esm/runtime/remixRouter.js"
|
44
46
|
},
|
45
47
|
"./runtime/nested-routes": {
|
46
48
|
"types": "./dist/types/runtime/nestedRoutes.d.ts",
|
49
|
+
"require": "./dist/cjs/runtime/nestedRoutes.js",
|
47
50
|
"default": "./dist/esm/runtime/nestedRoutes.js"
|
48
51
|
},
|
49
52
|
"./runtime-browser": {
|
50
53
|
"jsnext:source": "./src/runtime-browser/index.d.ts",
|
54
|
+
"require": "./dist/cjs/runtime-browser/index.js",
|
51
55
|
"default": "./dist/esm/runtime-browser/index.js"
|
52
56
|
},
|
53
57
|
"./runtime-node": {
|
54
58
|
"types": "./dist/types/runtime-node/index.d.ts",
|
59
|
+
"require": "./dist/cjs/runtime-node/index.js",
|
55
60
|
"default": "./dist/esm/runtime-node/index.js"
|
56
61
|
},
|
57
62
|
"./runtime-node/router": {
|
58
63
|
"types": "./dist/types/runtime-node/router.d.ts",
|
64
|
+
"require": "./dist/cjs/runtime-node/router.js",
|
59
65
|
"default": "./dist/esm/runtime-node/router.js"
|
60
66
|
},
|
61
67
|
"./universal/constants": {
|
62
68
|
"types": "./dist/types/universal/constants.d.ts",
|
63
69
|
"import": "./dist/esm/universal/constants.js",
|
70
|
+
"require": "./dist/cjs/universal/constants.js",
|
64
71
|
"default": "./dist/cjs/universal/constants.js"
|
65
72
|
},
|
66
73
|
"./universal/format-webpack": {
|
67
74
|
"types": "./dist/types/universal/format-webpack.d.ts",
|
68
75
|
"import": "./dist/esm/universal/formatWebpack.js",
|
76
|
+
"require": "./dist/cjs/universal/formatWebpack.js",
|
69
77
|
"default": "./dist/cjs/universal/formatWebpack.js"
|
70
78
|
},
|
71
79
|
"./universal/plugin-dag-sort": {
|
72
80
|
"types": "./dist/types/universal/pluginDagSort.d.ts",
|
73
81
|
"import": "./dist/esm/universal/pluginDagSort.js",
|
82
|
+
"require": "./dist/cjs/universal/pluginDagSort.js",
|
74
83
|
"default": "./dist/cjs/universal/pluginDagSort.js"
|
75
84
|
},
|
76
85
|
"./ajv": "./dist/compiled/ajv/index.js",
|