@modern-js/plugin-data-loader 2.0.0-canary.6 → 2.0.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.
@@ -20,7 +20,7 @@ var __async = (__this, __arguments, generator) => {
20
20
  };
21
21
  import { compile } from "path-to-regexp";
22
22
  import { redirect } from "react-router-dom";
23
- import { LOADER_SEARCH_PARAM } from "../common/constants";
23
+ import { LOADER_ID_PARAM, DIRECT_PARAM } from "../common/constants";
24
24
  const getRequestUrl = ({
25
25
  params,
26
26
  request,
@@ -32,7 +32,8 @@ const getRequestUrl = ({
32
32
  });
33
33
  const newPathName = toPath(params);
34
34
  url.pathname = newPathName;
35
- url.searchParams.append(LOADER_SEARCH_PARAM, routeId);
35
+ url.searchParams.append(LOADER_ID_PARAM, routeId);
36
+ url.searchParams.append(DIRECT_PARAM, "true");
36
37
  return url;
37
38
  };
38
39
  const handleRedirectResponse = (res) => {
@@ -1,4 +1,6 @@
1
- const LOADER_SEARCH_PARAM = "_ssrDirect";
1
+ const LOADER_ID_PARAM = "__loader";
2
+ const DIRECT_PARAM = "__ssrDirect";
2
3
  export {
3
- LOADER_SEARCH_PARAM
4
+ DIRECT_PARAM,
5
+ LOADER_ID_PARAM
4
6
  };
@@ -46,13 +46,8 @@ import {
46
46
  import {
47
47
  matchRoutes
48
48
  } from "react-router-dom";
49
- import {
50
- createDebugger,
51
- LOADER_ROUTES_DIR,
52
- MAIN_ENTRY_NAME
53
- } from "@modern-js/utils";
54
- import { LOADER_SEARCH_PARAM } from "../common/constants";
55
- const debug = createDebugger("plugin-data-loader");
49
+ import { LOADER_ROUTES_DIR, MAIN_ENTRY_NAME } from "@modern-js/utils";
50
+ import { LOADER_ID_PARAM } from "../common/constants";
56
51
  installGlobals();
57
52
  const redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
58
53
  function isRedirectResponse(response) {
@@ -78,7 +73,6 @@ const callRouteLoader = (_0) => __async(void 0, [_0], function* ({
78
73
  request,
79
74
  loadContext
80
75
  }) {
81
- debug("callRouteLoader", routeId, params);
82
76
  if (!loader) {
83
77
  throw new Error(
84
78
  `You made a ${request.method} request to ${request.url} but did not provide a default component or \`loader\` for route "${routeId}", so there is no way to handle the request.`
@@ -130,7 +124,6 @@ const createLoaderRequest = (context) => {
130
124
  return new Request(url.href, init);
131
125
  };
132
126
  const sendLoaderResponse = (res, nodeResponse) => __async(void 0, null, function* () {
133
- debug("sendLoaderResponse");
134
127
  res.statusMessage = nodeResponse.statusText;
135
128
  res.statusCode = nodeResponse.status;
136
129
  for (const [key, value] of nodeResponse.headers.entries()) {
@@ -157,15 +150,12 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
157
150
  distDir
158
151
  }) {
159
152
  const { method, query } = context;
160
- debug("handleRequest start");
161
- const routeId = query[LOADER_SEARCH_PARAM];
153
+ const routeId = query[LOADER_ID_PARAM];
162
154
  if (!routeId || method.toLowerCase() !== "get") {
163
- debug("routId not found");
164
155
  return;
165
156
  }
166
157
  const entry = matchEntry(context.path, serverRoutes);
167
158
  if (!entry) {
168
- debug("entry not found");
169
159
  return;
170
160
  }
171
161
  const routesPath = path.join(
@@ -175,7 +165,6 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
175
165
  );
176
166
  const { routes } = yield import(routesPath);
177
167
  if (!routes) {
178
- debug("routes not found");
179
168
  return;
180
169
  }
181
170
  const { res } = context;
@@ -203,7 +192,6 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
203
192
  loadContext: {}
204
193
  });
205
194
  if (isRedirectResponse(response)) {
206
- debug("redirect response, location is", response.headers.get("Location"));
207
195
  const headers = new Headers(response.headers);
208
196
  headers.set("X-Modernjs-Redirect", headers.get("Location"));
209
197
  headers.delete("Location");
@@ -220,7 +208,6 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
220
208
  "Content-Type": "text/plain"
221
209
  }
222
210
  });
223
- debug("error response", error);
224
211
  }
225
212
  sendLoaderResponse(res, response);
226
213
  });
@@ -55,7 +55,8 @@ const getRequestUrl = ({
55
55
  });
56
56
  const newPathName = toPath(params);
57
57
  url.pathname = newPathName;
58
- url.searchParams.append(import_constants.LOADER_SEARCH_PARAM, routeId);
58
+ url.searchParams.append(import_constants.LOADER_ID_PARAM, routeId);
59
+ url.searchParams.append(import_constants.DIRECT_PARAM, "true");
59
60
  return url;
60
61
  };
61
62
  const handleRedirectResponse = (res) => {
@@ -17,11 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var constants_exports = {};
19
19
  __export(constants_exports, {
20
- LOADER_SEARCH_PARAM: () => LOADER_SEARCH_PARAM
20
+ DIRECT_PARAM: () => DIRECT_PARAM,
21
+ LOADER_ID_PARAM: () => LOADER_ID_PARAM
21
22
  });
22
23
  module.exports = __toCommonJS(constants_exports);
23
- const LOADER_SEARCH_PARAM = "_ssrDirect";
24
+ const LOADER_ID_PARAM = "__loader";
25
+ const DIRECT_PARAM = "__ssrDirect";
24
26
  // Annotate the CommonJS export names for ESM import in node:
25
27
  0 && (module.exports = {
26
- LOADER_SEARCH_PARAM
28
+ DIRECT_PARAM,
29
+ LOADER_ID_PARAM
27
30
  });
@@ -72,7 +72,6 @@ var import_node = require("@remix-run/node");
72
72
  var import_react_router_dom = require("react-router-dom");
73
73
  var import_utils = require("@modern-js/utils");
74
74
  var import_constants = require("../common/constants");
75
- const debug = (0, import_utils.createDebugger)("plugin-data-loader");
76
75
  (0, import_node.installGlobals)();
77
76
  const redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
78
77
  function isRedirectResponse(response) {
@@ -98,7 +97,6 @@ const callRouteLoader = (_0) => __async(void 0, [_0], function* ({
98
97
  request,
99
98
  loadContext
100
99
  }) {
101
- debug("callRouteLoader", routeId, params);
102
100
  if (!loader) {
103
101
  throw new Error(
104
102
  `You made a ${request.method} request to ${request.url} but did not provide a default component or \`loader\` for route "${routeId}", so there is no way to handle the request.`
@@ -150,7 +148,6 @@ const createLoaderRequest = (context) => {
150
148
  return new Request(url.href, init);
151
149
  };
152
150
  const sendLoaderResponse = (res, nodeResponse) => __async(void 0, null, function* () {
153
- debug("sendLoaderResponse");
154
151
  res.statusMessage = nodeResponse.statusText;
155
152
  res.statusCode = nodeResponse.status;
156
153
  for (const [key, value] of nodeResponse.headers.entries()) {
@@ -177,15 +174,12 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
177
174
  distDir
178
175
  }) {
179
176
  const { method, query } = context;
180
- debug("handleRequest start");
181
- const routeId = query[import_constants.LOADER_SEARCH_PARAM];
177
+ const routeId = query[import_constants.LOADER_ID_PARAM];
182
178
  if (!routeId || method.toLowerCase() !== "get") {
183
- debug("routId not found");
184
179
  return;
185
180
  }
186
181
  const entry = matchEntry(context.path, serverRoutes);
187
182
  if (!entry) {
188
- debug("entry not found");
189
183
  return;
190
184
  }
191
185
  const routesPath = import_path.default.join(
@@ -195,7 +189,6 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
195
189
  );
196
190
  const { routes } = yield Promise.resolve().then(() => __toESM(require(routesPath)));
197
191
  if (!routes) {
198
- debug("routes not found");
199
192
  return;
200
193
  }
201
194
  const { res } = context;
@@ -223,7 +216,6 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
223
216
  loadContext: {}
224
217
  });
225
218
  if (isRedirectResponse(response)) {
226
- debug("redirect response, location is", response.headers.get("Location"));
227
219
  const headers = new Headers(response.headers);
228
220
  headers.set("X-Modernjs-Redirect", headers.get("Location"));
229
221
  headers.delete("Location");
@@ -240,7 +232,6 @@ const handleRequest = (_0) => __async(void 0, [_0], function* ({
240
232
  "Content-Type": "text/plain"
241
233
  }
242
234
  });
243
- debug("error response", error);
244
235
  }
245
236
  sendLoaderResponse(res, response);
246
237
  });
@@ -124,7 +124,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
124
124
  };
125
125
  import { compile } from "path-to-regexp";
126
126
  import { redirect } from "react-router-dom";
127
- import { LOADER_SEARCH_PARAM } from "../common/constants";
127
+ import { LOADER_ID_PARAM, DIRECT_PARAM } from "../common/constants";
128
128
  var getRequestUrl = function(param) {
129
129
  var params = param.params, request = param.request, routeId = param.routeId;
130
130
  var url = new URL(request.url);
@@ -133,7 +133,8 @@ var getRequestUrl = function(param) {
133
133
  });
134
134
  var newPathName = toPath(params);
135
135
  url.pathname = newPathName;
136
- url.searchParams.append(LOADER_SEARCH_PARAM, routeId);
136
+ url.searchParams.append(LOADER_ID_PARAM, routeId);
137
+ url.searchParams.append(DIRECT_PARAM, "true");
137
138
  return url;
138
139
  };
139
140
  var handleRedirectResponse = function(res) {
@@ -1,2 +1,3 @@
1
- var LOADER_SEARCH_PARAM = "_ssrDirect";
2
- export { LOADER_SEARCH_PARAM };
1
+ var LOADER_ID_PARAM = "__loader";
2
+ var DIRECT_PARAM = "__ssrDirect";
3
+ export { DIRECT_PARAM, LOADER_ID_PARAM };
@@ -223,9 +223,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
223
223
  import path from "path";
224
224
  import { installGlobals, writeReadableStreamToWritable, Response as NodeResponse } from "@remix-run/node";
225
225
  import { matchRoutes } from "react-router-dom";
226
- import { createDebugger, LOADER_ROUTES_DIR, MAIN_ENTRY_NAME } from "@modern-js/utils";
227
- import { LOADER_SEARCH_PARAM } from "../common/constants";
228
- var debug = createDebugger("plugin-data-loader");
226
+ import { LOADER_ROUTES_DIR, MAIN_ENTRY_NAME } from "@modern-js/utils";
227
+ import { LOADER_ID_PARAM } from "../common/constants";
229
228
  installGlobals();
230
229
  var redirectStatusCodes = /* @__PURE__ */ new Set([
231
230
  301,
@@ -260,7 +259,6 @@ var callRouteLoader = function() {
260
259
  switch(_state.label){
261
260
  case 0:
262
261
  routeId = param.routeId, loader = param.loader, params = param.params, request = param.request, loadContext = param.loadContext;
263
- debug("callRouteLoader", routeId, params);
264
262
  if (!loader) {
265
263
  throw new Error("You made a ".concat(request.method, " request to ").concat(request.url, ' but did not provide a default component or `loader` for route "').concat(routeId, '", so there is no way to handle the request.'));
266
264
  }
@@ -376,7 +374,6 @@ var sendLoaderResponse = function() {
376
374
  return __generator(this, function(_state) {
377
375
  switch(_state.label){
378
376
  case 0:
379
- debug("sendLoaderResponse");
380
377
  res.statusMessage = nodeResponse.statusText;
381
378
  res.statusCode = nodeResponse.status;
382
379
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -446,17 +443,14 @@ var handleRequest = function() {
446
443
  case 0:
447
444
  context = param.context, serverRoutes = param.serverRoutes, distDir = param.distDir;
448
445
  method = context.method, query = context.query;
449
- debug("handleRequest start");
450
- routeId = query[LOADER_SEARCH_PARAM];
446
+ routeId = query[LOADER_ID_PARAM];
451
447
  if (!routeId || method.toLowerCase() !== "get") {
452
- debug("routId not found");
453
448
  return [
454
449
  2
455
450
  ];
456
451
  }
457
452
  entry = matchEntry(context.path, serverRoutes);
458
453
  if (!entry) {
459
- debug("entry not found");
460
454
  return [
461
455
  2
462
456
  ];
@@ -469,7 +463,6 @@ var handleRequest = function() {
469
463
  case 1:
470
464
  routes = _state.sent().routes;
471
465
  if (!routes) {
472
- debug("routes not found");
473
466
  return [
474
467
  2
475
468
  ];
@@ -516,7 +509,6 @@ var handleRequest = function() {
516
509
  case 3:
517
510
  response = _state.sent();
518
511
  if (isRedirectResponse(response)) {
519
- debug("redirect response, location is", response.headers.get("Location"));
520
512
  headers = new Headers(response.headers);
521
513
  headers.set("X-Modernjs-Redirect", headers.get("Location"));
522
514
  headers.delete("Location");
@@ -538,7 +530,6 @@ var handleRequest = function() {
538
530
  "Content-Type": "text/plain"
539
531
  }
540
532
  });
541
- debug("error response", error);
542
533
  return [
543
534
  3,
544
535
  5
@@ -1 +1,2 @@
1
- export declare const LOADER_SEARCH_PARAM = "_ssrDirect";
1
+ export declare const LOADER_ID_PARAM = "__loader";
2
+ export declare const DIRECT_PARAM = "__ssrDirect";
@@ -1,7 +1,7 @@
1
1
  import type { ServerPlugin } from '@modern-js/server-core';
2
2
  import type { ModernServerContext, ServerRoute } from '@modern-js/types';
3
3
  import { Response as NodeResponse } from '@remix-run/node';
4
- export declare type ServerContext = Pick<ModernServerContext, 'req' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
4
+ export type ServerContext = Pick<ModernServerContext, 'req' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
5
5
  export declare function isRedirectResponse(response: NodeResponse): boolean;
6
6
  export declare function isResponse(value: any): value is NodeResponse;
7
7
  export declare const getPathWithoutEntry: (pathname: string, entryPath: string) => string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-canary.6",
14
+ "version": "2.0.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -40,18 +40,13 @@
40
40
  "dependencies": {
41
41
  "@babel/core": "^7.18.0",
42
42
  "@babel/runtime": "^7.18.0",
43
- "@modern-js/babel-compiler": "2.0.0-beta.6",
44
- "@modern-js/utils": "2.0.0-beta.6",
45
43
  "@remix-run/node": "^1.9.0",
46
44
  "path-to-regexp": "^6.2.0",
47
- "react-router-dom": "^6.6.0"
45
+ "react-router-dom": "^6.6.0",
46
+ "@modern-js/babel-compiler": "2.0.0",
47
+ "@modern-js/utils": "2.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@modern-js/core": "2.0.0-beta.6",
51
- "@modern-js/server-core": "2.0.0-beta.6",
52
- "@modern-js/types": "2.0.0-beta.6",
53
- "@scripts/build": "2.0.0-beta.6",
54
- "@scripts/jest-config": "2.0.0-beta.6",
55
50
  "@types/babel__core": "^7.1.15",
56
51
  "@types/jest": "^27",
57
52
  "@types/node": "^14",
@@ -63,7 +58,12 @@
63
58
  "ts-jest": "^27.0.5",
64
59
  "typescript": "^4",
65
60
  "webpack": "^5.75.0",
66
- "webpack-chain": "^6.5.1"
61
+ "webpack-chain": "^6.5.1",
62
+ "@modern-js/core": "2.0.0",
63
+ "@modern-js/server-core": "2.0.0",
64
+ "@modern-js/types": "2.0.0",
65
+ "@scripts/build": "2.0.0",
66
+ "@scripts/jest-config": "2.0.0"
67
67
  },
68
68
  "sideEffects": false,
69
69
  "publishConfig": {
@@ -75,6 +75,5 @@
75
75
  "build": "modern-lib build",
76
76
  "dev": "modern-lib build --watch",
77
77
  "test": "jest --passWithNoTests"
78
- },
79
- "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
78
+ }
80
79
  }