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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  2. package/dist/cjs/builder/generator/index.js +2 -2
  3. package/dist/cjs/builder/index.js +2 -2
  4. package/dist/cjs/commands/build.js +0 -19
  5. package/dist/cjs/commands/dev.js +0 -9
  6. package/dist/cjs/commands/index.js +8 -8
  7. package/dist/cjs/index.js +1 -1
  8. package/dist/cjs/plugins/analyze/index.js +3 -3
  9. package/dist/cjs/plugins/deploy/dependencies/index.js +0 -1
  10. package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -10
  11. package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -9
  12. package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +0 -26
  13. package/dist/cjs/plugins/deploy/platforms/node.js +2 -9
  14. package/dist/cjs/utils/loadPlugins.js +1 -1
  15. package/dist/cjs/utils/register.js +22 -38
  16. package/dist/esm/builder/generator/getBuilderEnvironments.js +2 -0
  17. package/dist/esm/builder/generator/index.js +1 -1
  18. package/dist/esm/builder/index.js +2 -2
  19. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
  20. package/dist/esm/commands/build.js +16 -9
  21. package/dist/esm/commands/dev.js +55 -37
  22. package/dist/esm/commands/index.js +6 -6
  23. package/dist/esm/index.js +1 -42
  24. package/dist/esm/plugins/analyze/index.js +3 -4
  25. package/dist/esm/plugins/deploy/dependencies/index.js +3 -2
  26. package/dist/esm/plugins/deploy/dependencies/utils.js +4 -1
  27. package/dist/esm/utils/createServer.js +1 -1
  28. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
  29. package/dist/esm-node/builder/generator/index.js +1 -1
  30. package/dist/esm-node/builder/index.js +2 -2
  31. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
  32. package/dist/esm-node/commands/build.js +3 -0
  33. package/dist/esm-node/commands/dev.js +24 -16
  34. package/dist/esm-node/commands/index.js +6 -6
  35. package/dist/esm-node/index.js +1 -17
  36. package/dist/esm-node/plugins/analyze/index.js +3 -4
  37. package/dist/esm-node/plugins/deploy/dependencies/index.js +2 -1
  38. package/dist/esm-node/plugins/deploy/dependencies/utils.js +4 -1
  39. package/dist/esm-node/utils/createServer.js +1 -1
  40. package/dist/types/builder/index.d.ts +1 -1
  41. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -1
  42. package/package.json +9 -9
  43. package/dist/cjs/esm/esbuild-loader.mjs +0 -20
  44. package/dist/cjs/esm/register-esm.mjs +0 -65
  45. package/dist/cjs/esm/ts-node-loader.mjs +0 -21
  46. package/dist/cjs/esm/utils.mjs +0 -28
  47. package/dist/cjs/plugins/deploy/platforms/netlify-entry-cjs.js +0 -1
  48. package/dist/cjs/plugins/deploy/platforms/netlify-entry-mjs.js +0 -10
  49. package/dist/esm/custom-loader.mjs +0 -41
  50. package/dist/esm/register-esm.mjs +0 -22
  51. package/dist/esm-node/esm/esbuild-loader.js +0 -39
  52. package/dist/esm-node/esm/register-esm.js +0 -39
  53. package/dist/esm-node/esm/ts-node-loader.js +0 -42
  54. package/dist/types/esm/esbuild-loader.d.mts +0 -6
  55. package/dist/types/esm/register-esm.d.mts +0 -5
  56. package/dist/types/esm/ts-node-loader.d.mts +0 -6
  57. package/dist/types/esm/utils.d.mts +0 -6
  58. package/dist/types/plugins/deploy/platforms/netlify-entry-cjs.d.ts +0 -0
  59. package/dist/types/plugins/deploy/platforms/netlify-entry-mjs.d.ts +0 -1
@@ -4,22 +4,21 @@ 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 } from "@modern-js/utils";
7
+ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } 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";
11
12
  import { printInstructions } from "../utils/printInstructions";
12
13
  import { setServer } from "../utils/createServer";
13
14
  import { generateRoutes } from "../utils/routes";
14
15
  import { buildServerConfig } from "../utils/config";
15
16
  var dev = function() {
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;
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;
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] : {};
23
22
  if (options.analyze) {
24
23
  process.env.BUNDLE_ANALYZE = "true";
25
24
  }
@@ -28,19 +27,9 @@ var dev = function() {
28
27
  hookRunners = api.useHookRunners();
29
28
  return [
30
29
  4,
31
- import("../esm/register-esm.mjs")
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)
32
31
  ];
33
32
  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:
44
33
  _state.sent();
45
34
  normalizedConfig = _object_spread_props(_object_spread({}, normalizedConfig), {
46
35
  cliOptions: options
@@ -56,7 +45,7 @@ var dev = function() {
56
45
  watch: true
57
46
  })
58
47
  ];
59
- case 3:
48
+ case 2:
60
49
  _state.sent();
61
50
  meta = getMeta(metaName);
62
51
  serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
@@ -64,7 +53,7 @@ var dev = function() {
64
53
  4,
65
54
  hookRunners.beforeDev()
66
55
  ];
67
- case 4:
56
+ case 3:
68
57
  _state.sent();
69
58
  if (!appContext.builder && !apiOnly) {
70
59
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -73,13 +62,13 @@ var dev = function() {
73
62
  4,
74
63
  generateRoutes(appContext)
75
64
  ];
76
- case 5:
65
+ case 4:
77
66
  _state.sent();
78
67
  return [
79
68
  4,
80
69
  loadServerPlugins(api, appDirectory, metaName)
81
70
  ];
82
- case 6:
71
+ case 5:
83
72
  pluginInstances = _state.sent();
84
73
  serverOptions = _object_spread({
85
74
  metaName,
@@ -101,19 +90,21 @@ var dev = function() {
101
90
  serverConfigFile,
102
91
  plugins: pluginInstances
103
92
  }, devServerOptions);
93
+ host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
104
94
  if (!apiOnly)
105
95
  return [
106
96
  3,
107
- 8
97
+ 7
108
98
  ];
109
99
  return [
110
100
  4,
111
- createDevServer(serverOptions, applyPlugins)
101
+ createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
102
+ runCompile: false
103
+ }), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
112
104
  ];
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({
105
+ case 6:
106
+ server = _state.sent().server;
107
+ server.listen({
117
108
  port,
118
109
  host
119
110
  }, function() {
@@ -121,28 +112,55 @@ var dev = function() {
121
112
  });
122
113
  return [
123
114
  3,
124
- 10
115
+ 9
125
116
  ];
126
- case 8:
117
+ case 7:
127
118
  return [
128
119
  4,
129
- appContext.builder.startDevServer({
130
- serverOptions,
131
- applyPlugins
132
- })
120
+ createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
121
+ builder: appContext.builder
122
+ }), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
133
123
  ];
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;
134
156
  case 9:
135
- server = _state.sent().server;
136
- setServer(server);
137
- _state.label = 10;
138
- case 10:
139
157
  return [
140
158
  2
141
159
  ];
142
160
  }
143
161
  });
144
162
  });
145
- return function dev2(api, options) {
163
+ return function dev2(api, options, devServerOptions) {
146
164
  return _ref.apply(this, arguments);
147
165
  };
148
166
  }();
@@ -26,7 +26,7 @@ var devCommand = function() {
26
26
  case 0:
27
27
  return [
28
28
  4,
29
- import("./dev.js")
29
+ import("./dev")
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.js")
155
+ import("./build")
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.js")
268
+ import("./serve")
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.js")
299
+ import("./build")
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.js")
313
+ import("./deploy")
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.js")
369
+ import("./inspect")
370
370
  ];
371
371
  case 1:
372
372
  inspect = _state.sent().inspect;
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, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
7
+ import { cleanRequireCache, emptyDir, getCommand, getArgv } 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,7 +52,6 @@ var appTools = function() {
52
52
  api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
53
53
  toolsType: "app-tools"
54
54
  }));
55
- var nestedRoutes = {};
56
55
  var locale = getLocaleLanguage();
57
56
  i18n.changeLanguage({
58
57
  locale
@@ -226,46 +225,6 @@ var appTools = function() {
226
225
  ];
227
226
  });
228
227
  })();
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
- })();
269
228
  }
270
229
  };
271
230
  }
@@ -12,7 +12,6 @@ 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";
16
15
  var debug = createDebugger("plugin-analyze");
17
16
  function analyze_default(param) {
18
17
  var bundler = param.bundler;
@@ -78,9 +77,9 @@ function analyze_default(param) {
78
77
  return [
79
78
  4,
80
79
  Promise.all([
81
- compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
82
- compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
83
- compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
80
+ import("./getBundleEntry"),
81
+ import("./getServerRoutes"),
82
+ import("./getHtmlTemplate")
84
83
  ])
85
84
  ];
86
85
  case 5:
@@ -10,7 +10,7 @@ import { parseNodeModulePath } from "mlly";
10
10
  import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
11
11
  var handleDependencies = function() {
12
12
  var _ref = _async_to_generator(function(param) {
13
- var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
13
+ var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, dependencySearchRoot, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
14
14
  return _ts_generator(this, function(_state) {
15
15
  switch (_state.label) {
16
16
  case 0:
@@ -29,6 +29,7 @@ var handleDependencies = function() {
29
29
  case 2:
30
30
  fileTrace = _state.sent();
31
31
  currentProjectModules = path.join(appDir, "node_modules");
32
+ dependencySearchRoot = path.resolve(appDir, "../../../../../../");
32
33
  _ = Object.fromEntries;
33
34
  return [
34
35
  4,
@@ -105,7 +106,7 @@ var handleDependencies = function() {
105
106
  _state2.label = 6;
106
107
  case 6:
107
108
  packageJsonPath = _tmp;
108
- if (!packageJsonPath)
109
+ if (!(packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)))
109
110
  return [
110
111
  3,
111
112
  8
@@ -346,7 +346,10 @@ var traceFiles = function() {
346
346
  4,
347
347
  nodeFileTrace(entryFiles, {
348
348
  base,
349
- processCwd: serverRootDir
349
+ processCwd: serverRootDir,
350
+ analysis: {
351
+ evaluatePureExpressions: false
352
+ }
350
353
  })
351
354
  ];
352
355
  case 1:
@@ -38,7 +38,7 @@ var createServer = function() {
38
38
  createDevServer(options, applyPlugins)
39
39
  ];
40
40
  case 1:
41
- server = _state.sent();
41
+ server = _state.sent().server;
42
42
  return [
43
43
  2,
44
44
  server
@@ -19,7 +19,7 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
19
19
  const serverEntries = {};
20
20
  for (const entry in entries) {
21
21
  const v = entries[entry];
22
- serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
22
+ serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx")).map((entry2) => entry2.replace("bootstrap.jsx", "bootstrap.server.jsx"));
23
23
  }
24
24
  const environments = {
25
25
  web: {
@@ -17,7 +17,7 @@ async function generateBuilder(options, bundlerType) {
17
17
  return builder;
18
18
  }
19
19
  async function applyBuilderPlugins(builder, options) {
20
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins/index.js");
20
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
21
21
  builder.addPlugins([
22
22
  builderPluginAdapterBasic(),
23
23
  builderPluginAdapterSSR(options),
@@ -1,9 +1,9 @@
1
1
  async function createBuilderGenerator(bundler) {
2
2
  if (bundler === "rspack") {
3
- const { createRspackBuilderForModern } = await import("./builder-rspack/index.js");
3
+ const { createRspackBuilderForModern } = await import("./builder-rspack");
4
4
  return createRspackBuilderForModern;
5
5
  }
6
- const { createWebpackBuilderForModern } = await import("./builder-webpack/index.js");
6
+ const { createWebpackBuilderForModern } = await import("./builder-webpack");
7
7
  return createWebpackBuilderForModern;
8
8
  }
9
9
  export {
@@ -24,7 +24,7 @@ function applyNodeCompat(isServiceWorker, chain) {
24
24
  ".node.ts",
25
25
  ".node.tsx",
26
26
  ".server.js",
27
- ".server.ts",
27
+ ".server.jsx",
28
28
  ".server.ts",
29
29
  ".server.tsx"
30
30
  ];
@@ -3,7 +3,9 @@ import { logger } from "@modern-js/utils";
3
3
  import { loadServerPlugins } from "../utils/loadPlugins";
4
4
  import { generateRoutes } from "../utils/routes";
5
5
  import { buildServerConfig } from "../utils/config";
6
+ import { registerCompiler } from "../utils/register";
6
7
  const build = async (api, options) => {
8
+ var _resolvedConfig_source;
7
9
  if (options === null || options === void 0 ? void 0 : options.analyze) {
8
10
  process.env.BUNDLE_ANALYZE = "true";
9
11
  }
@@ -11,6 +13,7 @@ const build = async (api, options) => {
11
13
  const appContext = api.useAppContext();
12
14
  const hookRunners = api.useHookRunners();
13
15
  await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
16
+ await 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);
14
17
  const { apiOnly } = appContext;
15
18
  if (apiOnly) {
16
19
  const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
@@ -1,27 +1,23 @@
1
1
  import path from "node:path";
2
2
  import { ResolvedConfigContext } from "@modern-js/core";
3
- import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
3
+ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
4
4
  import { createDevServer } from "@modern-js/server";
5
5
  import { applyPlugins } from "@modern-js/prod-server";
6
6
  import { loadServerPlugins } from "../utils/loadPlugins";
7
+ import { registerCompiler } from "../utils/register";
7
8
  import { printInstructions } from "../utils/printInstructions";
8
9
  import { setServer } from "../utils/createServer";
9
10
  import { generateRoutes } from "../utils/routes";
10
11
  import { buildServerConfig } from "../utils/config";
11
- const dev = async (api, options, devServerOptions = {}) => {
12
- var _normalizedConfig_source, _normalizedConfig_tools;
12
+ const dev = async (api, options, devServerOptions) => {
13
+ var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev;
13
14
  if (options.analyze) {
14
15
  process.env.BUNDLE_ANALYZE = "true";
15
16
  }
16
17
  let normalizedConfig = api.useResolvedConfigContext();
17
18
  const appContext = api.useAppContext();
18
19
  const hookRunners = api.useHookRunners();
19
- const { registerEsm } = await import("../esm/register-esm.mjs");
20
- await registerEsm({
21
- appDir: appContext.appDirectory,
22
- distDir: appContext.distDirectory,
23
- alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
24
- });
20
+ await 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);
25
21
  normalizedConfig = {
26
22
  ...normalizedConfig,
27
23
  cliOptions: options
@@ -64,20 +60,32 @@ const dev = async (api, options, devServerOptions = {}) => {
64
60
  plugins: pluginInstances,
65
61
  ...devServerOptions
66
62
  };
63
+ const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
67
64
  if (apiOnly) {
68
- var _normalizedConfig_dev;
69
- const app = await createDevServer(serverOptions, applyPlugins);
70
- const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
71
- app.listen({
65
+ const { server } = await createDevServer({
66
+ ...serverOptions,
67
+ runCompile: false
68
+ }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
69
+ server.listen({
72
70
  port,
73
71
  host
74
72
  }, () => {
75
73
  printInstructions(hookRunners, appContext, normalizedConfig);
76
74
  });
77
75
  } else {
78
- const { server } = await appContext.builder.startDevServer({
79
- serverOptions,
80
- applyPlugins
76
+ const { server, afterListen } = await createDevServer({
77
+ ...serverOptions,
78
+ builder: appContext.builder
79
+ }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
80
+ server.listen({
81
+ port,
82
+ host
83
+ }, async (err) => {
84
+ if (err) {
85
+ logger.error("Occur error %s, when start dev server", err);
86
+ }
87
+ logger.debug("listen dev server done");
88
+ await afterListen();
81
89
  });
82
90
  setServer(server);
83
91
  }
@@ -5,7 +5,7 @@ const devCommand = async (program, api) => {
5
5
  const runner = api.useHookRunners();
6
6
  const devToolMetas = await runner.registerDev();
7
7
  const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
8
- const { dev } = await import("./dev.js");
8
+ const { dev } = await import("./dev");
9
9
  await dev(api, options);
10
10
  });
11
11
  for (const meta of devToolMetas) {
@@ -28,7 +28,7 @@ const buildCommand = async (program, api) => {
28
28
  const runner = api.useHookRunners();
29
29
  const platformBuilders = await runner.registerBuildPlatform();
30
30
  const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
31
- const { build } = await import("./build.js");
31
+ const { build } = await import("./build");
32
32
  await build(api, options);
33
33
  });
34
34
  for (const platformBuilder of platformBuilders) {
@@ -47,17 +47,17 @@ const buildCommand = async (program, api) => {
47
47
  };
48
48
  const serverCommand = (program, api) => {
49
49
  program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
50
- const { start } = await import("./serve.js");
50
+ const { start } = await import("./serve");
51
51
  await start(api);
52
52
  });
53
53
  };
54
54
  const deployCommand = (program, api) => {
55
55
  program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options) => {
56
56
  if (!options.skipBuild) {
57
- const { build } = await import("./build.js");
57
+ const { build } = await import("./build");
58
58
  await build(api);
59
59
  }
60
- const { deploy } = await import("./deploy.js");
60
+ const { deploy } = await import("./deploy");
61
61
  await deploy(api, options);
62
62
  process.exit(0);
63
63
  });
@@ -72,7 +72,7 @@ const newCommand = (program, locale) => {
72
72
  };
73
73
  const inspectCommand = (program, api) => {
74
74
  program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options) => {
75
- const { inspect } = await import("./inspect.js");
75
+ const { inspect } = await import("./inspect");
76
76
  inspect(api, options);
77
77
  });
78
78
  };
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { lintPlugin } from "@modern-js/plugin-lint";
3
- import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
3
+ import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
4
4
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
5
5
  import initializePlugin from "./plugins/initialize";
6
6
  import analyzePlugin from "./plugins/analyze";
@@ -47,7 +47,6 @@ const appTools = (options = {
47
47
  ...appContext,
48
48
  toolsType: "app-tools"
49
49
  });
50
- const nestedRoutes = {};
51
50
  const locale = getLocaleLanguage();
52
51
  i18n.changeLanguage({
53
52
  locale
@@ -112,21 +111,6 @@ const appTools = (options = {
112
111
  cleanRequireCache([
113
112
  require.resolve("./plugins/analyze")
114
113
  ]);
115
- },
116
- async modifyFileSystemRoutes({ entrypoint, routes }) {
117
- nestedRoutes[entrypoint.entryName] = routes;
118
- return {
119
- entrypoint,
120
- routes
121
- };
122
- },
123
- async beforeGenerateRoutes({ entrypoint, code }) {
124
- const { distDirectory } = api.useAppContext();
125
- await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
126
- return {
127
- entrypoint,
128
- code
129
- };
130
114
  }
131
115
  };
132
116
  }
@@ -7,7 +7,6 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries";
7
7
  import { initialNormalizedConfig } from "../../config";
8
8
  import { createBuilderGenerator } from "../../builder";
9
9
  import { checkIsBuildCommands } from "./utils";
10
- import { compatibleRequire } from "@modern-js/utils";
11
10
  const debug = createDebugger("plugin-analyze");
12
11
  var analyze_default = ({ bundler }) => ({
13
12
  name: "@modern-js/plugin-analyze",
@@ -45,9 +44,9 @@ var analyze_default = ({ bundler }) => ({
45
44
  return;
46
45
  }
47
46
  const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
48
- compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
49
- compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
50
- compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
47
+ import("./getBundleEntry"),
48
+ import("./getServerRoutes"),
49
+ import("./getHtmlTemplate")
51
50
  ]);
52
51
  const { entrypoints } = await hookRunners.modifyEntrypoints({
53
52
  entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
@@ -8,6 +8,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
8
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
9
9
  const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
10
10
  const currentProjectModules = path.join(appDir, "node_modules");
11
+ const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
11
12
  const tracedFiles = Object.fromEntries(await Promise.all([
12
13
  ...fileTrace.reasons.entries()
13
14
  ].map(async ([_path, reasons]) => {
@@ -38,7 +39,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
38
39
  const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
39
40
  cwd: path.dirname(filePath)
40
41
  });
41
- if (packageJsonPath) {
42
+ if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
42
43
  const packageJson = await fse.readJSON(packageJsonPath);
43
44
  pkgPath = baseDir = path.dirname(packageJsonPath);
44
45
  subpath = path.relative(baseDir, filePath);
@@ -101,7 +101,10 @@ const findPackageParents = (pkg, version, tracedFiles) => {
101
101
  const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
102
102
  return await nodeFileTrace(entryFiles, {
103
103
  base,
104
- processCwd: serverRootDir
104
+ processCwd: serverRootDir,
105
+ analysis: {
106
+ evaluatePureExpressions: false
107
+ }
105
108
  });
106
109
  };
107
110
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
@@ -15,7 +15,7 @@ const createServer = async (options) => {
15
15
  if (server) {
16
16
  server.close();
17
17
  }
18
- server = await createDevServer(options, applyPlugins);
18
+ server = (await createDevServer(options, applyPlugins)).server;
19
19
  return server;
20
20
  };
21
21
  export {
@@ -1 +1 @@
1
- export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
1
+ export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack").createRspackBuilderForModern>;