@modern-js/app-tools 2.62.2-alpha.0 → 2.63.1-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 (144) hide show
  1. package/bin/modern.js +1 -1
  2. package/dist/cjs/commands/build.js +19 -13
  3. package/dist/cjs/commands/deploy.js +5 -5
  4. package/dist/cjs/commands/dev.js +11 -11
  5. package/dist/cjs/commands/index.js +6 -6
  6. package/dist/cjs/commands/inspect.js +1 -1
  7. package/dist/cjs/commands/serve.js +4 -4
  8. package/dist/cjs/{new/compat → compat}/hooks.js +20 -8
  9. package/dist/cjs/{new/compat → compat}/index.js +10 -2
  10. package/dist/cjs/{new/compat → compat}/utils.js +10 -1
  11. package/dist/cjs/index.js +156 -7
  12. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
  13. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
  14. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
  15. package/dist/cjs/plugins/analyze/index.js +128 -130
  16. package/dist/cjs/plugins/deploy/index.js +12 -14
  17. package/dist/cjs/plugins/initialize/index.js +44 -50
  18. package/dist/cjs/plugins/serverBuild.js +30 -32
  19. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  20. package/dist/cjs/{new/types/index.js → types/new.js} +2 -2
  21. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  22. package/dist/cjs/{new/context.js → utils/initAppContext.js} +5 -5
  23. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  24. package/dist/cjs/utils/loadPlugins.js +35 -4
  25. package/dist/cjs/utils/printInstructions.js +2 -2
  26. package/dist/cjs/utils/restart.js +4 -3
  27. package/dist/esm/commands/build.js +18 -12
  28. package/dist/esm/commands/deploy.js +6 -6
  29. package/dist/esm/commands/dev.js +10 -10
  30. package/dist/esm/commands/index.js +8 -8
  31. package/dist/esm/commands/inspect.js +1 -1
  32. package/dist/esm/commands/serve.js +5 -5
  33. package/dist/esm/{new/compat → compat}/hooks.js +65 -41
  34. package/dist/esm/{new/compat → compat}/index.js +13 -2
  35. package/dist/{esm-node/new → esm}/compat/utils.js +10 -1
  36. package/dist/esm/index.js +248 -5
  37. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  38. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  39. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  40. package/dist/esm/plugins/analyze/index.js +328 -331
  41. package/dist/esm/plugins/deploy/index.js +84 -88
  42. package/dist/esm/plugins/initialize/index.js +61 -64
  43. package/dist/esm/plugins/serverBuild.js +52 -56
  44. package/dist/esm/{new/run.js → run/index.js} +6 -6
  45. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  46. package/dist/esm/{new/context.js → utils/initAppContext.js} +3 -3
  47. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  48. package/dist/esm/utils/loadPlugins.js +95 -7
  49. package/dist/esm/utils/printInstructions.js +3 -3
  50. package/dist/esm/utils/restart.js +5 -4
  51. package/dist/esm-node/commands/build.js +19 -13
  52. package/dist/esm-node/commands/deploy.js +5 -5
  53. package/dist/esm-node/commands/dev.js +11 -11
  54. package/dist/esm-node/commands/index.js +6 -6
  55. package/dist/esm-node/commands/inspect.js +1 -1
  56. package/dist/esm-node/commands/serve.js +4 -4
  57. package/dist/esm-node/{new/compat → compat}/hooks.js +20 -8
  58. package/dist/esm-node/{new/compat → compat}/index.js +10 -2
  59. package/dist/{esm/new → esm-node}/compat/utils.js +10 -1
  60. package/dist/esm-node/index.js +143 -5
  61. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  62. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  63. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  64. package/dist/esm-node/plugins/analyze/index.js +128 -130
  65. package/dist/esm-node/plugins/deploy/index.js +12 -14
  66. package/dist/esm-node/plugins/initialize/index.js +44 -50
  67. package/dist/esm-node/plugins/serverBuild.js +30 -32
  68. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  69. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  70. package/dist/esm-node/{new/context.js → utils/initAppContext.js} +3 -3
  71. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  72. package/dist/esm-node/utils/loadPlugins.js +34 -4
  73. package/dist/esm-node/utils/printInstructions.js +2 -2
  74. package/dist/esm-node/utils/restart.js +4 -3
  75. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  76. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  77. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  78. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  79. package/dist/types/builder/index.d.ts +1 -1
  80. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  81. package/dist/types/builder/shared/types.d.ts +3 -2
  82. package/dist/types/commands/build.d.ts +2 -2
  83. package/dist/types/commands/deploy.d.ts +2 -2
  84. package/dist/types/commands/dev.d.ts +2 -2
  85. package/dist/types/commands/index.d.ts +6 -6
  86. package/dist/types/commands/inspect.d.ts +2 -2
  87. package/dist/types/commands/serve.d.ts +2 -2
  88. package/dist/types/compat/hooks.d.ts +7 -0
  89. package/dist/types/compat/index.d.ts +2 -0
  90. package/dist/types/config/default.d.ts +4 -3
  91. package/dist/types/config/initialize/index.d.ts +3 -2
  92. package/dist/types/config/initialize/inits.d.ts +4 -3
  93. package/dist/types/index.d.ts +8 -5
  94. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  95. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  96. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  97. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  98. package/dist/types/plugins/analyze/index.d.ts +2 -3
  99. package/dist/types/plugins/deploy/index.d.ts +2 -3
  100. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  101. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  102. package/dist/types/plugins/initialize/index.d.ts +2 -2
  103. package/dist/types/plugins/serverBuild.d.ts +2 -2
  104. package/dist/types/types/index.d.ts +7 -3
  105. package/dist/types/types/new.d.ts +157 -0
  106. package/dist/types/utils/env.d.ts +2 -2
  107. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  108. package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
  109. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  110. package/dist/types/utils/loadPlugins.d.ts +13 -3
  111. package/dist/types/utils/printInstructions.d.ts +3 -3
  112. package/dist/types/utils/restart.d.ts +2 -3
  113. package/dist/types/utils/routes.d.ts +2 -1
  114. package/lib/types.d.ts +82 -61
  115. package/package.json +24 -24
  116. package/dist/cjs/hooks.js +0 -60
  117. package/dist/cjs/new/index.js +0 -79
  118. package/dist/cjs/new/loadPlugins.js +0 -57
  119. package/dist/cjs/old.js +0 -179
  120. package/dist/esm/hooks.js +0 -36
  121. package/dist/esm/new/index.js +0 -55
  122. package/dist/esm/new/loadPlugins.js +0 -94
  123. package/dist/esm/old.js +0 -258
  124. package/dist/esm-node/hooks.js +0 -36
  125. package/dist/esm-node/new/index.js +0 -52
  126. package/dist/esm-node/new/loadPlugins.js +0 -33
  127. package/dist/esm-node/old.js +0 -140
  128. package/dist/types/hooks.d.ts +0 -2
  129. package/dist/types/new/compat/hooks.d.ts +0 -8
  130. package/dist/types/new/compat/index.d.ts +0 -4
  131. package/dist/types/new/index.d.ts +0 -9
  132. package/dist/types/new/loadPlugins.d.ts +0 -9
  133. package/dist/types/new/types/index.d.ts +0 -90
  134. package/dist/types/new/utils/index.d.ts +0 -1
  135. package/dist/types/old.d.ts +0 -13
  136. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  137. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  138. /package/dist/esm/{new/types/index.js → types/new.js} +0 -0
  139. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  140. /package/dist/esm-node/{new/types/index.js → types/new.js} +0 -0
  141. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  142. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  143. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  144. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
@@ -1,12 +1,13 @@
1
1
  import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
2
+ import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
3
+ const debug = createDebugger("load-plugins");
2
4
  async function getServerPlugins(api, metaName = "modern-js") {
3
- const runner = api.useHookRunners();
4
- const { plugins } = await runner._internalServerPlugins({
5
+ const hooks = api.getHooks();
6
+ const { plugins } = await hooks._internalServerPlugins.call({
5
7
  plugins: []
6
8
  });
7
9
  const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
8
- api.setAppContext({
9
- ...api.useAppContext(),
10
+ api.updateAppContext({
10
11
  serverPlugins: filtedPlugins
11
12
  });
12
13
  return filtedPlugins;
@@ -16,7 +17,36 @@ async function loadServerPlugins(api, appDirectory, metaName) {
16
17
  const instances = await loadServerPluginInstances(plugins, appDirectory);
17
18
  return instances;
18
19
  }
20
+ const resolveCliPlugin = async (p, appDirectory) => {
21
+ const pkg = typeof p === "string" ? p : p[0];
22
+ const pluginOptions = typeof p === "string" ? void 0 : p[1];
23
+ const path = tryResolve(pkg, appDirectory);
24
+ let module;
25
+ try {
26
+ module = await compatibleRequire(path);
27
+ } catch (e) {
28
+ ({ default: module } = await dynamicImport(path));
29
+ }
30
+ if (typeof module === "function") {
31
+ const result = module(pluginOptions);
32
+ return result;
33
+ }
34
+ return module;
35
+ };
36
+ const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
37
+ const plugins = [
38
+ ...autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : [],
39
+ ...autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []
40
+ ];
41
+ const loadedPlugins = await Promise.all(plugins.map((plugin) => {
42
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
43
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
44
+ return loadedPlugin;
45
+ }));
46
+ return loadedPlugins;
47
+ };
19
48
  export {
20
49
  getServerPlugins,
50
+ loadInternalPlugins,
21
51
  loadServerPlugins
22
52
  };
@@ -1,7 +1,7 @@
1
1
  import { logger, prettyInstructions } from "@modern-js/utils";
2
- const printInstructions = async (hookRunners, appContext, config) => {
2
+ const printInstructions = async (hooks, appContext, config) => {
3
3
  const message = prettyInstructions(appContext, config);
4
- const { instructions } = await hookRunners.beforePrintInstructions({
4
+ const { instructions } = await hooks.onBeforePrintInstructions.call({
5
5
  instructions: message
6
6
  });
7
7
  logger.log(instructions);
@@ -1,11 +1,12 @@
1
1
  import { cli } from "@modern-js/plugin-v2/cli";
2
- import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
3
- async function restart(hooksRunner, filename) {
2
+ import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
3
+ import { program } from "@modern-js/utils/commander";
4
+ async function restart(hooks, filename) {
4
5
  clearConsole();
5
6
  logger.info(`Restart because ${chalk.yellow(filename)} is changed...
6
7
  `);
7
8
  let hasGetError = false;
8
- await hooksRunner.beforeRestart();
9
+ await hooks.onBeforeRestart.call();
9
10
  try {
10
11
  await cli.init(cli.getPrevInitOptions());
11
12
  } catch (err) {
@@ -1,3 +1,4 @@
1
1
  import type { RsbuildPlugin } from '@modern-js/uni-builder';
2
+ import type { Bundler } from '../../types';
2
3
  import type { BuilderOptions } from '../shared';
3
- export declare const builderPluginAdapterCopy: (options: BuilderOptions<'shared'>) => RsbuildPlugin;
4
+ export declare const builderPluginAdapterCopy: <B extends Bundler>(options: BuilderOptions<B>) => RsbuildPlugin;
@@ -1,2 +1,3 @@
1
- import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
2
- export declare function createBuilderProviderConfig<B extends Bundler>(resolveConfig: AppNormalizedConfig<B>, appContext: IAppContext): Omit<AppNormalizedConfig<B>, 'plugins'>;
1
+ import type { AppNormalizedConfig, Bundler } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function createBuilderProviderConfig<B extends Bundler>(resolveConfig: AppNormalizedConfig<B>, appContext: AppToolsContext<B>): Omit<AppNormalizedConfig<B>, 'plugins'>;
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import type { Rspack, RspackChain } from '@rsbuild/core';
3
- import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
4
- export declare function createPublicPattern(appContext: IAppContext, config: AppNormalizedConfig, chain: RspackChain): {
3
+ import type { AppNormalizedConfig, Bundler } from '../../types';
4
+ import type { AppToolsContext } from '../../types/new';
5
+ export declare function createPublicPattern<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig, chain: RspackChain): {
5
6
  info: (file: {
6
7
  sourceFilename: string;
7
8
  }) => {
@@ -13,4 +14,4 @@ export declare function createPublicPattern(appContext: IAppContext, config: App
13
14
  noErrorOnMissing: boolean;
14
15
  transform: (content: Buffer, absoluteFrom: string) => string | Buffer;
15
16
  };
16
- export declare function createUploadPattern<B extends Bundler>(appContext: IAppContext, config: AppNormalizedConfig<B>): Rspack.CopyRspackPluginOptions['patterns']['0'];
17
+ export declare function createUploadPattern<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig<B>): Rspack.CopyRspackPluginOptions['patterns']['0'];
@@ -1,6 +1,6 @@
1
- import type { IAppContext } from '@modern-js/core';
2
1
  import type { AppNormalizedConfig, Bundler } from '../../types';
3
- export declare function getBuilderEnvironments<B extends Bundler>(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext, tempBuilderConfig: Omit<AppNormalizedConfig<B>, 'plugins'>): {
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function getBuilderEnvironments<B extends Bundler>(normalizedConfig: AppNormalizedConfig<B>, appContext: AppToolsContext<B>, tempBuilderConfig: Omit<AppNormalizedConfig<B>, 'plugins'>): {
4
4
  environments: {
5
5
  [name: string]: import("@rsbuild/core").EnvironmentConfig;
6
6
  };
@@ -1 +1 @@
1
- export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
1
+ export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern | typeof import("./builder-webpack/index.js").createWebpackBuilderForModern>;
@@ -1,5 +1,6 @@
1
- import type { AppNormalizedConfig, IAppContext } from '../../types';
2
- export declare function createCopyInfo(appContext: IAppContext, config: AppNormalizedConfig<'shared'>): {
1
+ import type { AppNormalizedConfig, Bundler } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function createCopyInfo<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig<B>): {
3
4
  configDir: string;
4
5
  uploadDir: string;
5
6
  publicDir: string;
@@ -1,5 +1,6 @@
1
- import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
1
+ import type { AppNormalizedConfig, Bundler } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
2
3
  export type BuilderOptions<B extends Bundler> = {
3
4
  normalizedConfig: AppNormalizedConfig<B>;
4
- appContext: IAppContext;
5
+ appContext: AppToolsContext<B>;
5
6
  };
@@ -1,4 +1,4 @@
1
- import { type PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
3
  import type { BuildOptions } from '../utils/types';
4
- export declare const build: (api: PluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
4
+ export declare const build: (api: CLIPluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
- export declare const deploy: (api: PluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
3
+ export declare const deploy: (api: CLIPluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
@@ -1,8 +1,8 @@
1
- import { type PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import { type ApplyPlugins } from '@modern-js/server';
3
3
  import type { AppTools } from '../types';
4
4
  import type { DevOptions } from '../utils/types';
5
5
  export interface ExtraServerOptions {
6
6
  applyPlugins?: ApplyPlugins;
7
7
  }
8
- export declare const dev: (api: PluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
8
+ export declare const dev: (api: CLIPluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
@@ -1,10 +1,10 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import { type Command } from '@modern-js/utils';
3
3
  import type { AppTools } from '../types';
4
- export declare const devCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
5
- export declare const buildCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
6
- export declare const serverCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
7
- export declare const deployCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
4
+ export declare const devCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
5
+ export declare const buildCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
6
+ export declare const serverCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => void;
7
+ export declare const deployCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => void;
8
8
  export declare const newCommand: (program: Command, locale: string) => void;
9
- export declare const inspectCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
9
+ export declare const inspectCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => void;
10
10
  export declare const upgradeCommand: (program: Command) => void;
@@ -1,4 +1,4 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
3
  import type { InspectOptions } from '../utils/types';
4
- export declare const inspect: (api: PluginAPI<AppTools<'shared'>>, options: InspectOptions) => Promise<import("@rsbuild/core").InspectConfigResult<"rspack">>;
4
+ export declare const inspect: (api: CLIPluginAPI<AppTools<'shared'>>, options: InspectOptions) => Promise<import("@rsbuild/core").InspectConfigResult<"rspack">>;
@@ -1,3 +1,3 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
- export declare const start: (api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
3
+ export declare const start: (api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
@@ -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<'shared'>>): 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<'shared'>>;
@@ -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,2 +1,3 @@
1
- import type { AppNormalizedConfig, IAppContext } from '../../types';
2
- export declare function initialNormalizedConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext, bundler: 'webpack' | 'rspack'): AppNormalizedConfig<'shared'>;
1
+ import type { AppNormalizedConfig } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function initialNormalizedConfig(config: AppNormalizedConfig<'shared'>, appContext: AppToolsContext<'shared'>, bundler: 'webpack' | 'rspack'): AppNormalizedConfig<'shared'>;
@@ -1,4 +1,5 @@
1
- import type { AppNormalizedConfig, IAppContext } from '../../types';
2
- export declare function initHtmlConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext): AppNormalizedConfig<'shared'>['html'];
3
- export declare function initSourceConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext, bundler: 'webpack' | 'rspack'): void;
1
+ import type { AppNormalizedConfig } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function initHtmlConfig(config: AppNormalizedConfig<'shared'>, appContext: AppToolsContext<'shared'>): AppNormalizedConfig<'shared'>['html'];
4
+ export declare function initSourceConfig(config: AppNormalizedConfig<'shared'>, appContext: AppToolsContext<'shared'>, bundler: 'webpack' | 'rspack'): void;
4
5
  export declare function createBuilderModuleScope(config: AppNormalizedConfig<'webpack'>): (string | RegExp)[] | undefined;
@@ -1,9 +1,12 @@
1
- import { appTools } from './new/index';
2
- export { appTools, initAppContext, type AppToolsPlugin } from './new/index';
1
+ import type { AppTools, AppToolsOptions, CliPluginFuture } from './types';
2
+ import { initAppContext } from './utils/initAppContext';
3
+ export * from './defineConfig';
4
+ export declare const appTools: (options?: AppToolsOptions) => CliPluginFuture<AppTools<'shared'>>;
5
+ export { defineConfig, defineLegacyConfig } from './defineConfig';
6
+ export { mergeConfig } from '@modern-js/core';
7
+ export type { RuntimeUserConfig } from './types/config';
3
8
  export { dev } from './commands/dev';
4
9
  export type { DevOptions } from './utils/types';
5
- export { mergeConfig } from '@modern-js/core';
6
- export { defineConfig, defineLegacyConfig } from './defineConfig';
7
10
  export * from './types';
8
- export type { RuntimeUserConfig } from './types/config';
11
+ export { initAppContext };
9
12
  export default appTools;
@@ -1,4 +1,4 @@
1
- import type { CliHooksRunner } from '@modern-js/core';
2
1
  import type { Entrypoint } from '@modern-js/types';
3
- import type { AppNormalizedConfig, AppTools, IAppContext } from '../../types';
4
- export declare const getBundleEntry: (hookRunners: CliHooksRunner<AppTools<'shared'>>, appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Promise<Entrypoint[]>;
2
+ import type { AppNormalizedConfig } from '../../types';
3
+ import type { AppToolsContext, AppToolsHooks } from '../../types/new';
4
+ export declare const getBundleEntry: (hooks: AppToolsHooks<'shared'>, appContext: AppToolsContext<'shared'>, config: AppNormalizedConfig<'shared'>) => Promise<Entrypoint[]>;
@@ -1,5 +1,5 @@
1
- import type { CliHooksRunner } from '@modern-js/core';
2
1
  import type { Entrypoint } from '@modern-js/types';
3
- import type { AppNormalizedConfig, AppTools, IAppContext } from '../../types';
2
+ import type { AppNormalizedConfig } from '../../types';
3
+ import type { AppToolsContext, AppToolsHooks } from '../../types/new';
4
4
  export type { Entrypoint };
5
- export declare const getFileSystemEntry: (hookRunners: CliHooksRunner<AppTools<'shared'>>, appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Promise<Entrypoint[]>;
5
+ export declare const getFileSystemEntry: (hooks: AppToolsHooks<'shared'>, appContext: AppToolsContext<'shared'>, config: AppNormalizedConfig<'shared'>) => Promise<Entrypoint[]>;
@@ -1,6 +1,27 @@
1
- import type { Entrypoint, HtmlTemplates } from '@modern-js/types';
2
- import type { AppNormalizedConfig, AppTools, IAppContext, PluginAPI } from '../../types';
3
- export declare const getHtmlTemplate: (entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>, { appContext, config, }: {
4
- appContext: IAppContext;
1
+ import type { Entrypoint, HtmlPartials, HtmlTemplates } from '@modern-js/types';
2
+ import type { AppNormalizedConfig } from '../../types';
3
+ import type { AppToolsContext, AppToolsHooks } from '../../types/new';
4
+ export declare const getModifyHtmlPartials: (partials: Record<keyof HtmlPartials, string[]>) => {
5
+ top: {
6
+ append: (...script: string[]) => void;
7
+ prepend: (...script: string[]) => void;
8
+ current: string[];
9
+ };
10
+ head: {
11
+ append: (...script: string[]) => void;
12
+ prepend: (...script: string[]) => void;
13
+ current: string[];
14
+ };
15
+ body: {
16
+ append: (...script: string[]) => void;
17
+ prepend: (...script: string[]) => void;
18
+ current: string[];
19
+ };
20
+ };
21
+ export declare const getHtmlTemplate: (entrypoints: Entrypoint[], hooks: AppToolsHooks<'shared'>, { appContext, config, }: {
22
+ appContext: AppToolsContext<'shared'>;
5
23
  config: AppNormalizedConfig<'shared'>;
6
- }) => Promise<HtmlTemplates>;
24
+ }) => Promise<{
25
+ partialsByEntrypoint: Record<string, HtmlPartials>;
26
+ htmlTemplates: HtmlTemplates;
27
+ }>;
@@ -1,7 +1,7 @@
1
- import type { IAppContext } from '@modern-js/core';
2
1
  import type { Entrypoint, ServerRoute } from '@modern-js/types';
3
2
  import type { AppNormalizedConfig } from '../../types';
3
+ import type { AppToolsContext } from '../../types/new';
4
4
  export declare const getServerRoutes: (entrypoints: Entrypoint[], { appContext, config, }: {
5
- appContext: IAppContext;
5
+ appContext: AppToolsContext<'shared'>;
6
6
  config: AppNormalizedConfig<'shared'>;
7
7
  }) => ServerRoute[];
@@ -1,6 +1,5 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- import type { AppTools } from '../../types';
1
+ import type { AppTools, CliPluginFuture } from '../../types';
3
2
  declare const _default: ({ bundler, }: {
4
3
  bundler: 'webpack' | 'rspack';
5
- }) => CliPlugin<AppTools<'shared'>>;
4
+ }) => CliPluginFuture<AppTools<'shared'>>;
6
5
  export default _default;
@@ -1,4 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- import type { AppTools } from '../../types';
3
- declare const _default: () => CliPlugin<AppTools>;
1
+ import type { AppTools, CliPluginFuture } from '../../types';
2
+ declare const _default: () => CliPluginFuture<AppTools<'shared'>>;
4
3
  export default _default;
@@ -1,6 +1,6 @@
1
- import type { IAppContext, NormalizedConfig } from '@modern-js/core';
2
- import type { AppTools } from '../../../types';
3
- export type CreatePreset = (appContext: IAppContext, config: NormalizedConfig<AppTools>, needModernServer?: boolean) => DeployPreset;
1
+ import type { AppToolsNormalizedConfig } from '../../../types';
2
+ import type { AppToolsContext } from '../../../types/new';
3
+ export type CreatePreset = (appContext: AppToolsContext<'shared'>, config: AppToolsNormalizedConfig, needModernServer?: boolean) => DeployPreset;
4
4
  type DeployPreset = {
5
5
  prepare?: () => Promise<void>;
6
6
  writeOutput?: () => Promise<void>;
@@ -1,11 +1,11 @@
1
- import type { IAppContext } from '@modern-js/core';
1
+ import type { AppToolsContext } from '../../types/new';
2
2
  export type ServerAppContext = {
3
3
  sharedDirectory: string;
4
4
  apiDirectory: string;
5
5
  lambdaDirectory: string;
6
6
  metaName: string;
7
7
  };
8
- export declare const serverAppContenxtTemplate: (appContext: IAppContext) => {
8
+ export declare const serverAppContenxtTemplate: (appContext: AppToolsContext<'shared'>) => {
9
9
  sharedDirectory: string;
10
10
  apiDirectory: string;
11
11
  lambdaDirectory: string;
@@ -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,3 +1,3 @@
1
- import type { AppTools, CliPlugin } from '../types';
2
- declare const _default: () => CliPlugin<AppTools>;
1
+ import type { AppTools, CliPluginFuture } from '../types';
2
+ declare const _default: () => CliPluginFuture<AppTools<'shared'>>;
3
3
  export default _default;
@@ -1,8 +1,11 @@
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';
8
+ export type { CLIPluginExtends };
6
9
  export * from './hooks';
7
10
  export * from './config';
8
11
  export * from './legacyConfig';
@@ -10,16 +13,16 @@ export type { webpack, Rspack } from '@modern-js/uni-builder';
10
13
  export type { Bundler } from './utils';
11
14
  export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries, Resource, Params, RequestHandlerConfig, LoaderContext, OnError, OnTiming, RequestHandlerOptions, RequestHandler, } from '@modern-js/server-core';
12
15
  export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig, } from '@modern-js/core';
13
- export type AppTools<B extends Bundler = 'webpack'> = {
14
- hooks: AppToolsHooks<B>;
16
+ export type AppTools<B extends Bundler = 'webpack'> = Required<CLIPluginExtends<AppToolsUserConfig<B>, AppToolsNormalizedConfig, AppToolsExtendContext<B>, AppToolsExtendAPI<B>, AppToolsExtendHooks>> & {
15
17
  userConfig: AppToolsUserConfig<B>;
16
- normalizedConfig: AppToolsNormalizedConfig<AppToolsUserConfig<'shared'>>;
18
+ hooks: AppToolsHooks<B>;
17
19
  };
18
20
  export type LegacyAppTools = {
19
21
  hooks: AppToolsHooks;
20
22
  userConfig: AppToolsLegacyUserConfig;
21
23
  normalizedConfig: AppToolsLegacyNormalizedConfig;
22
24
  };
25
+ export type CliPluginFuture<Extends extends CLIPluginExtends> = CLIPlugin<Extends>;
23
26
  export type AppNormalizedConfig<B extends Bundler = 'webpack'> = NormalizedConfig<AppTools<B>>;
24
27
  export type AppLegacyNormalizedConfig = NormalizedConfig<LegacyAppTools>;
25
28
  export type AppUserConfig<B extends Bundler = 'webpack'> = UserConfig<AppTools<B>>;
@@ -31,3 +34,4 @@ export type AppToolsOptions = {
31
34
  * */
32
35
  bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
33
36
  };
37
+ export type { AppToolsExtendAPI, AppToolsExtendContext, AppToolsExtendHooks, AppToolsContext, AppToolsHooks as AppToolsFeatureHooks, } from './new';
@@ -0,0 +1,157 @@
1
+ import type { DevToolData, RegisterBuildPlatformResult } from '@modern-js/core';
2
+ import type { AppContext, AsyncHook, CollectAsyncHook, InternalContext, PluginHook, PluginHookTap, TransformFunction } from '@modern-js/plugin-v2';
3
+ import type { Hooks } from '@modern-js/plugin-v2/cli';
4
+ import type { Entrypoint, HtmlPartials, HtmlTemplates, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
5
+ import type { AppTools } from '.';
6
+ import type { getHookRunners } from '../compat/hooks';
7
+ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
8
+ import type { RuntimePlugin } from './hooks';
9
+ import type { Bundler } from './utils';
10
+ export type BeforeConfigFn = () => Promise<void> | void;
11
+ export type AfterPrepareFn = () => Promise<void> | void;
12
+ export type InternalRuntimePluginsFn = TransformFunction<{
13
+ entrypoint: Entrypoint;
14
+ plugins: RuntimePlugin[];
15
+ }>;
16
+ export type InternalServerPluginsFn = TransformFunction<{
17
+ plugins: ServerPlugin[];
18
+ }>;
19
+ export type CheckEntryPointFn = TransformFunction<{
20
+ path: string;
21
+ entry: false | string;
22
+ }>;
23
+ export type ModifyEntrypointsFn = TransformFunction<{
24
+ entrypoints: Entrypoint[];
25
+ }>;
26
+ export type ModifyFileSystemRoutesFn = TransformFunction<{
27
+ entrypoint: Entrypoint;
28
+ routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
29
+ }>;
30
+ export type ModifyServerRoutesFn = TransformFunction<{
31
+ routes: ServerRoute[];
32
+ }>;
33
+ export type DeplpoyFn = () => Promise<void> | void;
34
+ export type GenerateEntryCodeFn = (params: {
35
+ entrypoints: Entrypoint[];
36
+ }) => Promise<void> | void;
37
+ export type BeforeGenerateRoutesFn = TransformFunction<{
38
+ entrypoint: Entrypoint;
39
+ code: string;
40
+ }>;
41
+ export type BeforePrintInstructionsFn = TransformFunction<{
42
+ instructions: string;
43
+ }>;
44
+ export type RegisterDevFn = () => Promise<DevToolData> | DevToolData;
45
+ export type RegisterBuildPlatformFn = () => Promise<RegisterBuildPlatformResult> | RegisterBuildPlatformResult;
46
+ export type AddRuntimeExportsFn = () => Promise<void> | void;
47
+ export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
48
+ onBeforeConfig: PluginHookTap<BeforeConfigFn>;
49
+ onAfterPrepare: PluginHookTap<AfterPrepareFn>;
50
+ deploy: PluginHookTap<DeplpoyFn>;
51
+ _internalRuntimePlugins: PluginHookTap<InternalRuntimePluginsFn>;
52
+ _internalServerPlugins: PluginHookTap<InternalServerPluginsFn>;
53
+ checkEntryPoint: PluginHookTap<CheckEntryPointFn>;
54
+ modifyEntrypoints: PluginHookTap<ModifyEntrypointsFn>;
55
+ modifyFileSystemRoutes: PluginHookTap<ModifyFileSystemRoutesFn>;
56
+ modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
57
+ generateEntryCode: PluginHookTap<GenerateEntryCodeFn>;
58
+ onBeforeGenerateRoutes: PluginHookTap<BeforeGenerateRoutesFn>;
59
+ /**
60
+ * @deprecated
61
+ */
62
+ onBeforePrintInstructions: PluginHookTap<BeforePrintInstructionsFn>;
63
+ /**
64
+ * @deprecated
65
+ */
66
+ registerDev: PluginHookTap<RegisterDevFn>;
67
+ /**
68
+ * @deprecated
69
+ */
70
+ registerBuildPlatform: PluginHookTap<RegisterBuildPlatformFn>;
71
+ /**
72
+ * @deprecated
73
+ */
74
+ addRuntimeExports: PluginHookTap<AddRuntimeExportsFn>;
75
+ /**
76
+ * @deprecated use getAppContext instead
77
+ */
78
+ useAppContext: () => AppToolsContext<B>;
79
+ /**
80
+ * @deprecated use getConfig instead
81
+ */
82
+ useConfigContext: () => AppToolsUserConfig<B>;
83
+ /**
84
+ * @deprecated use getNormalizedConfig instead
85
+ */
86
+ useResolvedConfigContext: () => AppToolsNormalizedConfig<AppToolsUserConfig<B>>;
87
+ /**
88
+ * @deprecated use api.xx instead
89
+ */
90
+ useHookRunners: () => ReturnType<typeof getHookRunners>;
91
+ }
92
+ export interface AppToolsExtendHooks extends Record<string, PluginHook<(...args: any[]) => any>> {
93
+ onBeforeConfig: AsyncHook<BeforeConfigFn>;
94
+ onAfterPrepare: AsyncHook<AfterPrepareFn>;
95
+ deploy: AsyncHook<DeplpoyFn>;
96
+ _internalRuntimePlugins: AsyncHook<InternalRuntimePluginsFn>;
97
+ _internalServerPlugins: AsyncHook<InternalServerPluginsFn>;
98
+ checkEntryPoint: AsyncHook<CheckEntryPointFn>;
99
+ modifyEntrypoints: AsyncHook<ModifyEntrypointsFn>;
100
+ modifyFileSystemRoutes: AsyncHook<ModifyFileSystemRoutesFn>;
101
+ modifyServerRoutes: AsyncHook<ModifyServerRoutesFn>;
102
+ generateEntryCode: AsyncHook<GenerateEntryCodeFn>;
103
+ onBeforeGenerateRoutes: AsyncHook<BeforeGenerateRoutesFn>;
104
+ /**
105
+ * @deprecated
106
+ */
107
+ onBeforePrintInstructions: AsyncHook<BeforePrintInstructionsFn>;
108
+ /**
109
+ * @deprecated
110
+ */
111
+ registerDev: CollectAsyncHook<RegisterDevFn>;
112
+ /**
113
+ * @deprecated
114
+ */
115
+ registerBuildPlatform: CollectAsyncHook<RegisterBuildPlatformFn>;
116
+ /**
117
+ * @deprecated
118
+ */
119
+ addRuntimeExports: AsyncHook<AddRuntimeExportsFn>;
120
+ }
121
+ export type AppToolsExtendContext<B extends Bundler = 'webpack'> = {
122
+ metaName: string;
123
+ internalDirectory: string;
124
+ sharedDirectory: string;
125
+ internalDirAlias: string;
126
+ internalSrcAlias: string;
127
+ apiDirectory: string;
128
+ lambdaDirectory: string;
129
+ serverConfigFile: string;
130
+ serverPlugins: ServerPlugin[];
131
+ moduleType: 'module' | 'commonjs';
132
+ /** Information for entry points */
133
+ entrypoints: Entrypoint[];
134
+ /** Selected entry points */
135
+ checkedEntries: string[];
136
+ /** Information for server routes */
137
+ serverRoutes: ServerRoute[];
138
+ /** Whether to use api only mode */
139
+ apiOnly: boolean;
140
+ _internalContext: InternalContext<AppTools<B>>;
141
+ /**
142
+ * Information for HTML templates by entry
143
+ * @private
144
+ */
145
+ partialsByEntrypoint?: Record<string, HtmlPartials>;
146
+ /**
147
+ * Information for HTML templates
148
+ * @private
149
+ */
150
+ htmlTemplates: HtmlTemplates;
151
+ /**
152
+ * @deprecated compat old plugin, default is app tools
153
+ */
154
+ toolsType?: string;
155
+ };
156
+ export type AppToolsContext<B extends Bundler = 'webpack'> = AppContext<AppTools<B>> & AppToolsExtendContext<B>;
157
+ export type AppToolsHooks<B extends Bundler = 'webpack'> = Hooks<AppToolsUserConfig<B>, AppToolsNormalizedConfig> & AppToolsExtendHooks;
@@ -1,2 +1,2 @@
1
- import type { IAppContext } from '../types';
2
- export declare function getAutoInjectEnv(appContext: IAppContext): Record<string, string>;
1
+ import type { AppToolsContext } from '../types/new';
2
+ export declare function getAutoInjectEnv(appContext: AppToolsContext<'shared'>): Record<string, string>;
@@ -1,3 +1,3 @@
1
- import type { IAppContext } from '../types';
1
+ import type { AppToolsContext } from '../types/new';
2
2
  export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
3
- export declare function generateWatchFiles(appContext: IAppContext, configDir?: string): Promise<string[]>;
3
+ export declare function generateWatchFiles(appContext: AppToolsContext<'shared'>, configDir?: string): Promise<string[]>;
@@ -20,7 +20,6 @@ export declare const initAppContext: ({ appDirectory, runtimeConfigFile, options
20
20
  apiDirectory: string;
21
21
  lambdaDirectory: string;
22
22
  sharedDirectory: string;
23
- distDirectory: string;
24
23
  serverPlugins: never[];
25
24
  internalDirectory: string;
26
25
  htmlTemplates: {};