@modern-js/app-tools 2.57.1 → 2.57.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cjs/builder/builder-rspack/adapterCopy.js +2 -2
  2. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -2
  4. package/dist/cjs/builder/index.js +2 -2
  5. package/dist/cjs/commands/build.js +19 -0
  6. package/dist/cjs/commands/dev.js +9 -0
  7. package/dist/cjs/commands/index.js +9 -9
  8. package/dist/cjs/esm/esbuild-loader.mjs +20 -0
  9. package/dist/cjs/esm/register-esm.mjs +65 -0
  10. package/dist/cjs/esm/ts-node-loader.mjs +21 -0
  11. package/dist/cjs/esm/utils.mjs +43 -0
  12. package/dist/cjs/index.js +1 -1
  13. package/dist/cjs/plugins/analyze/index.js +7 -4
  14. package/dist/cjs/plugins/deploy/dependencies/index.js +13 -4
  15. package/dist/cjs/plugins/deploy/dependencies/utils.js +14 -2
  16. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +3 -0
  17. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  18. package/dist/cjs/plugins/deploy/platforms/{netlifyEntry.js → netlify-handler.js} +6 -4
  19. package/dist/cjs/plugins/deploy/platforms/netlify.js +14 -5
  20. package/dist/cjs/plugins/deploy/platforms/node.js +13 -4
  21. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +3 -0
  22. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  23. package/dist/cjs/plugins/deploy/platforms/{vercelEntry.js → vercel-handler.js} +27 -1
  24. package/dist/cjs/plugins/deploy/platforms/vercel.js +14 -5
  25. package/dist/cjs/utils/config.js +1 -1
  26. package/dist/cjs/utils/loadPlugins.js +1 -1
  27. package/dist/cjs/utils/register.js +49 -22
  28. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -2
  29. package/dist/esm/builder/generator/index.js +1 -1
  30. package/dist/esm/builder/index.js +2 -2
  31. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
  32. package/dist/esm/commands/build.js +9 -16
  33. package/dist/esm/commands/dev.js +37 -55
  34. package/dist/esm/commands/index.js +6 -6
  35. package/dist/esm/custom-loader.mjs +41 -0
  36. package/dist/esm/index.js +42 -1
  37. package/dist/esm/plugins/analyze/index.js +4 -3
  38. package/dist/esm/plugins/deploy/dependencies/index.js +5 -6
  39. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -8
  40. package/dist/esm/register-esm.mjs +22 -0
  41. package/dist/esm/utils/createServer.js +1 -1
  42. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
  43. package/dist/esm-node/builder/generator/index.js +1 -1
  44. package/dist/esm-node/builder/index.js +2 -2
  45. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
  46. package/dist/esm-node/commands/build.js +0 -3
  47. package/dist/esm-node/commands/dev.js +16 -24
  48. package/dist/esm-node/commands/index.js +6 -6
  49. package/dist/esm-node/esm/esbuild-loader.js +39 -0
  50. package/dist/esm-node/esm/register-esm.js +39 -0
  51. package/dist/esm-node/esm/ts-node-loader.js +42 -0
  52. package/dist/esm-node/index.js +17 -1
  53. package/dist/esm-node/plugins/analyze/index.js +4 -3
  54. package/dist/esm-node/plugins/deploy/dependencies/index.js +4 -5
  55. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -8
  56. package/dist/esm-node/utils/createServer.js +1 -1
  57. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +1 -1
  58. package/dist/types/builder/index.d.ts +1 -1
  59. package/dist/types/esm/esbuild-loader.d.mts +6 -0
  60. package/dist/types/esm/register-esm.d.mts +5 -0
  61. package/dist/types/esm/ts-node-loader.d.mts +6 -0
  62. package/dist/types/esm/utils.d.mts +6 -0
  63. package/dist/types/plugins/deploy/dependencies/index.d.ts +11 -2
  64. package/dist/types/plugins/deploy/dependencies/utils.d.ts +7 -1
  65. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
  66. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +1 -0
  67. package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +1 -0
  68. package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +2 -0
  69. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +2 -0
  70. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +1 -0
  71. package/package.json +10 -10
  72. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +0 -2
  73. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  74. /package/dist/cjs/plugins/deploy/platforms/{nodeEntry.js → node-entry.js} +0 -0
  75. /package/dist/types/plugins/deploy/platforms/{nodeEntry.d.ts → node-entry.d.ts} +0 -0
@@ -37,12 +37,14 @@ var import_routes = require("../../../utils/routes");
37
37
  var import_utils2 = require("../utils");
38
38
  var import_dependencies = require("../dependencies");
39
39
  const createVercelPreset = (appContext, modernConfig, needModernServer) => {
40
- const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
40
+ const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
41
+ const isEsmProject = moduleType === "module";
41
42
  const plugins = serverPlugins.map((plugin) => plugin.name);
42
43
  const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
43
44
  const outputDirectory = import_node_path.default.join(vercelOutput, "output");
44
45
  const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
45
46
  const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
47
+ const handlerFilePath = import_node_path.default.join(funcsDirectory, "vercel-handler.cjs");
46
48
  return {
47
49
  async prepare() {
48
50
  await import_utils.fs.remove(vercelOutput);
@@ -118,7 +120,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
118
120
  prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
119
121
  },
120
122
  output: {
121
- path: "."
123
+ distPath: {
124
+ root: "."
125
+ }
122
126
  }
123
127
  };
124
128
  const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
@@ -130,9 +134,14 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
130
134
  return `plugin_${index}()`;
131
135
  }).join(",")}]`;
132
136
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
133
- let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
134
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
135
- await import_utils.fs.writeFile(entryFilePath, entryCode);
137
+ let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercel-handler.js"))).toString();
138
+ handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
139
+ await import_utils.fs.writeFile(handlerFilePath, handlerCode);
140
+ if (isEsmProject) {
141
+ await import_utils.fs.copy(import_node_path.default.join(__dirname, "./vercel-entry.mjs"), entryFilePath);
142
+ } else {
143
+ await import_utils.fs.copy(import_node_path.default.join(__dirname, "./vercel-entry.js"), entryFilePath);
144
+ }
136
145
  },
137
146
  async end() {
138
147
  if (!needModernServer) {
@@ -40,7 +40,7 @@ var import_utils = require("@modern-js/utils");
40
40
  const defineServerConfig = (config) => config;
41
41
  const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
42
42
  const configFilePath = await (0, import_utils.getServerConfig)(appDirectory, configFile);
43
- const getOutputFile = async (filepath) => path.resolve(distDirectory, `${filepath.replace(new RegExp(import_utils.CONFIG_FILE_EXTENSIONS.join("|")), "")}.js`);
43
+ const getOutputFile = async (filepath) => path.resolve(distDirectory, `${filepath.replace(new RegExp(import_utils.CONFIG_FILE_EXTENSIONS.join("|")), "")}.cjs`);
44
44
  if (configFilePath) {
45
45
  const configHelperFilePath = path.normalize(path.join(distDirectory, "./config-helper.js"));
46
46
  const helperCode = `
@@ -37,7 +37,7 @@ async function getServerPlugins(api, metaName = "modern-js") {
37
37
  }
38
38
  async function loadServerPlugins(api, appDirectory, metaName) {
39
39
  const plugins = await getServerPlugins(api, metaName);
40
- const instances = (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
40
+ const instances = await (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
41
41
  return instances;
42
42
  }
43
43
  // Annotate the CommonJS export names for ESM import in node:
@@ -33,6 +33,14 @@ __export(register_exports, {
33
33
  module.exports = __toCommonJS(register_exports);
34
34
  var import_node_path = __toESM(require("node:path"));
35
35
  var import_utils = require("@modern-js/utils");
36
+ const registerEsbuild = async ({ isTsProject, tsConfig, distDir }) => {
37
+ const esbuildRegister = await import("esbuild-register/dist/node");
38
+ esbuildRegister.register({
39
+ tsconfigRaw: isTsProject ? tsConfig : void 0,
40
+ hookIgnoreNodeModules: true,
41
+ hookMatcher: (fileName) => !fileName.startsWith(distDir)
42
+ });
43
+ };
36
44
  const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
37
45
  const TS_CONFIG_FILENAME = `tsconfig.json`;
38
46
  const tsconfigPath = import_node_path.default.resolve(appDir, TS_CONFIG_FILENAME);
@@ -44,6 +52,17 @@ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
44
52
  const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
45
53
  const tsPaths = Object.keys(paths).reduce((o, key) => {
46
54
  let tsPath = paths[key];
55
+ if (typeof tsPath === "string" && key.startsWith("@") && tsPath.startsWith("@")) {
56
+ try {
57
+ tsPath = require.resolve(tsPath, {
58
+ paths: [
59
+ process.cwd(),
60
+ ...module.paths
61
+ ]
62
+ });
63
+ } catch {
64
+ }
65
+ }
47
66
  if (typeof tsPath === "string" && import_node_path.default.isAbsolute(tsPath)) {
48
67
  tsPath = import_node_path.default.relative(absoluteBaseUrl, tsPath);
49
68
  }
@@ -61,32 +80,40 @@ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
61
80
  if (isTsProject) {
62
81
  tsConfig = (0, import_utils.readTsConfigByFile)(tsconfigPath);
63
82
  }
64
- try {
65
- const tsNode = await Promise.resolve().then(() => __toESM(require("ts-node")));
66
- const tsNodeOptions = tsConfig["ts-node"];
67
- if (isTsProject) {
68
- tsNode.register({
69
- project: tsconfigPath,
70
- scope: true,
71
- // for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
72
- files: true,
73
- transpileOnly: true,
74
- ignore: [
75
- "(?:^|/)node_modules/",
76
- `(?:^|/)${import_node_path.default.relative(appDir, distDir)}/`
77
- ],
78
- ...tsNodeOptions
83
+ const { MODERN_NODE_LOADER } = process.env;
84
+ if (MODERN_NODE_LOADER !== "esbuild") {
85
+ try {
86
+ const tsNode = await import("ts-node");
87
+ const tsNodeOptions = tsConfig["ts-node"];
88
+ if (isTsProject) {
89
+ tsNode.register({
90
+ project: tsconfigPath,
91
+ scope: true,
92
+ // for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
93
+ files: true,
94
+ transpileOnly: true,
95
+ ignore: [
96
+ "(?:^|/)node_modules/",
97
+ `(?:^|/)${import_node_path.default.relative(appDir, distDir)}/`
98
+ ],
99
+ ...tsNodeOptions
100
+ });
101
+ }
102
+ } catch (error) {
103
+ await registerEsbuild({
104
+ isTsProject,
105
+ tsConfig,
106
+ distDir
79
107
  });
80
108
  }
81
- } catch (error) {
82
- const esbuildRegister = await Promise.resolve().then(() => __toESM(require("esbuild-register/dist/node")));
83
- esbuildRegister.register({
84
- tsconfigRaw: isTsProject ? tsConfig : void 0,
85
- hookIgnoreNodeModules: true,
86
- hookMatcher: (fileName) => !fileName.startsWith(distDir)
109
+ } else {
110
+ await registerEsbuild({
111
+ isTsProject,
112
+ tsConfig,
113
+ distDir
87
114
  });
88
115
  }
89
- const tsConfigPaths = await Promise.resolve().then(() => __toESM(require("@modern-js/utils/tsconfig-paths")));
116
+ const tsConfigPaths = (await import("@modern-js/utils/tsconfig-paths")).default;
90
117
  if (await import_utils.fs.pathExists(appDir)) {
91
118
  const loaderRes = tsConfigPaths.loadConfig(appDir);
92
119
  if (loaderRes.resultType === "success") {
@@ -38,8 +38,6 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
38
38
  var v = entries[entry1];
39
39
  serverEntries[entry1] = v.map(function(entry2) {
40
40
  return entry2.replace("index.jsx", "index.server.jsx");
41
- }).map(function(entry2) {
42
- return entry2.replace("bootstrap.jsx", "bootstrap.server.jsx");
43
41
  });
44
42
  }
45
43
  var environments = {
@@ -54,7 +54,7 @@ function _applyBuilderPlugins() {
54
54
  case 0:
55
55
  return [
56
56
  4,
57
- import("../shared/builderPlugins")
57
+ import("../shared/builderPlugins/index.js")
58
58
  ];
59
59
  case 1:
60
60
  _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR, builderPluginAdapterWorker = _ref.builderPluginAdapterWorker;
@@ -16,7 +16,7 @@ function _createBuilderGenerator() {
16
16
  ];
17
17
  return [
18
18
  4,
19
- import("./builder-rspack")
19
+ import("./builder-rspack/index.js")
20
20
  ];
21
21
  case 1:
22
22
  createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
@@ -27,7 +27,7 @@ function _createBuilderGenerator() {
27
27
  case 2:
28
28
  return [
29
29
  4,
30
- import("./builder-webpack")
30
+ import("./builder-webpack/index.js")
31
31
  ];
32
32
  case 3:
33
33
  createWebpackBuilderForModern = _state.sent().createWebpackBuilderForModern;
@@ -27,7 +27,7 @@ function applyNodeCompat(isServiceWorker, chain) {
27
27
  ".node.ts",
28
28
  ".node.tsx",
29
29
  ".server.js",
30
- ".server.jsx",
30
+ ".server.ts",
31
31
  ".server.ts",
32
32
  ".server.tsx"
33
33
  ];
@@ -7,10 +7,9 @@ import { logger } from "@modern-js/utils";
7
7
  import { loadServerPlugins } from "../utils/loadPlugins";
8
8
  import { generateRoutes } from "../utils/routes";
9
9
  import { buildServerConfig } from "../utils/config";
10
- import { registerCompiler } from "../utils/register";
11
10
  var build = function() {
12
11
  var _ref = _async_to_generator(function(api, options) {
13
- var _resolvedConfig_source, resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
+ var resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
14
13
  return _ts_generator(this, function(_state) {
15
14
  switch (_state.label) {
16
15
  case 0:
@@ -25,18 +24,12 @@ var build = function() {
25
24
  loadServerPlugins(api, appContext.appDirectory, appContext.metaName)
26
25
  ];
27
26
  case 1:
28
- _state.sent();
29
- return [
30
- 4,
31
- registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias)
32
- ];
33
- case 2:
34
27
  _state.sent();
35
28
  apiOnly = appContext.apiOnly;
36
29
  if (!apiOnly)
37
30
  return [
38
31
  3,
39
- 7
32
+ 6
40
33
  ];
41
34
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
42
35
  return [
@@ -46,7 +39,7 @@ var build = function() {
46
39
  bundlerConfigs: void 0
47
40
  })
48
41
  ];
49
- case 3:
42
+ case 2:
50
43
  _state.sent();
51
44
  return [
52
45
  4,
@@ -56,13 +49,13 @@ var build = function() {
56
49
  configFile: serverConfigFile
57
50
  })
58
51
  ];
59
- case 4:
52
+ case 3:
60
53
  _state.sent();
61
54
  return [
62
55
  4,
63
56
  generateRoutes(appContext)
64
57
  ];
65
- case 5:
58
+ case 4:
66
59
  _state.sent();
67
60
  return [
68
61
  4,
@@ -71,12 +64,12 @@ var build = function() {
71
64
  stats: void 0
72
65
  })
73
66
  ];
74
- case 6:
67
+ case 5:
75
68
  _state.sent();
76
69
  return [
77
70
  2
78
71
  ];
79
- case 7:
72
+ case 6:
80
73
  resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
81
74
  cliOptions: options
82
75
  });
@@ -90,7 +83,7 @@ var build = function() {
90
83
  configFile: serverConfigFile1
91
84
  })
92
85
  ];
93
- case 8:
86
+ case 7:
94
87
  _state.sent();
95
88
  logger.info("Starting production build...");
96
89
  if (!appContext.builder) {
@@ -100,7 +93,7 @@ var build = function() {
100
93
  4,
101
94
  appContext.builder.build()
102
95
  ];
103
- case 9:
96
+ case 8:
104
97
  _state.sent();
105
98
  return [
106
99
  2
@@ -4,21 +4,22 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "node:path";
6
6
  import { ResolvedConfigContext } from "@modern-js/core";
7
- import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
7
+ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
8
8
  import { createDevServer } from "@modern-js/server";
9
9
  import { applyPlugins } from "@modern-js/prod-server";
10
10
  import { loadServerPlugins } from "../utils/loadPlugins";
11
- import { registerCompiler } from "../utils/register";
12
11
  import { printInstructions } from "../utils/printInstructions";
13
12
  import { setServer } from "../utils/createServer";
14
13
  import { generateRoutes } from "../utils/routes";
15
14
  import { buildServerConfig } from "../utils/config";
16
15
  var dev = function() {
17
- var _ref = _async_to_generator(function(api, options, devServerOptions) {
18
- var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, host, server, _ref2, server1, afterListen;
16
+ var _ref = _async_to_generator(function(api, options) {
17
+ var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, app, host, server;
18
+ var _arguments = arguments;
19
19
  return _ts_generator(this, function(_state) {
20
20
  switch (_state.label) {
21
21
  case 0:
22
+ devServerOptions = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
22
23
  if (options.analyze) {
23
24
  process.env.BUNDLE_ANALYZE = "true";
24
25
  }
@@ -27,9 +28,19 @@ var dev = function() {
27
28
  hookRunners = api.useHookRunners();
28
29
  return [
29
30
  4,
30
- registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias)
31
+ import("../esm/register-esm.mjs")
31
32
  ];
32
33
  case 1:
34
+ registerEsm = _state.sent().registerEsm;
35
+ return [
36
+ 4,
37
+ registerEsm({
38
+ appDir: appContext.appDirectory,
39
+ distDir: appContext.distDirectory,
40
+ alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
41
+ })
42
+ ];
43
+ case 2:
33
44
  _state.sent();
34
45
  normalizedConfig = _object_spread_props(_object_spread({}, normalizedConfig), {
35
46
  cliOptions: options
@@ -45,7 +56,7 @@ var dev = function() {
45
56
  watch: true
46
57
  })
47
58
  ];
48
- case 2:
59
+ case 3:
49
60
  _state.sent();
50
61
  meta = getMeta(metaName);
51
62
  serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
@@ -53,7 +64,7 @@ var dev = function() {
53
64
  4,
54
65
  hookRunners.beforeDev()
55
66
  ];
56
- case 3:
67
+ case 4:
57
68
  _state.sent();
58
69
  if (!appContext.builder && !apiOnly) {
59
70
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -62,13 +73,13 @@ var dev = function() {
62
73
  4,
63
74
  generateRoutes(appContext)
64
75
  ];
65
- case 4:
76
+ case 5:
66
77
  _state.sent();
67
78
  return [
68
79
  4,
69
80
  loadServerPlugins(api, appDirectory, metaName)
70
81
  ];
71
- case 5:
82
+ case 6:
72
83
  pluginInstances = _state.sent();
73
84
  serverOptions = _object_spread({
74
85
  metaName,
@@ -90,21 +101,19 @@ var dev = function() {
90
101
  serverConfigFile,
91
102
  plugins: pluginInstances
92
103
  }, devServerOptions);
93
- host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
94
104
  if (!apiOnly)
95
105
  return [
96
106
  3,
97
- 7
107
+ 8
98
108
  ];
99
109
  return [
100
110
  4,
101
- createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
102
- runCompile: false
103
- }), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
111
+ createDevServer(serverOptions, applyPlugins)
104
112
  ];
105
- case 6:
106
- server = _state.sent().server;
107
- server.listen({
113
+ case 7:
114
+ app = _state.sent();
115
+ host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
116
+ app.listen({
108
117
  port,
109
118
  host
110
119
  }, function() {
@@ -112,55 +121,28 @@ var dev = function() {
112
121
  });
113
122
  return [
114
123
  3,
115
- 9
124
+ 10
116
125
  ];
117
- case 7:
126
+ case 8:
118
127
  return [
119
128
  4,
120
- createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
121
- builder: appContext.builder
122
- }), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
129
+ appContext.builder.startDevServer({
130
+ serverOptions,
131
+ applyPlugins
132
+ })
123
133
  ];
124
- case 8:
125
- _ref2 = _state.sent(), server1 = _ref2.server, afterListen = _ref2.afterListen;
126
- server1.listen({
127
- port,
128
- host
129
- }, function() {
130
- var _ref3 = _async_to_generator(function(err) {
131
- return _ts_generator(this, function(_state2) {
132
- switch (_state2.label) {
133
- case 0:
134
- if (err) {
135
- logger.error("Occur error %s, when start dev server", err);
136
- }
137
- logger.debug("listen dev server done");
138
- return [
139
- 4,
140
- afterListen()
141
- ];
142
- case 1:
143
- _state2.sent();
144
- return [
145
- 2
146
- ];
147
- }
148
- });
149
- });
150
- return function(err) {
151
- return _ref3.apply(this, arguments);
152
- };
153
- }());
154
- setServer(server1);
155
- _state.label = 9;
156
134
  case 9:
135
+ server = _state.sent().server;
136
+ setServer(server);
137
+ _state.label = 10;
138
+ case 10:
157
139
  return [
158
140
  2
159
141
  ];
160
142
  }
161
143
  });
162
144
  });
163
- return function dev2(api, options, devServerOptions) {
145
+ return function dev2(api, options) {
164
146
  return _ref.apply(this, arguments);
165
147
  };
166
148
  }();
@@ -26,7 +26,7 @@ var devCommand = function() {
26
26
  case 0:
27
27
  return [
28
28
  4,
29
- import("./dev")
29
+ import("./dev.js")
30
30
  ];
31
31
  case 1:
32
32
  dev = _state2.sent().dev;
@@ -152,7 +152,7 @@ var buildCommand = function() {
152
152
  case 0:
153
153
  return [
154
154
  4,
155
- import("./build")
155
+ import("./build.js")
156
156
  ];
157
157
  case 1:
158
158
  build = _state2.sent().build;
@@ -265,7 +265,7 @@ var serverCommand = function(program, api) {
265
265
  case 0:
266
266
  return [
267
267
  4,
268
- import("./serve")
268
+ import("./serve.js")
269
269
  ];
270
270
  case 1:
271
271
  start = _state.sent().start;
@@ -296,7 +296,7 @@ var deployCommand = function(program, api) {
296
296
  ];
297
297
  return [
298
298
  4,
299
- import("./build")
299
+ import("./build.js")
300
300
  ];
301
301
  case 1:
302
302
  build = _state.sent().build;
@@ -310,7 +310,7 @@ var deployCommand = function(program, api) {
310
310
  case 3:
311
311
  return [
312
312
  4,
313
- import("./deploy")
313
+ import("./deploy.js")
314
314
  ];
315
315
  case 4:
316
316
  deploy = _state.sent().deploy;
@@ -366,7 +366,7 @@ var inspectCommand = function(program, api) {
366
366
  case 0:
367
367
  return [
368
368
  4,
369
- import("./inspect")
369
+ import("./inspect.js")
370
370
  ];
371
371
  case 1:
372
372
  inspect = _state.sent().inspect;
@@ -0,0 +1,41 @@
1
+ import { pathToFileURL } from 'url';
2
+ import { resolve as tsNodeResolve } from 'ts-node/esm';
3
+ import * as tsConfigPaths from 'tsconfig-paths';
4
+ import fs from 'fs/promises'
5
+ import { getAliasConfig } from '@modern-js/utils';
6
+ import path from 'path'
7
+
8
+
9
+ let matchPath;
10
+ export function initialize({ appDir, alias }){
11
+ const TS_CONFIG_FILENAME = `tsconfig.json`;
12
+ const aliasConfig = getAliasConfig(alias, {
13
+ appDirectory: appDir,
14
+ tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME),
15
+ });
16
+ const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
17
+ const tsPaths = Object.keys(paths).reduce((o, key) => {
18
+ let tsPath = paths[key];
19
+ if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
20
+ tsPath = path.relative(absoluteBaseUrl, tsPath);
21
+ }
22
+ if (typeof tsPath === 'string') {
23
+ tsPath = [tsPath];
24
+ }
25
+ return {
26
+ ...o,
27
+ [`${key}`]: tsPath,
28
+ };
29
+ }, {});
30
+
31
+ matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
32
+ }
33
+
34
+ export function resolve(specifier, context, defaultResolve) {
35
+ const match = matchPath(specifier);
36
+ return match
37
+ ? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
38
+ : tsNodeResolve(specifier, context, defaultResolve);
39
+ }
40
+
41
+ export { transformSource, load } from 'ts-node/esm';
package/dist/esm/index.js CHANGED
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "path";
6
6
  import { lintPlugin } from "@modern-js/plugin-lint";
7
- import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
7
+ import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
8
8
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
9
9
  import initializePlugin from "./plugins/initialize";
10
10
  import analyzePlugin from "./plugins/analyze";
@@ -52,6 +52,7 @@ var appTools = function() {
52
52
  api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
53
53
  toolsType: "app-tools"
54
54
  }));
55
+ var nestedRoutes = {};
55
56
  var locale = getLocaleLanguage();
56
57
  i18n.changeLanguage({
57
58
  locale
@@ -225,6 +226,46 @@ var appTools = function() {
225
226
  ];
226
227
  });
227
228
  })();
229
+ },
230
+ modifyFileSystemRoutes: function modifyFileSystemRoutes(param) {
231
+ var entrypoint = param.entrypoint, routes = param.routes;
232
+ return _async_to_generator(function() {
233
+ return _ts_generator(this, function(_state) {
234
+ nestedRoutes[entrypoint.entryName] = routes;
235
+ return [
236
+ 2,
237
+ {
238
+ entrypoint,
239
+ routes
240
+ }
241
+ ];
242
+ });
243
+ })();
244
+ },
245
+ beforeGenerateRoutes: function beforeGenerateRoutes(param) {
246
+ var entrypoint = param.entrypoint, code = param.code;
247
+ return _async_to_generator(function() {
248
+ var distDirectory;
249
+ return _ts_generator(this, function(_state) {
250
+ switch (_state.label) {
251
+ case 0:
252
+ distDirectory = api.useAppContext().distDirectory;
253
+ return [
254
+ 4,
255
+ fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes)
256
+ ];
257
+ case 1:
258
+ _state.sent();
259
+ return [
260
+ 2,
261
+ {
262
+ entrypoint,
263
+ code
264
+ }
265
+ ];
266
+ }
267
+ });
268
+ })();
228
269
  }
229
270
  };
230
271
  }
@@ -12,6 +12,7 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries";
12
12
  import { initialNormalizedConfig } from "../../config";
13
13
  import { createBuilderGenerator } from "../../builder";
14
14
  import { checkIsBuildCommands } from "./utils";
15
+ import { compatibleRequire } from "@modern-js/utils";
15
16
  var debug = createDebugger("plugin-analyze");
16
17
  function analyze_default(param) {
17
18
  var bundler = param.bundler;
@@ -77,9 +78,9 @@ function analyze_default(param) {
77
78
  return [
78
79
  4,
79
80
  Promise.all([
80
- import("./getBundleEntry"),
81
- import("./getServerRoutes"),
82
- import("./getHtmlTemplate")
81
+ compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
82
+ compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
83
+ compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
83
84
  ])
84
85
  ];
85
86
  case 5: