@modern-js/app-tools 2.13.3 → 2.14.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 (62) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/dist/cjs/analyze/constants.js +3 -1
  3. package/dist/cjs/analyze/getServerRoutes.js +5 -2
  4. package/dist/cjs/analyze/nestedRoutes.js +12 -0
  5. package/dist/cjs/analyze/templates.js +18 -1
  6. package/dist/cjs/builder/builder-rspack/adapterCopy.js +136 -0
  7. package/dist/cjs/builder/builder-rspack/index.js +6 -1
  8. package/dist/cjs/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +9 -10
  9. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +67 -0
  10. package/dist/cjs/builder/builder-webpack/index.js +4 -4
  11. package/dist/cjs/builder/shared/{createCopyPattern.js → createCopyInfo.js} +11 -44
  12. package/dist/cjs/builder/shared/index.js +1 -1
  13. package/dist/cjs/config/default.js +3 -1
  14. package/dist/cjs/config/initialize/inits.js +0 -7
  15. package/dist/cjs/index.js +6 -3
  16. package/dist/cjs/locale/en.js +5 -5
  17. package/dist/cjs/locale/zh.js +4 -4
  18. package/dist/cjs/schema/legacy.js +1 -1
  19. package/dist/esm/analyze/constants.js +3 -1
  20. package/dist/esm/analyze/getServerRoutes.js +4 -2
  21. package/dist/esm/analyze/nestedRoutes.js +13 -1
  22. package/dist/esm/analyze/templates.js +35 -3
  23. package/dist/esm/builder/builder-rspack/adapterCopy.js +372 -0
  24. package/dist/esm/builder/builder-rspack/index.js +8 -1
  25. package/dist/esm/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +5 -5
  26. package/dist/esm/builder/builder-webpack/createCopyPattern.js +39 -0
  27. package/dist/esm/builder/builder-webpack/index.js +4 -4
  28. package/dist/esm/builder/shared/createCopyInfo.js +12 -0
  29. package/dist/esm/builder/shared/index.js +1 -1
  30. package/dist/esm/config/default.js +3 -1
  31. package/dist/esm/config/initialize/inits.js +0 -7
  32. package/dist/esm/index.js +7 -2
  33. package/dist/esm/locale/en.js +5 -5
  34. package/dist/esm/locale/zh.js +4 -4
  35. package/dist/esm/schema/legacy.js +4 -1
  36. package/dist/esm-node/analyze/constants.js +3 -1
  37. package/dist/esm-node/analyze/getServerRoutes.js +5 -2
  38. package/dist/esm-node/analyze/nestedRoutes.js +12 -0
  39. package/dist/esm-node/analyze/templates.js +18 -1
  40. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +103 -0
  41. package/dist/esm-node/builder/builder-rspack/index.js +6 -1
  42. package/dist/esm-node/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +5 -6
  43. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +43 -0
  44. package/dist/esm-node/builder/builder-webpack/index.js +4 -4
  45. package/dist/esm-node/builder/shared/createCopyInfo.js +17 -0
  46. package/dist/esm-node/builder/shared/index.js +1 -1
  47. package/dist/esm-node/config/default.js +3 -1
  48. package/dist/esm-node/config/initialize/inits.js +0 -7
  49. package/dist/esm-node/index.js +6 -3
  50. package/dist/esm-node/locale/en.js +5 -5
  51. package/dist/esm-node/locale/zh.js +4 -4
  52. package/dist/esm-node/schema/legacy.js +1 -1
  53. package/dist/types/analyze/constants.d.ts +2 -0
  54. package/dist/types/builder/builder-rspack/adapterCopy.d.ts +4 -0
  55. package/dist/types/builder/builder-webpack/{builderPlugins/compatModern.d.ts → adapterModern.d.ts} +2 -2
  56. package/dist/types/builder/{shared → builder-webpack}/createCopyPattern.d.ts +3 -3
  57. package/dist/types/builder/shared/createCopyInfo.d.ts +6 -0
  58. package/dist/types/builder/shared/index.d.ts +2 -2
  59. package/dist/types/types/config/deploy.d.ts +3 -0
  60. package/package.json +24 -24
  61. package/dist/esm/builder/shared/createCopyPattern.js +0 -44
  62. package/dist/esm-node/builder/shared/createCopyPattern.js +0 -50
@@ -1,4 +1,5 @@
1
1
  import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
2
+ import { getAutoInjectEnv } from "../utils/env";
2
3
  function createDefaultConfig(appContext, bundler) {
3
4
  const defaultBuilderConfig = createDefaultBuilderConfig();
4
5
  const dev = {
@@ -18,6 +19,7 @@ function createDefaultConfig(appContext, bundler) {
18
19
  disableDefaultEntries: false,
19
20
  entriesDir: "./src",
20
21
  configDir: "./config",
22
+ globalVars: getAutoInjectEnv(appContext),
21
23
  alias: {
22
24
  [appContext.internalDirAlias]: appContext.internalDirectory,
23
25
  [appContext.internalSrcAlias]: appContext.srcDirectory,
@@ -78,7 +80,7 @@ function createLegacyDefaultConfig(appContext) {
78
80
  configDir: "./config",
79
81
  apiDir: "./api",
80
82
  envVars: [],
81
- globalVars: void 0,
83
+ globalVars: getAutoInjectEnv(appContext),
82
84
  alias: defaultAlias,
83
85
  moduleScopes: void 0,
84
86
  include: []
@@ -6,7 +6,6 @@ import {
6
6
  globby,
7
7
  isModernjsMonorepo
8
8
  } from "@modern-js/utils";
9
- import { getAutoInjectEnv } from "../../utils/env";
10
9
  function initHtmlConfig(config, appContext) {
11
10
  const ICON_EXTENSIONS = ["png", "jpg", "jpeg", "svg", "ico"];
12
11
  config.html.appIcon = createBuilderAppIcon(config, appContext);
@@ -42,15 +41,9 @@ function initHtmlConfig(config, appContext) {
42
41
  }
43
42
  function initSourceConfig(config, appContext, bundler) {
44
43
  config.source.include = createBuilderInclude(config, appContext);
45
- config.source.globalVars = createBuilderGlobalVars(config, appContext);
46
44
  if (bundler === "webpack") {
47
45
  config.source.moduleScopes = createBuilderModuleScope(config);
48
46
  }
49
- function createBuilderGlobalVars(config2, appContext2) {
50
- const { globalVars = {} } = config2.source;
51
- const publicEnv = getAutoInjectEnv(appContext2);
52
- return { ...globalVars, ...publicEnv };
53
- }
54
47
  function createBuilderInclude(config2, appContext2) {
55
48
  const { include } = config2.source;
56
49
  const defaultInclude = [appContext2.internalDirectory];
@@ -120,7 +120,7 @@ var src_default = (options = {
120
120
  const { MWANewAction } = await import("@modern-js/new-action");
121
121
  await MWANewAction({ ...options2, locale: options2.lang || locale });
122
122
  });
123
- program.command("inspect").description("inspect internal webpack config").option(
123
+ program.command("inspect").description("inspect the internal configs").option(
124
124
  `--env <env>`,
125
125
  i18n.t(localeKeys.command.inspect.env),
126
126
  "development"
@@ -140,8 +140,11 @@ var src_default = (options = {
140
140
  async prepare() {
141
141
  const command = getCommand();
142
142
  if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
143
- const appContext = api.useAppContext();
144
- await emptyDir(appContext.distDirectory);
143
+ const resolvedConfig = api.useResolvedConfigContext();
144
+ if (resolvedConfig.output.cleanDistPath) {
145
+ const appContext = api.useAppContext();
146
+ await emptyDir(appContext.distDirectory);
147
+ }
145
148
  }
146
149
  },
147
150
  async watchFiles() {
@@ -5,7 +5,7 @@ const EN_LOCALE = {
5
5
  config: "specify config file"
6
6
  },
7
7
  dev: {
8
- describe: "start dev server",
8
+ describe: "starting the dev server",
9
9
  entry: "compiler by entry",
10
10
  apiOnly: "start api server only",
11
11
  webOnly: "start web server only",
@@ -13,12 +13,12 @@ const EN_LOCALE = {
13
13
  requireEntry: "You must choose at least one entry"
14
14
  },
15
15
  build: {
16
- describe: "build application"
16
+ describe: "build the app for production"
17
17
  },
18
- serve: { describe: "start server" },
19
- deploy: { describe: "deploy application" },
18
+ serve: { describe: "preview the production build locally" },
19
+ deploy: { describe: "deploy the application" },
20
20
  new: {
21
- describe: "generator runner for MWA project",
21
+ describe: "enable optional features or add a new entry",
22
22
  debug: "using debug mode to log something",
23
23
  config: "set default generator config(json string)",
24
24
  distTag: `use specified tag version for it's generator`,
@@ -5,7 +5,7 @@ const ZH_LOCALE = {
5
5
  config: "指定配置文件路径,可以为相对路径或绝对路径"
6
6
  },
7
7
  dev: {
8
- describe: "本地开发命令",
8
+ describe: "启动开发服务器",
9
9
  entry: "指定入口,编译特定的页面",
10
10
  apiOnly: "仅启动 API 接口服务",
11
11
  webOnly: "仅启动 Web 服务",
@@ -13,10 +13,10 @@ const ZH_LOCALE = {
13
13
  requireEntry: "请至少选择一个入口"
14
14
  },
15
15
  build: {
16
- describe: "构建应用命令"
16
+ describe: "构建生产环境产物"
17
17
  },
18
- serve: { describe: "应用启动命令" },
19
- deploy: { describe: "部署应用命令" },
18
+ serve: { describe: "启动生产环境服务" },
19
+ deploy: { describe: "部署应用" },
20
20
  new: {
21
21
  describe: "Web App 项目中执行生成器",
22
22
  debug: "开启 Debug 模式,打印调试日志信息",
@@ -23,7 +23,7 @@ const source = {
23
23
  enableAsyncEntry: { type: "boolean" },
24
24
  disableDefaultEntries: { type: "boolean" },
25
25
  envVars: { type: "array" },
26
- globalVars: { type: "object" },
26
+ globalVars: { typeof: ["object", "function"] },
27
27
  moduleScopes: { instanceof: ["Array", "Function"] },
28
28
  entriesDir: { type: "string" },
29
29
  configDir: { type: "string" },
@@ -26,6 +26,8 @@ export declare const NESTED_ROUTE: {
26
26
  LOADER_FILE: string;
27
27
  SPLATE_FILE: string;
28
28
  SPLATE_LOADER_FILE: string;
29
+ LAYOUT_CONFIG_FILE: string;
30
+ PAGE_CONFIG_FILE: string;
29
31
  };
30
32
  export declare const APP_CONFIG_NAME = "config";
31
33
  export declare const APP_INIT_EXPORTED = "init";
@@ -0,0 +1,4 @@
1
+ import { BuilderPlugin } from '@modern-js/builder-shared';
2
+ import { BuilderPluginAPI } from '@modern-js/builder-rspack-provider';
3
+ import { BuilderOptions } from '../shared';
4
+ export declare const builderPluginAdpaterCopy: (options: BuilderOptions<'rspack'>) => BuilderPlugin<BuilderPluginAPI>;
@@ -1,8 +1,8 @@
1
1
  import { BuilderPlugin } from '@modern-js/builder-shared';
2
2
  import type { BuilderPluginAPI } from '@modern-js/builder-webpack-provider';
3
- import { BuilderOptions } from '../../shared';
3
+ import { BuilderOptions } from '../shared';
4
4
  /**
5
5
  * Provides default configuration consistent with modern.js v1
6
6
  */
7
7
 
8
- export declare const builderPluginCompatModern: (options: BuilderOptions<'webpack'>) => BuilderPlugin<BuilderPluginAPI>;
8
+ export declare const builderPluginAdapterModern: (options: BuilderOptions<'webpack'>) => BuilderPlugin<BuilderPluginAPI>;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { WebpackChain } from '@modern-js/builder-webpack-provider';
3
3
  import { AppNormalizedConfig, IAppContext } from '../../types';
4
- export declare function createCopyPattern(appContext: IAppContext, config: AppNormalizedConfig, patternsType: 'upload' | 'public', chain?: WebpackChain): {
4
+ export declare function createPublicPattern(appContext: IAppContext, config: AppNormalizedConfig, chain: WebpackChain): {
5
5
  info: (file: {
6
6
  sourceFilename: string;
7
7
  }) => {
@@ -12,7 +12,8 @@ export declare function createCopyPattern(appContext: IAppContext, config: AppNo
12
12
  context: string;
13
13
  noErrorOnMissing: boolean;
14
14
  transform: (content: Buffer, absoluteFrom: string) => string | Buffer;
15
- } | {
15
+ };
16
+ export declare function createUploadPattern(appContext: IAppContext, config: AppNormalizedConfig): {
16
17
  info: (file: {
17
18
  sourceFilename: string;
18
19
  }) => {
@@ -22,5 +23,4 @@ export declare function createCopyPattern(appContext: IAppContext, config: AppNo
22
23
  to: string;
23
24
  context: string;
24
25
  noErrorOnMissing: boolean;
25
- transform?: undefined;
26
26
  };
@@ -0,0 +1,6 @@
1
+ import { AppNormalizedConfig, IAppContext } from '../../types';
2
+ export declare function createCopyInfo(appContext: IAppContext, config: AppNormalizedConfig<'shared'>): {
3
+ configDir: string;
4
+ uploadDir: string;
5
+ publicDir: string;
6
+ };
@@ -1,3 +1,3 @@
1
- export * from './createCopyPattern';
2
1
  export * from './types';
3
- export * from './builderPlugins';
2
+ export * from './builderPlugins';
3
+ export * from './createCopyInfo';
@@ -5,4 +5,7 @@ export interface MicroFrontend {
5
5
  }
6
6
  export interface DeployUserConfig {
7
7
  microFrontend?: boolean | MicroFrontend;
8
+ worker?: {
9
+ ssr?: boolean;
10
+ };
8
11
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.13.3",
14
+ "version": "2.14.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -69,23 +69,23 @@
69
69
  "es-module-lexer": "^1.1.0",
70
70
  "esbuild": "0.15.7",
71
71
  "rspack-plugin-virtual-module": "0.1.0",
72
- "@modern-js/builder": "2.13.3",
73
- "@modern-js/builder-plugin-esbuild": "2.13.3",
74
- "@modern-js/builder-plugin-node-polyfill": "2.13.3",
75
- "@modern-js/builder-shared": "2.13.3",
76
- "@modern-js/builder-webpack-provider": "2.13.3",
77
- "@modern-js/core": "2.13.3",
78
- "@modern-js/new-action": "2.13.3",
79
- "@modern-js/node-bundle-require": "2.13.3",
80
- "@modern-js/plugin": "2.13.3",
81
- "@modern-js/plugin-data-loader": "2.13.3",
82
- "@modern-js/plugin-i18n": "2.13.3",
83
- "@modern-js/plugin-lint": "2.13.3",
84
- "@modern-js/prod-server": "2.13.3",
85
- "@modern-js/server": "2.13.3",
86
- "@modern-js/types": "2.13.3",
87
- "@modern-js/upgrade": "2.13.3",
88
- "@modern-js/utils": "2.13.3"
72
+ "@modern-js/builder": "2.14.0",
73
+ "@modern-js/builder-plugin-esbuild": "2.14.0",
74
+ "@modern-js/builder-plugin-node-polyfill": "2.14.0",
75
+ "@modern-js/builder-shared": "2.14.0",
76
+ "@modern-js/builder-webpack-provider": "2.14.0",
77
+ "@modern-js/core": "2.14.0",
78
+ "@modern-js/new-action": "2.14.0",
79
+ "@modern-js/node-bundle-require": "2.14.0",
80
+ "@modern-js/plugin": "2.14.0",
81
+ "@modern-js/plugin-data-loader": "2.14.0",
82
+ "@modern-js/plugin-i18n": "2.14.0",
83
+ "@modern-js/plugin-lint": "2.14.0",
84
+ "@modern-js/prod-server": "2.14.0",
85
+ "@modern-js/server": "2.14.0",
86
+ "@modern-js/types": "2.14.0",
87
+ "@modern-js/upgrade": "2.14.0",
88
+ "@modern-js/utils": "2.14.0"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@types/babel__traverse": "^7.14.2",
@@ -94,14 +94,14 @@
94
94
  "jest": "^29",
95
95
  "typescript": "^4",
96
96
  "webpack": "^5.76.2",
97
- "@modern-js/builder-plugin-swc": "2.13.3",
98
- "@modern-js/builder-rspack-provider": "2.13.3",
99
- "@modern-js/server-core": "2.13.3",
100
- "@scripts/build": "2.13.3",
101
- "@scripts/jest-config": "2.13.3"
97
+ "@modern-js/builder-plugin-swc": "2.14.0",
98
+ "@modern-js/builder-rspack-provider": "2.14.0",
99
+ "@modern-js/server-core": "2.14.0",
100
+ "@scripts/build": "2.14.0",
101
+ "@scripts/jest-config": "2.14.0"
102
102
  },
103
103
  "peerDependencies": {
104
- "@modern-js/builder-rspack-provider": "^2.13.3"
104
+ "@modern-js/builder-rspack-provider": "^2.14.0"
105
105
  },
106
106
  "peerDependenciesMeta": {
107
107
  "@modern-js/builder-rspack-provider": {
@@ -1,44 +0,0 @@
1
- import path from "path";
2
- import { removeTailSlash } from "@modern-js/utils";
3
- function createCopyPattern(appContext, config, patternsType, chain) {
4
- var configDir = path.resolve(appContext.appDirectory, config.source.configDir || "./config");
5
- var uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
6
- var publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
7
- var minifiedJsRexExp = /\.min\.js/;
8
- var info = function(file) {
9
- return {
10
- // If the file name ends with `.min.js`, we assume it's a compressed file.
11
- // So we don't want copy-webpack-plugin to minify it.
12
- // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
13
- minimized: minifiedJsRexExp.test(file.sourceFilename)
14
- };
15
- };
16
- if (patternsType === "public") {
17
- if (!chain) {
18
- throw new Error("expect get a webpackChain, but receive 'undefined'");
19
- }
20
- return {
21
- info: info,
22
- from: "**/*",
23
- to: "public",
24
- context: publicDir,
25
- noErrorOnMissing: true,
26
- // eslint-disable-next-line node/prefer-global/buffer
27
- transform: function(content, absoluteFrom) {
28
- if (!/\.html?$/.test(absoluteFrom)) {
29
- return content;
30
- }
31
- return content.toString("utf8").replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(chain.output.get("publicPath")));
32
- }
33
- };
34
- } else {
35
- return {
36
- info: info,
37
- from: "**/*",
38
- to: "upload",
39
- context: uploadDir,
40
- noErrorOnMissing: true
41
- };
42
- }
43
- }
44
- export { createCopyPattern };
@@ -1,50 +0,0 @@
1
- import path from "path";
2
- import { removeTailSlash } from "@modern-js/utils";
3
- function createCopyPattern(appContext, config, patternsType, chain) {
4
- const configDir = path.resolve(
5
- appContext.appDirectory,
6
- config.source.configDir || "./config"
7
- );
8
- const uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
9
- const publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
10
- const minifiedJsRexExp = /\.min\.js/;
11
- const info = (file) => ({
12
- // If the file name ends with `.min.js`, we assume it's a compressed file.
13
- // So we don't want copy-webpack-plugin to minify it.
14
- // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
15
- minimized: minifiedJsRexExp.test(file.sourceFilename)
16
- });
17
- if (patternsType === "public") {
18
- if (!chain) {
19
- throw new Error("expect get a webpackChain, but receive 'undefined'");
20
- }
21
- return {
22
- info,
23
- from: "**/*",
24
- to: "public",
25
- context: publicDir,
26
- noErrorOnMissing: true,
27
- // eslint-disable-next-line node/prefer-global/buffer
28
- transform: (content, absoluteFrom) => {
29
- if (!/\.html?$/.test(absoluteFrom)) {
30
- return content;
31
- }
32
- return content.toString("utf8").replace(
33
- /<%=\s*assetPrefix\s*%>/g,
34
- removeTailSlash(chain.output.get("publicPath"))
35
- );
36
- }
37
- };
38
- } else {
39
- return {
40
- info,
41
- from: "**/*",
42
- to: "upload",
43
- context: uploadDir,
44
- noErrorOnMissing: true
45
- };
46
- }
47
- }
48
- export {
49
- createCopyPattern
50
- };