@modern-js/app-tools 2.54.6 → 2.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +84 -0
  2. package/dist/cjs/builder/generator/index.js +6 -5
  3. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +7 -14
  4. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +8 -8
  5. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -8
  6. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +5 -3
  7. package/dist/cjs/commands/index.js +2 -2
  8. package/dist/cjs/commands/inspect.js +1 -2
  9. package/dist/cjs/commands/serve.js +1 -0
  10. package/dist/cjs/config/default.js +2 -2
  11. package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
  12. package/dist/cjs/config/legacy/index.js +1 -0
  13. package/dist/cjs/hooks.js +2 -5
  14. package/dist/cjs/plugins/analyze/constants.js +3 -18
  15. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +36 -11
  17. package/dist/cjs/plugins/analyze/index.js +7 -64
  18. package/dist/cjs/plugins/analyze/templates.js +2 -55
  19. package/dist/cjs/plugins/analyze/utils.js +0 -86
  20. package/dist/esm/builder/generator/{createBuilderOptions.js → getBuilderEnvironments.js} +43 -7
  21. package/dist/esm/builder/generator/index.js +9 -9
  22. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +7 -14
  23. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +8 -8
  24. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -8
  25. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +6 -4
  26. package/dist/esm/commands/index.js +1 -1
  27. package/dist/esm/commands/inspect.js +1 -2
  28. package/dist/esm/commands/serve.js +1 -0
  29. package/dist/esm/config/default.js +2 -5
  30. package/dist/esm/config/legacy/createSourceConfig.js +2 -1
  31. package/dist/esm/config/legacy/index.js +1 -0
  32. package/dist/esm/hooks.js +2 -5
  33. package/dist/esm/plugins/analyze/constants.js +2 -12
  34. package/dist/esm/plugins/analyze/getBundleEntry.js +2 -1
  35. package/dist/esm/plugins/analyze/getFileSystemEntry.js +57 -14
  36. package/dist/esm/plugins/analyze/index.js +25 -128
  37. package/dist/esm/plugins/analyze/templates.js +1 -17
  38. package/dist/esm/plugins/analyze/utils.js +1 -87
  39. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  40. package/dist/esm-node/builder/generator/index.js +6 -5
  41. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +7 -14
  42. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +7 -7
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +5 -7
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +5 -3
  45. package/dist/esm-node/commands/index.js +1 -1
  46. package/dist/esm-node/commands/inspect.js +1 -2
  47. package/dist/esm-node/commands/serve.js +1 -0
  48. package/dist/esm-node/config/default.js +2 -2
  49. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
  50. package/dist/esm-node/config/legacy/index.js +1 -0
  51. package/dist/esm-node/hooks.js +2 -5
  52. package/dist/esm-node/plugins/analyze/constants.js +2 -12
  53. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -1
  54. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +37 -12
  55. package/dist/esm-node/plugins/analyze/index.js +10 -67
  56. package/dist/esm-node/plugins/analyze/templates.js +1 -52
  57. package/dist/esm-node/plugins/analyze/utils.js +1 -86
  58. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  59. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +5 -0
  60. package/dist/types/builder/generator/index.d.ts +1 -2
  61. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
  62. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  63. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  64. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +1 -1
  65. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  66. package/dist/types/commands/inspect.d.ts +1 -1
  67. package/dist/types/plugins/analyze/constants.d.ts +1 -6
  68. package/dist/types/plugins/analyze/templates.d.ts +0 -14
  69. package/dist/types/plugins/analyze/utils.d.ts +0 -11
  70. package/dist/types/types/config/index.d.ts +2 -0
  71. package/dist/types/types/config/source.d.ts +11 -0
  72. package/dist/types/types/hooks.d.ts +7 -27
  73. package/dist/types/types/index.d.ts +1 -1
  74. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  75. package/dist/types/types/legacyConfig/source.d.ts +4 -0
  76. package/dist/types/utils/register.d.ts +1 -1
  77. package/package.json +22 -23
  78. package/dist/cjs/builder/generator/createBuilderOptions.js +0 -50
  79. package/dist/cjs/builder/generator/getBuilderTargets.js +0 -42
  80. package/dist/cjs/plugins/analyze/generateCode.js +0 -185
  81. package/dist/esm/builder/generator/getBuilderTargets.js +0 -18
  82. package/dist/esm/plugins/analyze/generateCode.js +0 -296
  83. package/dist/esm-node/builder/generator/createBuilderOptions.js +0 -26
  84. package/dist/esm-node/builder/generator/getBuilderTargets.js +0 -18
  85. package/dist/esm-node/plugins/analyze/generateCode.js +0 -149
  86. package/dist/types/builder/generator/createBuilderOptions.d.ts +0 -4
  87. package/dist/types/builder/generator/getBuilderTargets.d.ts +0 -3
  88. package/dist/types/plugins/analyze/generateCode.d.ts +0 -16
@@ -1,4 +1,4 @@
1
- import { isHtmlDisabled } from "@rsbuild/shared";
1
+ import { isHtmlDisabled } from "@modern-js/uni-builder";
2
2
  import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
3
3
  import { template as lodashTemplate } from "@modern-js/utils/lodash";
4
4
  import { BottomTemplatePlugin } from "../bundlerPlugins";
@@ -6,15 +6,15 @@ const createVirtualModule = (content) => `data:text/javascript,${content}`;
6
6
  const builderPluginAdapterHtml = (options) => ({
7
7
  name: "builder-plugin-adapter-modern-html",
8
8
  setup(api) {
9
- api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
10
- const builderConfig = api.getNormalizedConfig();
9
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin, environment }) => {
10
+ const builderConfig = environment.config;
11
11
  if (!isHtmlDisabled(builderConfig, target)) {
12
12
  applyBottomHtmlPlugin({
13
- api,
14
13
  options,
15
14
  chain,
16
15
  CHAIN_ID,
17
- HtmlBundlerPlugin
16
+ HtmlBundlerPlugin,
17
+ htmlPaths: environment.htmlPaths
18
18
  });
19
19
  await injectAssetPrefix({
20
20
  chain
@@ -32,9 +32,9 @@ async function injectAssetPrefix({ chain }) {
32
32
  entries[entryName].prepend(createVirtualModule(code));
33
33
  });
34
34
  }
35
- function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
35
+ function applyBottomHtmlPlugin({ chain, options, CHAIN_ID, HtmlBundlerPlugin, htmlPaths }) {
36
36
  const { normalizedConfig: modernConfig, appContext } = options;
37
- for (const entryName of Object.keys(api.context.entry)) {
37
+ for (const entryName of Object.keys(htmlPaths)) {
38
38
  const { source: { mainEntryName } } = modernConfig;
39
39
  const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
40
40
  const baseTemplateParams = {
@@ -1,7 +1,7 @@
1
1
  import * as path from "path";
2
- import { isHtmlDisabled } from "@rsbuild/shared";
3
2
  import { mergeRsbuildConfig } from "@rsbuild/core";
4
3
  import { fs, isUseSSRBundle } from "@modern-js/utils";
4
+ import { isHtmlDisabled, SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
5
5
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
6
6
  import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
7
7
  const builderPluginAdapterSSR = (options) => ({
@@ -20,18 +20,16 @@ const builderPluginAdapterSSR = (options) => ({
20
20
  }
21
21
  });
22
22
  });
23
- api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
24
- const builderConfig = api.getNormalizedConfig();
23
+ api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment }) => {
24
+ const builderConfig = environment.config;
25
25
  const { normalizedConfig: normalizedConfig2 } = options;
26
26
  applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
27
27
  if (isUseSSRBundle(normalizedConfig2)) {
28
28
  await applySSRLoaderEntry(chain, options, isServer);
29
29
  applySSRDataLoader(chain, options);
30
30
  }
31
- if ([
32
- "node",
33
- "service-worker"
34
- ].includes(target)) {
31
+ const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
32
+ if (target === "node" || isServiceWorker) {
35
33
  applyFilterEntriesBySSRConfig({
36
34
  isProd,
37
35
  chain,
@@ -1,4 +1,5 @@
1
1
  import { posix } from "path";
2
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
2
3
  const getDistPath = (outputConfig, type) => {
3
4
  const { distPath } = outputConfig;
4
5
  const ret = distPath[type];
@@ -10,10 +11,11 @@ const getDistPath = (outputConfig, type) => {
10
11
  const builderPluginAdapterWorker = () => ({
11
12
  name: "builder-plugin-adapter-worker",
12
13
  setup(api) {
13
- api.modifyBundlerChain(async (chain, { isServiceWorker }) => {
14
- const config = api.getNormalizedConfig();
14
+ api.modifyBundlerChain(async (chain, { environment }) => {
15
+ const { config, name } = environment;
16
+ const isServiceWorker = name === SERVICE_WORKER_ENVIRONMENT_NAME;
15
17
  if (isServiceWorker) {
16
- const workerPath = getDistPath(config.output, "worker");
18
+ const workerPath = getDistPath(config.output, "root");
17
19
  const filename = posix.join(workerPath, `[name].js`);
18
20
  chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
19
21
  }
@@ -1,5 +1,5 @@
1
1
  import { newAction, upgradeAction } from "@modern-js/utils";
2
- import { castArray } from "@rsbuild/shared";
2
+ import { castArray } from "@modern-js/uni-builder";
3
3
  import { i18n, localeKeys } from "../locale";
4
4
  const devCommand = async (program, api) => {
5
5
  const runner = api.useHookRunners();
@@ -1,4 +1,3 @@
1
- import { join } from "path";
2
1
  const inspect = async (api, options) => {
3
2
  const appContext = api.useAppContext();
4
3
  if (!appContext.builder) {
@@ -7,7 +6,7 @@ const inspect = async (api, options) => {
7
6
  return appContext.builder.inspectConfig({
8
7
  env: options.env,
9
8
  verbose: options.verbose,
10
- outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
9
+ outputPath: options.output,
11
10
  writeToDisk: true
12
11
  });
13
12
  };
@@ -24,6 +24,7 @@ const start = async (api) => {
24
24
  config: {
25
25
  ...userConfig,
26
26
  dev: userConfig.dev,
27
+ // server-core can't get RegExp & Function output.enableInlineScripts by JSON.stringy;
27
28
  output: {
28
29
  path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root,
29
30
  ...userConfig.output || {}
@@ -15,8 +15,6 @@ function createDefaultConfig(appContext) {
15
15
  server: "bundles",
16
16
  worker: "worker"
17
17
  },
18
- // no need to emit assets for SSR bundles
19
- emitAssets: ({ target }) => target !== "node",
20
18
  cleanDistPath: true,
21
19
  disableNodePolyfill: true,
22
20
  enableInlineRouteManifests: true,
@@ -26,6 +24,7 @@ function createDefaultConfig(appContext) {
26
24
  entries: void 0,
27
25
  mainEntryName: MAIN_ENTRY_NAME,
28
26
  enableAsyncEntry: false,
27
+ enableCustomEntry: false,
29
28
  disableDefaultEntries: false,
30
29
  entriesDir: "./src",
31
30
  configDir: "./config",
@@ -98,6 +97,7 @@ function createLegacyDefaultConfig(appContext) {
98
97
  entries: void 0,
99
98
  mainEntryName: MAIN_ENTRY_NAME,
100
99
  enableAsyncEntry: false,
100
+ enableCustomEntry: false,
101
101
  disableDefaultEntries: false,
102
102
  entriesDir: "./src",
103
103
  configDir: "./config",
@@ -1,5 +1,5 @@
1
1
  function createSourceConfig(config) {
2
- const { alias, envVars, globalVars, include, moduleScopes, preEntry, entries, mainEntryName, enableAsyncEntry, disableDefaultEntries, entriesDir, configDir } = config.source;
2
+ const { alias, envVars, globalVars, include, moduleScopes, preEntry, entries, mainEntryName, enableAsyncEntry, enableCustomEntry, disableDefaultEntries, entriesDir, configDir } = config.source;
3
3
  const builderGlobalVars = globalVars || {};
4
4
  for (const envVar of envVars || []) {
5
5
  const envVarValue = process.env[envVar];
@@ -14,6 +14,7 @@ function createSourceConfig(config) {
14
14
  entries,
15
15
  mainEntryName,
16
16
  enableAsyncEntry,
17
+ enableCustomEntry,
17
18
  disableDefaultEntries,
18
19
  entriesDir,
19
20
  configDir,
@@ -27,6 +27,7 @@ function transformNormalizedConfig(config) {
27
27
  security: {},
28
28
  _raw: {},
29
29
  experiments: {},
30
+ environments: {},
30
31
  autoLoadPlugins,
31
32
  performance: {
32
33
  removeMomentLocale: true
@@ -1,16 +1,13 @@
1
1
  import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
2
  const hooks = {
3
- modifyEntryExport: createAsyncWaterfall(),
4
- modifyEntryImports: createAsyncWaterfall(),
5
- modifyEntryRuntimePlugins: createAsyncWaterfall(),
6
- modifyEntryRenderFunction: createAsyncWaterfall(),
7
- modifyAsyncEntry: createAsyncWaterfall(),
3
+ _internalRuntimePlugins: createAsyncWaterfall(),
8
4
  modifyFileSystemRoutes: createAsyncWaterfall(),
9
5
  modifyServerRoutes: createAsyncWaterfall(),
10
6
  /** add entry point info to entrypoints array */
11
7
  modifyEntrypoints: createAsyncWaterfall(),
12
8
  /** add entry type */
13
9
  checkEntryPoint: createAsyncWaterfall(),
10
+ generateEntryCode: createAsyncWorkflow(),
14
11
  htmlPartials: createAsyncWaterfall(),
15
12
  beforeGenerateRoutes: createAsyncWaterfall(),
16
13
  addDefineTypes: createAsyncWaterfall(),
@@ -1,23 +1,13 @@
1
1
  const INDEX_FILE_NAME = "index";
2
- const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
3
- const ENTRY_POINT_FILE_NAME = "index.jsx";
4
- const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
2
+ const ENTRY_FILE_NAME = "entry";
5
3
  const HTML_PARTIALS_FOLDER = "html";
6
4
  const HTML_PARTIALS_EXTENSIONS = [
7
5
  ".htm",
8
6
  ".html",
9
7
  ".ejs"
10
8
  ];
11
- const APP_CONFIG_NAME = "config";
12
- const APP_INIT_EXPORTED = "init";
13
- const APP_INIT_IMPORTED = "appInit";
14
9
  export {
15
- APP_CONFIG_NAME,
16
- APP_INIT_EXPORTED,
17
- APP_INIT_IMPORTED,
18
- ENTRY_BOOTSTRAP_FILE_NAME,
19
- ENTRY_POINT_FILE_NAME,
20
- FILE_SYSTEM_ROUTES_FILE_NAME,
10
+ ENTRY_FILE_NAME,
21
11
  HTML_PARTIALS_EXTENSIONS,
22
12
  HTML_PARTIALS_FOLDER,
23
13
  INDEX_FILE_NAME
@@ -38,7 +38,8 @@ const getBundleEntry = async (hookRunners, appContext, config) => {
38
38
  absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, entryName)) ? ensureAbsolutePath(appDirectory, entryName) : path.dirname(ensureAbsolutePath(appDirectory, entryName)),
39
39
  isAutoMount,
40
40
  customBootstrap: typeof value === "string" ? false : value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
41
- fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0
41
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0,
42
+ isCustomSourceEntry: true
42
43
  };
43
44
  if (!ifAlreadyExists(defaults, entrypoint)) {
44
45
  defaults.push(entrypoint);
@@ -1,19 +1,31 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { findExists, ensureAbsolutePath, JS_EXTENSIONS } from "@modern-js/utils";
4
- import { INDEX_FILE_NAME } from "./constants";
4
+ import { ENTRY_FILE_NAME, INDEX_FILE_NAME } from "./constants";
5
5
  import { isDefaultExportFunction } from "./isDefaultExportFunction";
6
6
  const hasIndex = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
7
- const isBundleEntry = async (hookRunners, dir) => {
8
- return (await hookRunners.checkEntryPoint({
7
+ const hasEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}${ext}`)));
8
+ const hasServerEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}.server${ext}`)));
9
+ const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
10
+ const { entry } = await hookRunners.checkEntryPoint({
9
11
  path: dir,
10
12
  entry: false
11
- })).entry || hasIndex(dir);
13
+ });
14
+ if (entry) {
15
+ return entry;
16
+ }
17
+ const customEntry = hasEntry(dir);
18
+ if (enableCustomEntry && customEntry) {
19
+ return customEntry;
20
+ }
21
+ return hasIndex(dir);
12
22
  };
13
- const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
23
+ const scanDir = (hookRunners, dirs, enableCustomEntry) => Promise.all(dirs.map(async (dir) => {
14
24
  const indexFile = hasIndex(dir);
15
25
  const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
16
26
  const entryName = path.basename(dir);
27
+ const customEntryFile = hasEntry(dir);
28
+ const customServerEntry = hasServerEntry(dir);
17
29
  if (indexFile && !customBootstrap) {
18
30
  return {
19
31
  entryName,
@@ -32,17 +44,30 @@ const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
32
44
  return {
33
45
  entryName,
34
46
  isMainEntry: false,
35
- entry: entryFile,
47
+ entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
48
+ customServerEntry,
36
49
  absoluteEntryDir: path.resolve(dir),
37
50
  isAutoMount: true,
38
- customBootstrap
51
+ customBootstrap,
52
+ customEntry: enableCustomEntry ? Boolean(customEntryFile) : false
53
+ };
54
+ }
55
+ if (enableCustomEntry && customEntryFile) {
56
+ return {
57
+ entryName,
58
+ isMainEntry: false,
59
+ entry: customEntryFile,
60
+ customServerEntry,
61
+ absoluteEntryDir: path.resolve(dir),
62
+ isAutoMount: false,
63
+ customEntry: Boolean(customEntryFile)
39
64
  };
40
65
  }
41
66
  throw Error("There is no valid entry point in the current project!");
42
67
  }));
43
68
  const getFileSystemEntry = async (hookRunners, appContext, config) => {
44
69
  const { appDirectory } = appContext;
45
- const { source: { entriesDir, disableEntryDirs } } = config;
70
+ const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
46
71
  let disabledDirs = [];
47
72
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
48
73
  disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
@@ -50,19 +75,19 @@ const getFileSystemEntry = async (hookRunners, appContext, config) => {
50
75
  const src = ensureAbsolutePath(appDirectory, entriesDir || "");
51
76
  if (fs.existsSync(src)) {
52
77
  if (fs.statSync(src).isDirectory()) {
53
- if (await isBundleEntry(hookRunners, src)) {
78
+ if (await isBundleEntry(hookRunners, src, enableCustomEntry)) {
54
79
  return scanDir(hookRunners, [
55
80
  src
56
- ]);
81
+ ], enableCustomEntry);
57
82
  }
58
83
  const dirs = [];
59
84
  await Promise.all(fs.readdirSync(src).map(async (filename) => {
60
85
  const file = path.join(src, filename);
61
- if (fs.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file) && !disabledDirs.includes(file)) {
86
+ if (fs.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file, enableCustomEntry) && !disabledDirs.includes(file)) {
62
87
  dirs.push(file);
63
88
  }
64
89
  }));
65
- return scanDir(hookRunners, dirs);
90
+ return scanDir(hookRunners, dirs, enableCustomEntry);
66
91
  } else {
67
92
  throw Error(`source.entriesDir accept a directory.`);
68
93
  }
@@ -1,17 +1,18 @@
1
1
  import * as path from "path";
2
- import { createDebugger, findExists, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
2
+ import { createDebugger, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
3
3
  import { printInstructions } from "../../utils/printInstructions";
4
- import { generateRoutes, getPathWithoutExt } from "../../utils/routes";
4
+ import { generateRoutes } from "../../utils/routes";
5
5
  import { emitResolvedConfig } from "../../utils/config";
6
6
  import { getSelectedEntries } from "../../utils/getSelectedEntries";
7
7
  import { initialNormalizedConfig } from "../../config";
8
8
  import { createBuilderGenerator } from "../../builder";
9
- import { checkIsBuildCommands, parseModule, replaceWithAlias } from "./utils";
10
- import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
11
- import { generateIndexCode } from "./generateCode";
9
+ import { checkIsBuildCommands } from "./utils";
12
10
  const debug = createDebugger("plugin-analyze");
13
11
  var analyze_default = ({ bundler }) => ({
14
12
  name: "@modern-js/plugin-analyze",
13
+ post: [
14
+ "@modern-js/runtime"
15
+ ],
15
16
  setup: (api) => {
16
17
  let pagesDir = [];
17
18
  let nestedRouteEntries = [];
@@ -42,10 +43,9 @@ var analyze_default = ({ bundler }) => ({
42
43
  api.setAppContext(appContext);
43
44
  return;
44
45
  }
45
- const [{ getBundleEntry }, { getServerRoutes }, { generateCode }, { getHtmlTemplate }] = await Promise.all([
46
+ const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
46
47
  import("./getBundleEntry"),
47
48
  import("./getServerRoutes"),
48
- import("./generateCode"),
49
49
  import("./getHtmlTemplate")
50
50
  ]);
51
51
  const { entrypoints } = await hookRunners.modifyEntrypoints({
@@ -68,7 +68,6 @@ var analyze_default = ({ bundler }) => ({
68
68
  api.setAppContext(appContext);
69
69
  nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
70
70
  pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
71
- const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
72
71
  const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
73
72
  appContext,
74
73
  config: resolvedConfig
@@ -91,6 +90,9 @@ var analyze_default = ({ bundler }) => ({
91
90
  };
92
91
  api.setAppContext(appContext);
93
92
  if (checkIsBuildCommands()) {
93
+ await hookRunners.generateEntryCode({
94
+ entrypoints
95
+ });
94
96
  const normalizedConfig = api.useResolvedConfigContext();
95
97
  const createBuilderForModern = await createBuilderGenerator(bundler);
96
98
  const builder = await createBuilderForModern({
@@ -122,14 +124,6 @@ var analyze_default = ({ bundler }) => ({
122
124
  });
123
125
  builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
124
126
  const hookRunners2 = api.useHookRunners();
125
- await generateIndexCode({
126
- appContext,
127
- config: resolvedConfig,
128
- entrypoints,
129
- api,
130
- importsStatemets,
131
- bundlerConfigs
132
- });
133
127
  await hookRunners2.beforeCreateCompiler({
134
128
  bundlerConfigs
135
129
  });
@@ -160,57 +154,6 @@ var analyze_default = ({ bundler }) => ({
160
154
  return {
161
155
  resolved: config
162
156
  };
163
- },
164
- // This logic is not in the router plugin to avoid having to include some dependencies in the utils package
165
- async modifyEntryImports({ entrypoint, imports }) {
166
- const appContext = api.useAppContext();
167
- const { srcDirectory, internalSrcAlias } = appContext;
168
- const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
169
- if (fileSystemRoutes && nestedRoutesEntry) {
170
- const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
171
- const rootLayoutFile = findExists([
172
- ".js",
173
- ".ts",
174
- ".jsx",
175
- ".tsx"
176
- ].map((ext) => `${rootLayoutPath}${ext}`));
177
- if (rootLayoutFile) {
178
- const rootLayoutBuffer = await fs.readFile(rootLayoutFile);
179
- const rootLayout = rootLayoutBuffer.toString();
180
- const [, moduleExports] = await parseModule({
181
- source: rootLayout.toString(),
182
- filename: rootLayoutFile
183
- });
184
- const hasAppConfig = moduleExports.some((e) => e.n === APP_CONFIG_NAME);
185
- const generateLayoutPath = getPathWithoutExt(replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias));
186
- if (hasAppConfig) {
187
- imports.push({
188
- value: generateLayoutPath,
189
- specifiers: [
190
- {
191
- imported: APP_CONFIG_NAME
192
- }
193
- ]
194
- });
195
- }
196
- const hasAppInit = moduleExports.some((e) => e.n === APP_INIT_EXPORTED);
197
- if (hasAppInit) {
198
- imports.push({
199
- value: generateLayoutPath,
200
- specifiers: [
201
- {
202
- imported: APP_INIT_EXPORTED,
203
- local: APP_INIT_IMPORTED
204
- }
205
- ]
206
- });
207
- }
208
- }
209
- }
210
- return {
211
- entrypoint,
212
- imports
213
- };
214
157
  }
215
158
  };
216
159
  }
@@ -1,52 +1,3 @@
1
- import { APP_CONFIG_NAME } from "./constants";
2
- const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
3
- const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
4
- const IS_REACT18 = process.env.IS_REACT18 === 'true';
5
- const MOUNT_ID = '${mountId}';
6
-
7
- ${imports}
8
-
9
- let AppWrapper = null;
10
-
11
- let root = null;
12
-
13
- function render() {
14
- ${renderFunction2}
15
- }
16
-
17
- AppWrapper = render();
18
-
19
- ${exportStatement};
20
- `;
21
- const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig }) => {
22
- const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
23
- const runtimePlugins = `...(runtimeConfig?.plugins || []),`;
24
- return `
25
- const finalAppConfig = {
26
- ...App.config,
27
- ...typeof ${APP_CONFIG_NAME} === 'function' ? ${APP_CONFIG_NAME}() : {},
28
- }
29
-
30
- AppWrapper = createApp({
31
- plugins: [
32
- ${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
33
- ${customRuntimeConfig ? runtimePlugins : ""}
34
- ]
35
- })(${fileSystemRoutes ? "" : `App`})
36
-
37
-
38
- if(!AppWrapper.init && typeof appInit !== 'undefined') {
39
- AppWrapper.init = appInit;
40
- }
41
-
42
-
43
- if (IS_BROWSER) {
44
- ${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
45
- }
46
-
47
- return AppWrapper
48
- `;
49
- };
50
1
  const html = (partials) => `
51
2
  <!DOCTYPE html>
52
3
  <html>
@@ -69,7 +20,5 @@ const html = (partials) => `
69
20
  </html>
70
21
  `;
71
22
  export {
72
- html,
73
- index,
74
- renderFunction
23
+ html
75
24
  };
@@ -1,9 +1,8 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { isReact18, normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
3
+ import { normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
4
4
  import { transform } from "esbuild";
5
5
  import { parse } from "es-module-lexer";
6
- import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
7
6
  const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
8
7
  const filePath = path.join(dir, filename);
9
8
  if (fs.statSync(filePath).isDirectory()) {
@@ -18,89 +17,6 @@ const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) =
18
17
  ];
19
18
  }
20
19
  }, []);
21
- const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig }) => {
22
- const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
23
- const imports = [
24
- {
25
- specifiers: [
26
- {
27
- local: "React"
28
- }
29
- ],
30
- value: "react"
31
- },
32
- {
33
- specifiers: [
34
- {
35
- local: "ReactDOM"
36
- }
37
- ],
38
- value: isReact18(path.join(appDirectory)) ? "react-dom/client" : "react-dom"
39
- },
40
- {
41
- specifiers: [
42
- {
43
- imported: "createApp"
44
- },
45
- {
46
- imported: "bootstrap"
47
- }
48
- ],
49
- value: "@modern-js/runtime"
50
- },
51
- customBootstrap && {
52
- specifiers: [
53
- {
54
- local: "customBootstrap"
55
- }
56
- ],
57
- value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
58
- }
59
- ].filter(Boolean);
60
- if (fileSystemRoutes) {
61
- const route = {
62
- specifiers: [
63
- {
64
- imported: "routes"
65
- }
66
- ],
67
- value: normalizeToPosixPath(`${internalDirAlias}/${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME.replace(".js", "")}`)
68
- };
69
- if (fileSystemRoutes.globalApp) {
70
- imports.push({
71
- specifiers: [
72
- {
73
- local: "App"
74
- }
75
- ],
76
- value: normalizeToPosixPath(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
77
- });
78
- } else {
79
- route.initialize = "const App = false;";
80
- }
81
- imports.push(route);
82
- } else {
83
- imports.push({
84
- specifiers: [
85
- {
86
- local: "App"
87
- }
88
- ],
89
- value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
90
- });
91
- }
92
- if (customRuntimeConfig) {
93
- imports.push({
94
- specifiers: [
95
- {
96
- local: "runtimeConfig"
97
- }
98
- ],
99
- value: path.join(internalSrcAlias, runtimeConfigFile || "")
100
- });
101
- }
102
- return imports;
103
- };
104
20
  const replaceWithAlias = (base, filePath, alias) => {
105
21
  if (filePath.includes(base)) {
106
22
  return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
@@ -144,7 +60,6 @@ const isSubDirOrEqual = (parent, child) => {
144
60
  };
145
61
  export {
146
62
  checkIsBuildCommands,
147
- getDefaultImports,
148
63
  getServerCombinedModueFile,
149
64
  isSubDirOrEqual,
150
65
  parseModule,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { CopyPluginOptions, RspackChain } from '@modern-js/uni-builder';
2
+ import type { Rspack, RspackChain } from '@rsbuild/core';
3
3
  import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
4
4
  export declare function createPublicPattern(appContext: IAppContext, config: AppNormalizedConfig, chain: RspackChain): {
5
5
  info: (file: {
@@ -13,4 +13,4 @@ export declare function createPublicPattern(appContext: IAppContext, config: App
13
13
  noErrorOnMissing: boolean;
14
14
  transform: (content: Buffer, absoluteFrom: string) => string | Buffer;
15
15
  };
16
- export declare function createUploadPattern<B extends Bundler>(appContext: IAppContext, config: AppNormalizedConfig<B>): CopyPluginOptions['patterns']['0'];
16
+ export declare function createUploadPattern<B extends Bundler>(appContext: IAppContext, config: AppNormalizedConfig<B>): Rspack.CopyRspackPluginOptions['patterns']['0'];
@@ -0,0 +1,5 @@
1
+ import type { IAppContext } from '@modern-js/core';
2
+ import type { AppNormalizedConfig } from '../../types';
3
+ export declare function getBuilderEnvironments(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext): {
4
+ [name: string]: import("@rsbuild/core/dist-types/types").EnvironmentConfig;
5
+ };
@@ -1,5 +1,4 @@
1
- import { UniBuilderInstance } from '@modern-js/uni-builder';
2
- import { BundlerType } from '@rsbuild/shared';
1
+ import { type UniBuilderInstance, type BundlerType } from '@modern-js/uni-builder';
3
2
  import { BuilderOptions } from '../shared';
4
3
  import { Bundler } from '../../types';
5
4
  /**
@@ -1,2 +1,2 @@
1
- import { RsbuildPlugin } from '@rsbuild/shared';
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  export declare const builderPluginAdapterBasic: () => RsbuildPlugin;
@@ -1,4 +1,4 @@
1
- import { RsbuildPlugin } from '@rsbuild/shared';
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  import { Bundler } from '../../../types';
3
3
  import type { BuilderOptions } from '../types';
4
4
  export declare const builderPluginAdapterHtml: <B extends Bundler>(options: BuilderOptions<B>) => RsbuildPlugin;