@modern-js/app-tools 2.0.0-beta.7 → 2.0.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 (50) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/js/modern/analyze/constants.js +6 -0
  3. package/dist/js/modern/analyze/index.js +64 -2
  4. package/dist/js/modern/analyze/templates.js +17 -4
  5. package/dist/js/modern/analyze/utils.js +3 -3
  6. package/dist/js/modern/config/initial/inits.js +7 -0
  7. package/dist/js/modern/schema/index.js +1 -1
  8. package/dist/js/modern/schema/legacy.js +1 -1
  9. package/dist/js/modern/utils/env.js +15 -0
  10. package/dist/js/node/analyze/constants.js +9 -0
  11. package/dist/js/node/analyze/index.js +53 -0
  12. package/dist/js/node/analyze/templates.js +16 -3
  13. package/dist/js/node/analyze/utils.js +2 -3
  14. package/dist/js/node/config/initial/inits.js +7 -0
  15. package/dist/js/node/schema/index.js +1 -1
  16. package/dist/js/node/schema/legacy.js +1 -1
  17. package/dist/js/node/utils/env.js +38 -0
  18. package/dist/js/treeshaking/analyze/constants.js +4 -1
  19. package/dist/js/treeshaking/analyze/index.js +90 -2
  20. package/dist/js/treeshaking/analyze/templates.js +4 -4
  21. package/dist/js/treeshaking/analyze/utils.js +5 -4
  22. package/dist/js/treeshaking/config/initial/inits.js +7 -0
  23. package/dist/js/treeshaking/schema/index.js +1 -1
  24. package/dist/js/treeshaking/schema/legacy.js +1 -1
  25. package/dist/js/treeshaking/utils/env.js +13 -0
  26. package/dist/types/analyze/constants.d.ts +4 -1
  27. package/dist/types/builder/builderPlugins/compatModern.d.ts +3 -3
  28. package/dist/types/builder/index.d.ts +1 -1
  29. package/dist/types/schema/Schema.d.ts +1 -1
  30. package/dist/types/types/config/deploy.d.ts +1 -1
  31. package/dist/types/types/config/dev.d.ts +3 -3
  32. package/dist/types/types/config/experiments.d.ts +3 -3
  33. package/dist/types/types/config/html.d.ts +3 -3
  34. package/dist/types/types/config/index.d.ts +3 -3
  35. package/dist/types/types/config/output.d.ts +6 -6
  36. package/dist/types/types/config/performance.d.ts +3 -3
  37. package/dist/types/types/config/security.d.ts +3 -3
  38. package/dist/types/types/config/source.d.ts +4 -4
  39. package/dist/types/types/config/tools.d.ts +3 -3
  40. package/dist/types/types/hooks.d.ts +1 -1
  41. package/dist/types/types/index.d.ts +6 -6
  42. package/dist/types/types/legacyConfig/deploy.d.ts +1 -1
  43. package/dist/types/types/legacyConfig/dev.d.ts +2 -2
  44. package/dist/types/types/legacyConfig/index.d.ts +1 -1
  45. package/dist/types/types/legacyConfig/output.d.ts +2 -2
  46. package/dist/types/types/legacyConfig/source.d.ts +1 -1
  47. package/dist/types/types/legacyConfig/tools.d.ts +2 -2
  48. package/dist/types/utils/env.d.ts +2 -0
  49. package/dist/types/utils/types.d.ts +5 -5
  50. package/package.json +22 -22
package/CHANGELOG.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Minor Changes
10
+
11
+ - edd1cfb1af: feat: modernjs Access builder compiler
12
+ feat: modernjs 接入 builder 构建
13
+ - bbe4c4ab64: feat: add @modern-js/plugin-swc
14
+
15
+ feat: 新增 @modern-js/plugin-swc 插件
16
+
17
+ ### Patch Changes
18
+
19
+ - d4a456659b: chore: rename plugin-jarvis to plugin-lint
20
+
21
+ chore: 重命名 plugin-jarvis 为 plugin-lint
22
+
23
+ - 6bda14ed71: feat: refactor router with react-router@6.4
24
+
25
+ feat: 使用 react-router@6.4 重构路由模块
26
+
27
+ - 8b8e1bb571: feat: support nested routes
28
+ feat: 支持嵌套路由
29
+ - Updated dependencies [c9e800d39a]
30
+ - Updated dependencies [edd1cfb1af]
31
+ - Updated dependencies [d4a456659b]
32
+ - Updated dependencies [6bda14ed71]
33
+ - Updated dependencies [f680410886]
34
+ - Updated dependencies [dda38c9c3e]
35
+ - Updated dependencies [8b8e1bb571]
36
+ - Updated dependencies [ffb2ed4]
37
+ - Updated dependencies [bbe4c4ab64]
38
+ - @modern-js/core@2.0.0
39
+ - @modern-js/prod-server@2.0.0
40
+ - @modern-js/builder-webpack-provider@2.0.0
41
+ - @modern-js/builder-plugin-node-polyfill@2.0.0
42
+ - @modern-js/utils@2.0.0
43
+ - @modern-js/plugin-lint@2.0.0
44
+ - @modern-js/types@2.0.0
45
+ - @modern-js/builder@2.0.0
46
+ - @modern-js/builder-shared@2.0.0
47
+ - @modern-js/builder-plugin-esbuild@2.0.0
48
+ - @modern-js/plugin-data-loader@2.0.0
49
+ - @modern-js/plugin-i18n@2.0.0
50
+ - @modern-js/new-action@2.0.0
51
+ - @modern-js/server@2.0.0
52
+ - @modern-js/node-bundle-require@2.0.0
53
+ - @modern-js/plugin@2.0.0
54
+ - @modern-js/upgrade@2.0.0
55
+
3
56
  ## 2.0.0-beta.7
4
57
 
5
58
  ### Major Changes
@@ -25,8 +25,14 @@ const NESTED_ROUTE = {
25
25
  ERROR_FILE: "error",
26
26
  LOADER_FILE: "loader"
27
27
  };
28
+ const APP_CONFIG_NAME = "appConfig";
29
+ const APP_INIT_EXPORTED = "init";
30
+ const APP_INIT_IMPORTED = "appInit";
28
31
  export {
32
+ APP_CONFIG_NAME,
29
33
  APP_FILE_NAME,
34
+ APP_INIT_EXPORTED,
35
+ APP_INIT_IMPORTED,
30
36
  ENTRY_BOOTSTRAP_FILE_NAME,
31
37
  ENTRY_POINT_FILE_NAME,
32
38
  FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
@@ -38,7 +38,7 @@ var __async = (__this, __arguments, generator) => {
38
38
  });
39
39
  };
40
40
  import * as path from "path";
41
- import { createDebugger, fs, isApiOnly } from "@modern-js/utils";
41
+ import { createDebugger, findExists, fs, isApiOnly } from "@modern-js/utils";
42
42
  import { cloneDeep } from "@modern-js/utils/lodash";
43
43
  import { createBuilderForModern } from "../builder";
44
44
  import { printInstructions } from "../utils/printInstructions";
@@ -46,8 +46,18 @@ import { generateRoutes } from "../utils/routes";
46
46
  import { emitResolvedConfig } from "../utils/config";
47
47
  import { getCommand } from "../utils/commands";
48
48
  import { initialNormalizedConfig } from "../config";
49
- import { isNestedRouteComponent, isPageComponentFile } from "./utils";
49
+ import {
50
+ isNestedRouteComponent,
51
+ isPageComponentFile,
52
+ parseModule,
53
+ replaceWithAlias
54
+ } from "./utils";
50
55
  import { loaderBuilder, serverLoaderBuilder } from "./Builder";
56
+ import {
57
+ APP_CONFIG_NAME,
58
+ APP_INIT_EXPORTED,
59
+ APP_INIT_IMPORTED
60
+ } from "./constants";
51
61
  const debug = createDebugger("plugin-analyze");
52
62
  var analyze_default = () => ({
53
63
  name: "@modern-js/plugin-analyze",
@@ -204,6 +214,58 @@ var analyze_default = () => ({
204
214
  resolved: config
205
215
  };
206
216
  },
217
+ modifyEntryImports(_0) {
218
+ return __async(this, arguments, function* ({ entrypoint, imports }) {
219
+ const appContext = api.useAppContext();
220
+ const { srcDirectory } = appContext;
221
+ const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
222
+ if (fileSystemRoutes && nestedRoutesEntry) {
223
+ const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
224
+ const rootLayoutFile = findExists(
225
+ [".js", ".ts", ".jsx", ".tsx"].map(
226
+ (ext) => `${rootLayoutPath}${ext}`
227
+ )
228
+ );
229
+ if (rootLayoutFile) {
230
+ const rootLayoutBuffer = yield fs.readFile(rootLayoutFile);
231
+ const rootLayout = rootLayoutBuffer.toString();
232
+ const [, moduleExports] = yield parseModule({
233
+ source: rootLayout.toString(),
234
+ filename: rootLayoutFile
235
+ });
236
+ const hasAppConfig = moduleExports.some(
237
+ (e) => e.n === APP_CONFIG_NAME
238
+ );
239
+ const generateLayoutPath = replaceWithAlias(
240
+ srcDirectory,
241
+ rootLayoutFile,
242
+ "@_modern_js_src"
243
+ );
244
+ if (hasAppConfig) {
245
+ imports.push({
246
+ value: generateLayoutPath,
247
+ specifiers: [{ imported: APP_CONFIG_NAME }]
248
+ });
249
+ }
250
+ const hasAppInit = moduleExports.some(
251
+ (e) => e.n === APP_INIT_EXPORTED
252
+ );
253
+ if (hasAppInit) {
254
+ imports.push({
255
+ value: generateLayoutPath,
256
+ specifiers: [
257
+ { imported: APP_INIT_EXPORTED, local: APP_INIT_IMPORTED }
258
+ ]
259
+ });
260
+ }
261
+ }
262
+ }
263
+ return {
264
+ entrypoint,
265
+ imports
266
+ };
267
+ });
268
+ },
207
269
  beforeRestart() {
208
270
  return __async(this, null, function* () {
209
271
  serverLoaderBuilder.stop();
@@ -39,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
  import path from "path";
41
41
  import { fs, slash } from "@modern-js/utils";
42
- import { TEMP_LOADERS_DIR } from "./constants";
42
+ import { APP_CONFIG_NAME, TEMP_LOADERS_DIR } from "./constants";
43
43
  const index = ({
44
44
  mountId,
45
45
  imports,
@@ -68,21 +68,34 @@ const renderFunction = ({
68
68
  plugins,
69
69
  customBootstrap,
70
70
  fileSystemRoutes: fileSystemRoutes2
71
- }) => `
71
+ }) => {
72
+ return `
73
+ const finalAppConfig = {
74
+ ...App.config,
75
+ ...typeof ${APP_CONFIG_NAME} === 'object' ? ${APP_CONFIG_NAME} : {},
76
+ }
77
+
72
78
  AppWrapper = createApp({
73
79
  plugins: [
74
80
  ${plugins.map(
75
- ({ name, options, args }) => `${name}({...${options}, ...App?.config?.${args || name}}),`
76
- ).join("\n")}
81
+ ({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`
82
+ ).join("\n")}
77
83
  ]
78
84
  })(${fileSystemRoutes2 ? "" : `App`})
79
85
 
86
+
87
+ if(!AppWrapper.init && typeof appInit !== 'undefined') {
88
+ AppWrapper.init = appInit;
89
+ }
90
+
91
+
80
92
  if (IS_BROWSER) {
81
93
  ${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
82
94
  }
83
95
 
84
96
  return AppWrapper
85
97
  `;
98
+ };
86
99
  const html = (partials) => `
87
100
  <!DOCTYPE html>
88
101
  <html>
@@ -25,6 +25,7 @@ import { transform } from "esbuild";
25
25
  import { parse } from "es-module-lexer";
26
26
  import {
27
27
  FILE_SYSTEM_ROUTES_FILE_NAME,
28
+ JS_EXTENSIONS,
28
29
  LOADER_EXPORT_NAME,
29
30
  NESTED_ROUTE
30
31
  } from "./constants";
@@ -59,7 +60,6 @@ const getDefaultImports = ({
59
60
  },
60
61
  customBootstrap && {
61
62
  specifiers: [{ local: "customBootstrap" }],
62
- initialize: "const App = false;",
63
63
  value: normalizeToPosixPath(
64
64
  customBootstrap.replace(srcDirectory, internalSrcAlias)
65
65
  )
@@ -86,7 +86,7 @@ const getDefaultImports = ({
86
86
  route.initialize = "const App = false;";
87
87
  }
88
88
  imports.push(route);
89
- } else if (!customBootstrap) {
89
+ } else {
90
90
  imports.push({
91
91
  specifiers: [{ local: "App" }],
92
92
  value: normalizeToPosixPath(
@@ -122,7 +122,7 @@ const parseModule = (_0) => __async(void 0, [_0], function* ({
122
122
  filename
123
123
  }) {
124
124
  let content = source;
125
- if (filename.endsWith(".tsx") || filename.endsWith(".jsx")) {
125
+ if (JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
126
126
  const result = yield transform(content, {
127
127
  loader: path.extname(filename).slice(1),
128
128
  format: "esm"
@@ -25,6 +25,7 @@ import {
25
25
  globby,
26
26
  isModernjsMonorepo
27
27
  } from "@modern-js/utils";
28
+ import { getAutoInjectEnv } from "../../utils/env";
28
29
  function initHtmlConfig(config, appContext) {
29
30
  const ICON_EXTENSIONS = ["png", "jpg", "jpeg", "svg", "ico"];
30
31
  config.html.appIcon = createBuilderAppIcon(config, appContext);
@@ -61,6 +62,12 @@ function initHtmlConfig(config, appContext) {
61
62
  function initSourceConfig(config, appContext) {
62
63
  config.source.include = createBuilderInclude(config, appContext);
63
64
  config.source.moduleScopes = createBuilderModuleScope(config);
65
+ config.source.globalVars = createBuilderGlobalVars(config, appContext);
66
+ function createBuilderGlobalVars(config2, appContext2) {
67
+ const { globalVars = {} } = config2.source;
68
+ const publicEnv = getAutoInjectEnv(appContext2);
69
+ return __spreadValues(__spreadValues({}, globalVars), publicEnv);
70
+ }
64
71
  function createBuilderInclude(config2, appContext2) {
65
72
  const { include } = config2.source;
66
73
  const defaultInclude = [appContext2.internalDirectory];
@@ -68,7 +68,7 @@ const server = {
68
68
  enableMicroFrontendDebug: { type: "boolean" },
69
69
  watchOptions: { type: "object" },
70
70
  compiler: { type: "string" },
71
- disableFrameworkExt: { type: "boolean" }
71
+ enableFrameworkExt: { type: "boolean" }
72
72
  };
73
73
  const tools = {
74
74
  tailwindcss: { type: "object" },
@@ -114,7 +114,7 @@ const server = {
114
114
  enableMicroFrontendDebug: { type: "boolean" },
115
115
  watchOptions: { type: "object" },
116
116
  compiler: { type: "string" },
117
- disableFrameworkExt: { type: "boolean" }
117
+ enableFrameworkExt: { type: "boolean" }
118
118
  };
119
119
  const dev = {
120
120
  proxy: {
@@ -0,0 +1,15 @@
1
+ function getAutoInjectEnv(appContext) {
2
+ const { metaName } = appContext;
3
+ const prefix = `${metaName.split(/[-_]/)[0]}_`.toUpperCase();
4
+ const envReg = new RegExp(`^${prefix}`);
5
+ return Object.keys(process.env).reduce((prev, key) => {
6
+ const value = process.env[key];
7
+ if (envReg.test(key) && typeof value !== "undefined") {
8
+ prev[`process.env.${key}`] = value;
9
+ }
10
+ return prev;
11
+ }, {});
12
+ }
13
+ export {
14
+ getAutoInjectEnv
15
+ };
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var constants_exports = {};
19
19
  __export(constants_exports, {
20
+ APP_CONFIG_NAME: () => APP_CONFIG_NAME,
20
21
  APP_FILE_NAME: () => APP_FILE_NAME,
22
+ APP_INIT_EXPORTED: () => APP_INIT_EXPORTED,
23
+ APP_INIT_IMPORTED: () => APP_INIT_IMPORTED,
21
24
  ENTRY_BOOTSTRAP_FILE_NAME: () => ENTRY_BOOTSTRAP_FILE_NAME,
22
25
  ENTRY_POINT_FILE_NAME: () => ENTRY_POINT_FILE_NAME,
23
26
  FILE_SYSTEM_ROUTES_COMPONENTS_DIR: () => FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
@@ -65,9 +68,15 @@ const NESTED_ROUTE = {
65
68
  ERROR_FILE: "error",
66
69
  LOADER_FILE: "loader"
67
70
  };
71
+ const APP_CONFIG_NAME = "appConfig";
72
+ const APP_INIT_EXPORTED = "init";
73
+ const APP_INIT_IMPORTED = "appInit";
68
74
  // Annotate the CommonJS export names for ESM import in node:
69
75
  0 && (module.exports = {
76
+ APP_CONFIG_NAME,
70
77
  APP_FILE_NAME,
78
+ APP_INIT_EXPORTED,
79
+ APP_INIT_IMPORTED,
71
80
  ENTRY_BOOTSTRAP_FILE_NAME,
72
81
  ENTRY_POINT_FILE_NAME,
73
82
  FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
@@ -74,6 +74,7 @@ var import_commands = require("../utils/commands");
74
74
  var import_config2 = require("../config");
75
75
  var import_utils2 = require("./utils");
76
76
  var import_Builder = require("./Builder");
77
+ var import_constants = require("./constants");
77
78
  const debug = (0, import_utils.createDebugger)("plugin-analyze");
78
79
  var analyze_default = () => ({
79
80
  name: "@modern-js/plugin-analyze",
@@ -230,6 +231,58 @@ var analyze_default = () => ({
230
231
  resolved: config
231
232
  };
232
233
  },
234
+ modifyEntryImports(_0) {
235
+ return __async(this, arguments, function* ({ entrypoint, imports }) {
236
+ const appContext = api.useAppContext();
237
+ const { srcDirectory } = appContext;
238
+ const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
239
+ if (fileSystemRoutes && nestedRoutesEntry) {
240
+ const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
241
+ const rootLayoutFile = (0, import_utils.findExists)(
242
+ [".js", ".ts", ".jsx", ".tsx"].map(
243
+ (ext) => `${rootLayoutPath}${ext}`
244
+ )
245
+ );
246
+ if (rootLayoutFile) {
247
+ const rootLayoutBuffer = yield import_utils.fs.readFile(rootLayoutFile);
248
+ const rootLayout = rootLayoutBuffer.toString();
249
+ const [, moduleExports] = yield (0, import_utils2.parseModule)({
250
+ source: rootLayout.toString(),
251
+ filename: rootLayoutFile
252
+ });
253
+ const hasAppConfig = moduleExports.some(
254
+ (e) => e.n === import_constants.APP_CONFIG_NAME
255
+ );
256
+ const generateLayoutPath = (0, import_utils2.replaceWithAlias)(
257
+ srcDirectory,
258
+ rootLayoutFile,
259
+ "@_modern_js_src"
260
+ );
261
+ if (hasAppConfig) {
262
+ imports.push({
263
+ value: generateLayoutPath,
264
+ specifiers: [{ imported: import_constants.APP_CONFIG_NAME }]
265
+ });
266
+ }
267
+ const hasAppInit = moduleExports.some(
268
+ (e) => e.n === import_constants.APP_INIT_EXPORTED
269
+ );
270
+ if (hasAppInit) {
271
+ imports.push({
272
+ value: generateLayoutPath,
273
+ specifiers: [
274
+ { imported: import_constants.APP_INIT_EXPORTED, local: import_constants.APP_INIT_IMPORTED }
275
+ ]
276
+ });
277
+ }
278
+ }
279
+ }
280
+ return {
281
+ entrypoint,
282
+ imports
283
+ };
284
+ });
285
+ },
233
286
  beforeRestart() {
234
287
  return __async(this, null, function* () {
235
288
  import_Builder.serverLoaderBuilder.stop();
@@ -98,21 +98,34 @@ const renderFunction = ({
98
98
  plugins,
99
99
  customBootstrap,
100
100
  fileSystemRoutes: fileSystemRoutes2
101
- }) => `
101
+ }) => {
102
+ return `
103
+ const finalAppConfig = {
104
+ ...App.config,
105
+ ...typeof ${import_constants.APP_CONFIG_NAME} === 'object' ? ${import_constants.APP_CONFIG_NAME} : {},
106
+ }
107
+
102
108
  AppWrapper = createApp({
103
109
  plugins: [
104
110
  ${plugins.map(
105
- ({ name, options, args }) => `${name}({...${options}, ...App?.config?.${args || name}}),`
106
- ).join("\n")}
111
+ ({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`
112
+ ).join("\n")}
107
113
  ]
108
114
  })(${fileSystemRoutes2 ? "" : `App`})
109
115
 
116
+
117
+ if(!AppWrapper.init && typeof appInit !== 'undefined') {
118
+ AppWrapper.init = appInit;
119
+ }
120
+
121
+
110
122
  if (IS_BROWSER) {
111
123
  ${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
112
124
  }
113
125
 
114
126
  return AppWrapper
115
127
  `;
128
+ };
116
129
  const html = (partials) => `
117
130
  <!DOCTYPE html>
118
131
  <html>
@@ -89,7 +89,6 @@ const getDefaultImports = ({
89
89
  },
90
90
  customBootstrap && {
91
91
  specifiers: [{ local: "customBootstrap" }],
92
- initialize: "const App = false;",
93
92
  value: (0, import_utils.normalizeToPosixPath)(
94
93
  customBootstrap.replace(srcDirectory, internalSrcAlias)
95
94
  )
@@ -116,7 +115,7 @@ const getDefaultImports = ({
116
115
  route.initialize = "const App = false;";
117
116
  }
118
117
  imports.push(route);
119
- } else if (!customBootstrap) {
118
+ } else {
120
119
  imports.push({
121
120
  specifiers: [{ local: "App" }],
122
121
  value: (0, import_utils.normalizeToPosixPath)(
@@ -152,7 +151,7 @@ const parseModule = (_0) => __async(void 0, [_0], function* ({
152
151
  filename
153
152
  }) {
154
153
  let content = source;
155
- if (filename.endsWith(".tsx") || filename.endsWith(".jsx")) {
154
+ if (import_constants.JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
156
155
  const result = yield (0, import_esbuild.transform)(content, {
157
156
  loader: import_path.default.extname(filename).slice(1),
158
157
  format: "esm"
@@ -47,6 +47,7 @@ __export(inits_exports, {
47
47
  module.exports = __toCommonJS(inits_exports);
48
48
  var import_path = __toESM(require("path"));
49
49
  var import_utils = require("@modern-js/utils");
50
+ var import_env = require("../../utils/env");
50
51
  function initHtmlConfig(config, appContext) {
51
52
  const ICON_EXTENSIONS = ["png", "jpg", "jpeg", "svg", "ico"];
52
53
  config.html.appIcon = createBuilderAppIcon(config, appContext);
@@ -83,6 +84,12 @@ function initHtmlConfig(config, appContext) {
83
84
  function initSourceConfig(config, appContext) {
84
85
  config.source.include = createBuilderInclude(config, appContext);
85
86
  config.source.moduleScopes = createBuilderModuleScope(config);
87
+ config.source.globalVars = createBuilderGlobalVars(config, appContext);
88
+ function createBuilderGlobalVars(config2, appContext2) {
89
+ const { globalVars = {} } = config2.source;
90
+ const publicEnv = (0, import_env.getAutoInjectEnv)(appContext2);
91
+ return __spreadValues(__spreadValues({}, globalVars), publicEnv);
92
+ }
86
93
  function createBuilderInclude(config2, appContext2) {
87
94
  const { include } = config2.source;
88
95
  const defaultInclude = [appContext2.internalDirectory];
@@ -98,7 +98,7 @@ const server = {
98
98
  enableMicroFrontendDebug: { type: "boolean" },
99
99
  watchOptions: { type: "object" },
100
100
  compiler: { type: "string" },
101
- disableFrameworkExt: { type: "boolean" }
101
+ enableFrameworkExt: { type: "boolean" }
102
102
  };
103
103
  const tools = {
104
104
  tailwindcss: { type: "object" },
@@ -136,7 +136,7 @@ const server = {
136
136
  enableMicroFrontendDebug: { type: "boolean" },
137
137
  watchOptions: { type: "object" },
138
138
  compiler: { type: "string" },
139
- disableFrameworkExt: { type: "boolean" }
139
+ enableFrameworkExt: { type: "boolean" }
140
140
  };
141
141
  const dev = {
142
142
  proxy: {
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var env_exports = {};
19
+ __export(env_exports, {
20
+ getAutoInjectEnv: () => getAutoInjectEnv
21
+ });
22
+ module.exports = __toCommonJS(env_exports);
23
+ function getAutoInjectEnv(appContext) {
24
+ const { metaName } = appContext;
25
+ const prefix = `${metaName.split(/[-_]/)[0]}_`.toUpperCase();
26
+ const envReg = new RegExp(`^${prefix}`);
27
+ return Object.keys(process.env).reduce((prev, key) => {
28
+ const value = process.env[key];
29
+ if (envReg.test(key) && typeof value !== "undefined") {
30
+ prev[`process.env.${key}`] = value;
31
+ }
32
+ return prev;
33
+ }, {});
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ getAutoInjectEnv
38
+ });
@@ -34,4 +34,7 @@ var NESTED_ROUTE = {
34
34
  ERROR_FILE: "error",
35
35
  LOADER_FILE: "loader"
36
36
  };
37
- export { APP_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
37
+ var APP_CONFIG_NAME = "appConfig";
38
+ var APP_INIT_EXPORTED = "init";
39
+ var APP_INIT_IMPORTED = "appInit";
40
+ export { APP_CONFIG_NAME, APP_FILE_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
@@ -221,7 +221,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
221
221
  }
222
222
  };
223
223
  import * as path from "path";
224
- import { createDebugger, fs, isApiOnly } from "@modern-js/utils";
224
+ import { createDebugger, findExists, fs, isApiOnly } from "@modern-js/utils";
225
225
  import { cloneDeep } from "@modern-js/utils/lodash";
226
226
  import { createBuilderForModern } from "../builder";
227
227
  import { printInstructions } from "../utils/printInstructions";
@@ -229,8 +229,9 @@ import { generateRoutes } from "../utils/routes";
229
229
  import { emitResolvedConfig } from "../utils/config";
230
230
  import { getCommand } from "../utils/commands";
231
231
  import { initialNormalizedConfig } from "../config";
232
- import { isNestedRouteComponent, isPageComponentFile } from "./utils";
232
+ import { isNestedRouteComponent, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
233
233
  import { loaderBuilder, serverLoaderBuilder } from "./Builder";
234
+ import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
234
235
  var debug = createDebugger("plugin-analyze");
235
236
  var analyze_default = function() {
236
237
  return {
@@ -532,6 +533,93 @@ var analyze_default = function() {
532
533
  resolved: config
533
534
  };
534
535
  },
536
+ modifyEntryImports: function modifyEntryImports(param) {
537
+ var entrypoint = param.entrypoint, imports = param.imports;
538
+ return _asyncToGenerator(function() {
539
+ var appContext, srcDirectory, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
540
+ return __generator(this, function(_state) {
541
+ switch(_state.label){
542
+ case 0:
543
+ appContext = api.useAppContext();
544
+ srcDirectory = appContext.srcDirectory;
545
+ fileSystemRoutes = entrypoint.fileSystemRoutes, nestedRoutesEntry = entrypoint.nestedRoutesEntry;
546
+ if (!(fileSystemRoutes && nestedRoutesEntry)) return [
547
+ 3,
548
+ 3
549
+ ];
550
+ rootLayoutPath = path.join(nestedRoutesEntry, "layout");
551
+ rootLayoutFile = findExists([
552
+ ".js",
553
+ ".ts",
554
+ ".jsx",
555
+ ".tsx"
556
+ ].map(function(ext) {
557
+ return "".concat(rootLayoutPath).concat(ext);
558
+ }));
559
+ if (!rootLayoutFile) return [
560
+ 3,
561
+ 3
562
+ ];
563
+ return [
564
+ 4,
565
+ fs.readFile(rootLayoutFile)
566
+ ];
567
+ case 1:
568
+ rootLayoutBuffer = _state.sent();
569
+ rootLayout = rootLayoutBuffer.toString();
570
+ return [
571
+ 4,
572
+ parseModule({
573
+ source: rootLayout.toString(),
574
+ filename: rootLayoutFile
575
+ })
576
+ ];
577
+ case 2:
578
+ ref = _slicedToArray.apply(void 0, [
579
+ _state.sent(),
580
+ 2
581
+ ]), moduleExports = ref[1];
582
+ hasAppConfig = moduleExports.some(function(e) {
583
+ return e.n === APP_CONFIG_NAME;
584
+ });
585
+ generateLayoutPath = replaceWithAlias(srcDirectory, rootLayoutFile, "@_modern_js_src");
586
+ if (hasAppConfig) {
587
+ imports.push({
588
+ value: generateLayoutPath,
589
+ specifiers: [
590
+ {
591
+ imported: APP_CONFIG_NAME
592
+ }
593
+ ]
594
+ });
595
+ }
596
+ hasAppInit = moduleExports.some(function(e) {
597
+ return e.n === APP_INIT_EXPORTED;
598
+ });
599
+ if (hasAppInit) {
600
+ imports.push({
601
+ value: generateLayoutPath,
602
+ specifiers: [
603
+ {
604
+ imported: APP_INIT_EXPORTED,
605
+ local: APP_INIT_IMPORTED
606
+ }
607
+ ]
608
+ });
609
+ }
610
+ _state.label = 3;
611
+ case 3:
612
+ return [
613
+ 2,
614
+ {
615
+ entrypoint: entrypoint,
616
+ imports: imports
617
+ }
618
+ ];
619
+ }
620
+ });
621
+ })();
622
+ },
535
623
  beforeRestart: function beforeRestart() {
536
624
  return _asyncToGenerator(function() {
537
625
  return __generator(this, function(_state) {
@@ -176,17 +176,17 @@ var __generator = this && this.__generator || function(thisArg, body) {
176
176
  };
177
177
  import path from "path";
178
178
  import { fs, slash } from "@modern-js/utils";
179
- import { TEMP_LOADERS_DIR } from "./constants";
179
+ import { APP_CONFIG_NAME, TEMP_LOADERS_DIR } from "./constants";
180
180
  var index = function(param) {
181
181
  var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
182
182
  return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
183
183
  };
184
184
  var renderFunction = function(param) {
185
185
  var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes2 = param.fileSystemRoutes;
186
- return "\n AppWrapper = createApp({\n plugins: [\n ".concat(plugins.map(function(param) {
186
+ return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'object' ? ").concat(APP_CONFIG_NAME, " : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param) {
187
187
  var name = param.name, options = param.options, args = param.args;
188
- return "".concat(name, "({...").concat(options, ", ...App?.config?.").concat(args || name, "}),");
189
- }).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
188
+ return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
189
+ }).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
190
190
  };
191
191
  var html = function(partials) {
192
192
  return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join("\n"), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join("\n"), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\n <div id=\"<%= mountId %>\"><!--<?- html ?>--></div>\n ").concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
@@ -185,7 +185,7 @@ import path from "path";
185
185
  import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
186
186
  import { transform } from "esbuild";
187
187
  import { parse } from "es-module-lexer";
188
- import { FILE_SYSTEM_ROUTES_FILE_NAME, LOADER_EXPORT_NAME, NESTED_ROUTE } from "./constants";
188
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE } from "./constants";
189
189
  var walkDirectory = function(dir) {
190
190
  return fs.readdirSync(dir).reduce(function(previous, filename) {
191
191
  var filePath = path.join(dir, filename);
@@ -235,7 +235,6 @@ var getDefaultImports = function(param) {
235
235
  local: "customBootstrap"
236
236
  }
237
237
  ],
238
- initialize: "const App = false;",
239
238
  value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
240
239
  }
241
240
  ].filter(Boolean);
@@ -261,7 +260,7 @@ var getDefaultImports = function(param) {
261
260
  route.initialize = "const App = false;";
262
261
  }
263
262
  imports.push(route);
264
- } else if (!customBootstrap) {
263
+ } else {
265
264
  imports.push({
266
265
  specifiers: [
267
266
  {
@@ -307,7 +306,9 @@ var parseModule = function() {
307
306
  case 0:
308
307
  source = param.source, filename = param.filename;
309
308
  content = source;
310
- if (!(filename.endsWith(".tsx") || filename.endsWith(".jsx"))) return [
309
+ if (!JS_EXTENSIONS.some(function(ext) {
310
+ return filename.endsWith(ext);
311
+ })) return [
311
312
  3,
312
313
  2
313
314
  ];
@@ -77,6 +77,7 @@ function _unsupportedIterableToArray(o, minLen) {
77
77
  }
78
78
  import path, { dirname, isAbsolute, posix, sep } from "path";
79
79
  import { applyOptionsChain, findExists, findMonorepoRoot, globby, isModernjsMonorepo } from "@modern-js/utils";
80
+ import { getAutoInjectEnv } from "../../utils/env";
80
81
  function initHtmlConfig(config, appContext) {
81
82
  var createBuilderAppIcon = function createBuilderAppIcon(config2, appContext2) {
82
83
  var configDir = config2.source.configDir;
@@ -105,6 +106,11 @@ function initHtmlConfig(config, appContext) {
105
106
  return config.html;
106
107
  }
107
108
  function initSourceConfig(config, appContext) {
109
+ var createBuilderGlobalVars = function createBuilderGlobalVars(config2, appContext2) {
110
+ var _source = config2.source, _globalVars = _source.globalVars, globalVars = _globalVars === void 0 ? {} : _globalVars;
111
+ var publicEnv = getAutoInjectEnv(appContext2);
112
+ return _objectSpread({}, globalVars, publicEnv);
113
+ };
108
114
  var createBuilderInclude = function createBuilderInclude(config2, appContext2) {
109
115
  var include = config2.source.include;
110
116
  var defaultInclude = [
@@ -171,6 +177,7 @@ function initSourceConfig(config, appContext) {
171
177
  };
172
178
  config.source.include = createBuilderInclude(config, appContext);
173
179
  config.source.moduleScopes = createBuilderModuleScope(config);
180
+ config.source.globalVars = createBuilderGlobalVars(config, appContext);
174
181
  }
175
182
  function initToolsConfig(config) {
176
183
  var defaultTsChecker = {
@@ -144,7 +144,7 @@ var server = {
144
144
  compiler: {
145
145
  type: "string"
146
146
  },
147
- disableFrameworkExt: {
147
+ enableFrameworkExt: {
148
148
  type: "boolean"
149
149
  }
150
150
  };
@@ -284,7 +284,7 @@ var server = {
284
284
  compiler: {
285
285
  type: "string"
286
286
  },
287
- disableFrameworkExt: {
287
+ enableFrameworkExt: {
288
288
  type: "boolean"
289
289
  }
290
290
  };
@@ -0,0 +1,13 @@
1
+ function getAutoInjectEnv(appContext) {
2
+ var metaName = appContext.metaName;
3
+ var prefix = "".concat(metaName.split(/[-_]/)[0], "_").toUpperCase();
4
+ var envReg = new RegExp("^".concat(prefix));
5
+ return Object.keys(process.env).reduce(function(prev, key) {
6
+ var value = process.env[key];
7
+ if (envReg.test(key) && typeof value !== "undefined") {
8
+ prev["process.env.".concat(key)] = value;
9
+ }
10
+ return prev;
11
+ }, {});
12
+ }
13
+ export { getAutoInjectEnv };
@@ -24,4 +24,7 @@ export declare const NESTED_ROUTE: {
24
24
  LOADING_FILE: string;
25
25
  ERROR_FILE: string;
26
26
  LOADER_FILE: string;
27
- };
27
+ };
28
+ export declare const APP_CONFIG_NAME = "appConfig";
29
+ export declare const APP_INIT_EXPORTED = "init";
30
+ export declare const APP_INIT_IMPORTED = "appInit";
@@ -1,11 +1,11 @@
1
1
  import { BuilderPlugin } from '@modern-js/builder-shared';
2
2
  import type { BuilderPluginAPI } from '@modern-js/builder-webpack-provider';
3
3
  import type { IAppContext, AppNormalizedConfig } from '../../types';
4
- declare type Parameter<T extends (arg: any) => void> = Parameters<T>[0];
5
- declare type FnParameter<T extends {
4
+ type Parameter<T extends (arg: any) => void> = Parameters<T>[0];
5
+ type FnParameter<T extends {
6
6
  [p: string]: (arg: any) => void;
7
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'>>>;
8
+ export type PluginCompatModernOptions = FnParameter<Partial<Pick<BuilderPluginAPI, 'onAfterBuild' | 'onAfterCreateCompiler' | 'onAfterStartDevServer' | 'onBeforeBuild' | 'onBeforeCreateCompiler' | 'onBeforeStartDevServer' | 'onDevCompileDone' | 'onExit'>>>;
9
9
  /**
10
10
  * Provides default configuration consistent with modern.js v1
11
11
  */
@@ -3,7 +3,7 @@ import { BuilderConfig, BuilderWebpackProvider } from '@modern-js/builder-webpac
3
3
  import type { IAppContext } from '@modern-js/core';
4
4
  import type { AppNormalizedConfig } from '../types';
5
5
  import { PluginCompatModernOptions } from './builderPlugins/compatModern';
6
- export declare type BuilderOptions = {
6
+ export type BuilderOptions = {
7
7
  target?: BuilderTarget | BuilderTarget[];
8
8
  normalizedConfig: AppNormalizedConfig;
9
9
  appContext: IAppContext;
@@ -1,4 +1,4 @@
1
- export declare type ValidateSchema = {
1
+ export type ValidateSchema = {
2
2
  target: string;
3
3
  schema: any;
4
4
  };
@@ -6,4 +6,4 @@ export interface MicroFrontend {
6
6
  export interface DeployUserConfig {
7
7
  microFrontend?: boolean | MicroFrontend;
8
8
  }
9
- export declare type DeployNormalizedConfig = DeployUserConfig;
9
+ export type DeployNormalizedConfig = DeployUserConfig;
@@ -1,6 +1,6 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- declare type BuilderDevConfig = Required<BuilderConfig>['dev'];
3
- export declare type DevProxyOptions = string | Record<string, string>;
2
+ type BuilderDevConfig = Required<BuilderConfig>['dev'];
3
+ export type DevProxyOptions = string | Record<string, string>;
4
4
  export interface DevUserConfig extends Omit<BuilderDevConfig, 'port'> {
5
5
  /**
6
6
  * The configuration of `dev.proxy` is provided by `proxy` plugin.
@@ -9,5 +9,5 @@ export interface DevUserConfig extends Omit<BuilderDevConfig, 'port'> {
9
9
  */
10
10
  proxy?: string | Record<string, string>;
11
11
  }
12
- export declare type DevNormalizedConfig = DevUserConfig;
12
+ export type DevNormalizedConfig = DevUserConfig;
13
13
  export {};
@@ -1,4 +1,4 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- export declare type BuilderExperimentsConfig = Required<BuilderConfig>['experiments'];
3
- export declare type ExperimentsUserConfig = BuilderExperimentsConfig;
4
- export declare type ExperimentsNormalizedConfig = ExperimentsUserConfig;
2
+ export type BuilderExperimentsConfig = Required<BuilderConfig>['experiments'];
3
+ export type ExperimentsUserConfig = BuilderExperimentsConfig;
4
+ export type ExperimentsNormalizedConfig = ExperimentsUserConfig;
@@ -1,4 +1,4 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- export declare type BuilderHtmlConfig = Required<BuilderConfig>['html'];
3
- export declare type HtmlUserConfig = BuilderHtmlConfig;
4
- export declare type HtmlNormalizedConfig = HtmlUserConfig;
2
+ export type BuilderHtmlConfig = Required<BuilderConfig>['html'];
3
+ export type HtmlUserConfig = BuilderHtmlConfig;
4
+ export type HtmlNormalizedConfig = HtmlUserConfig;
@@ -18,8 +18,8 @@ export interface RuntimeUserConfig {
18
18
  export interface RuntimeByEntriesUserConfig {
19
19
  [name: string]: RuntimeUserConfig;
20
20
  }
21
- export declare type RuntimeNormalizedConfig = RuntimeUserConfig;
22
- export declare type RuntimeByEntriesNormalizedConfig = RuntimeByEntriesUserConfig;
21
+ export type RuntimeNormalizedConfig = RuntimeUserConfig;
22
+ export type RuntimeByEntriesNormalizedConfig = RuntimeByEntriesUserConfig;
23
23
  export interface AppToolsUserConfig {
24
24
  source?: SourceUserConfig;
25
25
  output?: OutputUserConfig;
@@ -42,7 +42,7 @@ export interface AppToolsUserConfig {
42
42
 
43
43
  bff?: BffUserConfig;
44
44
  }
45
- export declare type AppToolsNormalizedConfig = {
45
+ export type AppToolsNormalizedConfig = {
46
46
  source: SourceNormalizedConfig;
47
47
  bff: BffNormalizedConfig;
48
48
  dev: DevNormalizedConfig;
@@ -1,22 +1,22 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- export declare type BuilderOutputConfig = Required<BuilderConfig>['output'];
2
+ export type BuilderOutputConfig = Required<BuilderConfig>['output'];
3
3
  export interface OutputUserConfig extends BuilderOutputConfig {
4
4
  ssg?: SSGConfig;
5
5
  disableNodePolyfill?: boolean;
6
6
  }
7
- export declare type OutputNormalizedConfig = OutputUserConfig;
8
- export declare type SSGRouteOptions = string | {
7
+ export type OutputNormalizedConfig = OutputUserConfig;
8
+ export type SSGRouteOptions = string | {
9
9
  url: string;
10
10
  output?: string;
11
11
  params?: Record<string, any>[];
12
12
  headers?: Record<string, any>;
13
13
  };
14
- export declare type SSGSingleEntryOptions = boolean | {
14
+ export type SSGSingleEntryOptions = boolean | {
15
15
  preventDefault?: string[];
16
16
  headers?: Record<string, any>;
17
17
  routes?: SSGRouteOptions[];
18
18
  };
19
- export declare type SSGMultiEntryOptions = Record<string, SSGSingleEntryOptions>;
20
- export declare type SSGConfig = boolean | SSGSingleEntryOptions | SSGMultiEntryOptions | ((entryName: string, payload: {
19
+ export type SSGMultiEntryOptions = Record<string, SSGSingleEntryOptions>;
20
+ export type SSGConfig = boolean | SSGSingleEntryOptions | SSGMultiEntryOptions | ((entryName: string, payload: {
21
21
  baseUrl?: string;
22
22
  }) => SSGSingleEntryOptions);
@@ -1,4 +1,4 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- export declare type BuilderPerformanceConfig = Required<BuilderConfig>['performance'];
3
- export declare type PerformanceUserConfig = BuilderPerformanceConfig;
4
- export declare type PerformanceNormalizedConfig = PerformanceUserConfig;
2
+ export type BuilderPerformanceConfig = Required<BuilderConfig>['performance'];
3
+ export type PerformanceUserConfig = BuilderPerformanceConfig;
4
+ export type PerformanceNormalizedConfig = PerformanceUserConfig;
@@ -1,4 +1,4 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- export declare type BuilderSecurityConfig = Required<BuilderConfig>['security'];
3
- export declare type SecurityUserConfig = BuilderSecurityConfig;
4
- export declare type SecurityNormalizedConfig = SecurityUserConfig;
2
+ export type BuilderSecurityConfig = Required<BuilderConfig>['security'];
3
+ export type SecurityUserConfig = BuilderSecurityConfig;
4
+ export type SecurityNormalizedConfig = SecurityUserConfig;
@@ -1,11 +1,11 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
- export declare type BuilderSourceConfig = Required<BuilderConfig>['source'];
3
- export declare type Entry = string | {
2
+ export type BuilderSourceConfig = Required<BuilderConfig>['source'];
3
+ export type Entry = string | {
4
4
  entry: string;
5
5
  disableMount?: boolean;
6
6
  customBootstrap?: string;
7
7
  };
8
- export declare type Entries = Record<string, Entry>;
8
+ export type Entries = Record<string, Entry>;
9
9
  export interface SourceUserConfig extends BuilderSourceConfig {
10
10
  entries?: Entries;
11
11
  enableAsyncEntry?: boolean;
@@ -21,4 +21,4 @@ export interface SourceUserConfig extends BuilderSourceConfig {
21
21
 
22
22
  designSystem?: Record<string, any>;
23
23
  }
24
- export declare type SourceNormalizedConfig = SourceUserConfig;
24
+ export type SourceNormalizedConfig = SourceUserConfig;
@@ -2,14 +2,14 @@ import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
2
  import type { JestConfig } from '@modern-js/core';
3
3
  import type { PluginSwcOptions } from '@modern-js/builder-plugin-swc';
4
4
  import type { PluginEsbuildOptions } from '@modern-js/builder-plugin-esbuild';
5
- export declare type BuilderToolsConfig = Required<BuilderConfig>['tools'];
5
+ export type BuilderToolsConfig = Required<BuilderConfig>['tools'];
6
6
  /**
7
7
  * The configuration of `tools.tailwindcss` is provided by `tailwindcss` plugin.
8
8
  * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
9
9
  * @requires `tailwindcss` plugin
10
10
  */
11
11
 
12
- export declare type Tailwindcss = Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
12
+ export type Tailwindcss = Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
13
13
  export interface ToolsUserConfig extends BuilderToolsConfig {
14
14
  tailwindcss?: Tailwindcss;
15
15
  jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
@@ -21,4 +21,4 @@ export interface ToolsUserConfig extends BuilderToolsConfig {
21
21
 
22
22
  swc?: PluginSwcOptions;
23
23
  }
24
- export declare type ToolsNormalizedConfig = ToolsUserConfig;
24
+ export type ToolsNormalizedConfig = ToolsUserConfig;
@@ -17,7 +17,7 @@ export interface RuntimePlugin {
17
17
  options: string;
18
18
  args?: string;
19
19
  }
20
- export declare type AppToolsHooks = {
20
+ export type AppToolsHooks = {
21
21
  modifyEntryExport: AsyncWaterfall<{
22
22
  entrypoint: Entrypoint;
23
23
  exportStatement: string;
@@ -7,17 +7,17 @@ export * from './config';
7
7
  export * from './legacyConfig';
8
8
  export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries } from '@modern-js/server-core';
9
9
  export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig } from '@modern-js/core';
10
- export declare type AppTools = {
10
+ export type AppTools = {
11
11
  hooks: AppToolsHooks;
12
12
  userConfig: AppToolsUserConfig;
13
13
  normalizedConfig: AppToolsNormalizedConfig;
14
14
  };
15
- export declare type LegacyAppTools = {
15
+ export type LegacyAppTools = {
16
16
  hooks: AppToolsHooks;
17
17
  userConfig: AppToolsLegacyUserConfig;
18
18
  normalizedConfig: AppToolsLegacyNormalizedConfig;
19
19
  };
20
- export declare type AppNormalizedConfig = NormalizedConfig<AppTools>;
21
- export declare type AppLegacyNormalizedConfig = NormalizedConfig<LegacyAppTools>;
22
- export declare type AppUserConfig = UserConfig<AppTools>;
23
- export declare type AppLegacyUserConfig = UserConfig<LegacyAppTools>;
20
+ export type AppNormalizedConfig = NormalizedConfig<AppTools>;
21
+ export type AppLegacyNormalizedConfig = NormalizedConfig<LegacyAppTools>;
22
+ export type AppUserConfig = UserConfig<AppTools>;
23
+ export type AppLegacyUserConfig = UserConfig<LegacyAppTools>;
@@ -3,6 +3,6 @@ export interface MicroFrontend {
3
3
  externalBasicLibrary?: boolean;
4
4
  moduleApp?: string;
5
5
  }
6
- export declare type DeployLegacyUserConfig = {
6
+ export type DeployLegacyUserConfig = {
7
7
  microFrontend?: boolean | MicroFrontend;
8
8
  };
@@ -1,6 +1,6 @@
1
1
  import type { DevServerHttpsOptions } from '@modern-js/types';
2
- export declare type DevProxyOptions = string | Record<string, string>;
3
- export declare type DevUserLegacyConfig = {
2
+ export type DevProxyOptions = string | Record<string, string>;
3
+ export type DevUserLegacyConfig = {
4
4
  assetPrefix?: string | boolean;
5
5
  https?: DevServerHttpsOptions;
6
6
  /**
@@ -15,7 +15,7 @@ export interface RuntimeLegacyConfig {
15
15
  export interface RuntimeByEntriesLegacyConfig {
16
16
  [name: string]: RuntimeLegacyConfig;
17
17
  }
18
- export declare type AppToolsLegacyUserConfig = {
18
+ export type AppToolsLegacyUserConfig = {
19
19
  source?: SourceLegacyUserConfig;
20
20
  output?: OutputLegacyUserConfig;
21
21
  server?: LegacyServerUserConfig;
@@ -1,7 +1,7 @@
1
1
  import { MetaOptions } from '@modern-js/utils';
2
2
  import { SSGConfig } from '../config';
3
- declare type CrossOrigin = 'anonymous' | 'use-credentials';
4
- export declare type OutputLegacyUserConfig = {
3
+ type CrossOrigin = 'anonymous' | 'use-credentials';
4
+ export type OutputLegacyUserConfig = {
5
5
  assetPrefix?: string;
6
6
  htmlPath?: string;
7
7
  jsPath?: string;
@@ -1,5 +1,5 @@
1
1
  import type { AliasOption } from '@modern-js/utils';
2
- export declare type SourceLegacyUserConfig = {
2
+ export type SourceLegacyUserConfig = {
3
3
  alias?: AliasOption;
4
4
  entries?: Record<string, string | {
5
5
  entry: string;
@@ -1,8 +1,8 @@
1
1
  import type { DevServerOptions } from '@modern-js/types';
2
2
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
3
3
  import type { JestConfig } from '@modern-js/core';
4
- declare type BuilderToolsConfig = Required<BuilderConfig>['tools'];
5
- export declare type ToolsLegacyUserConfig = BuilderToolsConfig & {
4
+ type BuilderToolsConfig = Required<BuilderConfig>['tools'];
5
+ export type ToolsLegacyUserConfig = BuilderToolsConfig & {
6
6
  esbuild?: Record<string, unknown>;
7
7
  devServer?: DevServerOptions;
8
8
  /**
@@ -0,0 +1,2 @@
1
+ import type { IAppContext } from '../types';
2
+ export declare function getAutoInjectEnv(appContext: IAppContext): Record<string, string>;
@@ -1,20 +1,20 @@
1
- export declare type DevOptions = {
1
+ export type DevOptions = {
2
2
  entry?: string[] | boolean;
3
3
  config?: string;
4
4
  apiOnly?: boolean;
5
5
  analyze?: boolean;
6
6
  };
7
- export declare type BuildOptions = {
7
+ export type BuildOptions = {
8
8
  config?: string;
9
9
  analyze?: boolean;
10
10
  };
11
- export declare type DeployOptions = {
11
+ export type DeployOptions = {
12
12
  config?: string;
13
13
  };
14
- export declare type StartOptions = {
14
+ export type StartOptions = {
15
15
  apiOnly?: boolean;
16
16
  };
17
- export declare type InspectOptions = {
17
+ export type InspectOptions = {
18
18
  env: string;
19
19
  output: string;
20
20
  verbose?: boolean;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.7",
14
+ "version": "2.0.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -65,23 +65,23 @@
65
65
  "@babel/types": "^7.18.0",
66
66
  "es-module-lexer": "^1.1.0",
67
67
  "esbuild": "0.15.7",
68
- "@modern-js/builder": "2.0.0-beta.7",
69
- "@modern-js/builder-plugin-esbuild": "2.0.0-beta.7",
70
- "@modern-js/builder-plugin-node-polyfill": "2.0.0-beta.7",
71
- "@modern-js/builder-shared": "2.0.0-beta.7",
72
- "@modern-js/builder-webpack-provider": "2.0.0-beta.7",
73
- "@modern-js/core": "2.0.0-beta.7",
74
- "@modern-js/new-action": "2.0.0-beta.7",
75
- "@modern-js/node-bundle-require": "2.0.0-beta.7",
76
- "@modern-js/plugin": "2.0.0-beta.7",
77
- "@modern-js/plugin-data-loader": "2.0.0-beta.7",
78
- "@modern-js/plugin-i18n": "2.0.0-beta.7",
79
- "@modern-js/plugin-lint": "2.0.0-beta.7",
80
- "@modern-js/prod-server": "2.0.0-beta.7",
81
- "@modern-js/server": "2.0.0-beta.7",
82
- "@modern-js/types": "2.0.0-beta.7",
83
- "@modern-js/upgrade": "2.0.0-beta.7",
84
- "@modern-js/utils": "2.0.0-beta.7"
68
+ "@modern-js/builder": "2.0.0",
69
+ "@modern-js/builder-plugin-node-polyfill": "2.0.0",
70
+ "@modern-js/builder-plugin-esbuild": "2.0.0",
71
+ "@modern-js/builder-shared": "2.0.0",
72
+ "@modern-js/builder-webpack-provider": "2.0.0",
73
+ "@modern-js/core": "2.0.0",
74
+ "@modern-js/new-action": "2.0.0",
75
+ "@modern-js/node-bundle-require": "2.0.0",
76
+ "@modern-js/plugin": "2.0.0",
77
+ "@modern-js/plugin-data-loader": "2.0.0",
78
+ "@modern-js/plugin-i18n": "2.0.0",
79
+ "@modern-js/plugin-lint": "2.0.0",
80
+ "@modern-js/prod-server": "2.0.0",
81
+ "@modern-js/server": "2.0.0",
82
+ "@modern-js/types": "2.0.0",
83
+ "@modern-js/upgrade": "2.0.0",
84
+ "@modern-js/utils": "2.0.0"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@types/babel__traverse": "^7.14.2",
@@ -90,10 +90,10 @@
90
90
  "jest": "^27",
91
91
  "typescript": "^4",
92
92
  "webpack": "^5.75.0",
93
- "@modern-js/builder-plugin-swc": "2.0.0-beta.7",
94
- "@modern-js/server-core": "2.0.0-beta.7",
95
- "@scripts/jest-config": "2.0.0-beta.7",
96
- "@scripts/build": "2.0.0-beta.7"
93
+ "@modern-js/builder-plugin-swc": "2.0.0",
94
+ "@modern-js/server-core": "2.0.0",
95
+ "@scripts/jest-config": "2.0.0",
96
+ "@scripts/build": "2.0.0"
97
97
  },
98
98
  "sideEffects": false,
99
99
  "publishConfig": {