@modern-js/plugin 2.69.5 → 3.0.0-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.
- package/dist/cjs/cli/api.js +119 -0
- package/dist/cjs/cli/context.js +85 -0
- package/dist/cjs/cli/hooks.js +65 -0
- package/dist/cjs/cli/index.js +68 -0
- package/dist/cjs/cli/run/config/createLoadedConfig.js +87 -0
- package/dist/cjs/cli/run/config/createResolvedConfig.js +48 -0
- package/dist/cjs/cli/run/config/loadConfig.js +113 -0
- package/dist/cjs/cli/run/create.js +187 -0
- package/dist/cjs/cli/run/index.js +56 -0
- package/dist/cjs/cli/run/run.js +57 -0
- package/dist/cjs/cli/run/types.js +18 -0
- package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
- package/dist/cjs/cli/run/utils/commander.js +56 -0
- package/dist/cjs/cli/run/utils/createFileWatcher.js +112 -0
- package/dist/cjs/cli/run/utils/debug.js +37 -0
- package/dist/cjs/cli/run/utils/initAppDir.js +55 -0
- package/dist/cjs/cli/run/utils/mergeConfig.js +66 -0
- package/dist/cjs/hooks.js +169 -0
- package/dist/cjs/index.js +53 -26
- package/dist/cjs/manager.js +135 -0
- package/dist/cjs/runtime/api.js +95 -0
- package/dist/cjs/runtime/context.js +60 -0
- package/dist/cjs/runtime/hooks.js +46 -0
- package/dist/cjs/runtime/index.js +51 -0
- package/dist/cjs/runtime/run/create.js +79 -0
- package/dist/cjs/runtime/run/index.js +37 -0
- package/dist/cjs/runtime/run/types.js +18 -0
- package/dist/cjs/server/api.js +96 -0
- package/dist/cjs/server/context.js +75 -0
- package/dist/cjs/server/hooks.js +43 -0
- package/dist/cjs/server/index.js +54 -0
- package/dist/cjs/server/run/create.js +79 -0
- package/dist/cjs/server/run/index.js +40 -0
- package/dist/cjs/server/run/types.js +18 -0
- package/dist/cjs/types/cli/api.js +18 -0
- package/dist/cjs/types/cli/context.js +18 -0
- package/dist/cjs/types/cli/hooks.js +18 -0
- package/dist/cjs/types/cli/index.js +18 -0
- package/dist/cjs/types/cli/plugin.js +18 -0
- package/dist/cjs/types/hooks.js +18 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/cjs/types/plugin.js +18 -0
- package/dist/cjs/types/runtime/api.js +18 -0
- package/dist/cjs/types/runtime/context.js +18 -0
- package/dist/cjs/types/runtime/hooks.js +18 -0
- package/dist/cjs/types/runtime/index.js +18 -0
- package/dist/cjs/types/runtime/plugin.js +18 -0
- package/dist/cjs/types/server/api.js +18 -0
- package/dist/cjs/types/server/context.js +18 -0
- package/dist/cjs/types/server/hooks.js +18 -0
- package/dist/cjs/types/server/index.js +18 -0
- package/dist/cjs/types/server/plugin.js +18 -0
- package/dist/cjs/types/utils.js +18 -0
- package/dist/esm/cli/api.mjs +85 -0
- package/dist/esm/cli/context.mjs +38 -0
- package/dist/esm/cli/hooks.mjs +31 -0
- package/dist/esm/cli/index.mjs +7 -0
- package/dist/esm/cli/run/config/createLoadedConfig.mjs +53 -0
- package/dist/esm/cli/run/config/createResolvedConfig.mjs +14 -0
- package/dist/esm/cli/run/config/loadConfig.mjs +59 -0
- package/dist/esm/cli/run/create.mjs +150 -0
- package/dist/esm/cli/run/index.mjs +7 -0
- package/dist/esm/cli/run/run.mjs +23 -0
- package/dist/esm/cli/run/types.mjs +0 -0
- package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
- package/dist/esm/cli/run/utils/commander.mjs +16 -0
- package/dist/esm/cli/run/utils/createFileWatcher.mjs +68 -0
- package/dist/esm/cli/run/utils/debug.mjs +3 -0
- package/dist/esm/cli/run/utils/initAppDir.mjs +11 -0
- package/dist/esm/cli/run/utils/mergeConfig.mjs +32 -0
- package/dist/esm/hooks.mjs +120 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/manager.mjs +101 -0
- package/dist/esm/runtime/api.mjs +61 -0
- package/dist/esm/runtime/context.mjs +23 -0
- package/dist/esm/runtime/hooks.mjs +12 -0
- package/dist/esm/runtime/index.mjs +5 -0
- package/dist/esm/runtime/run/create.mjs +45 -0
- package/dist/esm/runtime/run/index.mjs +3 -0
- package/dist/esm/runtime/run/types.mjs +0 -0
- package/dist/esm/server/api.mjs +59 -0
- package/dist/esm/server/context.mjs +38 -0
- package/dist/esm/server/hooks.mjs +9 -0
- package/dist/esm/server/index.mjs +5 -0
- package/dist/esm/server/run/create.mjs +45 -0
- package/dist/esm/server/run/index.mjs +3 -0
- package/dist/esm/server/run/types.mjs +0 -0
- package/dist/esm/types/cli/api.mjs +0 -0
- package/dist/esm/types/cli/context.mjs +0 -0
- package/dist/esm/types/cli/hooks.mjs +0 -0
- package/dist/esm/types/cli/index.mjs +0 -0
- package/dist/esm/types/cli/plugin.mjs +0 -0
- package/dist/esm/types/hooks.mjs +0 -0
- package/dist/esm/types/index.mjs +0 -0
- package/dist/esm/types/plugin.mjs +0 -0
- package/dist/esm/types/runtime/api.mjs +0 -0
- package/dist/esm/types/runtime/context.mjs +0 -0
- package/dist/esm/types/runtime/hooks.mjs +0 -0
- package/dist/esm/types/runtime/index.mjs +0 -0
- package/dist/esm/types/runtime/plugin.mjs +0 -0
- package/dist/esm/types/server/api.mjs +0 -0
- package/dist/esm/types/server/context.mjs +0 -0
- package/dist/esm/types/server/hooks.mjs +0 -0
- package/dist/esm/types/server/index.mjs +0 -0
- package/dist/esm/types/server/plugin.mjs +0 -0
- package/dist/esm/types/utils.mjs +0 -0
- package/dist/esm-node/cli/api.mjs +85 -0
- package/dist/esm-node/cli/context.mjs +38 -0
- package/dist/esm-node/cli/hooks.mjs +31 -0
- package/dist/esm-node/cli/index.mjs +7 -0
- package/dist/esm-node/cli/run/config/createLoadedConfig.mjs +53 -0
- package/dist/esm-node/cli/run/config/createResolvedConfig.mjs +14 -0
- package/dist/esm-node/cli/run/config/loadConfig.mjs +59 -0
- package/dist/esm-node/cli/run/create.mjs +150 -0
- package/dist/esm-node/cli/run/index.mjs +7 -0
- package/dist/esm-node/cli/run/run.mjs +23 -0
- package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
- package/dist/esm-node/cli/run/utils/commander.mjs +16 -0
- package/dist/esm-node/cli/run/utils/createFileWatcher.mjs +68 -0
- package/dist/esm-node/cli/run/utils/debug.mjs +3 -0
- package/dist/esm-node/cli/run/utils/initAppDir.mjs +11 -0
- package/dist/esm-node/cli/run/utils/mergeConfig.mjs +32 -0
- package/dist/esm-node/hooks.mjs +120 -0
- package/dist/esm-node/index.mjs +3 -0
- package/dist/esm-node/manager.mjs +101 -0
- package/dist/esm-node/runtime/api.mjs +61 -0
- package/dist/esm-node/runtime/context.mjs +23 -0
- package/dist/esm-node/runtime/hooks.mjs +12 -0
- package/dist/esm-node/runtime/index.mjs +5 -0
- package/dist/esm-node/runtime/run/create.mjs +45 -0
- package/dist/esm-node/runtime/run/index.mjs +3 -0
- package/dist/esm-node/runtime/run/types.mjs +0 -0
- package/dist/esm-node/server/api.mjs +59 -0
- package/dist/esm-node/server/context.mjs +38 -0
- package/dist/esm-node/server/hooks.mjs +9 -0
- package/dist/esm-node/server/index.mjs +5 -0
- package/dist/esm-node/server/run/create.mjs +45 -0
- package/dist/esm-node/server/run/index.mjs +3 -0
- package/dist/esm-node/server/run/types.mjs +0 -0
- package/dist/esm-node/types/cli/api.mjs +0 -0
- package/dist/esm-node/types/cli/context.mjs +0 -0
- package/dist/esm-node/types/cli/hooks.mjs +0 -0
- package/dist/esm-node/types/cli/index.mjs +0 -0
- package/dist/esm-node/types/cli/plugin.mjs +0 -0
- package/dist/esm-node/types/hooks.mjs +0 -0
- package/dist/esm-node/types/index.mjs +0 -0
- package/dist/esm-node/types/plugin.mjs +0 -0
- package/dist/esm-node/types/runtime/api.mjs +0 -0
- package/dist/esm-node/types/runtime/context.mjs +0 -0
- package/dist/esm-node/types/runtime/hooks.mjs +0 -0
- package/dist/esm-node/types/runtime/index.mjs +0 -0
- package/dist/esm-node/types/runtime/plugin.mjs +0 -0
- package/dist/esm-node/types/server/api.mjs +0 -0
- package/dist/esm-node/types/server/context.mjs +0 -0
- package/dist/esm-node/types/server/hooks.mjs +0 -0
- package/dist/esm-node/types/server/index.mjs +0 -0
- package/dist/esm-node/types/server/plugin.mjs +0 -0
- package/dist/esm-node/types/utils.mjs +0 -0
- package/dist/types/cli/api.d.ts +8 -0
- package/dist/types/cli/context.d.ts +19 -0
- package/dist/types/cli/hooks.d.ts +42 -0
- package/dist/types/cli/index.d.ts +6 -0
- package/dist/types/cli/run/config/createLoadedConfig.d.ts +2 -0
- package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
- package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
- package/dist/types/cli/run/create.d.ts +16 -0
- package/dist/types/cli/run/index.d.ts +13 -0
- package/dist/types/cli/run/run.d.ts +2 -0
- package/dist/types/cli/run/types.d.ts +32 -0
- package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
- package/dist/types/cli/run/utils/commander.d.ts +5 -0
- package/dist/types/cli/run/utils/createFileWatcher.d.ts +3 -0
- package/dist/types/cli/run/utils/debug.d.ts +1 -0
- package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
- package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
- package/dist/types/hooks.d.ts +7 -0
- package/dist/types/index.d.ts +7 -4
- package/dist/types/manager.d.ts +5 -0
- package/dist/types/runtime/api.d.ts +9 -0
- package/dist/types/runtime/context.d.ts +11 -0
- package/dist/types/runtime/hooks.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/run/create.d.ts +7 -0
- package/dist/types/runtime/run/index.d.ts +5 -0
- package/dist/types/runtime/run/types.d.ts +6 -0
- package/dist/types/server/api.d.ts +9 -0
- package/dist/types/server/context.d.ts +13 -0
- package/dist/types/server/hooks.d.ts +9 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/run/create.d.ts +7 -0
- package/dist/types/server/run/index.d.ts +8 -0
- package/dist/types/server/run/types.d.ts +22 -0
- package/dist/types/types/cli/api.d.ts +49 -0
- package/dist/types/types/cli/context.d.ts +42 -0
- package/dist/types/types/cli/hooks.d.ts +72 -0
- package/dist/types/types/cli/index.d.ts +4 -0
- package/dist/types/types/cli/plugin.d.ts +17 -0
- package/dist/types/types/hooks.d.ts +27 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/plugin.d.ts +46 -0
- package/dist/types/types/runtime/api.d.ts +22 -0
- package/dist/types/types/runtime/context.d.ts +13 -0
- package/dist/types/types/runtime/hooks.d.ts +39 -0
- package/dist/types/types/runtime/index.d.ts +4 -0
- package/dist/types/types/runtime/plugin.d.ts +14 -0
- package/dist/types/types/server/api.d.ts +19 -0
- package/dist/types/types/server/context.d.ts +28 -0
- package/dist/types/types/server/hooks.d.ts +24 -0
- package/dist/types/types/server/index.d.ts +4 -0
- package/dist/types/types/server/plugin.d.ts +14 -0
- package/dist/types/types/utils.d.ts +7 -0
- package/package.json +68 -14
- package/rslib.config.mts +4 -0
- package/rstest.config.ts +5 -0
- package/dist/cjs/farrow-pipeline/context.js +0 -44
- package/dist/cjs/farrow-pipeline/counter.js +0 -37
- package/dist/cjs/farrow-pipeline/index.js +0 -87
- package/dist/cjs/manager/async.js +0 -124
- package/dist/cjs/manager/index.js +0 -26
- package/dist/cjs/manager/shared.js +0 -60
- package/dist/cjs/manager/sync.js +0 -194
- package/dist/cjs/manager/types.js +0 -16
- package/dist/cjs/waterfall/async.js +0 -68
- package/dist/cjs/waterfall/index.js +0 -24
- package/dist/cjs/waterfall/sync.js +0 -67
- package/dist/cjs/workflow/async.js +0 -60
- package/dist/cjs/workflow/index.js +0 -30
- package/dist/cjs/workflow/interrupt.js +0 -64
- package/dist/cjs/workflow/parallel.js +0 -53
- package/dist/cjs/workflow/sync.js +0 -56
- package/dist/cjs/workflow/syncParallel.js +0 -55
- package/dist/esm/index.js +0 -882
- package/dist/esm-node/farrow-pipeline/context.js +0 -20
- package/dist/esm-node/farrow-pipeline/counter.js +0 -13
- package/dist/esm-node/farrow-pipeline/index.js +0 -60
- package/dist/esm-node/index.js +0 -4
- package/dist/esm-node/manager/async.js +0 -106
- package/dist/esm-node/manager/index.js +0 -3
- package/dist/esm-node/manager/shared.js +0 -32
- package/dist/esm-node/manager/sync.js +0 -172
- package/dist/esm-node/waterfall/async.js +0 -42
- package/dist/esm-node/waterfall/index.js +0 -2
- package/dist/esm-node/waterfall/sync.js +0 -41
- package/dist/esm-node/workflow/async.js +0 -35
- package/dist/esm-node/workflow/index.js +0 -5
- package/dist/esm-node/workflow/interrupt.js +0 -39
- package/dist/esm-node/workflow/parallel.js +0 -28
- package/dist/esm-node/workflow/sync.js +0 -31
- package/dist/esm-node/workflow/syncParallel.js +0 -30
- package/dist/types/farrow-pipeline/context.d.ts +0 -12
- package/dist/types/farrow-pipeline/counter.d.ts +0 -11
- package/dist/types/farrow-pipeline/index.d.ts +0 -29
- package/dist/types/manager/async.d.ts +0 -54
- package/dist/types/manager/index.d.ts +0 -3
- package/dist/types/manager/shared.d.ts +0 -12
- package/dist/types/manager/sync.d.ts +0 -66
- package/dist/types/manager/types.d.ts +0 -33
- package/dist/types/waterfall/async.d.ts +0 -21
- package/dist/types/waterfall/index.d.ts +0 -2
- package/dist/types/waterfall/sync.d.ts +0 -20
- package/dist/types/workflow/async.d.ts +0 -12
- package/dist/types/workflow/index.d.ts +0 -5
- package/dist/types/workflow/interrupt.d.ts +0 -12
- package/dist/types/workflow/parallel.d.ts +0 -10
- package/dist/types/workflow/sync.d.ts +0 -11
- package/dist/types/workflow/syncParallel.d.ts +0 -10
- /package/dist/esm-node/{manager/types.js → cli/run/types.mjs} +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createServer } from './create';
|
|
2
|
+
export declare const server: {
|
|
3
|
+
run: (options: import("./types").ServerRunOptions) => Promise<{
|
|
4
|
+
serverContext: import("../..").InternalServerContext<import("../..").ServerPluginExtends<{}, {}, {}, {}>>;
|
|
5
|
+
}>;
|
|
6
|
+
};
|
|
7
|
+
export { createServer };
|
|
8
|
+
export type { ServerCreateOptions } from './types';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerRoute } from '@modern-js/types';
|
|
2
|
+
import type { Plugin } from '../../types/plugin';
|
|
3
|
+
export type ServerCreateOptions = {
|
|
4
|
+
/** server working directory, and then also dist directory */
|
|
5
|
+
pwd: string;
|
|
6
|
+
metaName?: string;
|
|
7
|
+
routes?: ServerRoute[];
|
|
8
|
+
appContext: {
|
|
9
|
+
internalDirectory?: string;
|
|
10
|
+
appDirectory?: string;
|
|
11
|
+
sharedDirectory?: string;
|
|
12
|
+
apiDirectory?: string;
|
|
13
|
+
lambdaDirectory?: string;
|
|
14
|
+
bffRuntimeFramework?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type ServerRunOptions = {
|
|
18
|
+
options: ServerCreateOptions;
|
|
19
|
+
config: Record<string, any>;
|
|
20
|
+
plugins: Plugin[];
|
|
21
|
+
handleSetupResult?: (params: any, api: Record<string, any>) => Promise<void> | void;
|
|
22
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn } from '@rsbuild/core';
|
|
2
|
+
import type { Hooks } from '../../cli/hooks';
|
|
3
|
+
import type { PluginHook, PluginHookTap } from '../hooks';
|
|
4
|
+
import type { DeepPartial } from '../utils';
|
|
5
|
+
import type { AppContext } from './context';
|
|
6
|
+
import type { AddCommandFn, AddWatchFilesFn, ConfigFn, InternalRuntimePluginsFn, InternalServerPluginsFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyServerRoutesFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn } from './hooks';
|
|
7
|
+
import type { CLIPluginExtends } from './plugin';
|
|
8
|
+
/**
|
|
9
|
+
* Define a generic CLI plugin API that provider can extend as needed.
|
|
10
|
+
*/
|
|
11
|
+
export type CLIPluginAPI<Extends extends CLIPluginExtends> = Readonly<{
|
|
12
|
+
isPluginExists: (name: string) => boolean;
|
|
13
|
+
getAppContext: () => Readonly<AppContext<Extends> & Extends['extendContext']>;
|
|
14
|
+
getConfig: () => Readonly<Extends['config']>;
|
|
15
|
+
getNormalizedConfig: () => Readonly<Extends['normalizedConfig']>;
|
|
16
|
+
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils'], Extends['extendConfigUtils']> & Extends['extendHooks']>;
|
|
17
|
+
updateAppContext: (appContext: DeepPartial<AppContext<Extends> & Extends['extendContext']>) => void;
|
|
18
|
+
config: PluginHookTap<ConfigFn<DeepPartial<Extends['config']>>>;
|
|
19
|
+
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config'], Extends['extendConfigUtils']>>;
|
|
20
|
+
modifyResolvedConfig: PluginHookTap<ModifyResolvedConfigFn<Extends['normalizedConfig'], Extends['extendConfigUtils']>>;
|
|
21
|
+
modifyRsbuildConfig: PluginHookTap<ModifyRsbuildConfigFn<Extends['extendBuildUtils']>>;
|
|
22
|
+
modifyBundlerChain: PluginHookTap<ModifyBundlerChainFn<Extends['extendBuildUtils']>>;
|
|
23
|
+
/** Only works when bundler is Rspack */
|
|
24
|
+
modifyRspackConfig: PluginHookTap<ModifyRspackConfigFn<Extends['extendBuildUtils']>>;
|
|
25
|
+
modifyHtmlPartials: PluginHookTap<ModifyHtmlPartialsFn>;
|
|
26
|
+
addCommand: PluginHookTap<AddCommandFn>;
|
|
27
|
+
onPrepare: PluginHookTap<OnPrepareFn>;
|
|
28
|
+
addWatchFiles: PluginHookTap<AddWatchFilesFn>;
|
|
29
|
+
onFileChanged: PluginHookTap<OnFileChangedFn>;
|
|
30
|
+
onBeforeRestart: PluginHookTap<OnBeforeRestartFn>;
|
|
31
|
+
onBeforeCreateCompiler: PluginHookTap<OnBeforeCreateCompilerFn>;
|
|
32
|
+
onAfterCreateCompiler: PluginHookTap<OnAfterCreateCompilerFn>;
|
|
33
|
+
onDevCompileDone: PluginHookTap<OnDevCompileDoneFn>;
|
|
34
|
+
onBeforeBuild: PluginHookTap<OnBeforeBuildFn>;
|
|
35
|
+
onAfterBuild: PluginHookTap<OnAfterBuildFn>;
|
|
36
|
+
onBeforeDev: PluginHookTap<OnBeforeDevFn>;
|
|
37
|
+
onAfterDev: PluginHookTap<OnAfterDevFn>;
|
|
38
|
+
onBeforeDeploy: PluginHookTap<OnBeforeDeployFn>;
|
|
39
|
+
onAfterDeploy: PluginHookTap<OnAfterDeployFn>;
|
|
40
|
+
onBeforeExit: PluginHookTap<OnBeforeExitFn>;
|
|
41
|
+
_internalRuntimePlugins: PluginHookTap<InternalRuntimePluginsFn>;
|
|
42
|
+
_internalServerPlugins: PluginHookTap<InternalServerPluginsFn>;
|
|
43
|
+
modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
|
|
44
|
+
} & CLIPluginExtendsAPI<Extends>>;
|
|
45
|
+
export type CLIPluginExtendsAPI<Extends extends CLIPluginExtends> = {
|
|
46
|
+
[K in keyof Extends['extendHooks']]: PluginHookTap<Extends['extendHooks'][K] extends PluginHook<infer Args> ? Args extends (...args: any[]) => any ? Args : (...args: any[]) => any : (...args: any[]) => any>;
|
|
47
|
+
} & Extends['extendApi'];
|
|
48
|
+
export type AllKeysForCLIPluginExtendsAPI<Extends extends CLIPluginExtends> = keyof CLIPluginExtendsAPI<Extends>;
|
|
49
|
+
export type AllValueForCLIPluginExtendsAPI<Extends extends CLIPluginExtends> = CLIPluginExtendsAPI<Extends>[AllKeysForCLIPluginExtendsAPI<Extends>];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BuilderInstance } from '@modern-js/builder';
|
|
2
|
+
import type { ServerRoute } from '@modern-js/types';
|
|
3
|
+
import type { Hooks } from '../../cli/hooks';
|
|
4
|
+
import type { CLIPluginAPI } from './api';
|
|
5
|
+
import type { CLIPlugin, CLIPluginExtends } from './plugin';
|
|
6
|
+
export interface Entrypoint {
|
|
7
|
+
isMainEntry?: boolean;
|
|
8
|
+
entryName: string;
|
|
9
|
+
entry: string;
|
|
10
|
+
}
|
|
11
|
+
/** The public context */
|
|
12
|
+
export type AppContext<Extends extends CLIPluginExtends> = {
|
|
13
|
+
metaName: string;
|
|
14
|
+
packageName: string;
|
|
15
|
+
configFile: string;
|
|
16
|
+
command: string;
|
|
17
|
+
isProd: boolean;
|
|
18
|
+
appDirectory: string;
|
|
19
|
+
srcDirectory: string;
|
|
20
|
+
distDirectory: string;
|
|
21
|
+
nodeModulesDirectory: string;
|
|
22
|
+
plugins: CLIPlugin<Extends>[];
|
|
23
|
+
bundlerType?: 'rspack';
|
|
24
|
+
builder?: BuilderInstance;
|
|
25
|
+
port?: number;
|
|
26
|
+
host?: string;
|
|
27
|
+
ip?: string;
|
|
28
|
+
serverRoutes?: ServerRoute[];
|
|
29
|
+
};
|
|
30
|
+
/** The inner context. */
|
|
31
|
+
export type InternalContext<Extends extends CLIPluginExtends> = AppContext<Extends> & {
|
|
32
|
+
/** All hooks. */
|
|
33
|
+
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils'], Extends['extendConfigUtils']> & Extends['extendHooks'];
|
|
34
|
+
/** All plugin registry hooks */
|
|
35
|
+
extendsHooks: Extends['extendHooks'];
|
|
36
|
+
/** Current App config. */
|
|
37
|
+
config: Readonly<Extends['config']>;
|
|
38
|
+
/** The normalized Rsbuild config. */
|
|
39
|
+
normalizedConfig?: Extends['normalizedConfig'];
|
|
40
|
+
pluginAPI?: CLIPluginAPI<Extends> & Record<string, (...args: any[]) => any>;
|
|
41
|
+
_internalContext?: InternalContext<Extends>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ServerPlugin as ServerPluginConfig, ServerRoute } from '@modern-js/types';
|
|
2
|
+
import type { Command } from '@modern-js/utils/commander';
|
|
3
|
+
import type { ModifyBundlerChainUtils, ModifyRspackConfigUtils, RsbuildConfig, Rspack, RspackChain } from '@rsbuild/core';
|
|
4
|
+
import type { TransformFunction } from '../plugin';
|
|
5
|
+
import type { MaybePromise } from '../utils';
|
|
6
|
+
import type { Entrypoint } from './context';
|
|
7
|
+
declare module '@modern-js/utils/commander' {
|
|
8
|
+
interface Command {
|
|
9
|
+
commandsMap: Map<string, Command>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export interface RuntimePluginConfig {
|
|
13
|
+
name: string;
|
|
14
|
+
path: string;
|
|
15
|
+
config: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
export type { ServerPluginConfig };
|
|
18
|
+
export type ConfigFn<Config> = () => Config | Promise<Config>;
|
|
19
|
+
export type ModifyConfigFn<Config, ExtendConfigUtils> = (arg: Config, utils?: ExtendConfigUtils) => Config | Promise<Config>;
|
|
20
|
+
export type ModifyResolvedConfigFn<NormalizedConfig, ExtendConfigUtils> = (arg: NormalizedConfig, utils?: ExtendConfigUtils) => NormalizedConfig | Promise<NormalizedConfig>;
|
|
21
|
+
type IPartialMethod = (...script: string[]) => void;
|
|
22
|
+
export interface PartialMethod {
|
|
23
|
+
append: IPartialMethod;
|
|
24
|
+
prepend: IPartialMethod;
|
|
25
|
+
}
|
|
26
|
+
export type ModifyHtmlPartialsFn = (params: {
|
|
27
|
+
entrypoint: Entrypoint;
|
|
28
|
+
partials: {
|
|
29
|
+
top: PartialMethod;
|
|
30
|
+
head: PartialMethod;
|
|
31
|
+
body: PartialMethod;
|
|
32
|
+
};
|
|
33
|
+
}) => Promise<void> | void;
|
|
34
|
+
export type AddCommandFn = (params: {
|
|
35
|
+
program: Command;
|
|
36
|
+
}) => void;
|
|
37
|
+
export type OnPrepareFn = () => Promise<void> | void;
|
|
38
|
+
type WatchFilesReturnType = Array<string> | {
|
|
39
|
+
files: string[];
|
|
40
|
+
isPrivate: boolean;
|
|
41
|
+
};
|
|
42
|
+
export type AddWatchFilesFn = () => WatchFilesReturnType | Promise<WatchFilesReturnType>;
|
|
43
|
+
export type OnFileChangedFn = (params: {
|
|
44
|
+
filename: string;
|
|
45
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
46
|
+
isPrivate: boolean;
|
|
47
|
+
}) => void;
|
|
48
|
+
export type OnBeforeRestartFn = () => Promise<void> | void;
|
|
49
|
+
export type OnBeforeDevFn = () => Promise<void> | void;
|
|
50
|
+
export type OnAfterDevFn = (params: {
|
|
51
|
+
port: number;
|
|
52
|
+
}) => Promise<void> | void;
|
|
53
|
+
export type OnBeforeDeployFn = (options?: Record<string, any>) => Promise<void> | void;
|
|
54
|
+
export type OnAfterDeployFn = (options?: Record<string, any>) => Promise<void> | void;
|
|
55
|
+
export type OnBeforeExitFn = () => Promise<void> | void;
|
|
56
|
+
export type ModifyBundlerChainFn<ExtendsUtils> = (chain: RspackChain, utils: ModifyBundlerChainUtils & ExtendsUtils) => MaybePromise<void>;
|
|
57
|
+
export type ModifyRsbuildConfigUtils = {
|
|
58
|
+
/** Merge multiple Rsbuild config objects into one. */
|
|
59
|
+
mergeRsbuildConfig: (...configs: RsbuildConfig[]) => RsbuildConfig;
|
|
60
|
+
};
|
|
61
|
+
export type ModifyRsbuildConfigFn<ExtendsUtils> = (config: RsbuildConfig, utils: ModifyRsbuildConfigUtils & ExtendsUtils) => MaybePromise<RsbuildConfig | void>;
|
|
62
|
+
export type ModifyRspackConfigFn<ExtendsUtils> = (config: Rspack.Configuration, utils: ModifyRspackConfigUtils & ExtendsUtils) => MaybePromise<Rspack.Configuration | void>;
|
|
63
|
+
export type InternalRuntimePluginsFn = TransformFunction<{
|
|
64
|
+
entrypoint: Entrypoint;
|
|
65
|
+
plugins: RuntimePluginConfig[];
|
|
66
|
+
}>;
|
|
67
|
+
export type InternalServerPluginsFn = TransformFunction<{
|
|
68
|
+
plugins: ServerPluginConfig[];
|
|
69
|
+
}>;
|
|
70
|
+
export type ModifyServerRoutesFn = TransformFunction<{
|
|
71
|
+
routes: ServerRoute[];
|
|
72
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PluginHook } from '../hooks';
|
|
2
|
+
import type { Plugin } from '../plugin';
|
|
3
|
+
import type { CLIPluginAPI } from './api';
|
|
4
|
+
import type { AppContext } from './context';
|
|
5
|
+
export interface CLIPluginExtends<Config extends Record<string, any> = {}, NormalizedConfig extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}, ExtendBuildUtils extends Record<string, any> = {}, ExtendConfigUtils extends Record<string, any> = {}> {
|
|
6
|
+
config?: Config;
|
|
7
|
+
normalizedConfig?: NormalizedConfig;
|
|
8
|
+
extendContext?: ExtendContext;
|
|
9
|
+
extendApi?: ExtendAPI;
|
|
10
|
+
extendHooks?: ExtendHook;
|
|
11
|
+
extendBuildUtils?: ExtendBuildUtils;
|
|
12
|
+
extendConfigUtils?: ExtendConfigUtils;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The type of the CLI plugin object.
|
|
16
|
+
*/
|
|
17
|
+
export type CLIPlugin<Extends extends CLIPluginExtends> = Plugin<CLIPluginAPI<Extends> & Extends['extendApi'], AppContext<Extends> & Extends['extendContext']>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Tail, UnwrapPromise } from './utils';
|
|
2
|
+
export type SyncHook<Callback extends (...args: any[]) => any> = {
|
|
3
|
+
tap: (cb: Callback) => void;
|
|
4
|
+
call: (...args: Parameters<Callback>) => ReturnType<Callback>;
|
|
5
|
+
};
|
|
6
|
+
export type AsyncHook<Callback extends (...args: any[]) => any> = {
|
|
7
|
+
tap: (cb: Callback) => void;
|
|
8
|
+
call: (...args: Parameters<Callback>) => Promise<UnwrapPromise<ReturnType<Callback>>>;
|
|
9
|
+
};
|
|
10
|
+
export type AsyncInterruptHook<Callback extends (...args: any[]) => any> = {
|
|
11
|
+
tap: (cb: Callback) => void;
|
|
12
|
+
call: (...args: Tail<Parameters<Callback>>) => Promise<UnwrapPromise<ReturnType<Callback>>>;
|
|
13
|
+
};
|
|
14
|
+
export type AsyncPipelineHook<Callback extends (...args: any[]) => any> = {
|
|
15
|
+
tap: (cb: Callback) => void;
|
|
16
|
+
call: (...args: Parameters<Callback>) => Promise<UnwrapPromise<ReturnType<Callback>>>;
|
|
17
|
+
};
|
|
18
|
+
export type CollectAsyncHook<Callback extends (...params: any[]) => any> = {
|
|
19
|
+
tap: (cb: Callback) => void;
|
|
20
|
+
call: (...params: Parameters<Callback>) => Promise<UnwrapPromise<ReturnType<Callback>>[]>;
|
|
21
|
+
};
|
|
22
|
+
export type CollectSyncHook<Callback extends (...params: any[]) => any> = {
|
|
23
|
+
tap: (cb: Callback) => void;
|
|
24
|
+
call: (...params: Parameters<Callback>) => ReturnType<Callback>[];
|
|
25
|
+
};
|
|
26
|
+
export type PluginHook<Callback extends (...args: any[]) => any> = SyncHook<Callback> | AsyncHook<Callback> | CollectSyncHook<Callback> | CollectAsyncHook<Callback> | AsyncInterruptHook<Callback> | AsyncPipelineHook<Callback>;
|
|
27
|
+
export type PluginHookTap<T extends (...args: any[]) => any> = (options: T) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { Plugin, PluginManager, TransformFunction, } from './plugin';
|
|
2
|
+
export type { CLIPluginAPI, AppContext, InternalContext, Entrypoint, CLIPlugin, } from './cli';
|
|
3
|
+
export type { RuntimePluginAPI, RuntimeContext, InternalRuntimeContext, RuntimePlugin, } from './runtime';
|
|
4
|
+
export type { AsyncHook, CollectAsyncHook, PluginHook, PluginHookTap, } from './hooks';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PluginHook } from './hooks';
|
|
2
|
+
import type { Falsy } from './utils';
|
|
3
|
+
import type { MaybePromise } from './utils';
|
|
4
|
+
export type TransformFunction<T> = (arg: T) => T | Promise<T>;
|
|
5
|
+
export type Plugin<PluginAPI = {}, Context = {}> = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the plugin, a unique identifier.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The plugins that this plugin depends on.
|
|
12
|
+
*/
|
|
13
|
+
usePlugins?: Plugin<PluginAPI, Context>[];
|
|
14
|
+
/**
|
|
15
|
+
* The plugins add new hooks to the plugin manager.
|
|
16
|
+
*/
|
|
17
|
+
registryHooks?: Record<string, PluginHook<(...args: any[]) => any>>;
|
|
18
|
+
/**
|
|
19
|
+
* The plugins add new apis to the plugin manager.
|
|
20
|
+
*/
|
|
21
|
+
_registryApi?: (...params: any[]) => Record<string, (...args: any[]) => any>;
|
|
22
|
+
/**
|
|
23
|
+
* The setup function of the plugin, which can be an async function.
|
|
24
|
+
* This function is called once when the plugin is initialized.
|
|
25
|
+
* @param api provides the context info, utility functions and lifecycle hooks.
|
|
26
|
+
*/
|
|
27
|
+
setup?: (api: PluginAPI) => MaybePromise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Declare the names of pre-plugins, which will be executed before the current plugin.
|
|
30
|
+
*/
|
|
31
|
+
pre?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Declare the names of post-plugins, which will be executed after the current plugin.
|
|
34
|
+
*/
|
|
35
|
+
post?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Declare the names of required plugins, which will check if the plugin is added.
|
|
38
|
+
*/
|
|
39
|
+
required?: string[];
|
|
40
|
+
};
|
|
41
|
+
export type PluginManager = {
|
|
42
|
+
getPlugins: () => Plugin[];
|
|
43
|
+
addPlugins: (plugins: Array<Plugin | Falsy>) => void;
|
|
44
|
+
clear: () => void;
|
|
45
|
+
isPluginExists: (name: string) => boolean;
|
|
46
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PluginHook, PluginHookTap } from '../hooks';
|
|
2
|
+
import type { DeepPartial } from '../utils';
|
|
3
|
+
import type { RuntimeContext } from './context';
|
|
4
|
+
import type { Hooks } from './hooks';
|
|
5
|
+
import type { ConfigFn, ExtendStreamSSRFn, ExtendStringSSRCollectorsFn, OnBeforeRenderFn, PickContextFn, StringSSRCollectorsInfo, 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
|
+
config: PluginHookTap<ConfigFn<Extends['config']>>;
|
|
15
|
+
extendStringSSRCollectors: PluginHookTap<ExtendStringSSRCollectorsFn<StringSSRCollectorsInfo>>;
|
|
16
|
+
extendStreamSSR: PluginHookTap<ExtendStreamSSRFn>;
|
|
17
|
+
} & RuntimePluginExtendsAPI<Extends>>;
|
|
18
|
+
export type RuntimePluginExtendsAPI<Extends extends RuntimePluginExtends> = {
|
|
19
|
+
[K in keyof Extends['extendHooks']]: PluginHookTap<Extends['extendHooks'][K] extends PluginHook<infer Args> ? Args extends (...args: any[]) => any ? Args : (...args: any[]) => any : (...args: any[]) => any>;
|
|
20
|
+
} & Extends['extendApi'];
|
|
21
|
+
export type AllKeysForRuntimePluginExtendsAPI<Extends extends RuntimePluginExtends> = keyof RuntimePluginExtendsAPI<Extends>;
|
|
22
|
+
export type AllValueForRuntimePluginExtendsAPI<Extends extends RuntimePluginExtends> = RuntimePluginExtendsAPI<Extends>[AllKeysForRuntimePluginExtendsAPI<Extends>];
|
|
@@ -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,39 @@
|
|
|
1
|
+
export type HandleRequestConfig = Record<string, any>;
|
|
2
|
+
export type ChunkSet = {
|
|
3
|
+
renderLevel: any;
|
|
4
|
+
ssrScripts: string;
|
|
5
|
+
jsChunk: string;
|
|
6
|
+
cssChunk: string;
|
|
7
|
+
};
|
|
8
|
+
export type Collector = {
|
|
9
|
+
collect?: (component: React.ReactElement) => React.ReactElement;
|
|
10
|
+
effect: () => void | Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
import type React from 'react';
|
|
13
|
+
import type { AsyncInterruptHook, CollectSyncHook, SyncHook } from '../hooks';
|
|
14
|
+
export type OnBeforeRenderFn<RuntimeContext> = (context: RuntimeContext, interrupt: (info: any) => any) => Promise<any> | any;
|
|
15
|
+
export type ExtendStringSSRCollectorsFn<RuntimeContext> = (context: RuntimeContext) => Collector;
|
|
16
|
+
export type StringSSRCollectorsInfo = {
|
|
17
|
+
chunkSet: ChunkSet;
|
|
18
|
+
};
|
|
19
|
+
export interface StreamSSRExtender {
|
|
20
|
+
init?: (params: {
|
|
21
|
+
rootElement: React.ReactElement;
|
|
22
|
+
forceStream2String: boolean;
|
|
23
|
+
}) => void;
|
|
24
|
+
modifyRootElement?: (rootElement: React.ReactElement) => React.ReactElement;
|
|
25
|
+
getStyleTags?: () => string;
|
|
26
|
+
processStream?: (stream: NodeJS.ReadWriteStream) => NodeJS.ReadWriteStream;
|
|
27
|
+
}
|
|
28
|
+
export type ExtendStreamSSRFn = () => StreamSSRExtender;
|
|
29
|
+
export type WrapRootFn = (root: React.ComponentType<any>) => React.ComponentType<any>;
|
|
30
|
+
export type PickContextFn<RuntimeContext> = (context: RuntimeContext) => RuntimeContext;
|
|
31
|
+
export type ConfigFn<RuntimeConfig> = () => RuntimeConfig;
|
|
32
|
+
export type Hooks<RuntimeConfig, RuntimeContext> = {
|
|
33
|
+
onBeforeRender: AsyncInterruptHook<OnBeforeRenderFn<RuntimeContext>>;
|
|
34
|
+
wrapRoot: SyncHook<WrapRootFn>;
|
|
35
|
+
pickContext: SyncHook<PickContextFn<RuntimeContext>>;
|
|
36
|
+
config: CollectSyncHook<ConfigFn<RuntimeConfig>>;
|
|
37
|
+
extendStringSSRCollectors: CollectSyncHook<ExtendStringSSRCollectorsFn<StringSSRCollectorsInfo>>;
|
|
38
|
+
extendStreamSSR: CollectSyncHook<ExtendStreamSSRFn>;
|
|
39
|
+
};
|
|
@@ -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']>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PluginHook, PluginHookTap } from '../hooks';
|
|
2
|
+
import type { DeepPartial } from '../utils';
|
|
3
|
+
import type { ServerContext } from './context';
|
|
4
|
+
import type { Hooks, ModifyConfigFn, OnPrepareFn, OnResetFn } from './hooks';
|
|
5
|
+
import type { ServerPluginExtends } from './plugin';
|
|
6
|
+
export type ServerPluginAPI<Extends extends ServerPluginExtends> = Readonly<{
|
|
7
|
+
getServerContext: () => Readonly<ServerContext<Extends> & Extends['extendContext']>;
|
|
8
|
+
updateServerContext: (updateContext: DeepPartial<ServerContext<Extends> & Extends['extendContext']>) => void;
|
|
9
|
+
getHooks: () => Readonly<Hooks<Extends['config']> & Extends['extendHooks']>;
|
|
10
|
+
getServerConfig: () => Readonly<Extends['config']>;
|
|
11
|
+
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config']>>;
|
|
12
|
+
onPrepare: PluginHookTap<OnPrepareFn>;
|
|
13
|
+
onReset: PluginHookTap<OnResetFn>;
|
|
14
|
+
} & ServerPluginExtendsAPI<Extends>>;
|
|
15
|
+
export type ServerPluginExtendsAPI<Extends extends ServerPluginExtends> = {
|
|
16
|
+
[K in keyof Extends['extendHooks']]: PluginHookTap<Extends['extendHooks'][K] extends PluginHook<infer Args> ? Args extends (...args: any[]) => any ? Args : (...args: any[]) => any : (...args: any[]) => any>;
|
|
17
|
+
} & Extends['extendApi'];
|
|
18
|
+
export type AllKeysForServerPluginExtendsAPI<Extends extends ServerPluginExtends> = keyof ServerPluginExtendsAPI<Extends>;
|
|
19
|
+
export type AllValueForServerPluginExtendsAPI<Extends extends ServerPluginExtends> = ServerPluginExtendsAPI<Extends>[AllKeysForServerPluginExtendsAPI<Extends>];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ServerRoute } from '@modern-js/types';
|
|
2
|
+
import type { ServerPluginAPI } from './api';
|
|
3
|
+
import type { Hooks } from './hooks';
|
|
4
|
+
import type { ServerPlugin, ServerPluginExtends } from './plugin';
|
|
5
|
+
export interface Middleware {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
export type ServerContext<Extends extends ServerPluginExtends> = {
|
|
9
|
+
middlewares: Middleware[];
|
|
10
|
+
routes: ServerRoute[];
|
|
11
|
+
appDirectory: string;
|
|
12
|
+
apiDirectory?: string;
|
|
13
|
+
lambdaDirectory?: string;
|
|
14
|
+
internalDirectory?: string;
|
|
15
|
+
sharedDirectory?: string;
|
|
16
|
+
distDirectory?: string;
|
|
17
|
+
metaName: string;
|
|
18
|
+
plugins: ServerPlugin<Extends>[];
|
|
19
|
+
};
|
|
20
|
+
export type InternalServerContext<Extends extends ServerPluginExtends> = ServerContext<Extends> & {
|
|
21
|
+
/** All hooks. */
|
|
22
|
+
hooks: Hooks<Extends['config']> & Extends['extendHooks'];
|
|
23
|
+
/** All plugin registry hooks */
|
|
24
|
+
extendsHooks: Extends['extendHooks'];
|
|
25
|
+
config: Extends['config'];
|
|
26
|
+
pluginAPI?: ServerPluginAPI<Extends>;
|
|
27
|
+
_internalContext?: InternalServerContext<Extends>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AsyncHook } from '../hooks';
|
|
2
|
+
export type ModifyConfigFn<ServerConfig> = (arg: ServerConfig) => ServerConfig | Promise<ServerConfig>;
|
|
3
|
+
export type OnPrepareFn = () => Promise<void> | void;
|
|
4
|
+
export type ChangeEvent = 'add' | 'change' | 'unlink';
|
|
5
|
+
export interface Change {
|
|
6
|
+
filename: string;
|
|
7
|
+
event: ChangeEvent;
|
|
8
|
+
}
|
|
9
|
+
export interface RepackEvent {
|
|
10
|
+
type: 'repack';
|
|
11
|
+
}
|
|
12
|
+
export interface FileChangeEvent {
|
|
13
|
+
type: 'file-change';
|
|
14
|
+
payload: Change[];
|
|
15
|
+
}
|
|
16
|
+
export type ResetEvent = RepackEvent | FileChangeEvent;
|
|
17
|
+
export type OnResetFn = (params: {
|
|
18
|
+
event: ResetEvent;
|
|
19
|
+
}) => Promise<void> | void;
|
|
20
|
+
export type Hooks<ServerConfig> = {
|
|
21
|
+
modifyConfig: AsyncHook<ModifyConfigFn<ServerConfig>>;
|
|
22
|
+
onPrepare: AsyncHook<OnPrepareFn>;
|
|
23
|
+
onReset: AsyncHook<OnResetFn>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PluginHook } from '../hooks';
|
|
2
|
+
import type { Plugin } from '../plugin';
|
|
3
|
+
import type { ServerPluginAPI } from './api';
|
|
4
|
+
import type { ServerContext } from './context';
|
|
5
|
+
export interface ServerPluginExtends<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 Server plugin object.
|
|
13
|
+
*/
|
|
14
|
+
export type ServerPlugin<Extends extends ServerPluginExtends> = Plugin<ServerPluginAPI<Extends> & Extends['extendApi'], ServerContext<Extends> & Extends['extendContext']>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Falsy = false | null | undefined;
|
|
2
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
export type DeepPartial<T> = {
|
|
4
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
5
|
+
};
|
|
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,33 +15,88 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "
|
|
18
|
+
"version": "3.0.0-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
22
|
-
"module": "./dist/esm/index.
|
|
22
|
+
"module": "./dist/esm-node/index.mjs",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"types": "./dist/types/index.d.ts",
|
|
26
26
|
"node": {
|
|
27
|
+
"modern:source": "./src/index.ts",
|
|
27
28
|
"jsnext:source": "./src/index.ts",
|
|
28
|
-
"import": "./dist/esm
|
|
29
|
+
"import": "./dist/esm/index.mjs",
|
|
29
30
|
"require": "./dist/cjs/index.js"
|
|
30
31
|
},
|
|
31
|
-
"default": "./dist/esm/index.
|
|
32
|
+
"default": "./dist/esm/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./run": {
|
|
35
|
+
"types": "./dist/types/cli/run/index.d.ts",
|
|
36
|
+
"jsnext:source": "./src/cli/run/index.ts",
|
|
37
|
+
"default": "./dist/cjs/cli/run/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./cli": {
|
|
40
|
+
"types": "./dist/types/cli/index.d.ts",
|
|
41
|
+
"modern:source": "./src/cli/index.ts",
|
|
42
|
+
"jsnext:source": "./src/cli/index.ts",
|
|
43
|
+
"default": "./dist/cjs/cli/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./runtime": {
|
|
46
|
+
"types": "./dist/types/runtime/index.d.ts",
|
|
47
|
+
"modern:source": "./src/runtime/index.tsx",
|
|
48
|
+
"jsnext:source": "./src/runtime/index.tsx",
|
|
49
|
+
"node": {
|
|
50
|
+
"import": "./dist/esm/runtime/index.mjs",
|
|
51
|
+
"require": "./dist/cjs/runtime/index.js"
|
|
52
|
+
},
|
|
53
|
+
"default": "./dist/esm/runtime/index.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./server": {
|
|
56
|
+
"types": "./dist/types/server/index.d.ts",
|
|
57
|
+
"modern:source": "./src/server/index.ts",
|
|
58
|
+
"jsnext:source": "./src/server/index.ts",
|
|
59
|
+
"node": {
|
|
60
|
+
"require": "./dist/cjs/server/index.js",
|
|
61
|
+
"default": "./dist/cjs/server/index.js"
|
|
62
|
+
},
|
|
63
|
+
"default": "./dist/esm/server/index.mjs"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"typesVersions": {
|
|
67
|
+
"*": {
|
|
68
|
+
".": [
|
|
69
|
+
"./dist/index.d.ts"
|
|
70
|
+
],
|
|
71
|
+
"run": [
|
|
72
|
+
"./dist/types/cli/run/index.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"cli": [
|
|
75
|
+
"./dist/types/cli/index.d.ts"
|
|
76
|
+
],
|
|
77
|
+
"runtime": [
|
|
78
|
+
"./dist/types/runtime/index.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"server": [
|
|
81
|
+
"./dist/types/server/index.d.ts"
|
|
82
|
+
]
|
|
32
83
|
}
|
|
33
84
|
},
|
|
34
85
|
"dependencies": {
|
|
35
86
|
"@swc/helpers": "^0.5.17",
|
|
36
|
-
"
|
|
87
|
+
"jiti": "1.21.7",
|
|
88
|
+
"@rsbuild/core": "1.6.15",
|
|
89
|
+
"@modern-js/runtime-utils": "3.0.0-alpha.0",
|
|
90
|
+
"@modern-js/utils": "3.0.0-alpha.0",
|
|
91
|
+
"@modern-js/types": "3.0.0-alpha.0"
|
|
37
92
|
},
|
|
38
93
|
"devDependencies": {
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/
|
|
41
|
-
"
|
|
94
|
+
"@types/node": "^20",
|
|
95
|
+
"@types/react": "^19.2.7",
|
|
96
|
+
"@rslib/core": "0.18.5",
|
|
42
97
|
"typescript": "^5",
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
98
|
+
"@modern-js/builder": "3.0.0-alpha.0",
|
|
99
|
+
"@modern-js/rslib": "2.68.10"
|
|
45
100
|
},
|
|
46
101
|
"sideEffects": false,
|
|
47
102
|
"publishConfig": {
|
|
@@ -49,9 +104,8 @@
|
|
|
49
104
|
"access": "public"
|
|
50
105
|
},
|
|
51
106
|
"scripts": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"test": "jest --passWithNoTests"
|
|
107
|
+
"dev": "rslib build --watch",
|
|
108
|
+
"build": "rslib build",
|
|
109
|
+
"test": "rstest"
|
|
56
110
|
}
|
|
57
111
|
}
|
package/rslib.config.mts
ADDED