@modern-js/plugin-data-loader 2.7.0 → 2.9.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @modern-js/plugin-data-loader
2
+
3
+ ## 2.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @modern-js/utils@2.9.0
8
+
9
+ ## 2.8.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 0cf8540ffe: fix: should match the most similar entry
14
+ fix: 应该匹配最相似的 entry
15
+ - Updated dependencies [1104a9f18b]
16
+ - Updated dependencies [1f6ca2c7fb]
17
+ - @modern-js/utils@2.8.0
package/README.md CHANGED
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
19
19
 
20
20
  ## Contributing
21
21
 
22
- Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
23
 
24
24
  ## License
25
25
 
26
- Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -37,6 +37,20 @@ function isRedirectResponse(status) {
37
37
  function isResponse(value) {
38
38
  return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
39
39
  }
40
+ function sortByUrlPath(entries) {
41
+ entries.sort(function(a, b) {
42
+ const length1 = a.urlPath.length;
43
+ const length2 = b.urlPath.length;
44
+ if (length1 < length2) {
45
+ return 1;
46
+ }
47
+ if (length1 > length2) {
48
+ return -1;
49
+ }
50
+ return 0;
51
+ });
52
+ return entries;
53
+ }
40
54
  function convertModernRedirectResponse(headers, basename) {
41
55
  const newHeaders = new Headers(headers);
42
56
  let redirectUrl = headers.get("Location");
@@ -89,6 +103,7 @@ const sendLoaderResponse = async (res, nodeResponse) => {
89
103
  }
90
104
  };
91
105
  const matchEntry = (pathname, entries) => {
106
+ sortByUrlPath(entries);
92
107
  return entries.find((entry) => pathname.startsWith(entry.urlPath));
93
108
  };
94
109
  const handleRequest = async ({
@@ -195,6 +195,20 @@ function isRedirectResponse(status) {
195
195
  function isResponse(value) {
196
196
  return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
197
197
  }
198
+ function sortByUrlPath(entries) {
199
+ entries.sort(function(a, b) {
200
+ var length1 = a.urlPath.length;
201
+ var length2 = b.urlPath.length;
202
+ if (length1 < length2) {
203
+ return 1;
204
+ }
205
+ if (length1 > length2) {
206
+ return -1;
207
+ }
208
+ return 0;
209
+ });
210
+ return entries;
211
+ }
198
212
  function convertModernRedirectResponse(headers, basename) {
199
213
  var newHeaders = new Headers(headers);
200
214
  var redirectUrl = headers.get("Location");
@@ -325,6 +339,7 @@ var sendLoaderResponse = function() {
325
339
  };
326
340
  }();
327
341
  var matchEntry = function(pathname, entries) {
342
+ sortByUrlPath(entries);
328
343
  return entries.find(function(entry) {
329
344
  return pathname.startsWith(entry.urlPath);
330
345
  });
@@ -20,6 +20,20 @@ function isRedirectResponse(status) {
20
20
  function isResponse(value) {
21
21
  return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
22
22
  }
23
+ function sortByUrlPath(entries) {
24
+ entries.sort(function(a, b) {
25
+ const length1 = a.urlPath.length;
26
+ const length2 = b.urlPath.length;
27
+ if (length1 < length2) {
28
+ return 1;
29
+ }
30
+ if (length1 > length2) {
31
+ return -1;
32
+ }
33
+ return 0;
34
+ });
35
+ return entries;
36
+ }
23
37
  function convertModernRedirectResponse(headers, basename) {
24
38
  const newHeaders = new Headers(headers);
25
39
  let redirectUrl = headers.get("Location");
@@ -72,6 +86,7 @@ const sendLoaderResponse = async (res, nodeResponse) => {
72
86
  }
73
87
  };
74
88
  const matchEntry = (pathname, entries) => {
89
+ sortByUrlPath(entries);
75
90
  return entries.find((entry) => pathname.startsWith(entry.urlPath));
76
91
  };
77
92
  const handleRequest = async ({
@@ -1,6 +1,11 @@
1
1
  /**
2
- * modified from https://github.com/remix-run/remix/blob/main/packages/remix-react/data.ts
3
- * license at https://github.com/remix-run/remix/blob/main/LICENSE.md
2
+ * The following code is modified based on
3
+ * https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/packages/remix-react/data.ts
4
+ *
5
+ * MIT Licensed
6
+ * Author Michael Jackson
7
+ * Copyright 2021 Remix Software Inc.
8
+ * https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/LICENSE.md
4
9
  */
5
10
  import { UNSAFE_DeferredData as DeferredData } from '@modern-js/utils/remix-router';
6
11
  export declare function parseDeferredReadableStream(stream: ReadableStream<Uint8Array>): Promise<DeferredData>;
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@modern-js/plugin-data-loader",
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": "web-infra-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
9
  "react",
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.7.0",
14
+ "version": "2.9.0",
15
15
  "engines": {
16
16
  "node": ">=14.17.6"
17
17
  },
@@ -52,7 +52,7 @@
52
52
  "@remix-run/node": "^1.12.0",
53
53
  "path-to-regexp": "^6.2.0",
54
54
  "react-router-dom": "^6.8.1",
55
- "@modern-js/utils": "2.7.0"
55
+ "@modern-js/utils": "2.9.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/babel__core": "^7.1.15",
@@ -67,11 +67,11 @@
67
67
  "typescript": "^4",
68
68
  "webpack": "^5.75.0",
69
69
  "webpack-chain": "^6.5.1",
70
- "@modern-js/core": "2.7.0",
71
- "@modern-js/server-core": "2.7.0",
72
- "@modern-js/types": "2.7.0",
73
- "@scripts/build": "2.7.0",
74
- "@scripts/jest-config": "2.7.0"
70
+ "@modern-js/core": "2.9.0",
71
+ "@modern-js/server-core": "2.9.0",
72
+ "@modern-js/types": "2.9.0",
73
+ "@scripts/build": "2.9.0",
74
+ "@scripts/jest-config": "2.9.0"
75
75
  },
76
76
  "sideEffects": false,
77
77
  "publishConfig": {