@modern-js/utils 2.5.0-alpha.0 → 2.5.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/alias.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export declare type Alias = Record<string, string | string[]>;
2
- export declare type AliasOption = Alias | ((aliases: Alias) => Alias | void);
1
+ export type Alias = Record<string, string | string[]>;
2
+ export type AliasOption = Alias | ((aliases: Alias) => Alias | void);
3
3
  interface NormalizedConfig {
4
4
  source: {
5
5
  alias?: AliasOption | Array<AliasOption>;
package/dist/chainId.d.ts CHANGED
@@ -255,4 +255,4 @@ export declare const CHAIN_ID: {
255
255
  readonly TS_CONFIG_PATHS: "ts-config-paths";
256
256
  };
257
257
  };
258
- export declare type ChainIdentifier = typeof CHAIN_ID;
258
+ export type ChainIdentifier = typeof CHAIN_ID;
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Modified from https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L800
9
9
  */
10
- export declare type MetaAttributes = {
10
+ export type MetaAttributes = {
11
11
  [attributeName: string]: string | boolean;
12
12
  };
13
13
  export interface MetaOptions {
package/dist/index.d.ts CHANGED
@@ -41,6 +41,4 @@ export * from './plugin';
41
41
  export * from './routes';
42
42
  export * from './test-utils';
43
43
  export * from './getCoreJsVersion';
44
- export * from './react';
45
- export * from './nestedRoutes';
46
- export * from './serialize';
44
+ export * from './react';
package/dist/index.js CHANGED
@@ -58,5 +58,3 @@ __reExport(src_exports, require("./routes"), module.exports);
58
58
  __reExport(src_exports, require("./test-utils"), module.exports);
59
59
  __reExport(src_exports, require("./getCoreJsVersion"), module.exports);
60
60
  __reExport(src_exports, require("./react"), module.exports);
61
- __reExport(src_exports, require("./nestedRoutes"), module.exports);
62
- __reExport(src_exports, require("./serialize"), module.exports);
@@ -40,6 +40,13 @@ export declare const isUseSSRBundle: (config: any) => boolean;
40
40
 
41
41
  export declare const isServiceWorker: (config: any) => boolean;
42
42
  export declare const isFastRefresh: () => boolean;
43
+ export declare const isRouterV5: (config: {
44
+ runtime?: {
45
+ router?: {
46
+ mode?: string;
47
+ } | boolean;
48
+ };
49
+ }) => boolean;
43
50
  export * from './node-env';
44
51
  export * from './platform';
45
52
  export * from './type';
package/dist/is/index.js CHANGED
@@ -27,6 +27,7 @@ __export(is_exports, {
27
27
  isDepExists: () => isDepExists,
28
28
  isEmpty: () => isEmpty,
29
29
  isFastRefresh: () => isFastRefresh,
30
+ isRouterV5: () => isRouterV5,
30
31
  isSSR: () => isSSR,
31
32
  isServiceWorker: () => isServiceWorker,
32
33
  isTypescript: () => isTypescript,
@@ -82,11 +83,16 @@ const isServiceWorker = (config) => {
82
83
  return false;
83
84
  };
84
85
  const isFastRefresh = () => (0, import_node_env.isDev)() && process.env.FAST_REFRESH !== "false";
86
+ const isRouterV5 = (config) => {
87
+ var _a, _b, _c;
88
+ 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";
89
+ };
85
90
  // Annotate the CommonJS export names for ESM import in node:
86
91
  0 && (module.exports = {
87
92
  isDepExists,
88
93
  isEmpty,
89
94
  isFastRefresh,
95
+ isRouterV5,
90
96
  isSSR,
91
97
  isServiceWorker,
92
98
  isTypescript,
package/dist/logger.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Color } from '../compiled/chalk';
2
- declare type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
- declare type LogMsg = number | string | Error | null;
2
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ type LogMsg = number | string | Error | null;
4
4
  interface LoggerConfiguration {
5
5
  color?: typeof Color;
6
6
  label?: string;
@@ -15,7 +15,7 @@ interface ConstructorOptions {
15
15
  level?: string;
16
16
  types?: Record<string, LoggerConfiguration>;
17
17
  }
18
- declare type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
18
+ type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
19
19
  declare const LOG_TYPES: {
20
20
  error: {
21
21
  color: string;
@@ -58,7 +58,7 @@ declare class Logger {
58
58
  private getLongestLabel;
59
59
  }
60
60
 
61
- declare type LoggerInterface = { [key in keyof typeof LOG_TYPES]: LoggerFunction };
61
+ type LoggerInterface = { [key in keyof typeof LOG_TYPES]: LoggerFunction };
62
62
  declare const logger: Logger & LoggerInterface;
63
63
  export { Logger };
64
64
  export { logger };
@@ -1,5 +1,5 @@
1
1
  /** Different from */
2
- export declare type PathMatchExpression = string | RegExp;
2
+ export type PathMatchExpression = string | RegExp;
3
3
  export interface PathMatcher {
4
4
  match: PathMatchExpression;
5
5
  mark: string | ((substring: string, ...args: any[]) => string);
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export declare type Falsy = false | null | undefined | 0 | '';
1
+ export type Falsy = false | null | undefined | 0 | '';
package/dist/watch.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export declare type WatchChangeTypeValueT = 'add' | 'unlink' | 'change';
1
+ export type WatchChangeTypeValueT = 'add' | 'unlink' | 'change';
2
2
  export declare const WatchChangeType: Record<'ADD' | 'UNLINK' | 'CHANGE', WatchChangeTypeValueT>;
3
- declare type RunTaskType = (option: {
3
+ type RunTaskType = (option: {
4
4
  changedFilePath: string;
5
5
  changeType: WatchChangeTypeValueT;
6
6
  }) => void | Promise<void>;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.5.0-alpha.0",
14
+ "version": "2.5.1-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -23,9 +23,6 @@
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",
29
26
  "./ajv": "./compiled/ajv/index.js",
30
27
  "./glob": "./compiled/glob/index.js",
31
28
  "./chalk": "./compiled/chalk/index.js",
@@ -64,12 +61,6 @@
64
61
  "constants": [
65
62
  "./dist/constants.d.ts"
66
63
  ],
67
- "serialize": [
68
- "./dist/serialize.d.ts"
69
- ],
70
- "nestedRoutes": [
71
- "./dist/nestedRoutes.d.ts"
72
- ],
73
64
  "ajv": [
74
65
  "./compiled/ajv/types/ajv.d.ts"
75
66
  ],
@@ -129,36 +120,22 @@
129
120
  ],
130
121
  "chain-id": [
131
122
  "./dist/chainId.d.ts"
132
- ],
133
- "remix-router": [
134
- "./dist/remix-router.d.ts"
135
123
  ]
136
124
  }
137
125
  },
138
126
  "dependencies": {
139
127
  "caniuse-lite": "^1.0.30001451",
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"
128
+ "lodash": "^4.17.21"
148
129
  },
149
130
  "devDependencies": {
150
- "react": ">=17.0.0",
151
- "react-dom": ">=17.0.0",
152
- "react-router-dom": "^6.8.1",
131
+ "@modern-js/types": "2.5.0",
132
+ "@scripts/build": "2.5.0",
133
+ "@scripts/jest-config": "2.5.0",
153
134
  "@types/jest": "^27",
154
135
  "@types/node": "^14",
155
136
  "jest": "^27",
156
137
  "typescript": "^4",
157
- "webpack": "^5.75.0",
158
- "@types/serialize-javascript": "^5.0.1",
159
- "@modern-js/types": "2.5.0",
160
- "@scripts/build": "2.5.0",
161
- "@scripts/jest-config": "2.5.0"
138
+ "webpack": "^5.75.0"
162
139
  },
163
140
  "sideEffects": false,
164
141
  "scripts": {
@@ -1,9 +0,0 @@
1
- /**
2
- * runtime utils for nested routes generating
3
- */
4
- import type { NestedRoute } from '@modern-js/types';
5
- export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
6
- export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
7
- parent?: NestedRoute;
8
- DeferredDataComponent?: () => JSX.Element;
9
- }) => JSX.Element;
@@ -1,144 +0,0 @@
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, {
79
- fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {})
80
- });
81
- } else {
82
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
83
- fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}),
84
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
85
- });
86
- }
87
- } else if (isLoadableComponent(Component)) {
88
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
89
- } else if (isRoot) {
90
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
91
- children: [
92
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}),
93
- typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DeferredDataComponent, {})
94
- ]
95
- });
96
- } else {
97
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
98
- fallback: null,
99
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
100
- });
101
- }
102
- } else {
103
- nestedRoute.loading = parent == null ? void 0 : parent.loading;
104
- }
105
- if (element) {
106
- routeProps.element = element;
107
- }
108
- const childElements = children == null ? void 0 : children.map((childRoute) => {
109
- return renderNestedRoute(childRoute, { parent: nestedRoute });
110
- });
111
- const routeElement = index ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, __spreadProps(__spreadValues({}, routeProps), {
112
- index: true
113
- }), id) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, __spreadProps(__spreadValues({}, routeProps), {
114
- index: false,
115
- children: childElements
116
- }), id);
117
- return routeElement;
118
- };
119
- function createLoader(route) {
120
- const { loader } = route;
121
- if (loader) {
122
- return (args) => {
123
- if (typeof route.lazyImport === "function") {
124
- route.lazyImport();
125
- }
126
- return loader(args);
127
- };
128
- } else {
129
- return () => {
130
- if (typeof route.lazyImport === "function") {
131
- route.lazyImport();
132
- }
133
- return null;
134
- };
135
- }
136
- }
137
- function isLoadableComponent(component) {
138
- return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
139
- }
140
- // Annotate the CommonJS export names for ESM import in node:
141
- 0 && (module.exports = {
142
- renderNestedRoute,
143
- transformNestedRoutes
144
- });
@@ -1 +0,0 @@
1
- export * from '@remix-run/router';
@@ -1,17 +0,0 @@
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);
@@ -1 +0,0 @@
1
- export declare const serializeJson: (data: any) => string;
package/dist/serialize.js DELETED
@@ -1,36 +0,0 @@
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
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var serialize_exports = {};
25
- __export(serialize_exports, {
26
- serializeJson: () => serializeJson
27
- });
28
- module.exports = __toCommonJS(serialize_exports);
29
- var import_serialize_javascript = __toESM(require("serialize-javascript"));
30
- const serializeJson = (data) => {
31
- return (0, import_serialize_javascript.default)(data, { isJSON: true });
32
- };
33
- // Annotate the CommonJS export names for ESM import in node:
34
- 0 && (module.exports = {
35
- serializeJson
36
- });