@modern-js/runtime 2.66.0 → 2.67.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.
Files changed (50) hide show
  1. package/dist/cjs/cli/index.js +2 -7
  2. package/dist/cjs/router/cli/code/index.js +3 -4
  3. package/dist/cjs/router/cli/code/templates.js +3 -0
  4. package/dist/cjs/router/cli/entry.js +2 -2
  5. package/dist/cjs/router/cli/handler.js +6 -7
  6. package/dist/cjs/router/cli/index.js +12 -10
  7. package/dist/esm/cli/index.js +1 -5
  8. package/dist/esm/router/cli/code/index.js +6 -7
  9. package/dist/esm/router/cli/code/templates.js +13 -6
  10. package/dist/esm/router/cli/entry.js +3 -4
  11. package/dist/esm/router/cli/handler.js +9 -11
  12. package/dist/esm/router/cli/index.js +13 -11
  13. package/dist/esm-node/cli/index.js +1 -5
  14. package/dist/esm-node/router/cli/code/index.js +4 -5
  15. package/dist/esm-node/router/cli/code/templates.js +3 -0
  16. package/dist/esm-node/router/cli/entry.js +3 -3
  17. package/dist/esm-node/router/cli/handler.js +6 -7
  18. package/dist/esm-node/router/cli/index.js +13 -11
  19. package/dist/types/cli/index.d.ts +1 -2
  20. package/dist/types/common.d.ts +0 -6
  21. package/dist/types/config.d.ts +0 -2
  22. package/dist/types/core/context/runtime.d.ts +0 -3
  23. package/dist/types/index.d.ts +1 -2
  24. package/dist/types/router/cli/code/index.d.ts +1 -1
  25. package/dist/types/router/cli/entry.d.ts +1 -1
  26. package/dist/types/router/cli/handler.d.ts +3 -3
  27. package/package.json +12 -27
  28. package/types/index.d.ts +1 -13
  29. package/types/router.d.ts +0 -1
  30. package/dist/cjs/state/cli/index.js +0 -62
  31. package/dist/cjs/state/index.js +0 -43
  32. package/dist/cjs/state/plugins.js +0 -50
  33. package/dist/cjs/state/runtime/index.js +0 -42
  34. package/dist/cjs/state/runtime/plugin.js +0 -95
  35. package/dist/esm/state/cli/index.js +0 -41
  36. package/dist/esm/state/index.js +0 -7
  37. package/dist/esm/state/plugins.js +0 -19
  38. package/dist/esm/state/runtime/index.js +0 -6
  39. package/dist/esm/state/runtime/plugin.js +0 -93
  40. package/dist/esm-node/state/cli/index.js +0 -38
  41. package/dist/esm-node/state/index.js +0 -7
  42. package/dist/esm-node/state/plugins.js +0 -13
  43. package/dist/esm-node/state/runtime/index.js +0 -6
  44. package/dist/esm-node/state/runtime/plugin.js +0 -69
  45. package/dist/types/state/cli/index.d.ts +0 -3
  46. package/dist/types/state/index.d.ts +0 -3
  47. package/dist/types/state/plugins.d.ts +0 -4
  48. package/dist/types/state/runtime/index.d.ts +0 -3
  49. package/dist/types/state/runtime/plugin.d.ts +0 -11
  50. package/types/model.d.ts +0 -7
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
2
+ import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
3
3
  import { filterRoutesForServer } from "@modern-js/utils";
4
4
  import { isRouteEntry } from "./entry";
5
5
  import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler";
@@ -13,16 +13,19 @@ const routerPlugin = () => ({
13
13
  setup: (api) => {
14
14
  const nestedRoutes = {};
15
15
  const nestedRoutesForServer = {};
16
+ const { metaName } = api.getAppContext();
17
+ const isRouterV5 = api.isPluginExists(`@${metaName}/plugin-router-v5`);
16
18
  api._internalRuntimePlugins(({ entrypoint, plugins }) => {
17
19
  var _getEntryOptions;
18
- const { packageName, serverRoutes, metaName } = api.getAppContext();
20
+ const { nestedRoutesEntry, pageRoutesEntry } = entrypoint;
21
+ const { packageName, serverRoutes, metaName: metaName2 } = api.getAppContext();
19
22
  const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
20
23
  const userConfig = api.getNormalizedConfig();
21
24
  const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
22
- if (routerConfig && !isV5(userConfig)) {
25
+ if ((nestedRoutesEntry || pageRoutesEntry) && !isRouterV5) {
23
26
  plugins.push({
24
27
  name: "router",
25
- path: `@${metaName}/runtime/router`,
28
+ path: `@${metaName2}/runtime/router`,
26
29
  config: typeof routerConfig === "boolean" ? {
27
30
  serverBase
28
31
  } : {
@@ -57,24 +60,23 @@ const routerPlugin = () => ({
57
60
  };
58
61
  });
59
62
  api.modifyEntrypoints(async ({ entrypoints }) => {
60
- const newEntryPoints = await handleModifyEntrypoints(api, entrypoints);
63
+ const newEntryPoints = await handleModifyEntrypoints(isRouterV5, entrypoints);
61
64
  return {
62
65
  entrypoints: newEntryPoints
63
66
  };
64
67
  });
65
68
  api.generateEntryCode(async ({ entrypoints }) => {
66
- await handleGeneratorEntryCode(api, entrypoints);
69
+ await handleGeneratorEntryCode(api, entrypoints, isRouterV5);
67
70
  });
68
71
  api.addRuntimeExports(() => {
69
- const userConfig = api.useResolvedConfigContext();
70
- const { internalDirectory, metaName } = api.useAppContext();
72
+ const { internalDirectory, metaName: metaName2 } = api.useAppContext();
71
73
  const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
72
- if (!isV5(userConfig)) {
73
- pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/runtime/router'`);
74
+ if (!isRouterV5) {
75
+ pluginsExportsUtils.addExport(`export { default as router } from '@${metaName2}/runtime/router'`);
74
76
  }
75
77
  });
76
78
  api.onFileChanged(async (e) => {
77
- await handleFileChange(api, e);
79
+ await handleFileChange(api, isRouterV5, e);
78
80
  });
79
81
  api.modifyFileSystemRoutes(({ entrypoint, routes }) => {
80
82
  nestedRoutes[entrypoint.entryName] = routes;
@@ -1,10 +1,9 @@
1
1
  import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
2
  import { documentPlugin } from '../document/cli';
3
3
  import { routerPlugin } from '../router/cli';
4
- import { statePlugin } from '../state/cli';
5
4
  import { ssrPlugin } from './ssr';
6
5
  export { isRuntimeEntry } from './entry';
7
- export { statePlugin, ssrPlugin, routerPlugin, documentPlugin };
6
+ export { ssrPlugin, routerPlugin, documentPlugin };
8
7
  export declare const runtimePlugin: (params?: {
9
8
  plugins?: CliPluginFuture<AppTools<"shared">>[];
10
9
  }) => CliPluginFuture<AppTools<"shared">>;
@@ -1,17 +1,11 @@
1
1
  import type { Plugin, RuntimePluginFuture } from './core/plugin';
2
2
  import type { RouterConfig } from './router';
3
- import type { StateConfig } from './state';
4
3
  export declare const isBrowser: () => boolean;
5
4
  export interface AppConfig {
6
- state?: StateConfig | boolean;
7
5
  router?: Pick<RouterConfig, 'future' | 'basename'>;
8
6
  [key: string]: any;
9
7
  }
10
8
  export interface RuntimeConfig {
11
- state?: StateConfig;
12
- stateByEntries?: {
13
- [name: string]: StateConfig;
14
- };
15
9
  plugins?: (Plugin | RuntimePluginFuture)[];
16
10
  [key: string]: any;
17
11
  }
@@ -1,8 +1,6 @@
1
1
  import type { RouterConfig } from './router';
2
- import type { StateConfig } from './state';
3
2
  export interface RuntimeUserConfig {
4
3
  runtime?: {
5
- state?: boolean | StateConfig;
6
4
  router?: boolean | RouterConfig;
7
5
  };
8
6
  }
@@ -1,4 +1,3 @@
1
- import type { Store } from '@modern-js-reduck/store';
2
1
  import type { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
3
2
  import type { RouteManifest } from '../../router/runtime/types';
4
3
  import { createLoaderManager } from '../loader/loaderManager';
@@ -8,7 +7,6 @@ interface BaseRuntimeContext {
8
7
  loaderManager: ReturnType<typeof createLoaderManager>;
9
8
  isBrowser: boolean;
10
9
  ssrContext?: SSRServerContext;
11
- store?: Store;
12
10
  routeManifest: RouteManifest;
13
11
  routerContext?: StaticHandlerContext;
14
12
  context?: TSSRContext;
@@ -30,7 +28,6 @@ export interface TRuntimeContext extends Partial<BaseRuntimeContext> {
30
28
  request?: SSRServerContext['request'];
31
29
  /** @deprecated use context.response field instead */
32
30
  response?: SSRServerContext['response'];
33
- store?: Store;
34
31
  [key: string]: any;
35
32
  }
36
33
  export declare const getInitialContext: (isBrowser?: boolean, routeManifest?: RouteManifest) => RuntimeContext;
@@ -1,5 +1,4 @@
1
1
  import type { RouterConfig } from './router';
2
- import type { StateConfig } from './state';
3
2
  export type { Plugin, RuntimePluginFuture } from './core';
4
3
  export type { AppConfig, RuntimeConfig } from './common';
5
4
  export { isBrowser } from './common';
@@ -9,4 +8,4 @@ export { getMonitors } from './core/context/monitors';
9
8
  export { getRequest } from './core/context/request';
10
9
  export { setHeaders, setStatus, redirect } from './core/context/response';
11
10
  export { createApp, useLoader, bootstrap, RuntimeReactContext, defineConfig, defineRuntimeConfig, useRuntimeContext, } from './core';
12
- export type { StateConfig, RouterConfig };
11
+ export type { RouterConfig };
@@ -1,5 +1,5 @@
1
1
  import type { AppNormalizedConfig, AppTools, AppToolsContext } from '@modern-js/app-tools';
2
2
  import type { CLIPluginAPI } from '@modern-js/plugin-v2';
3
3
  import type { Entrypoint } from '@modern-js/types';
4
- export declare const generateCode: (appContext: AppToolsContext<"shared">, config: AppNormalizedConfig<"shared">, entrypoints: Entrypoint[], api: CLIPluginAPI<AppTools<"shared">>) => Promise<void>;
4
+ export declare const generateCode: (appContext: AppToolsContext<"shared">, config: AppNormalizedConfig<"shared">, entrypoints: Entrypoint[], api: CLIPluginAPI<AppTools<"shared">>, isRouterV5: boolean) => Promise<void>;
5
5
  export declare function generatorRegisterCode(internalDirectory: string, entryName: string, code: string): void;
@@ -2,4 +2,4 @@ import type { Entrypoint } from '@modern-js/types';
2
2
  export declare const hasPages: (dir: string) => boolean;
3
3
  export declare const hasNestedRoutes: (dir: string) => boolean;
4
4
  export declare const isRouteEntry: (dir: string) => string | false;
5
- export declare const modifyEntrypoints: (entrypoints: Entrypoint[], config?: Record<string, any>) => Entrypoint[];
5
+ export declare const modifyEntrypoints: (entrypoints: Entrypoint[], isRouterV5: boolean) => Entrypoint[];
@@ -1,6 +1,6 @@
1
1
  import type { AppTools } from '@modern-js/app-tools';
2
2
  import type { CLIPluginAPI } from '@modern-js/plugin-v2';
3
3
  import type { Entrypoint } from '@modern-js/types';
4
- export declare function handleModifyEntrypoints(api: CLIPluginAPI<AppTools<'shared'>>, entrypoints: Entrypoint[]): Promise<Entrypoint[]>;
5
- export declare function handleGeneratorEntryCode(api: CLIPluginAPI<AppTools<'shared'>>, entrypoints: Entrypoint[]): Promise<Entrypoint[]>;
6
- export declare function handleFileChange(api: CLIPluginAPI<AppTools<'shared'>>, e: any): Promise<void>;
4
+ export declare function handleModifyEntrypoints(isRouterV5: boolean, entrypoints: Entrypoint[]): Promise<Entrypoint[]>;
5
+ export declare function handleGeneratorEntryCode(api: CLIPluginAPI<AppTools<'shared'>>, entrypoints: Entrypoint[], isRouterV5: boolean): Promise<Entrypoint[]>;
6
+ export declare function handleFileChange(api: CLIPluginAPI<AppTools<'shared'>>, isRouterV5: boolean, e: any): Promise<void>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.66.0",
18
+ "version": "2.67.0",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -34,7 +34,6 @@
34
34
  "./types": "./types/index.d.ts",
35
35
  "./types/index": "./types/index.d.ts",
36
36
  "./types/router": "./types/router.d.ts",
37
- "./types/model": "./types/model.d.ts",
38
37
  "./context": {
39
38
  "types": "./dist/types/core/context/index.d.ts",
40
39
  "jsnext:source": "./src/core/context/index.ts",
@@ -92,11 +91,6 @@
92
91
  "node": "./dist/cjs/document/index.js",
93
92
  "default": "./dist/esm/document/index.js"
94
93
  },
95
- "./model": {
96
- "types": "./types/model.d.ts",
97
- "jsnext:source": "./src/state/index.ts",
98
- "default": "./dist/esm/state/index.js"
99
- },
100
94
  "./cli": {
101
95
  "types": "./dist/types/cli/index.d.ts",
102
96
  "jsnext:source": "./src/cli/index.ts",
@@ -178,9 +172,6 @@
178
172
  "ssr/server": [
179
173
  "./dist/types/core/server/server.d.ts"
180
174
  ],
181
- "model": [
182
- "./types/model.d.ts"
183
- ],
184
175
  "router": [
185
176
  "./dist/types/router/index.d.ts"
186
177
  ],
@@ -207,12 +198,6 @@
207
198
  "@loadable/babel-plugin": "5.15.3",
208
199
  "@loadable/component": "5.15.3",
209
200
  "@loadable/server": "5.15.3",
210
- "@modern-js-reduck/plugin-auto-actions": "^1.1.10",
211
- "@modern-js-reduck/plugin-devtools": "^1.1.10",
212
- "@modern-js-reduck/plugin-effects": "^1.1.10",
213
- "@modern-js-reduck/plugin-immutable": "^1.1.10",
214
- "@modern-js-reduck/react": "^1.1.10",
215
- "@modern-js-reduck/store": "^1.1.10",
216
201
  "@swc/helpers": "0.5.13",
217
202
  "@types/loadable__component": "^5.13.4",
218
203
  "@types/react-helmet": "^6.1.2",
@@ -226,13 +211,13 @@
226
211
  "react-is": "^18",
227
212
  "react-side-effect": "^2.1.1",
228
213
  "styled-components": "^5.3.1",
229
- "@modern-js/plugin": "2.66.0",
230
- "@modern-js/plugin-v2": "2.66.0",
231
- "@modern-js/plugin-data-loader": "2.66.0",
232
- "@modern-js/render": "2.66.0",
233
- "@modern-js/runtime-utils": "2.66.0",
234
- "@modern-js/types": "2.66.0",
235
- "@modern-js/utils": "2.66.0"
214
+ "@modern-js/plugin": "2.67.0",
215
+ "@modern-js/plugin-data-loader": "2.67.0",
216
+ "@modern-js/plugin-v2": "2.67.0",
217
+ "@modern-js/runtime-utils": "2.67.0",
218
+ "@modern-js/render": "2.67.0",
219
+ "@modern-js/types": "2.67.0",
220
+ "@modern-js/utils": "2.67.0"
236
221
  },
237
222
  "peerDependencies": {
238
223
  "react": ">=17",
@@ -240,7 +225,7 @@
240
225
  },
241
226
  "devDependencies": {
242
227
  "@remix-run/web-fetch": "^4.1.3",
243
- "@rsbuild/core": "1.2.19",
228
+ "@rsbuild/core": "1.3.2",
244
229
  "@testing-library/react": "^13.4.0",
245
230
  "@types/cookie": "0.6.0",
246
231
  "@types/invariant": "^2.2.30",
@@ -256,9 +241,9 @@
256
241
  "ts-node": "^10.9.1",
257
242
  "typescript": "^5",
258
243
  "webpack": "^5.98.0",
259
- "@modern-js/app-tools": "2.66.0",
260
- "@scripts/jest-config": "2.66.0",
261
- "@scripts/build": "2.66.0"
244
+ "@modern-js/app-tools": "2.67.0",
245
+ "@scripts/build": "2.66.0",
246
+ "@scripts/jest-config": "2.66.0"
262
247
  },
263
248
  "sideEffects": false,
264
249
  "publishConfig": {
package/types/index.d.ts CHANGED
@@ -1,16 +1,4 @@
1
- import type { StateConfig } from '../dist/types';
2
-
3
- declare module '@modern-js/app-tools' {
4
- interface RuntimeUserConfig {
5
- state?: StateConfig | boolean;
6
- }
7
- }
8
-
9
- declare module '@modern-js/module-tools' {
10
- interface RuntimeUserConfig {
11
- state?: StateConfig | boolean;
12
- }
13
- }
1
+ /// <reference types='@modern-js/plugin-state/types' />
14
2
 
15
3
  declare module 'http' {
16
4
  interface ServerResponse {
package/types/router.d.ts CHANGED
@@ -20,6 +20,5 @@ declare module '@modern-js/runtime' {
20
20
 
21
21
  interface RuntimeConfig {
22
22
  router?: Partial<RouterConfig>;
23
- routerByEntries?: { [name: string]: Partial<RouterConfig> };
24
23
  }
25
24
  }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cli_exports = {};
20
- __export(cli_exports, {
21
- default: () => cli_default,
22
- statePlugin: () => statePlugin
23
- });
24
- module.exports = __toCommonJS(cli_exports);
25
- var import_utils = require("@modern-js/utils");
26
- const PLUGIN_IDENTIFIER = "state";
27
- const statePlugin = () => ({
28
- name: "@modern-js/plugin-state",
29
- required: [
30
- "@modern-js/runtime"
31
- ],
32
- setup: (api) => {
33
- api._internalRuntimePlugins(({ entrypoint, plugins }) => {
34
- var _getEntryOptions;
35
- const { entryName, isMainEntry } = entrypoint;
36
- const userConfig = api.getNormalizedConfig();
37
- const { packageName, metaName } = api.getAppContext();
38
- const stateConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
39
- if (stateConfig) {
40
- plugins.push({
41
- name: PLUGIN_IDENTIFIER,
42
- path: `@${metaName}/runtime/model`,
43
- config: typeof stateConfig === "boolean" ? {} : stateConfig
44
- });
45
- }
46
- return {
47
- entrypoint,
48
- plugins
49
- };
50
- });
51
- api.addRuntimeExports(() => {
52
- const { internalDirectory, metaName } = api.useAppContext();
53
- const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
54
- pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/runtime/model'`);
55
- });
56
- }
57
- });
58
- var cli_default = statePlugin;
59
- // Annotate the CommonJS export names for ESM import in node:
60
- 0 && (module.exports = {
61
- statePlugin
62
- });
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var state_exports = {};
31
- __export(state_exports, {
32
- default: () => import_runtime2.default,
33
- state: () => import_runtime.default
34
- });
35
- module.exports = __toCommonJS(state_exports);
36
- var import_runtime = __toESM(require("./runtime"));
37
- var import_runtime2 = __toESM(require("./runtime"));
38
- __reExport(state_exports, require("./runtime"), module.exports);
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- state,
42
- ...require("./runtime")
43
- });
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var plugins_exports = {};
30
- __export(plugins_exports, {
31
- autoActions: () => autoActions,
32
- devtools: () => import_plugin_devtools.default,
33
- effects: () => effects,
34
- immer: () => immer
35
- });
36
- module.exports = __toCommonJS(plugins_exports);
37
- var import_plugin_auto_actions = __toESM(require("@modern-js-reduck/plugin-auto-actions"));
38
- var import_plugin_effects = require("@modern-js-reduck/plugin-effects");
39
- var import_plugin_immutable = __toESM(require("@modern-js-reduck/plugin-immutable"));
40
- var import_plugin_devtools = __toESM(require("@modern-js-reduck/plugin-devtools"));
41
- const effects = () => import_plugin_effects.plugin;
42
- const immer = () => import_plugin_immutable.default;
43
- const autoActions = () => import_plugin_auto_actions.default;
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {
46
- autoActions,
47
- devtools,
48
- effects,
49
- immer
50
- });
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var runtime_exports = {};
31
- __export(runtime_exports, {
32
- default: () => import_plugin.default
33
- });
34
- module.exports = __toCommonJS(runtime_exports);
35
- __reExport(runtime_exports, require("@modern-js-reduck/react"), module.exports);
36
- var import_plugin = __toESM(require("./plugin"));
37
- __reExport(runtime_exports, require("./plugin"), module.exports);
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- ...require("@modern-js-reduck/react"),
41
- ...require("./plugin")
42
- });
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var plugin_exports = {};
21
- __export(plugin_exports, {
22
- default: () => plugin_default,
23
- statePlugin: () => statePlugin
24
- });
25
- module.exports = __toCommonJS(plugin_exports);
26
- var import_jsx_runtime = require("react/jsx-runtime");
27
- var import_react = require("@modern-js-reduck/react");
28
- var import_store = require("@modern-js-reduck/store");
29
- var import_merge = require("@modern-js/runtime-utils/merge");
30
- var import_react2 = require("react");
31
- var import_common = require("../../common");
32
- var import_core = require("../../core");
33
- var import_plugins = require("../plugins");
34
- __reExport(plugin_exports, require("../plugins"), module.exports);
35
- const StatePluginHandleMap = {
36
- immer: import_plugins.immer,
37
- effects: import_plugins.effects,
38
- autoActions: import_plugins.autoActions,
39
- devtools: import_plugins.devtools
40
- };
41
- const getStoreConfig = (config) => {
42
- const internalPlugins = [
43
- "immer",
44
- "effects",
45
- "autoActions",
46
- "devtools"
47
- ];
48
- const plugins = [];
49
- internalPlugins.filter((plugin) => config[plugin] !== false).forEach((plugin) => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
50
- const storeConfig = {};
51
- for (const [key, value] of Object.entries(config)) {
52
- if (!internalPlugins.includes(key)) {
53
- storeConfig[key] = value;
54
- }
55
- }
56
- storeConfig.plugins = plugins;
57
- return storeConfig;
58
- };
59
- const statePlugin = (userConfig = {}) => ({
60
- name: "@modern-js/plugin-state",
61
- setup: (api) => {
62
- let storeConfig;
63
- return {
64
- wrapRoot(App) {
65
- const getStateApp = (props) => {
66
- const context = (0, import_react2.useContext)(import_core.RuntimeReactContext);
67
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Provider, {
68
- store: context.store,
69
- config: storeConfig,
70
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
71
- ...props
72
- })
73
- });
74
- };
75
- return getStateApp;
76
- },
77
- beforeRender(context) {
78
- const pluginConfig = api.useRuntimeConfigContext();
79
- const config = (0, import_merge.merge)(pluginConfig.state || {}, userConfig);
80
- storeConfig = getStoreConfig(config);
81
- if ((0, import_common.isBrowser)()) {
82
- var _window__SSR_DATA_data, _window__SSR_DATA, _window;
83
- storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.storeState) || {};
84
- }
85
- context.store = (0, import_store.createStore)(storeConfig);
86
- }
87
- };
88
- }
89
- });
90
- var plugin_default = statePlugin;
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- statePlugin,
94
- ...require("../plugins")
95
- });
@@ -1,41 +0,0 @@
1
- import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
2
- var PLUGIN_IDENTIFIER = "state";
3
- var statePlugin = function() {
4
- return {
5
- name: "@modern-js/plugin-state",
6
- required: [
7
- "@modern-js/runtime"
8
- ],
9
- setup: function(api) {
10
- api._internalRuntimePlugins(function(param) {
11
- var entrypoint = param.entrypoint, plugins = param.plugins;
12
- var _getEntryOptions;
13
- var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
14
- var userConfig = api.getNormalizedConfig();
15
- var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, metaName = _api_getAppContext.metaName;
16
- var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
17
- if (stateConfig) {
18
- plugins.push({
19
- name: PLUGIN_IDENTIFIER,
20
- path: "@".concat(metaName, "/runtime/model"),
21
- config: typeof stateConfig === "boolean" ? {} : stateConfig
22
- });
23
- }
24
- return {
25
- entrypoint,
26
- plugins
27
- };
28
- });
29
- api.addRuntimeExports(function() {
30
- var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
31
- var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
32
- pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/runtime/model'"));
33
- });
34
- }
35
- };
36
- };
37
- var cli_default = statePlugin;
38
- export {
39
- cli_default as default,
40
- statePlugin
41
- };
@@ -1,7 +0,0 @@
1
- import { default as default2 } from "./runtime";
2
- import { default as default3 } from "./runtime";
3
- export * from "./runtime";
4
- export {
5
- default3 as default,
6
- default2 as state
7
- };
@@ -1,19 +0,0 @@
1
- import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
2
- import { plugin as effectsPlugin } from "@modern-js-reduck/plugin-effects";
3
- import immerPlugin from "@modern-js-reduck/plugin-immutable";
4
- import { default as default2 } from "@modern-js-reduck/plugin-devtools";
5
- var effects = function() {
6
- return effectsPlugin;
7
- };
8
- var immer = function() {
9
- return immerPlugin;
10
- };
11
- var autoActions = function() {
12
- return autoActionsPlugin;
13
- };
14
- export {
15
- autoActions,
16
- default2 as devtools,
17
- effects,
18
- immer
19
- };