@modern-js/plugin-v2 2.63.7 → 2.63.8-alpha.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 (96) hide show
  1. package/dist/cjs/cli/run/create.js +25 -14
  2. package/dist/cjs/hooks.js +74 -2
  3. package/dist/cjs/index.js +8 -2
  4. package/dist/cjs/manager.js +3 -5
  5. package/dist/cjs/runtime/api.js +79 -0
  6. package/dist/cjs/runtime/context.js +51 -0
  7. package/dist/cjs/runtime/hooks.js +36 -0
  8. package/dist/cjs/runtime/index.js +39 -0
  9. package/dist/cjs/runtime/run/create.js +74 -0
  10. package/dist/cjs/runtime/run/index.js +29 -0
  11. package/dist/cjs/runtime/run/types.js +16 -0
  12. package/dist/cjs/types/runtime/api.js +16 -0
  13. package/dist/cjs/types/runtime/context.js +16 -0
  14. package/dist/cjs/types/runtime/hooks.js +16 -0
  15. package/dist/cjs/types/runtime/index.js +16 -0
  16. package/dist/cjs/types/runtime/plugin.js +16 -0
  17. package/dist/esm/cli/api.js +103 -0
  18. package/dist/esm/cli/context.js +53 -0
  19. package/dist/esm/cli/hooks.js +42 -0
  20. package/dist/esm/cli/index.js +14 -0
  21. package/dist/esm/cli/run/config/createLoadedConfig.js +190 -0
  22. package/dist/esm/cli/run/config/createResolvedConfig.js +30 -0
  23. package/dist/esm/cli/run/config/loadConfig.js +210 -0
  24. package/dist/esm/cli/run/create.js +300 -0
  25. package/dist/esm/cli/run/index.js +10 -0
  26. package/dist/esm/cli/run/run.js +60 -0
  27. package/dist/esm/cli/run/types.js +0 -0
  28. package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.js +24 -0
  29. package/dist/esm/cli/run/utils/commander.js +42 -0
  30. package/dist/esm/cli/run/utils/createFileWatcher.js +110 -0
  31. package/dist/esm/cli/run/utils/debug.js +5 -0
  32. package/dist/esm/cli/run/utils/initAppDir.js +36 -0
  33. package/dist/esm/cli/run/utils/loadEnv.js +24 -0
  34. package/dist/esm/cli/run/utils/mergeConfig.js +43 -0
  35. package/dist/esm/hooks.js +378 -0
  36. package/dist/esm/index.js +6 -357
  37. package/dist/esm/manager.js +161 -0
  38. package/dist/esm/runtime/api.js +59 -0
  39. package/dist/esm/runtime/context.js +25 -0
  40. package/dist/esm/runtime/hooks.js +12 -0
  41. package/dist/esm/runtime/index.js +11 -0
  42. package/dist/esm/runtime/run/create.js +72 -0
  43. package/dist/esm/runtime/run/index.js +5 -0
  44. package/dist/esm/runtime/run/types.js +0 -0
  45. package/dist/esm/types/cli/api.js +0 -0
  46. package/dist/esm/types/cli/context.js +0 -0
  47. package/dist/esm/types/cli/hooks.js +0 -0
  48. package/dist/esm/types/cli/index.js +0 -0
  49. package/dist/esm/types/cli/plugin.js +0 -0
  50. package/dist/esm/types/hooks.js +0 -0
  51. package/dist/esm/types/index.js +0 -0
  52. package/dist/esm/types/plugin.js +0 -0
  53. package/dist/esm/types/runtime/api.js +0 -0
  54. package/dist/esm/types/runtime/context.js +0 -0
  55. package/dist/esm/types/runtime/hooks.js +0 -0
  56. package/dist/esm/types/runtime/index.js +0 -0
  57. package/dist/esm/types/runtime/plugin.js +0 -0
  58. package/dist/esm/types/utils.js +0 -0
  59. package/dist/esm-node/cli/run/create.js +26 -15
  60. package/dist/esm-node/hooks.js +70 -1
  61. package/dist/esm-node/index.js +5 -2
  62. package/dist/esm-node/manager.js +2 -4
  63. package/dist/esm-node/runtime/api.js +55 -0
  64. package/dist/esm-node/runtime/context.js +26 -0
  65. package/dist/esm-node/runtime/hooks.js +12 -0
  66. package/dist/esm-node/runtime/index.js +11 -0
  67. package/dist/esm-node/runtime/run/create.js +50 -0
  68. package/dist/esm-node/runtime/run/index.js +5 -0
  69. package/dist/esm-node/runtime/run/types.js +0 -0
  70. package/dist/esm-node/types/runtime/api.js +0 -0
  71. package/dist/esm-node/types/runtime/context.js +0 -0
  72. package/dist/esm-node/types/runtime/hooks.js +0 -0
  73. package/dist/esm-node/types/runtime/index.js +0 -0
  74. package/dist/esm-node/types/runtime/plugin.js +0 -0
  75. package/dist/types/cli/run/create.d.ts +2 -1
  76. package/dist/types/hooks.d.ts +4 -1
  77. package/dist/types/index.d.ts +2 -1
  78. package/dist/types/manager.d.ts +3 -0
  79. package/dist/types/runtime/api.d.ts +9 -0
  80. package/dist/types/runtime/context.d.ts +11 -0
  81. package/dist/types/runtime/hooks.d.ts +2 -0
  82. package/dist/types/runtime/index.d.ts +5 -0
  83. package/dist/types/runtime/run/create.d.ts +7 -0
  84. package/dist/types/runtime/run/index.d.ts +5 -0
  85. package/dist/types/runtime/run/types.d.ts +6 -0
  86. package/dist/types/types/cli/hooks.d.ts +2 -2
  87. package/dist/types/types/hooks.d.ts +14 -2
  88. package/dist/types/types/index.d.ts +1 -0
  89. package/dist/types/types/plugin.d.ts +1 -1
  90. package/dist/types/types/runtime/api.d.ts +15 -0
  91. package/dist/types/types/runtime/context.d.ts +13 -0
  92. package/dist/types/types/runtime/hooks.d.ts +12 -0
  93. package/dist/types/types/runtime/index.d.ts +4 -0
  94. package/dist/types/types/runtime/plugin.d.ts +14 -0
  95. package/dist/types/types/utils.d.ts +1 -0
  96. package/package.json +15 -11
@@ -0,0 +1,15 @@
1
+ import type { PluginHookTap } from '../hooks';
2
+ import type { DeepPartial } from '../utils';
3
+ import type { RuntimeContext } from './context';
4
+ import type { Hooks } from './hooks';
5
+ import type { ModifyRuntimeConfigFn, OnBeforeRenderFn, PickContextFn, WrapRootFn } from './hooks';
6
+ import type { RuntimePluginExtends } from './plugin';
7
+ export type RuntimePluginAPI<Extends extends RuntimePluginExtends> = Readonly<{
8
+ updateRuntimeContext: (updateContext: DeepPartial<RuntimeContext>) => void;
9
+ getHooks: () => Readonly<Hooks<Extends['config'], RuntimeContext & Extends['extendContext']> & Extends['extendHooks']>;
10
+ getRuntimeConfig: () => Readonly<Extends['config']>;
11
+ onBeforeRender: PluginHookTap<OnBeforeRenderFn<Extends['extendContext']>>;
12
+ wrapRoot: PluginHookTap<WrapRootFn>;
13
+ pickContext: PluginHookTap<PickContextFn<RuntimeContext>>;
14
+ modifyRuntimeConfig: PluginHookTap<ModifyRuntimeConfigFn<Extends['config']>>;
15
+ }>;
@@ -0,0 +1,13 @@
1
+ import type { RuntimePluginAPI } from './api';
2
+ import type { Hooks } from './hooks';
3
+ import type { RuntimePluginExtends } from './plugin';
4
+ export type RuntimeContext = {};
5
+ export type InternalRuntimeContext<Extends extends RuntimePluginExtends> = RuntimeContext & {
6
+ /** All hooks. */
7
+ hooks: Hooks<Extends['config'], RuntimeContext & Extends['extendContext']> & Extends['extendHooks'];
8
+ /** All plugin registry hooks */
9
+ extendsHooks: Extends['extendHooks'];
10
+ config: Extends['config'];
11
+ pluginAPI?: RuntimePluginAPI<Extends>;
12
+ _internalContext?: InternalRuntimeContext<Extends>;
13
+ };
@@ -0,0 +1,12 @@
1
+ import type React from 'react';
2
+ import type { AsyncInterruptHook, CollectSyncHook, SyncHook } from '../hooks';
3
+ export type OnBeforeRenderFn<RuntimeContext> = (context: RuntimeContext, interrupt: (info: any) => any) => Promise<any> | any;
4
+ export type WrapRootFn = (root: React.ComponentType<any>) => React.ComponentType<any>;
5
+ export type PickContextFn<RuntimeContext> = (context: RuntimeContext) => RuntimeContext;
6
+ export type ModifyRuntimeConfigFn<RuntimeConfig> = (config: RuntimeConfig) => RuntimeConfig;
7
+ export type Hooks<RuntimeConfig, RuntimeContext> = {
8
+ onBeforeRender: AsyncInterruptHook<OnBeforeRenderFn<RuntimeContext>>;
9
+ wrapRoot: SyncHook<WrapRootFn>;
10
+ pickContext: SyncHook<PickContextFn<RuntimeContext>>;
11
+ modifyRuntimeConfig: CollectSyncHook<ModifyRuntimeConfigFn<RuntimeConfig>>;
12
+ };
@@ -0,0 +1,4 @@
1
+ export type { RuntimePluginAPI } from './api';
2
+ export type { RuntimeContext, InternalRuntimeContext } from './context';
3
+ export type { RuntimePlugin, RuntimePluginExtends } from './plugin';
4
+ export type { Hooks } from './hooks';
@@ -0,0 +1,14 @@
1
+ import type { PluginHook } from '../hooks';
2
+ import type { Plugin } from '../plugin';
3
+ import type { RuntimePluginAPI } from './api';
4
+ import type { RuntimeContext } from './context';
5
+ export interface RuntimePluginExtends<Config extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}> {
6
+ config?: Config;
7
+ extendContext?: ExtendContext;
8
+ extendApi?: ExtendAPI;
9
+ extendHooks?: ExtendHook;
10
+ }
11
+ /**
12
+ * The type of the Runtime plugin object.
13
+ */
14
+ export type RuntimePlugin<Extends extends RuntimePluginExtends> = Plugin<RuntimePluginAPI<Extends> & Extends['extendApi'], RuntimeContext & Extends['extendContext']>;
@@ -4,3 +4,4 @@ export type DeepPartial<T> = {
4
4
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
5
5
  };
6
6
  export type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
7
+ export type Tail<T extends any[]> = T extends [...infer Rest, any] ? Rest : never;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.7",
18
+ "version": "2.63.8-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -30,11 +30,6 @@
30
30
  },
31
31
  "default": "./dist/esm/index.js"
32
32
  },
33
- "./types": {
34
- "types": "./dist/types/types/index.d.ts",
35
- "jsnext:source": "./src/types/index.ts",
36
- "default": "./dist/cjs/types/index.js"
37
- },
38
33
  "./run": {
39
34
  "types": "./dist/types/cli/run/run.d.ts",
40
35
  "jsnext:source": "./src/cli/run/run.ts",
@@ -44,6 +39,11 @@
44
39
  "types": "./dist/types/cli/index.d.ts",
45
40
  "jsnext:source": "./src/cli/index.ts",
46
41
  "default": "./dist/cjs/cli/index.js"
42
+ },
43
+ "./runtime": {
44
+ "types": "./dist/types/runtime/index.d.ts",
45
+ "jsnext:source": "./src/runtime/index.ts",
46
+ "default": "./dist/esm/runtime/index.js"
47
47
  }
48
48
  },
49
49
  "typesVersions": {
@@ -56,30 +56,34 @@
56
56
  ],
57
57
  "cli": [
58
58
  "./dist/types/cli/index.d.ts"
59
+ ],
60
+ "runtime": [
61
+ "./dist/types/runtime/index.d.ts"
59
62
  ]
60
63
  }
61
64
  },
62
65
  "dependencies": {
63
66
  "@swc/helpers": "0.5.13",
64
67
  "@modern-js/node-bundle-require": "2.63.7",
68
+ "@modern-js/runtime-utils": "2.63.7",
65
69
  "@modern-js/utils": "2.63.7"
66
70
  },
67
71
  "devDependencies": {
68
72
  "@rsbuild/core": "1.1.13",
73
+ "@types/react": "^18.3.11",
69
74
  "@types/jest": "^29",
70
75
  "@types/node": "^14",
71
76
  "jest": "^29",
72
77
  "typescript": "^5",
73
- "@modern-js/types": "2.63.7",
74
- "@modern-js/uni-builder": "2.63.7",
78
+ "@scripts/jest-config": "2.63.7",
75
79
  "@scripts/build": "2.63.7",
76
- "@scripts/jest-config": "2.63.7"
80
+ "@modern-js/types": "2.63.7",
81
+ "@modern-js/uni-builder": "2.63.7"
77
82
  },
78
83
  "sideEffects": false,
79
84
  "publishConfig": {
80
85
  "registry": "https://registry.npmjs.org/",
81
- "access": "public",
82
- "provenance": true
86
+ "access": "public"
83
87
  },
84
88
  "scripts": {
85
89
  "new": "modern-lib new",