@modern-js/utils 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dcad887024: feat: support deferred data for streaming ssr
8
+ feat: 流式渲染支持 deferred data
9
+ - 84bfb439b8: feat: support custom apiDir, lambdaDir and style of writing for bff
10
+ feat: 支持定制 api 目录,lambda 目录,bff 的写法
11
+
12
+ ### Patch Changes
13
+
14
+ - 0f15fc597c: fix: remove nestedRoutes export
15
+ fix: 移除 nestedRoutes 导出
16
+ - a4672f7c16: fix: lock @modern-js/utils/ssr by webpack alias
17
+ fix: 通过 webpack 别名将 @modern-js/utils/ssr 锁到同一版本
18
+ - 7fff9020e1: chore: make file naming consistent
19
+
20
+ chore: 统一文件命名为小驼峰格式
21
+
3
22
  ## 2.6.0
4
23
 
5
24
  ### Patch Changes
@@ -0,0 +1 @@
1
+ export declare const getTargetDir: (from: string, baseDir: string, targetBaseDir: string) => string;
@@ -0,0 +1,41 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var getTargetDir_exports = {};
29
+ __export(getTargetDir_exports, {
30
+ getTargetDir: () => getTargetDir
31
+ });
32
+ module.exports = __toCommonJS(getTargetDir_exports);
33
+ var path = __toESM(require("path"));
34
+ const getTargetDir = (from, baseDir, targetBaseDir) => {
35
+ const relativePath = path.relative(baseDir, from);
36
+ return path.resolve(targetBaseDir, relativePath);
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ getTargetDir
41
+ });
package/dist/index.d.ts CHANGED
@@ -32,13 +32,13 @@ export * from './nodeEnv';
32
32
  export * from './wait';
33
33
  export * from './emptyDir';
34
34
  export * from './getServerConfig';
35
- export * from './ssr';
36
35
  export * from './tryResolve';
37
36
  export * from './analyzeProject';
38
37
  export * from './chainId';
39
38
  export * from './version';
40
39
  export * from './plugin';
41
40
  export * from './routes';
42
- export * from './test-utils';
41
+ export * from './testUtils';
43
42
  export * from './getCoreJsVersion';
44
- export * from './react';
43
+ export * from './react';
44
+ export * from './getTargetDir';
package/dist/index.js CHANGED
@@ -48,13 +48,13 @@ __reExport(src_exports, require("./nodeEnv"), module.exports);
48
48
  __reExport(src_exports, require("./wait"), module.exports);
49
49
  __reExport(src_exports, require("./emptyDir"), module.exports);
50
50
  __reExport(src_exports, require("./getServerConfig"), module.exports);
51
- __reExport(src_exports, require("./ssr"), module.exports);
52
51
  __reExport(src_exports, require("./tryResolve"), module.exports);
53
52
  __reExport(src_exports, require("./analyzeProject"), module.exports);
54
53
  __reExport(src_exports, require("./chainId"), module.exports);
55
54
  __reExport(src_exports, require("./version"), module.exports);
56
55
  __reExport(src_exports, require("./plugin"), module.exports);
57
56
  __reExport(src_exports, require("./routes"), module.exports);
58
- __reExport(src_exports, require("./test-utils"), module.exports);
57
+ __reExport(src_exports, require("./testUtils"), module.exports);
59
58
  __reExport(src_exports, require("./getCoreJsVersion"), module.exports);
60
59
  __reExport(src_exports, require("./react"), module.exports);
60
+ __reExport(src_exports, require("./getTargetDir"), module.exports);
@@ -47,6 +47,6 @@ export declare const isRouterV5: (config: {
47
47
  } | boolean;
48
48
  };
49
49
  }) => boolean;
50
- export * from './node-env';
50
+ export * from './nodeEnv';
51
51
  export * from './platform';
52
52
  export * from './type';
package/dist/is/index.js CHANGED
@@ -41,8 +41,8 @@ module.exports = __toCommonJS(is_exports);
41
41
  var import_fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var import_debug = require("../debug");
44
- var import_node_env = require("./node-env");
45
- __reExport(is_exports, require("./node-env"), module.exports);
44
+ var import_nodeEnv = require("./nodeEnv");
45
+ __reExport(is_exports, require("./nodeEnv"), module.exports);
46
46
  __reExport(is_exports, require("./platform"), module.exports);
47
47
  __reExport(is_exports, require("./type"), module.exports);
48
48
  const debug = (0, import_debug.createDebugger)("judge-depExists");
@@ -86,7 +86,7 @@ const isServiceWorker = (config) => {
86
86
  }
87
87
  return false;
88
88
  };
89
- const isFastRefresh = () => (0, import_node_env.isDev)() && process.env.FAST_REFRESH !== "false";
89
+ const isFastRefresh = () => (0, import_nodeEnv.isDev)() && process.env.FAST_REFRESH !== "false";
90
90
  const isRouterV5 = (config) => {
91
91
  var _a, _b, _c;
92
92
  return typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
@@ -15,15 +15,15 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var node_env_exports = {};
19
- __export(node_env_exports, {
18
+ var nodeEnv_exports = {};
19
+ __export(nodeEnv_exports, {
20
20
  getNodeEnv: () => getNodeEnv,
21
21
  isDev: () => isDev,
22
22
  isProd: () => isProd,
23
23
  isProdProfile: () => isProdProfile,
24
24
  isTest: () => isTest
25
25
  });
26
- module.exports = __toCommonJS(node_env_exports);
26
+ module.exports = __toCommonJS(nodeEnv_exports);
27
27
  const getNodeEnv = () => process.env.NODE_ENV || "development";
28
28
  const isDev = () => getNodeEnv() === "development";
29
29
  const isProd = () => getNodeEnv() === "production";
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+
3
+ /**
4
+ * runtime utils for nested routes generating
5
+ */
6
+ import type { NestedRoute } from '@modern-js/types';
7
+ export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
8
+ export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
9
+ parent?: NestedRoute;
10
+ DeferredDataComponent?: () => JSX.Element | null;
11
+ }) => JSX.Element;
@@ -0,0 +1,129 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var nestedRoutes_exports = {};
36
+ __export(nestedRoutes_exports, {
37
+ renderNestedRoute: () => renderNestedRoute,
38
+ transformNestedRoutes: () => transformNestedRoutes
39
+ });
40
+ module.exports = __toCommonJS(nestedRoutes_exports);
41
+ var import_jsx_runtime = require("react/jsx-runtime");
42
+ var import_react = require("react");
43
+ var import_react_router_dom = require("react-router-dom");
44
+ const transformNestedRoutes = (routes) => {
45
+ const routeElements = [];
46
+ for (const route of routes) {
47
+ const routeElement = renderNestedRoute(route);
48
+ routeElements.push(routeElement);
49
+ }
50
+ return (0, import_react_router_dom.createRoutesFromElements)(routeElements);
51
+ };
52
+ const renderNestedRoute = (nestedRoute, options = {}) => {
53
+ const { children, index, id, component, isRoot } = nestedRoute;
54
+ const Component = component;
55
+ const { parent, DeferredDataComponent } = options;
56
+ const routeProps = {
57
+ caseSensitive: nestedRoute.caseSensitive,
58
+ path: nestedRoute.path,
59
+ id: nestedRoute.id,
60
+ loader: createLoader(nestedRoute),
61
+ action: nestedRoute.action,
62
+ hasErrorBoundary: nestedRoute.hasErrorBoundary,
63
+ shouldRevalidate: nestedRoute.shouldRevalidate,
64
+ handle: nestedRoute.handle,
65
+ index: nestedRoute.index,
66
+ element: nestedRoute.element,
67
+ errorElement: nestedRoute.errorElement
68
+ };
69
+ if (nestedRoute.error) {
70
+ const errorElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(nestedRoute.error, {});
71
+ routeProps.errorElement = errorElement;
72
+ }
73
+ let element;
74
+ if (Component) {
75
+ if (parent == null ? void 0 : parent.loading) {
76
+ const Loading = parent.loading;
77
+ if (isLoadableComponent(Component)) {
78
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}) });
79
+ } else {
80
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
81
+ }
82
+ } else if (isLoadableComponent(Component)) {
83
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
84
+ } else if (isRoot) {
85
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
86
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}),
87
+ typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DeferredDataComponent, {})
88
+ ] });
89
+ } else {
90
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
91
+ }
92
+ } else {
93
+ nestedRoute.loading = parent == null ? void 0 : parent.loading;
94
+ }
95
+ if (element) {
96
+ routeProps.element = element;
97
+ }
98
+ const childElements = children == null ? void 0 : children.map((childRoute) => {
99
+ return renderNestedRoute(childRoute, { parent: nestedRoute });
100
+ });
101
+ const routeElement = index ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, __spreadProps(__spreadValues({}, routeProps), { index: true }), id) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, __spreadProps(__spreadValues({}, routeProps), { index: false, children: childElements }), id);
102
+ return routeElement;
103
+ };
104
+ function createLoader(route) {
105
+ const { loader } = route;
106
+ if (loader) {
107
+ return (args) => {
108
+ if (typeof route.lazyImport === "function") {
109
+ route.lazyImport();
110
+ }
111
+ return loader(args);
112
+ };
113
+ } else {
114
+ return () => {
115
+ if (typeof route.lazyImport === "function") {
116
+ route.lazyImport();
117
+ }
118
+ return null;
119
+ };
120
+ }
121
+ }
122
+ function isLoadableComponent(component) {
123
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
124
+ }
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ renderNestedRoute,
128
+ transformNestedRoutes
129
+ });
@@ -0,0 +1 @@
1
+ export * from '@remix-run/router';
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var remix_router_exports = {};
16
+ module.exports = __toCommonJS(remix_router_exports);
17
+ __reExport(remix_router_exports, require("@remix-run/router"), module.exports);
@@ -0,0 +1 @@
1
+ export declare const serializeJson: (data: any) => string;
@@ -0,0 +1,40 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var serialize_exports = {};
29
+ __export(serialize_exports, {
30
+ serializeJson: () => serializeJson
31
+ });
32
+ module.exports = __toCommonJS(serialize_exports);
33
+ var import_serialize_javascript = __toESM(require("serialize-javascript"));
34
+ const serializeJson = (data) => {
35
+ return (0, import_serialize_javascript.default)(data, { isJSON: true });
36
+ };
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ serializeJson
40
+ });
@@ -15,11 +15,11 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var test_utils_exports = {};
19
- __export(test_utils_exports, {
18
+ var testUtils_exports = {};
19
+ __export(testUtils_exports, {
20
20
  initSnapshotSerializer: () => initSnapshotSerializer
21
21
  });
22
- module.exports = __toCommonJS(test_utils_exports);
22
+ module.exports = __toCommonJS(testUtils_exports);
23
23
  const initSnapshotSerializer = (root) => {
24
24
  expect.addSnapshotSerializer({
25
25
  test: (val) => typeof val === "string" && (val.includes("modern.js") || val.includes("node_modules") || val.includes(root)),
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.6.0",
14
+ "version": "2.7.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -23,6 +23,9 @@
23
23
  "./format": "./dist/format.js",
24
24
  "./logger": "./dist/logger.js",
25
25
  "./constants": "./dist/constants.js",
26
+ "./serialize": "./dist/serialize.js",
27
+ "./nestedRoutes": "./dist/nestedRoutes.js",
28
+ "./remix-router": "./dist/remix-router.js",
26
29
  "./ajv": "./compiled/ajv/index.js",
27
30
  "./glob": "./compiled/glob/index.js",
28
31
  "./chalk": "./compiled/chalk/index.js",
@@ -61,6 +64,12 @@
61
64
  "constants": [
62
65
  "./dist/constants.d.ts"
63
66
  ],
67
+ "serialize": [
68
+ "./dist/serialize.d.ts"
69
+ ],
70
+ "nestedRoutes": [
71
+ "./dist/nestedRoutes.d.ts"
72
+ ],
64
73
  "ajv": [
65
74
  "./compiled/ajv/types/ajv.d.ts"
66
75
  ],
@@ -120,22 +129,47 @@
120
129
  ],
121
130
  "chain-id": [
122
131
  "./dist/chainId.d.ts"
132
+ ],
133
+ "remix-router": [
134
+ "./dist/remix-router.d.ts"
123
135
  ]
124
136
  }
125
137
  },
126
138
  "dependencies": {
127
139
  "caniuse-lite": "^1.0.30001451",
128
- "lodash": "^4.17.21"
140
+ "lodash": "^4.17.21",
141
+ "serialize-javascript": "^6.0.0",
142
+ "@remix-run/router": "^1.3.2"
143
+ },
144
+ "peerDependencies": {
145
+ "react": ">=17.0.0",
146
+ "react-dom": ">=17.0.0",
147
+ "react-router-dom": "^6.8.1"
148
+ },
149
+ "peerDependenciesMeta": {
150
+ "react": {
151
+ "optional": true
152
+ },
153
+ "react-dom": {
154
+ "optional": true
155
+ },
156
+ "react-router-dom": {
157
+ "optional": true
158
+ }
129
159
  },
130
160
  "devDependencies": {
161
+ "react": ">=17.0.0",
162
+ "react-dom": ">=17.0.0",
163
+ "react-router-dom": "^6.8.1",
131
164
  "@types/jest": "^27",
132
165
  "@types/node": "^14",
133
166
  "jest": "^27",
134
167
  "typescript": "^4",
135
168
  "webpack": "^5.75.0",
136
- "@modern-js/types": "2.6.0",
137
- "@scripts/jest-config": "2.6.0",
138
- "@scripts/build": "2.6.0"
169
+ "@types/serialize-javascript": "^5.0.1",
170
+ "@modern-js/types": "2.7.0",
171
+ "@scripts/jest-config": "2.7.0",
172
+ "@scripts/build": "2.7.0"
139
173
  },
140
174
  "sideEffects": false,
141
175
  "scripts": {
File without changes
File without changes