@modern-js/app-tools 2.62.1 → 2.63.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/bin/modern.js +2 -2
  2. package/dist/cjs/index.js +12 -144
  3. package/dist/cjs/new/compat/hooks.js +165 -0
  4. package/dist/cjs/new/compat/index.js +60 -0
  5. package/dist/cjs/new/compat/utils.js +95 -0
  6. package/dist/cjs/new/constants.js +37 -0
  7. package/dist/cjs/new/context.js +64 -0
  8. package/dist/cjs/new/getConfigFile.js +41 -0
  9. package/dist/cjs/new/index.js +79 -0
  10. package/dist/cjs/new/loadPlugins.js +57 -0
  11. package/dist/cjs/new/run.js +67 -0
  12. package/dist/cjs/new/utils/index.js +34 -0
  13. package/dist/cjs/old.js +179 -0
  14. package/dist/cjs/plugins/initialize/index.js +44 -50
  15. package/dist/cjs/types/new.js +16 -0
  16. package/dist/cjs/utils/restart.js +2 -2
  17. package/dist/esm/index.js +7 -249
  18. package/dist/esm/new/compat/hooks.js +452 -0
  19. package/dist/esm/new/compat/index.js +41 -0
  20. package/dist/esm/new/compat/utils.js +69 -0
  21. package/dist/esm/new/constants.js +10 -0
  22. package/dist/esm/new/context.js +31 -0
  23. package/dist/esm/new/getConfigFile.js +11 -0
  24. package/dist/esm/new/index.js +55 -0
  25. package/dist/esm/new/loadPlugins.js +94 -0
  26. package/dist/esm/new/run.js +80 -0
  27. package/dist/esm/new/utils/index.js +33 -0
  28. package/dist/esm/old.js +258 -0
  29. package/dist/esm/plugins/initialize/index.js +61 -64
  30. package/dist/esm/types/new.js +0 -0
  31. package/dist/esm/utils/restart.js +1 -1
  32. package/dist/esm-node/index.js +7 -131
  33. package/dist/esm-node/new/compat/hooks.js +140 -0
  34. package/dist/esm-node/new/compat/index.js +36 -0
  35. package/dist/esm-node/new/compat/utils.js +69 -0
  36. package/dist/esm-node/new/constants.js +10 -0
  37. package/dist/esm-node/new/context.js +30 -0
  38. package/dist/esm-node/new/getConfigFile.js +7 -0
  39. package/dist/esm-node/new/index.js +52 -0
  40. package/dist/esm-node/new/loadPlugins.js +33 -0
  41. package/dist/esm-node/new/run.js +43 -0
  42. package/dist/esm-node/new/utils/index.js +10 -0
  43. package/dist/esm-node/old.js +140 -0
  44. package/dist/esm-node/plugins/initialize/index.js +44 -50
  45. package/dist/esm-node/types/new.js +0 -0
  46. package/dist/esm-node/utils/restart.js +1 -1
  47. package/dist/types/config/default.d.ts +4 -3
  48. package/dist/types/index.d.ts +6 -16
  49. package/dist/types/new/compat/hooks.d.ts +7 -0
  50. package/dist/types/new/compat/index.d.ts +2 -0
  51. package/dist/types/new/compat/utils.d.ts +6 -0
  52. package/dist/types/new/constants.d.ts +4 -0
  53. package/dist/types/new/context.d.ts +33 -0
  54. package/dist/types/new/getConfigFile.d.ts +1 -0
  55. package/dist/types/new/index.d.ts +6 -0
  56. package/dist/types/new/loadPlugins.d.ts +9 -0
  57. package/dist/types/new/run.d.ts +13 -0
  58. package/dist/types/new/utils/index.d.ts +1 -0
  59. package/dist/types/old.d.ts +13 -0
  60. package/dist/types/plugins/initialize/index.d.ts +2 -2
  61. package/dist/types/types/index.d.ts +12 -3
  62. package/dist/types/types/new.d.ts +145 -0
  63. package/dist/types/utils/env.d.ts +2 -2
  64. package/dist/types/utils/restart.d.ts +1 -1
  65. package/lib/types.d.ts +82 -61
  66. package/package.json +27 -18
@@ -0,0 +1,43 @@
1
+ import { initAppDir } from "@modern-js/plugin-v2/cli";
2
+ import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
3
+ import { minimist } from "@modern-js/utils";
4
+ import { handleSetupResult } from "./compat/hooks";
5
+ import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
6
+ import { getConfigFile } from "./getConfigFile";
7
+ import { loadInternalPlugins } from "./loadPlugins";
8
+ import { getIsAutoLoadPlugins } from "./utils";
9
+ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
10
+ const command = process.argv[2];
11
+ const cliParams = minimist(process.argv.slice(2));
12
+ const SUPPORT_CONFIG_PARAM_COMMANDS = [
13
+ "dev",
14
+ "build",
15
+ "deploy",
16
+ "start",
17
+ "serve",
18
+ "inspect",
19
+ "upgrade"
20
+ ];
21
+ let customConfigFile;
22
+ if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command)) {
23
+ customConfigFile = cliParams.config || cliParams.c;
24
+ }
25
+ if (command === "new") {
26
+ customConfigFile = cliParams["config-file"];
27
+ }
28
+ const appDirectory = await initAppDir(cwd);
29
+ const finalConfigFile = customConfigFile || getConfigFile(configFile);
30
+ const autoLoadPlugins = await getIsAutoLoadPlugins(appDirectory, finalConfigFile);
31
+ const plugins = await loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
32
+ await CLIPluginRun({
33
+ cwd,
34
+ initialLog: initialLog || `Modern.js Framework v${version}`,
35
+ configFile: finalConfigFile,
36
+ packageJsonConfig: packageJsonConfig || PACKAGE_JSON_CONFIG_NAME,
37
+ internalPlugins: plugins,
38
+ handleSetupResult
39
+ });
40
+ }
41
+ export {
42
+ run
43
+ };
@@ -0,0 +1,10 @@
1
+ import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
2
+ async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
3
+ var _loaded_config;
4
+ const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig);
5
+ const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
6
+ return autoLoadPlugins || false;
7
+ }
8
+ export {
9
+ getIsAutoLoadPlugins
10
+ };
@@ -0,0 +1,140 @@
1
+ import path from "path";
2
+ import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
3
+ import { castArray } from "@modern-js/uni-builder";
4
+ import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
5
+ import { hooks } from "./hooks";
6
+ import { i18n } from "./locale";
7
+ import analyzePlugin from "./plugins/analyze";
8
+ import deployPlugin from "./plugins/deploy";
9
+ import initializePlugin from "./plugins/initialize";
10
+ import serverBuildPlugin from "./plugins/serverBuild";
11
+ import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
12
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
13
+ import { restart } from "./utils/restart";
14
+ import { dev } from "./commands/dev";
15
+ import { mergeConfig } from "@modern-js/core";
16
+ export * from "./defineConfig";
17
+ export * from "./types";
18
+ const appTools = (options = {
19
+ // default webpack to be compatible with original projects
20
+ bundler: "webpack"
21
+ }) => ({
22
+ name: "@modern-js/app-tools-old",
23
+ post: [
24
+ "@modern-js/plugin-initialize",
25
+ "@modern-js/plugin-analyze",
26
+ "@modern-js/plugin-ssr",
27
+ "@modern-js/plugin-document",
28
+ "@modern-js/plugin-state",
29
+ "@modern-js/plugin-router",
30
+ "@modern-js/plugin-router-v5",
31
+ "@modern-js/plugin-polyfill"
32
+ ],
33
+ registerHook: hooks,
34
+ usePlugins: [
35
+ initializePlugin({
36
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
37
+ "rspack",
38
+ "experimental-rspack"
39
+ ].includes(options.bundler) ? "rspack" : "webpack"
40
+ }),
41
+ analyzePlugin({
42
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
43
+ "rspack",
44
+ "experimental-rspack"
45
+ ].includes(options.bundler) ? "rspack" : "webpack"
46
+ }),
47
+ serverBuildPlugin(),
48
+ deployPlugin()
49
+ ],
50
+ setup: (api) => {
51
+ const appContext = api.useAppContext();
52
+ api.setAppContext({
53
+ ...appContext,
54
+ toolsType: "app-tools"
55
+ });
56
+ const locale = getLocaleLanguage();
57
+ i18n.changeLanguage({
58
+ locale
59
+ });
60
+ return {
61
+ async beforeConfig() {
62
+ var _userConfig_output;
63
+ const userConfig = api.useConfigContext();
64
+ const appContext2 = api.useAppContext();
65
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
66
+ api.setAppContext({
67
+ ...appContext2,
68
+ internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
69
+ });
70
+ }
71
+ },
72
+ async commands({ program }) {
73
+ await devCommand(program, api);
74
+ await buildCommand(program, api);
75
+ serverCommand(program, api);
76
+ deployCommand(program, api);
77
+ newCommand(program, locale);
78
+ inspectCommand(program, api);
79
+ upgradeCommand(program);
80
+ deprecatedCommands(program);
81
+ },
82
+ async prepare() {
83
+ const command = getCommand();
84
+ if (command === "deploy") {
85
+ const isSkipBuild = [
86
+ "-s",
87
+ "--skip-build"
88
+ ].some((tag) => {
89
+ return getArgv().includes(tag);
90
+ });
91
+ if (isSkipBuild) {
92
+ return;
93
+ }
94
+ }
95
+ if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
96
+ const resolvedConfig = api.useResolvedConfigContext();
97
+ if (resolvedConfig.output.cleanDistPath) {
98
+ const appContext2 = api.useAppContext();
99
+ await emptyDir(appContext2.distDirectory);
100
+ }
101
+ }
102
+ },
103
+ async watchFiles() {
104
+ const appContext2 = api.useAppContext();
105
+ const config = api.useResolvedConfigContext();
106
+ const files = await generateWatchFiles(appContext2, config.source.configDir);
107
+ const watchFiles = castArray(config.dev.watchFiles);
108
+ watchFiles.forEach(({ type, paths }) => {
109
+ if (type === "reload-server") {
110
+ files.push(...Array.isArray(paths) ? paths : [
111
+ paths
112
+ ]);
113
+ }
114
+ });
115
+ return files;
116
+ },
117
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
118
+ async fileChange(e) {
119
+ const { filename, eventType, isPrivate } = e;
120
+ if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
121
+ const { closeServer } = await import("./utils/createServer.js");
122
+ await closeServer();
123
+ await restart(api.useHookRunners(), filename);
124
+ }
125
+ },
126
+ async beforeRestart() {
127
+ cleanRequireCache([
128
+ require.resolve("./plugins/analyze")
129
+ ]);
130
+ }
131
+ };
132
+ }
133
+ });
134
+ var old_default = appTools;
135
+ export {
136
+ appTools,
137
+ old_default as default,
138
+ dev,
139
+ mergeConfig
140
+ };
@@ -11,60 +11,54 @@ var initialize_default = ({ bundler }) => ({
11
11
  "@modern-js/plugin-polyfill"
12
12
  ],
13
13
  setup(api) {
14
- const config = () => {
15
- const appContext = api.useAppContext();
16
- const userConfig = api.useConfigContext();
17
- api.setAppContext({
18
- ...appContext,
14
+ api.config(() => {
15
+ const appContext = api.getAppContext();
16
+ const userConfig = api.getConfig();
17
+ api.updateAppContext({
19
18
  bundlerType: bundler
20
19
  });
21
20
  return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
22
- };
23
- return {
24
- config,
25
- async resolvedConfig({ resolved }) {
26
- var _resolved_output_distPath;
27
- let appContext = api.useAppContext();
28
- const userConfig = api.useConfigContext();
29
- const port = await getServerPort(resolved);
30
- appContext = {
31
- ...appContext,
32
- port,
33
- distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
34
- };
35
- api.setAppContext(appContext);
36
- const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
37
- resolved._raw = userConfig;
38
- resolved.server = {
39
- ...normalizedConfig.server || {},
40
- port
41
- };
42
- var _normalizedConfig_autoLoadPlugins;
43
- resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
44
- stabilizeConfig(resolved, normalizedConfig, [
45
- "source",
46
- "bff",
47
- "dev",
48
- "html",
49
- "output",
50
- "tools",
51
- "testing",
52
- "plugins",
53
- "builderPlugins",
54
- "runtime",
55
- "runtimeByEntries",
56
- "deploy",
57
- "performance"
58
- ]);
59
- if (bundler === "webpack") {
60
- resolved.security = normalizedConfig.security || {};
61
- resolved.experiments = normalizedConfig.experiments;
62
- }
63
- return {
64
- resolved
65
- };
21
+ });
22
+ api.modifyResolvedConfig(async (resolved) => {
23
+ var _resolved_output_distPath;
24
+ let appContext = api.getAppContext();
25
+ const userConfig = api.getConfig();
26
+ const port = await getServerPort(resolved);
27
+ appContext = {
28
+ ...appContext,
29
+ port,
30
+ distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
31
+ };
32
+ api.updateAppContext(appContext);
33
+ const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
34
+ resolved._raw = userConfig;
35
+ resolved.server = {
36
+ ...normalizedConfig.server || {},
37
+ port
38
+ };
39
+ var _normalizedConfig_autoLoadPlugins;
40
+ resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
41
+ stabilizeConfig(resolved, normalizedConfig, [
42
+ "source",
43
+ "bff",
44
+ "dev",
45
+ "html",
46
+ "output",
47
+ "tools",
48
+ "testing",
49
+ "plugins",
50
+ "builderPlugins",
51
+ "runtime",
52
+ "runtimeByEntries",
53
+ "deploy",
54
+ "performance"
55
+ ]);
56
+ if (bundler === "webpack") {
57
+ resolved.security = normalizedConfig.security || {};
58
+ resolved.experiments = normalizedConfig.experiments;
66
59
  }
67
- };
60
+ return resolved;
61
+ });
68
62
  }
69
63
  });
70
64
  function stabilizeConfig(resolve, config, keys) {
File without changes
@@ -1,4 +1,4 @@
1
- import { cli } from "@modern-js/core";
1
+ import { cli } from "@modern-js/plugin-v2/cli";
2
2
  import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
3
3
  async function restart(hooksRunner, filename) {
4
4
  clearConsole();
@@ -1,3 +1,4 @@
1
- import type { AppLegacyUserConfig, AppUserConfig, IAppContext } from '../types';
2
- export declare function createDefaultConfig(appContext: IAppContext): AppUserConfig<'webpack'> | AppUserConfig<'rspack'>;
3
- export declare function createLegacyDefaultConfig(appContext: IAppContext): AppLegacyUserConfig;
1
+ import type { AppLegacyUserConfig, AppUserConfig } from '../types';
2
+ import type { AppToolsContext } from '../types/new';
3
+ export declare function createDefaultConfig(appContext: AppToolsContext<'shared'>): AppUserConfig<'webpack'> | AppUserConfig<'rspack'>;
4
+ export declare function createLegacyDefaultConfig(appContext: AppToolsContext<'shared'>): AppLegacyUserConfig;
@@ -1,20 +1,10 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- import type { AppTools } from './types';
1
+ import { appTools } from './new/index';
2
+ export { appTools };
3
+ export { initAppContext } from './new/index';
4
+ export { defineConfig, defineLegacyConfig } from './defineConfig';
5
+ export { mergeConfig } from '@modern-js/core';
6
+ export type { RuntimeUserConfig } from './types/config';
3
7
  export { dev } from './commands/dev';
4
8
  export type { DevOptions } from './utils/types';
5
- export { mergeConfig } from '@modern-js/core';
6
- export * from './defineConfig';
7
9
  export * from './types';
8
- export type { RuntimeUserConfig } from './types/config';
9
- export type AppToolsOptions = {
10
- /**
11
- * Specify which bundler to use for the build.
12
- * @default `webpack`
13
- * */
14
- bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
15
- };
16
- /**
17
- * The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
18
- */
19
- export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
20
10
  export default appTools;
@@ -0,0 +1,7 @@
1
+ import type { InternalContext } from '@modern-js/plugin-v2';
2
+ import type { AppTools } from '../../types';
3
+ /**
4
+ * old plugin useHookRunners function result
5
+ */
6
+ export declare function getHookRunners(context: InternalContext<AppTools>): Record<string, any>;
7
+ export declare function handleSetupResult(setupResult: Record<string, (...args: any) => any>, api: Record<string, any>): void;
@@ -0,0 +1,2 @@
1
+ import type { AppTools, CliPluginFuture } from '../../types';
2
+ export declare const compatPlugin: () => CliPluginFuture<AppTools>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Maps old plugin hook function names to new plugin API names
3
+ */
4
+ export declare function transformHookRunner(hookRunnerName: string): string;
5
+ export declare function transformHookParams(hookRunnerName: string, params: any): any;
6
+ export declare function transformHookResult(hookRunnerName: string, result: any): any;
@@ -0,0 +1,4 @@
1
+ export declare const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
2
+ export declare const DEFAULT_CONFIG_FILE = "modern.config";
3
+ export declare const DEFAULT_SERVER_CONFIG_FILE = "modern.server-runtime.config";
4
+ export declare const DEFAULT_RUNTIME_CONFIG_FILE = "modern.runtime";
@@ -0,0 +1,33 @@
1
+ export declare const initAppContext: ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir, }: {
2
+ appDirectory: string;
3
+ runtimeConfigFile: string | false;
4
+ options?: {
5
+ metaName?: string | undefined;
6
+ srcDir?: string | undefined;
7
+ apiDir?: string | undefined;
8
+ distDir?: string | undefined;
9
+ sharedDir?: string | undefined;
10
+ } | undefined;
11
+ serverConfigFile: string;
12
+ tempDir?: string | undefined;
13
+ }) => {
14
+ metaName: string;
15
+ runtimeConfigFile: string | false;
16
+ serverConfigFile: string;
17
+ ip: any;
18
+ port: number;
19
+ moduleType: any;
20
+ apiDirectory: string;
21
+ lambdaDirectory: string;
22
+ sharedDirectory: string;
23
+ distDirectory: string;
24
+ serverPlugins: never[];
25
+ internalDirectory: string;
26
+ htmlTemplates: {};
27
+ serverRoutes: never[];
28
+ entrypoints: never[];
29
+ checkedEntries: never[];
30
+ apiOnly: boolean;
31
+ internalDirAlias: string;
32
+ internalSrcAlias: string;
33
+ };
@@ -0,0 +1 @@
1
+ export declare const getConfigFile: (configFile?: string) => string | false;
@@ -0,0 +1,6 @@
1
+ import { type AppToolsOptions } from '../old';
2
+ import type { AppTools, CliPluginFuture } from '../types';
3
+ import { initAppContext } from './context';
4
+ export * from '../defineConfig';
5
+ export { initAppContext };
6
+ export declare const appTools: (options?: AppToolsOptions) => CliPluginFuture<AppTools<'shared'>>;
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from '@modern-js/plugin-v2';
2
+ import type { InternalPlugins } from '@modern-js/types';
3
+ /**
4
+ * Load internal plugins which in @modern-js scope and user's custom plugins.
5
+ * @param appDirectory - Application root directory.
6
+ * @param internalPlugins - Internal plugins.
7
+ * @returns Plugin Objects has been required.
8
+ */
9
+ export declare const loadInternalPlugins: (appDirectory: string, internalPlugins?: InternalPlugins, autoLoad?: InternalPlugins, autoLoadPlugins?: boolean) => Promise<Plugin[]>;
@@ -0,0 +1,13 @@
1
+ import type { InternalPlugins } from '@modern-js/types';
2
+ export interface RunOptions {
3
+ cwd?: string;
4
+ configFile?: string;
5
+ packageJsonConfig?: string;
6
+ internalPlugins?: {
7
+ cli?: InternalPlugins;
8
+ autoLoad?: InternalPlugins;
9
+ };
10
+ initialLog?: string;
11
+ version: string;
12
+ }
13
+ export declare function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile, }: RunOptions): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function getIsAutoLoadPlugins(appDirectory: string, configFile?: string, packageJsonConfig?: string): Promise<boolean>;
@@ -0,0 +1,13 @@
1
+ import type { CliPlugin } from '@modern-js/core';
2
+ import type { AppTools, AppToolsOptions } from './types';
3
+ export { dev } from './commands/dev';
4
+ export type { DevOptions } from './utils/types';
5
+ export { mergeConfig } from '@modern-js/core';
6
+ export * from './defineConfig';
7
+ export * from './types';
8
+ export type { RuntimeUserConfig } from './types/config';
9
+ /**
10
+ * The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
11
+ */
12
+ export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
13
+ export default appTools;
@@ -1,5 +1,5 @@
1
- import type { AppTools, CliPlugin } from '../../types';
1
+ import type { AppTools, CliPluginFuture } from '../../types';
2
2
  declare const _default: ({ bundler, }: {
3
3
  bundler: 'rspack' | 'webpack';
4
- }) => CliPlugin<AppTools<'shared'>>;
4
+ }) => CliPluginFuture<AppTools<'shared'>>;
5
5
  export default _default;
@@ -1,7 +1,9 @@
1
1
  import type { NormalizedConfig, UserConfig } from '@modern-js/core';
2
+ import type { CLIPlugin, CLIPluginExtends } from '@modern-js/plugin-v2';
2
3
  import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
3
4
  import type { AppToolsHooks } from './hooks';
4
5
  import type { AppToolsLegacyNormalizedConfig, AppToolsLegacyUserConfig } from './legacyConfig';
6
+ import type { AppToolsExtendAPI, AppToolsExtendContext, AppToolsExtendHooks } from './new';
5
7
  import type { Bundler } from './utils';
6
8
  export * from './hooks';
7
9
  export * from './config';
@@ -10,17 +12,24 @@ export type { webpack, Rspack } from '@modern-js/uni-builder';
10
12
  export type { Bundler } from './utils';
11
13
  export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries, Resource, Params, RequestHandlerConfig, LoaderContext, OnError, OnTiming, RequestHandlerOptions, RequestHandler, } from '@modern-js/server-core';
12
14
  export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig, } from '@modern-js/core';
13
- export type AppTools<B extends Bundler = 'webpack'> = {
14
- hooks: AppToolsHooks<B>;
15
+ export type AppTools<B extends Bundler = 'webpack'> = Required<CLIPluginExtends<AppToolsUserConfig<B>, AppToolsNormalizedConfig, AppToolsExtendContext<B>, AppToolsExtendAPI<B>, AppToolsExtendHooks>> & {
15
16
  userConfig: AppToolsUserConfig<B>;
16
- normalizedConfig: AppToolsNormalizedConfig<AppToolsUserConfig<'shared'>>;
17
+ hooks: AppToolsHooks<B>;
17
18
  };
18
19
  export type LegacyAppTools = {
19
20
  hooks: AppToolsHooks;
20
21
  userConfig: AppToolsLegacyUserConfig;
21
22
  normalizedConfig: AppToolsLegacyNormalizedConfig;
22
23
  };
24
+ export type CliPluginFuture<Extends extends CLIPluginExtends> = CLIPlugin<Extends>;
23
25
  export type AppNormalizedConfig<B extends Bundler = 'webpack'> = NormalizedConfig<AppTools<B>>;
24
26
  export type AppLegacyNormalizedConfig = NormalizedConfig<LegacyAppTools>;
25
27
  export type AppUserConfig<B extends Bundler = 'webpack'> = UserConfig<AppTools<B>>;
26
28
  export type AppLegacyUserConfig = UserConfig<LegacyAppTools>;
29
+ export type AppToolsOptions = {
30
+ /**
31
+ * Specify which bundler to use for the build.
32
+ * @default `webpack`
33
+ * */
34
+ bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
35
+ };
@@ -0,0 +1,145 @@
1
+ import type { DevToolData, RegisterBuildPlatformResult } from '@modern-js/core';
2
+ import type { AppContext, InternalContext, PluginHook, PluginHookTap, TransformFunction } from '@modern-js/plugin-v2';
3
+ import type { Entrypoint, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
4
+ import type { AppTools } from '.';
5
+ import type { getHookRunners } from '../new/compat/hooks';
6
+ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
7
+ import type { RuntimePlugin } from './hooks';
8
+ import type { Bundler } from './utils';
9
+ export type BeforeConfigFn = () => Promise<void> | void;
10
+ export type AfterPrepareFn = () => Promise<void> | void;
11
+ export type InternalRuntimePluginsFn = TransformFunction<{
12
+ entrypoint: Entrypoint;
13
+ plugins: RuntimePlugin[];
14
+ }>;
15
+ export type InternalServerPluginsFn = TransformFunction<{
16
+ plugins: ServerPlugin[];
17
+ }>;
18
+ export type CheckEntryPointFn = TransformFunction<{
19
+ path: string;
20
+ entry: false | string;
21
+ }>;
22
+ export type ModifyEntrypointsFn = TransformFunction<{
23
+ entrypoints: Entrypoint[];
24
+ }>;
25
+ export type ModifyFileSystemRoutesFn = TransformFunction<{
26
+ entrypoint: Entrypoint;
27
+ routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
28
+ }>;
29
+ export type ModifyServerRoutesFn = TransformFunction<{
30
+ routes: ServerRoute[];
31
+ }>;
32
+ export type DeplpoyFn = () => Promise<void> | void;
33
+ export type GenerateEntryCodeFn = (params: {
34
+ entrypoints: Entrypoint[];
35
+ }) => Promise<void> | void;
36
+ export type BeforeGenerateRoutesFn = TransformFunction<{
37
+ entrypoint: Entrypoint;
38
+ code: string;
39
+ }>;
40
+ export type BeforePrintInstructionsFn = TransformFunction<{
41
+ instructions: string;
42
+ }>;
43
+ export type RegisterDevFn = (params: {
44
+ name: string;
45
+ entry: string;
46
+ type: string;
47
+ config: any;
48
+ }) => Promise<DevToolData> | DevToolData;
49
+ export type RegisterBuildPlatformFn = (params: {
50
+ name: string;
51
+ entry: string;
52
+ type: string;
53
+ config: any;
54
+ }) => Promise<RegisterBuildPlatformResult> | RegisterBuildPlatformResult;
55
+ export type AddRuntimeExportsFn = (params: {
56
+ entrypoint: Entrypoint;
57
+ exports: string[];
58
+ }) => Promise<void> | void;
59
+ export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
60
+ onBeforeConfig: PluginHookTap<BeforeConfigFn>;
61
+ onAfterPrepare: PluginHookTap<AfterPrepareFn>;
62
+ deploy: PluginHookTap<DeplpoyFn>;
63
+ _internalRuntimePlugins: PluginHookTap<InternalRuntimePluginsFn>;
64
+ _internalServerPlugins: PluginHookTap<InternalServerPluginsFn>;
65
+ checkEntryPoint: PluginHookTap<CheckEntryPointFn>;
66
+ modifyEntrypoints: PluginHookTap<ModifyEntrypointsFn>;
67
+ modifyFileSystemRoutes: PluginHookTap<ModifyFileSystemRoutesFn>;
68
+ modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
69
+ generateEntryCode: PluginHookTap<GenerateEntryCodeFn>;
70
+ onBeforeGenerateRoutes: PluginHookTap<BeforeGenerateRoutesFn>;
71
+ /**
72
+ * @deprecated
73
+ */
74
+ onBeforePrintInstructions: PluginHookTap<BeforePrintInstructionsFn>;
75
+ /**
76
+ * @deprecated
77
+ */
78
+ registerDev: PluginHookTap<RegisterDevFn>;
79
+ /**
80
+ * @deprecated
81
+ */
82
+ registerBuildPlatform: PluginHookTap<RegisterBuildPlatformFn>;
83
+ /**
84
+ * @deprecated
85
+ */
86
+ addRuntimeExports: PluginHookTap<AddRuntimeExportsFn>;
87
+ /**
88
+ * @deprecated use getAppContext instead
89
+ */
90
+ useAppContext: () => AppToolsContext<B>;
91
+ /**
92
+ * @deprecated use getConfig instead
93
+ */
94
+ useConfigContext: () => AppToolsUserConfig<B>;
95
+ /**
96
+ * @deprecated use getNormalizedConfig instead
97
+ */
98
+ useResolvedConfigContext: () => AppToolsNormalizedConfig<AppToolsUserConfig<B>>;
99
+ /**
100
+ * @deprecated use api.xx instead
101
+ */
102
+ useHookRunners: () => ReturnType<typeof getHookRunners>;
103
+ }
104
+ export interface AppToolsExtendHooks extends Record<string, PluginHook<(...args: any[]) => any>> {
105
+ onBeforeConfig: PluginHook<BeforeConfigFn>;
106
+ onAfterPrepare: PluginHook<AfterPrepareFn>;
107
+ deploy: PluginHook<DeplpoyFn>;
108
+ _internalRuntimePlugins: PluginHook<InternalRuntimePluginsFn>;
109
+ _internalServerPlugins: PluginHook<InternalServerPluginsFn>;
110
+ checkEntryPoint: PluginHook<CheckEntryPointFn>;
111
+ modifyEntrypoints: PluginHook<ModifyEntrypointsFn>;
112
+ modifyFileSystemRoutes: PluginHook<ModifyFileSystemRoutesFn>;
113
+ modifyServerRoutes: PluginHook<ModifyServerRoutesFn>;
114
+ generateEntryCode: PluginHook<GenerateEntryCodeFn>;
115
+ onBeforeGenerateRoutes: PluginHook<BeforeGenerateRoutesFn>;
116
+ /**
117
+ * @deprecated
118
+ */
119
+ onBeforePrintInstructions: PluginHook<BeforePrintInstructionsFn>;
120
+ /**
121
+ * @deprecated
122
+ */
123
+ registerDev: PluginHook<RegisterDevFn>;
124
+ /**
125
+ * @deprecated
126
+ */
127
+ registerBuildPlatform: PluginHook<RegisterBuildPlatformFn>;
128
+ /**
129
+ * @deprecated
130
+ */
131
+ addRuntimeExports: PluginHook<AddRuntimeExportsFn>;
132
+ }
133
+ export type AppToolsExtendContext<B extends Bundler = 'webpack'> = {
134
+ metaName: string;
135
+ internalDirectory: string;
136
+ sharedDirectory: string;
137
+ internalDirAlias: string;
138
+ internalSrcAlias: string;
139
+ apiDirectory: string;
140
+ lambdaDirectory: string;
141
+ serverPlugins: ServerPlugin[];
142
+ moduleType: 'module' | 'commonjs';
143
+ _internalContext: InternalContext<AppTools<B>>;
144
+ };
145
+ export type AppToolsContext<B extends Bundler = 'webpack'> = AppContext<AppTools<B>> & AppToolsExtendContext<B>;