@modern-js/app-tools 1.21.5 → 2.0.0-beta.1

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 (170) hide show
  1. package/CHANGELOG.md +319 -51
  2. package/dist/js/modern/analyze/constants.js +1 -0
  3. package/dist/js/modern/analyze/generateCode.js +126 -32
  4. package/dist/js/modern/analyze/getBundleEntry.js +7 -14
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +173 -0
  6. package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +13 -58
  7. package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
  8. package/dist/js/modern/analyze/getClientRoutes/utils.js +18 -0
  9. package/dist/js/modern/analyze/getFileSystemEntry.js +27 -21
  10. package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
  11. package/dist/js/modern/analyze/getServerRoutes.js +15 -32
  12. package/dist/js/modern/analyze/index.js +81 -23
  13. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  14. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  15. package/dist/js/modern/analyze/nestedRoutes.js +102 -0
  16. package/dist/js/modern/analyze/templates.js +151 -12
  17. package/dist/js/modern/analyze/utils.js +2 -8
  18. package/dist/js/modern/builder/builderPlugins/compatModern.js +208 -0
  19. package/dist/js/modern/builder/createHtmlConfig.js +58 -0
  20. package/dist/js/modern/builder/createOutputConfig.js +70 -0
  21. package/dist/js/modern/builder/createSourceConfig.js +74 -0
  22. package/dist/js/modern/builder/createToolsConfig.js +87 -0
  23. package/dist/js/modern/builder/index.js +108 -0
  24. package/dist/js/modern/builder/share.js +44 -0
  25. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +29 -0
  26. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +33 -0
  27. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  28. package/dist/js/modern/commands/build.js +16 -110
  29. package/dist/js/modern/commands/dev.js +12 -28
  30. package/dist/js/modern/commands/inspect.js +8 -66
  31. package/dist/js/modern/commands/start.js +2 -3
  32. package/dist/js/modern/index.js +17 -16
  33. package/dist/js/modern/locale/en.js +0 -1
  34. package/dist/js/modern/locale/zh.js +0 -1
  35. package/dist/js/modern/utils/commands.js +5 -0
  36. package/dist/js/modern/utils/config.js +1 -12
  37. package/dist/js/modern/utils/createServer.js +12 -1
  38. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  39. package/dist/js/modern/utils/printInstructions.js +3 -2
  40. package/dist/js/modern/utils/routes.js +0 -2
  41. package/dist/js/node/analyze/constants.js +3 -1
  42. package/dist/js/node/analyze/generateCode.js +123 -47
  43. package/dist/js/node/analyze/getBundleEntry.js +7 -20
  44. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +181 -0
  45. package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +19 -78
  46. package/dist/js/node/analyze/getClientRoutes/index.js +19 -0
  47. package/dist/js/node/analyze/getClientRoutes/utils.js +28 -0
  48. package/dist/js/node/analyze/getFileSystemEntry.js +26 -28
  49. package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
  50. package/dist/js/node/analyze/getServerRoutes.js +14 -40
  51. package/dist/js/node/analyze/index.js +81 -33
  52. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  53. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  54. package/dist/js/node/analyze/nestedRoutes.js +111 -0
  55. package/dist/js/node/analyze/templates.js +153 -21
  56. package/dist/js/node/analyze/utils.js +4 -20
  57. package/dist/js/node/builder/builderPlugins/compatModern.js +216 -0
  58. package/dist/js/node/builder/createHtmlConfig.js +68 -0
  59. package/dist/js/node/builder/createOutputConfig.js +76 -0
  60. package/dist/js/node/builder/createSourceConfig.js +82 -0
  61. package/dist/js/node/builder/createToolsConfig.js +94 -0
  62. package/dist/js/node/builder/index.js +117 -0
  63. package/dist/js/node/builder/share.js +51 -0
  64. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +36 -0
  65. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +40 -0
  66. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  67. package/dist/js/node/commands/build.js +14 -121
  68. package/dist/js/node/commands/deploy.js +0 -2
  69. package/dist/js/node/commands/dev.js +10 -44
  70. package/dist/js/node/commands/index.js +0 -6
  71. package/dist/js/node/commands/inspect.js +10 -90
  72. package/dist/js/node/commands/start.js +2 -11
  73. package/dist/js/node/exports/server.js +0 -1
  74. package/dist/js/node/hooks.js +0 -2
  75. package/dist/js/node/index.js +22 -32
  76. package/dist/js/node/locale/en.js +0 -1
  77. package/dist/js/node/locale/index.js +0 -4
  78. package/dist/js/node/locale/zh.js +0 -1
  79. package/dist/js/node/utils/commands.js +12 -0
  80. package/dist/js/node/utils/config.js +1 -25
  81. package/dist/js/node/utils/createServer.js +15 -11
  82. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  83. package/dist/js/node/utils/language.js +0 -2
  84. package/dist/js/node/utils/printInstructions.js +3 -6
  85. package/dist/js/node/utils/routes.js +0 -5
  86. package/dist/js/treeshaking/analyze/constants.js +16 -0
  87. package/dist/js/treeshaking/analyze/generateCode.js +369 -0
  88. package/dist/js/treeshaking/analyze/getBundleEntry.js +69 -0
  89. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +184 -0
  90. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +185 -0
  91. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
  92. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +24 -0
  93. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +96 -0
  94. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +129 -0
  95. package/dist/js/treeshaking/analyze/getServerRoutes.js +157 -0
  96. package/dist/js/treeshaking/analyze/index.js +334 -0
  97. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +28 -0
  98. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +16 -0
  99. package/dist/js/treeshaking/analyze/nestedRoutes.js +165 -0
  100. package/dist/js/treeshaking/analyze/templates.js +170 -0
  101. package/dist/js/treeshaking/analyze/utils.js +88 -0
  102. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +212 -0
  103. package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
  104. package/dist/js/treeshaking/builder/createOutputConfig.js +70 -0
  105. package/dist/js/treeshaking/builder/createSourceConfig.js +88 -0
  106. package/dist/js/treeshaking/builder/createToolsConfig.js +85 -0
  107. package/dist/js/treeshaking/builder/index.js +161 -0
  108. package/dist/js/treeshaking/builder/share.js +46 -0
  109. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
  110. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +41 -0
  111. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  112. package/dist/js/treeshaking/commands/build.js +83 -0
  113. package/dist/js/treeshaking/commands/deploy.js +26 -0
  114. package/dist/js/treeshaking/commands/dev.js +124 -0
  115. package/dist/js/treeshaking/commands/index.js +3 -0
  116. package/dist/js/treeshaking/commands/inspect.js +29 -0
  117. package/dist/js/treeshaking/commands/start.js +69 -0
  118. package/dist/js/treeshaking/exports/server.js +1 -0
  119. package/dist/js/treeshaking/hooks.js +21 -0
  120. package/dist/js/treeshaking/index.js +267 -0
  121. package/dist/js/treeshaking/locale/en.js +34 -0
  122. package/dist/js/treeshaking/locale/index.js +9 -0
  123. package/dist/js/treeshaking/locale/zh.js +34 -0
  124. package/dist/js/treeshaking/utils/commands.js +5 -0
  125. package/dist/js/treeshaking/utils/config.js +124 -0
  126. package/dist/js/treeshaking/utils/createServer.js +73 -0
  127. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +58 -0
  128. package/dist/js/treeshaking/utils/language.js +5 -0
  129. package/dist/js/treeshaking/utils/printInstructions.js +30 -0
  130. package/dist/js/treeshaking/utils/routes.js +29 -0
  131. package/dist/js/treeshaking/utils/types.js +0 -0
  132. package/dist/types/analyze/constants.d.ts +1 -0
  133. package/dist/types/analyze/generateCode.d.ts +1 -1
  134. package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
  135. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
  136. package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
  137. package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
  138. package/dist/types/analyze/index.d.ts +4 -5
  139. package/dist/types/analyze/nestedRoutes.d.ts +5 -0
  140. package/dist/types/analyze/templates.d.ts +19 -3
  141. package/dist/types/analyze/utils.d.ts +2 -1
  142. package/dist/types/builder/builderPlugins/compatModern.d.ts +13 -0
  143. package/dist/types/builder/createHtmlConfig.d.ts +6 -0
  144. package/dist/types/builder/createOutputConfig.d.ts +3 -0
  145. package/dist/types/builder/createSourceConfig.d.ts +5 -0
  146. package/dist/types/builder/createToolsConfig.d.ts +13 -0
  147. package/dist/types/builder/index.d.ts +15 -0
  148. package/dist/types/builder/share.d.ts +26 -0
  149. package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
  150. package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
  151. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  152. package/dist/types/commands/build.d.ts +2 -1
  153. package/dist/types/commands/deploy.d.ts +2 -1
  154. package/dist/types/commands/dev.d.ts +2 -1
  155. package/dist/types/commands/inspect.d.ts +2 -6
  156. package/dist/types/commands/start.d.ts +2 -1
  157. package/dist/types/hooks.d.ts +15 -10
  158. package/dist/types/index.d.ts +4 -4
  159. package/dist/types/locale/en.d.ts +0 -1
  160. package/dist/types/locale/index.d.ts +0 -2
  161. package/dist/types/locale/zh.d.ts +0 -1
  162. package/dist/types/utils/commands.d.ts +1 -0
  163. package/dist/types/utils/config.d.ts +0 -1
  164. package/dist/types/utils/createServer.d.ts +8 -1
  165. package/dist/types/utils/printInstructions.d.ts +3 -2
  166. package/dist/types/utils/types.d.ts +2 -3
  167. package/package.json +25 -42
  168. package/dist/js/modern/utils/createCompiler.js +0 -61
  169. package/dist/js/node/utils/createCompiler.js +0 -81
  170. package/dist/types/utils/createCompiler.d.ts +0 -13
@@ -2,6 +2,7 @@ export declare const JS_EXTENSIONS: string[];
2
2
  export declare const INDEX_FILE_NAME = "index";
3
3
  export declare const APP_FILE_NAME = "App";
4
4
  export declare const PAGES_DIR_NAME = "pages";
5
+ export declare const NESTED_ROUTES_DIR = "routes";
5
6
  export declare const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
6
7
  export declare const ENTRY_POINT_FILE_NAME = "index.js";
7
8
  export declare const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
@@ -1,4 +1,4 @@
1
- import type { IAppContext, NormalizedConfig, PluginAPI, ImportStatement } from '@modern-js/core';
1
+ import { IAppContext, NormalizedConfig, PluginAPI, ImportStatement } from '@modern-js/core';
2
2
  import type { Entrypoint } from '@modern-js/types';
3
3
  export declare const createImportStatements: (statements: ImportStatement[]) => string;
4
4
  export declare const generateCode: (appContext: IAppContext, config: NormalizedConfig, entrypoints: Entrypoint[], api: PluginAPI) => Promise<void>;
@@ -1,9 +1,4 @@
1
- import type { Entrypoint, Route } from '@modern-js/types';
2
- export type { Route };
3
- export interface Identifier {
4
- name: string;
5
- path: string;
6
- }
1
+ import type { Entrypoint, NestedRoute, PageRoute } from '@modern-js/types';
7
2
  export declare const getClientRoutes: ({
8
3
  entrypoint,
9
4
  srcDirectory,
@@ -16,4 +11,4 @@ export declare const getClientRoutes: ({
16
11
  srcAlias: string;
17
12
  internalDirectory: string;
18
13
  internalDirAlias: string;
19
- }) => Route[];
14
+ }) => (NestedRoute | PageRoute)[];
@@ -0,0 +1,15 @@
1
+ import type { Entrypoint, RouteLegacy } from '@modern-js/types';
2
+ export type { RouteLegacy as Route };
3
+ export declare const getClientRoutes: ({
4
+ entrypoint,
5
+ srcDirectory,
6
+ srcAlias,
7
+ internalDirectory,
8
+ internalDirAlias
9
+ }: {
10
+ entrypoint: Entrypoint;
11
+ srcDirectory: string;
12
+ srcAlias: string;
13
+ internalDirectory: string;
14
+ internalDirAlias: string;
15
+ }) => RouteLegacy[];
@@ -0,0 +1,2 @@
1
+ export { getClientRoutes } from './getRoutes';
2
+ export { getClientRoutes as getClientRoutesLegacy } from './getRoutesLegacy';
@@ -0,0 +1,5 @@
1
+ declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
2
+ export { debug };
3
+ export declare const findLayout: (dir: string) => string | false;
4
+ export declare const getRouteWeight: (route: string) => number;
5
+ export declare const shouldSkip: (file: string) => boolean;
@@ -1,5 +1,6 @@
1
1
  import type { CliPlugin, RuntimePlugin, ImportStatement } from '@modern-js/core';
2
- import type { Route, Entrypoint, ServerRoute, HtmlPartials } from '@modern-js/types';
2
+ import type { RouteLegacy, Entrypoint, ServerRoute, HtmlPartials, NestedRoute, PageRoute } from '@modern-js/types';
3
+ import type { AppHooks } from '../hooks';
3
4
  export declare const modifyEntryImports: import("@modern-js/plugin").AsyncWaterfall<{
4
5
  imports: ImportStatement[];
5
6
  entrypoint: Entrypoint;
@@ -23,7 +24,7 @@ export declare const modifyAsyncEntry: import("@modern-js/plugin").AsyncWaterfal
23
24
  }>;
24
25
  export declare const modifyFileSystemRoutes: import("@modern-js/plugin").AsyncWaterfall<{
25
26
  entrypoint: Entrypoint;
26
- routes: Route[];
27
+ routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
27
28
  }>;
28
29
  export declare const modifyServerRoutes: import("@modern-js/plugin").AsyncWaterfall<{
29
30
  routes: ServerRoute[];
@@ -37,7 +38,5 @@ export declare const beforeGenerateRoutes: import("@modern-js/plugin").AsyncWate
37
38
  code: string;
38
39
  }>;
39
40
  export declare const addDefineTypes: import("@modern-js/plugin").AsyncWaterfall<void>;
40
-
41
- declare const _default: () => CliPlugin;
42
-
41
+ declare const _default: () => CliPlugin<AppHooks>;
43
42
  export default _default;
@@ -0,0 +1,5 @@
1
+ import type { NestedRoute } from '@modern-js/types';
2
+ export declare const walk: (dirname: string, rootDir: string, alias: {
3
+ name: string;
4
+ basename: string;
5
+ }, entryName: string) => Promise<NestedRoute | null>;
@@ -1,5 +1,5 @@
1
1
  import type { RuntimePlugin } from '@modern-js/core';
2
- import type { Entrypoint, Route } from '@modern-js/types';
2
+ import type { Entrypoint, NestedRoute, PageRoute, RouteLegacy } from '@modern-js/types';
3
3
  export declare const index: ({
4
4
  mountId,
5
5
  imports,
@@ -25,8 +25,24 @@ export declare const html: (partials: {
25
25
  head: string[];
26
26
  body: string[];
27
27
  }) => string;
28
+ export declare const routesForServer: ({
29
+ routes,
30
+ alias
31
+ }: {
32
+ routes: (NestedRoute | PageRoute)[];
33
+ alias: {
34
+ name: string;
35
+ basename: string;
36
+ };
37
+ }) => string;
28
38
  export declare const fileSystemRoutes: ({
29
- routes
39
+ routes,
40
+ ssrMode,
41
+ nestedRoutesEntry,
42
+ entryName
30
43
  }: {
31
- routes: Route[];
44
+ routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
45
+ ssrMode: 'string' | 'stream' | false;
46
+ nestedRoutesEntry?: string | undefined;
47
+ entryName: string;
32
48
  }) => string;
@@ -14,4 +14,5 @@ export declare const getDefaultImports: ({
14
14
  internalDirAlias: string;
15
15
  internalDirectory: string;
16
16
  }) => ImportStatement[];
17
- export declare const isRouteComponentFile: (filePath: string) => boolean;
17
+ export declare const isRouteComponentFile: (filePath: string) => boolean;
18
+ export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
@@ -0,0 +1,13 @@
1
+ import { BuilderPlugin } from '@modern-js/builder-shared';
2
+ import type { BuilderPluginAPI } from '@modern-js/builder-webpack-provider';
3
+ import type { IAppContext, NormalizedConfig } from '@modern-js/core';
4
+ declare type Parameter<T extends (arg: any) => void> = Parameters<T>[0];
5
+ declare type FnParameter<T extends {
6
+ [p: string]: (arg: any) => void;
7
+ }> = { [P in keyof T]: Parameter<T[P]> };
8
+ export declare type PluginCompatModernOptions = FnParameter<Partial<Pick<BuilderPluginAPI, 'onAfterBuild' | 'onAfterCreateCompiler' | 'onAfterStartDevServer' | 'onBeforeBuild' | 'onBeforeCreateCompiler' | 'onBeforeStartDevServer' | 'onDevCompileDone' | 'onExit'>>>;
9
+ /**
10
+ * Provides default configuration consistent with `@modern-js/webpack`
11
+ */
12
+ export declare const PluginCompatModern: (appContext: IAppContext, modernConfig: NormalizedConfig, options?: PluginCompatModernOptions) => BuilderPlugin<BuilderPluginAPI>;
13
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
+ import type { IAppContext, NormalizedConfig } from '@modern-js/core';
3
+ export declare function createHtmlConfig(normalizedConfig: NormalizedConfig, appContext: IAppContext): BuilderConfig['html'];
4
+ export declare function createBuilderAppIcon(configDir: NormalizedConfig['source']['configDir'], appContext: IAppContext): string | undefined;
5
+ export declare function createBuilderCrossorigin(scriptExt: NormalizedConfig['output']['scriptExt']): "anonymous" | "use-credentials" | undefined;
6
+ export declare function createBuilderFavicon(favicon: NormalizedConfig['output']['favicon'], configDir: NormalizedConfig['source']['configDir'], appContext: IAppContext): string | undefined;
@@ -0,0 +1,3 @@
1
+ import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
+ import type { IAppContext, NormalizedConfig } from '@modern-js/core';
3
+ export declare function createOutputConfig(normalizedConfig: NormalizedConfig, appContext: IAppContext): BuilderConfig['output'];
@@ -0,0 +1,5 @@
1
+ import { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
+ import { IAppContext, NormalizedConfig } from '@modern-js/core';
3
+ export declare function createSourceConfig(normalizedConfig: NormalizedConfig, appContext: IAppContext): BuilderConfig['source'];
4
+ export declare function createBuilderInclude(include: NormalizedConfig['source']['include'], appContext: IAppContext): (string | RegExp)[];
5
+ export declare function createBuilderModuleScope(moduleScopes: NormalizedConfig['source']['moduleScopes']): any[] | undefined;
@@ -0,0 +1,13 @@
1
+ import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
+ import type { NormalizedConfig } from '@modern-js/core';
3
+ export declare function createToolsConfig(normalizedConfig: NormalizedConfig): BuilderConfig['tools'];
4
+ export declare function createBuilderTsChecker(output: NormalizedConfig['output']): false | {
5
+ issue: {
6
+ include: {
7
+ file: string;
8
+ }[];
9
+ exclude: {
10
+ file: string;
11
+ }[];
12
+ };
13
+ };
@@ -0,0 +1,15 @@
1
+ import { BuilderInstance, BuilderTarget, CreateBuilderOptions } from '@modern-js/builder';
2
+ import type { IAppContext, NormalizedConfig } from '@modern-js/core';
3
+ import { PluginCompatModernOptions } from './builderPlugins/compatModern';
4
+ export declare type BuilderOptions = {
5
+ target?: BuilderTarget | BuilderTarget[];
6
+ normalizedConfig: NormalizedConfig;
7
+ appContext: IAppContext;
8
+ compatPluginConfig?: PluginCompatModernOptions;
9
+ };
10
+ export declare function createBuilderForEdenX({
11
+ normalizedConfig,
12
+ appContext,
13
+ compatPluginConfig
14
+ }: BuilderOptions): Promise<BuilderInstance>;
15
+ export declare function createBuilderOptions(target: BuilderTarget | BuilderTarget[], appContext: IAppContext): CreateBuilderOptions;
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ import { WebpackChain } from '@modern-js/builder-webpack-provider';
3
+ import { IAppContext, NormalizedConfig } from '@modern-js/core';
4
+ export declare function createCopyPattern(appContext: IAppContext, config: NormalizedConfig, patternsType: 'upload' | 'public', chain?: WebpackChain): {
5
+ info: (file: {
6
+ sourceFilename: string;
7
+ }) => {
8
+ minimized: boolean;
9
+ };
10
+ from: string;
11
+ to: string;
12
+ context: string;
13
+ noErrorOnMissing: boolean;
14
+ transform: (content: Buffer, absoluteFrom: string) => string | Buffer;
15
+ } | {
16
+ info: (file: {
17
+ sourceFilename: string;
18
+ }) => {
19
+ minimized: boolean;
20
+ };
21
+ from: string;
22
+ to: string;
23
+ context: string;
24
+ noErrorOnMissing: boolean;
25
+ transform?: undefined;
26
+ };
@@ -0,0 +1,8 @@
1
+ import type { webpack } from '@modern-js/builder-webpack-provider';
2
+ import type HtmlWebpackPlugin from '@modern-js/builder-webpack-provider/html-webpack-plugin';
3
+ export declare class HtmlAsyncChunkPlugin {
4
+ name: string;
5
+ htmlWebpackPlugin: typeof HtmlWebpackPlugin;
6
+ constructor(htmlWebpackPlugin: typeof HtmlWebpackPlugin);
7
+ apply(compiler: webpack.Compiler): void;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { webpack } from '@modern-js/builder-webpack-provider';
2
+ import type HtmlWebpackPlugin from '@modern-js/builder-webpack-provider/html-webpack-plugin';
3
+ export declare class BottomTemplatePlugin {
4
+ htmlWebpackPlugin: typeof HtmlWebpackPlugin;
5
+ bottomTemplateReg: RegExp;
6
+ bodyRegExp: RegExp;
7
+ name: string;
8
+ constructor(htmlWebpackPlugin: typeof HtmlWebpackPlugin);
9
+ apply(compiler: webpack.Compiler): void;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { Compiler } from 'webpack';
2
+ interface Options {
3
+ existNestedRoutes: boolean;
4
+ }
5
+ export default class RouterPlugin {
6
+ private existNestedRoutes;
7
+ constructor(options: Options);
8
+ apply(compiler: Compiler): void;
9
+ }
10
+ export {};
@@ -1,3 +1,4 @@
1
1
  import { PluginAPI } from '@modern-js/core';
2
2
  import type { BuildOptions } from '../utils/types';
3
- export declare const build: (api: PluginAPI, options?: BuildOptions) => Promise<void>;
3
+ import type { AppHooks } from '../hooks';
4
+ export declare const build: (api: PluginAPI<AppHooks>, options?: BuildOptions) => Promise<void>;
@@ -1,2 +1,3 @@
1
1
  import type { PluginAPI } from '@modern-js/core';
2
- export declare const deploy: (api: PluginAPI, options: any) => Promise<void>;
2
+ import type { AppHooks } from '../hooks';
3
+ export declare const deploy: (api: PluginAPI<AppHooks>, options: any) => Promise<void>;
@@ -1,3 +1,4 @@
1
1
  import { PluginAPI } from '@modern-js/core';
2
2
  import { DevOptions } from '../utils/types';
3
- export declare const dev: (api: PluginAPI, options: DevOptions) => Promise<void>;
3
+ import type { AppHooks } from '../hooks';
4
+ export declare const dev: (api: PluginAPI<AppHooks>, options: DevOptions) => Promise<void>;
@@ -1,7 +1,3 @@
1
- import { Configuration, WebpackConfigTarget } from '@modern-js/webpack';
2
- import type { PluginAPI, NormalizedConfig, IAppContext } from '@modern-js/core';
1
+ import type { PluginAPI } from '@modern-js/core';
3
2
  import type { InspectOptions } from '../utils/types';
4
- export declare const formatWebpackConfig: (config: Configuration, verbose?: boolean) => string;
5
- export declare const inspect: (api: PluginAPI, options: InspectOptions) => void;
6
- export declare const getTagByWebpackTarget: (webpackTarget: WebpackConfigTarget) => "client" | "modern" | "ssr";
7
- export declare const printInspectResult: (webpackTarget: WebpackConfigTarget, appContext: IAppContext, resolvedConfig: NormalizedConfig, options: InspectOptions) => string;
3
+ export declare const inspect: (api: PluginAPI, options: InspectOptions) => Promise<any>;
@@ -1,2 +1,3 @@
1
1
  import type { PluginAPI } from '@modern-js/core';
2
- export declare const start: (api: PluginAPI) => Promise<void>;
2
+ import type { AppHooks } from '../hooks';
3
+ export declare const start: (api: PluginAPI<AppHooks>) => Promise<void>;
@@ -1,37 +1,42 @@
1
- import type { Compiler, Configuration, MultiCompiler } from '@modern-js/webpack';
1
+ import type { webpack } from '@modern-js/builder-webpack-provider/types';
2
2
  export declare const beforeDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
3
3
  export declare const afterDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
4
4
  export declare const beforeCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
5
- webpackConfigs: Configuration[];
5
+ bundlerConfigs: webpack.Configuration[];
6
6
  }, unknown>;
7
7
  export declare const afterCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
8
- compiler: Compiler | MultiCompiler | undefined;
8
+ compiler: webpack.Compiler | webpack.MultiCompiler | undefined;
9
9
  }, unknown>;
10
10
  export declare const beforePrintInstructions: import("@modern-js/plugin").AsyncWaterfall<{
11
11
  instructions: string;
12
12
  }>;
13
13
  export declare const beforeBuild: import("@modern-js/plugin").AsyncWorkflow<{
14
- webpackConfigs: Configuration[];
14
+ bundlerConfigs?: webpack.Configuration[] | undefined;
15
+ }, unknown>;
16
+ export declare const afterBuild: import("@modern-js/plugin").AsyncWorkflow<{
17
+ stats?: webpack.Stats | webpack.MultiStats | undefined;
15
18
  }, unknown>;
16
- export declare const afterBuild: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
17
19
  export declare const beforeDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
18
20
  export declare const afterDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
19
21
  export declare const hooks: {
20
22
  beforeDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
21
23
  afterDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
22
24
  beforeCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
23
- webpackConfigs: Configuration[];
25
+ bundlerConfigs: webpack.Configuration[];
24
26
  }, unknown>;
25
27
  afterCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
26
- compiler: Compiler | MultiCompiler | undefined;
28
+ compiler: webpack.Compiler | webpack.MultiCompiler | undefined;
27
29
  }, unknown>;
28
30
  beforePrintInstructions: import("@modern-js/plugin").AsyncWaterfall<{
29
31
  instructions: string;
30
32
  }>;
31
33
  beforeBuild: import("@modern-js/plugin").AsyncWorkflow<{
32
- webpackConfigs: Configuration[];
34
+ bundlerConfigs?: webpack.Configuration[] | undefined;
35
+ }, unknown>;
36
+ afterBuild: import("@modern-js/plugin").AsyncWorkflow<{
37
+ stats?: webpack.Stats | webpack.MultiStats | undefined;
33
38
  }, unknown>;
34
- afterBuild: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
35
39
  beforeDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
36
40
  afterDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
37
- };
41
+ };
42
+ export declare type AppHooks = typeof hooks;
@@ -1,6 +1,6 @@
1
1
  import { defineConfig, CliPlugin } from '@modern-js/core';
2
- export { defineConfig };
3
-
4
- declare const _default: () => CliPlugin;
5
-
2
+ import { hooks, AppHooks } from './hooks';
3
+ export { defineConfig, hooks };
4
+ export type { AppHooks, CliPlugin };
5
+ declare const _default: () => CliPlugin<AppHooks>;
6
6
  export default _default;
@@ -28,7 +28,6 @@ export declare const EN_LOCALE: {
28
28
  inspect: {
29
29
  env: string;
30
30
  output: string;
31
- noConsole: string;
32
31
  verbose: string;
33
32
  };
34
33
  };
@@ -30,7 +30,6 @@ declare const localeKeys: {
30
30
  inspect: {
31
31
  env: string;
32
32
  output: string;
33
- noConsole: string;
34
33
  verbose: string;
35
34
  };
36
35
  };
@@ -64,7 +63,6 @@ declare const localeKeys: {
64
63
  inspect: {
65
64
  env: string;
66
65
  output: string;
67
- noConsole: string;
68
66
  verbose: string;
69
67
  };
70
68
  };
@@ -28,7 +28,6 @@ export declare const ZH_LOCALE: {
28
28
  inspect: {
29
29
  env: string;
30
30
  output: string;
31
- noConsole: string;
32
31
  verbose: string;
33
32
  };
34
33
  };
@@ -0,0 +1 @@
1
+ export declare const getCommand: () => string;
@@ -17,6 +17,5 @@ export declare const buildServerConfig: ({
17
17
  *
18
18
  * 处理循环引用的 replacer
19
19
  */
20
-
21
20
  export declare const safeReplacer: () => (key: string, value: unknown) => unknown;
22
21
  export declare const emitResolvedConfig: (appDirectory: string, resolvedConfig: NormalizedConfig) => Promise<void>;
@@ -1,4 +1,11 @@
1
1
  import { Server, ModernDevServerOptions } from '@modern-js/server';
2
+ import type { InternalPlugins } from '@modern-js/types';
2
3
  export declare const getServer: () => Server | null;
3
4
  export declare const closeServer: () => Promise<void>;
4
- export declare const createServer: (options: ModernDevServerOptions) => Promise<Server>;
5
+ export declare const createServer: (options: ModernDevServerOptions) => Promise<Server>;
6
+ export declare const injectDataLoaderPlugin: (internalPlugins: InternalPlugins) => {
7
+ '@modern-js/plugin-data-loader': {
8
+ path: string;
9
+ forced: boolean;
10
+ };
11
+ };
@@ -1,2 +1,3 @@
1
- import type { IAppContext, NormalizedConfig, ToRunners, CliHooks } from '@modern-js/core';
2
- export declare const printInstructions: (hookRunners: ToRunners<CliHooks>, appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
1
+ import type { IAppContext, NormalizedConfig, ToRunners } from '@modern-js/core';
2
+ import type { AppHooks } from '../hooks';
3
+ export declare const printInstructions: (hookRunners: ToRunners<AppHooks>, appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
@@ -15,8 +15,7 @@ export declare type StartOptions = {
15
15
  apiOnly?: boolean;
16
16
  };
17
17
  export declare type InspectOptions = {
18
- env?: string;
19
- output?: string;
20
- console?: boolean;
18
+ env: string;
19
+ output: string;
21
20
  verbose?: boolean;
22
21
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.21.5",
14
+ "version": "2.0.0-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -55,22 +55,27 @@
55
55
  "modern": "./bin/modern.js"
56
56
  },
57
57
  "dependencies": {
58
- "@babel/runtime": "^7.18.0",
59
58
  "@babel/parser": "^7.18.0",
59
+ "@babel/runtime": "^7.18.0",
60
60
  "@babel/traverse": "^7.18.0",
61
61
  "@babel/types": "^7.18.0",
62
- "@modern-js/core": "1.21.5",
63
- "@modern-js/new-action": "1.21.5",
64
- "@modern-js/upgrade": "1.21.5",
65
- "@modern-js/node-bundle-require": "1.21.5",
66
- "@modern-js/plugin": "1.21.5",
67
- "@modern-js/plugin-i18n": "1.21.5",
68
- "@modern-js/plugin-jarvis": "1.21.5",
69
- "@modern-js/prod-server": "1.21.5",
70
- "@modern-js/server": "1.21.5",
71
- "@modern-js/types": "1.21.5",
72
- "@modern-js/utils": "1.21.5",
73
- "@modern-js/webpack": "1.21.5"
62
+ "@modern-js/builder": "2.0.0-beta.1",
63
+ "@modern-js/builder-plugin-esbuild": "2.0.0-beta.1",
64
+ "@modern-js/builder-plugin-node-polyfill": "2.0.0-beta.1",
65
+ "@modern-js/builder-shared": "2.0.0-beta.1",
66
+ "@modern-js/builder-webpack-provider": "2.0.0-beta.1",
67
+ "@modern-js/core": "2.0.0-beta.1",
68
+ "@modern-js/new-action": "2.0.0-beta.1",
69
+ "@modern-js/node-bundle-require": "2.0.0-beta.1",
70
+ "@modern-js/plugin": "2.0.0-beta.1",
71
+ "@modern-js/plugin-data-loader": "2.0.0-beta.1",
72
+ "@modern-js/plugin-i18n": "2.0.0-beta.1",
73
+ "@modern-js/plugin-lint": "2.0.0-beta.1",
74
+ "@modern-js/prod-server": "2.0.0-beta.1",
75
+ "@modern-js/server": "2.0.0-beta.1",
76
+ "@modern-js/types": "2.0.0-beta.1",
77
+ "@modern-js/upgrade": "2.0.0-beta.1",
78
+ "@modern-js/utils": "2.0.0-beta.1"
74
79
  },
75
80
  "devDependencies": {
76
81
  "@types/babel__traverse": "^7.14.2",
@@ -78,42 +83,20 @@
78
83
  "@types/node": "^14",
79
84
  "jest": "^27",
80
85
  "typescript": "^4",
81
- "@modern-js/server-core": "1.21.5",
82
- "@scripts/build": "1.21.5",
83
- "@scripts/jest-config": "1.21.5"
86
+ "webpack": "^5.75.0",
87
+ "@modern-js/server-core": "2.0.0-beta.1",
88
+ "@scripts/build": "2.0.0-beta.1",
89
+ "@scripts/jest-config": "2.0.0-beta.1"
84
90
  },
85
91
  "sideEffects": false,
86
92
  "publishConfig": {
87
93
  "registry": "https://registry.npmjs.org/",
88
94
  "access": "public"
89
95
  },
90
- "wireit": {
91
- "build": {
92
- "command": "modern build",
93
- "files": [
94
- "src/**/*",
95
- "tsconfig.json",
96
- "package.json"
97
- ],
98
- "output": [
99
- "dist/**/*"
100
- ]
101
- },
102
- "test": {
103
- "command": "jest --passWithNoTests",
104
- "files": [
105
- "src/**/*",
106
- "tsconfig.json",
107
- "package.json",
108
- "tests/**/*"
109
- ],
110
- "output": []
111
- }
112
- },
113
96
  "scripts": {
114
97
  "new": "modern new",
115
98
  "dev": "modern build --watch",
116
- "build": "wireit",
117
- "test": "wireit"
99
+ "build": "modern build",
100
+ "test": "jest --passWithNoTests"
118
101
  }
119
102
  }
@@ -1,61 +0,0 @@
1
- import { webpack } from '@modern-js/webpack';
2
- import { chalk, logger, formatWebpackMessages, clearConsole } from '@modern-js/utils';
3
- import { printInstructions } from "./printInstructions";
4
- export const createCompiler = async ({
5
- api,
6
- webpackConfigs,
7
- // TODO: params
8
- userConfig,
9
- appContext
10
- }) => {
11
- try {
12
- const hookRunners = api.useHookRunners();
13
- await hookRunners.beforeCreateCompiler({
14
- webpackConfigs
15
- });
16
- const compiler = webpack(webpackConfigs);
17
- await hookRunners.afterCreateCompiler({
18
- compiler
19
- });
20
- let isFirstCompile = true;
21
- compiler.hooks.invalid.tap('invalid', () => {
22
- clearConsole();
23
- logger.log('Compiling...');
24
- });
25
- compiler.hooks.done.tap('done', async stats => {
26
- const statsData = stats.toJson({
27
- preset: 'errors-warnings'
28
- });
29
- const {
30
- errors,
31
- warnings
32
- } = formatWebpackMessages(statsData);
33
-
34
- if (errors.length) {
35
- logger.log(chalk.red(`Failed to compile.\n`));
36
- logger.log(errors.join('\n\n'));
37
- logger.log();
38
- } else if (process.stdout.isTTY || isFirstCompile) {
39
- await hookRunners.afterDev();
40
-
41
- if (warnings.length) {
42
- logger.log(chalk.yellow(`Compiled with warnings.\n`));
43
- logger.log(warnings.join('\n\n'));
44
- logger.log();
45
- }
46
-
47
- await printInstructions(hookRunners, appContext, userConfig);
48
- }
49
-
50
- isFirstCompile = false;
51
- });
52
- return compiler;
53
- } catch (err) {
54
- logger.log(chalk.red(`Failed to compile.`));
55
- logger.log();
56
- logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
57
- // eslint-disable-next-line no-process-exit
58
-
59
- process.exit(1);
60
- }
61
- };