@modern-js/app-tools 2.56.2 → 2.57.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.
@@ -42,8 +42,8 @@ var import_printInstructions = require("../utils/printInstructions");
42
42
  var import_createServer = require("../utils/createServer");
43
43
  var import_routes = require("../utils/routes");
44
44
  var import_config = require("../utils/config");
45
- const dev = async (api, options, devServerOptions = {}) => {
46
- var _normalizedConfig_source, _normalizedConfig_tools;
45
+ const dev = async (api, options, devServerOptions) => {
46
+ var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev;
47
47
  if (options.analyze) {
48
48
  process.env.BUNDLE_ANALYZE = "true";
49
49
  }
@@ -93,13 +93,12 @@ const dev = async (api, options, devServerOptions = {}) => {
93
93
  plugins: pluginInstances,
94
94
  ...devServerOptions
95
95
  };
96
+ const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
96
97
  if (apiOnly) {
97
- var _normalizedConfig_dev;
98
- const server = await (0, import_server.createDevServer)({
98
+ const { server } = await (0, import_server.createDevServer)({
99
99
  ...serverOptions,
100
100
  runCompile: false
101
- }, import_prod_server.applyPlugins);
102
- const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
101
+ }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || import_prod_server.applyPlugins);
103
102
  server.listen({
104
103
  port,
105
104
  host
@@ -107,10 +106,20 @@ const dev = async (api, options, devServerOptions = {}) => {
107
106
  (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
108
107
  });
109
108
  } else {
110
- const server = await (0, import_server.createDevServer)({
109
+ const { server, afterListen } = await (0, import_server.createDevServer)({
111
110
  ...serverOptions,
112
111
  builder: appContext.builder
113
- }, import_prod_server.applyPlugins);
112
+ }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || import_prod_server.applyPlugins);
113
+ server.listen({
114
+ port,
115
+ host
116
+ }, async (err) => {
117
+ if (err) {
118
+ import_utils.logger.error("Occur error %s, when start dev server", err);
119
+ }
120
+ import_utils.logger.debug("listen dev server done");
121
+ await afterListen();
122
+ });
114
123
  (0, import_createServer.setServer)(server);
115
124
  }
116
125
  };
package/dist/cjs/index.js CHANGED
@@ -84,7 +84,6 @@ const appTools = (options = {
84
84
  ...appContext,
85
85
  toolsType: "app-tools"
86
86
  });
87
- const nestedRoutes = {};
88
87
  const locale = (0, import_language_detector.getLocaleLanguage)();
89
88
  import_locale.i18n.changeLanguage({
90
89
  locale
@@ -149,21 +148,6 @@ const appTools = (options = {
149
148
  (0, import_utils.cleanRequireCache)([
150
149
  require.resolve("./plugins/analyze")
151
150
  ]);
152
- },
153
- async modifyFileSystemRoutes({ entrypoint, routes }) {
154
- nestedRoutes[entrypoint.entryName] = routes;
155
- return {
156
- entrypoint,
157
- routes
158
- };
159
- },
160
- async beforeGenerateRoutes({ entrypoint, code }) {
161
- const { distDirectory } = api.useAppContext();
162
- await import_utils.fs.outputJSON(import_path.default.resolve(distDirectory, import_utils.NESTED_ROUTE_SPEC_FILE), nestedRoutes);
163
- return {
164
- entrypoint,
165
- code
166
- };
167
151
  }
168
152
  };
169
153
  }
@@ -41,7 +41,7 @@ const createServer = async (options) => {
41
41
  if (server) {
42
42
  server.close();
43
43
  }
44
- server = await (0, import_server.createDevServer)(options, import_prod_server.applyPlugins);
44
+ server = (await (0, import_server.createDevServer)(options, import_prod_server.applyPlugins)).server;
45
45
  return server;
46
46
  };
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -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 "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";
@@ -14,13 +14,11 @@ import { setServer } from "../utils/createServer";
14
14
  import { generateRoutes } from "../utils/routes";
15
15
  import { buildServerConfig } from "../utils/config";
16
16
  var dev = function() {
17
- var _ref = _async_to_generator(function(api, options) {
18
- var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, server, host, server1;
19
- 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;
20
19
  return _ts_generator(this, function(_state) {
21
20
  switch (_state.label) {
22
21
  case 0:
23
- devServerOptions = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
24
22
  if (options.analyze) {
25
23
  process.env.BUNDLE_ANALYZE = "true";
26
24
  }
@@ -92,6 +90,7 @@ var dev = function() {
92
90
  serverConfigFile,
93
91
  plugins: pluginInstances
94
92
  }, devServerOptions);
93
+ host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
95
94
  if (!apiOnly)
96
95
  return [
97
96
  3,
@@ -101,11 +100,10 @@ var dev = function() {
101
100
  4,
102
101
  createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
103
102
  runCompile: false
104
- }), applyPlugins)
103
+ }), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
105
104
  ];
106
105
  case 6:
107
- server = _state.sent();
108
- host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
106
+ server = _state.sent().server;
109
107
  server.listen({
110
108
  port,
111
109
  host
@@ -121,10 +119,38 @@ var dev = function() {
121
119
  4,
122
120
  createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
123
121
  builder: appContext.builder
124
- }), applyPlugins)
122
+ }), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
125
123
  ];
126
124
  case 8:
127
- server1 = _state.sent();
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
+ }());
128
154
  setServer(server1);
129
155
  _state.label = 9;
130
156
  case 9:
@@ -134,7 +160,7 @@ var dev = function() {
134
160
  }
135
161
  });
136
162
  });
137
- return function dev2(api, options) {
163
+ return function dev2(api, options, devServerOptions) {
138
164
  return _ref.apply(this, arguments);
139
165
  };
140
166
  }();
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
  }
@@ -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
@@ -1,6 +1,6 @@
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";
@@ -9,8 +9,8 @@ import { printInstructions } from "../utils/printInstructions";
9
9
  import { setServer } from "../utils/createServer";
10
10
  import { generateRoutes } from "../utils/routes";
11
11
  import { buildServerConfig } from "../utils/config";
12
- const dev = async (api, options, devServerOptions = {}) => {
13
- var _normalizedConfig_source, _normalizedConfig_tools;
12
+ const dev = async (api, options, devServerOptions) => {
13
+ var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev;
14
14
  if (options.analyze) {
15
15
  process.env.BUNDLE_ANALYZE = "true";
16
16
  }
@@ -60,13 +60,12 @@ const dev = async (api, options, devServerOptions = {}) => {
60
60
  plugins: pluginInstances,
61
61
  ...devServerOptions
62
62
  };
63
+ const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
63
64
  if (apiOnly) {
64
- var _normalizedConfig_dev;
65
- const server = await createDevServer({
65
+ const { server } = await createDevServer({
66
66
  ...serverOptions,
67
67
  runCompile: false
68
- }, applyPlugins);
69
- const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
68
+ }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
70
69
  server.listen({
71
70
  port,
72
71
  host
@@ -74,10 +73,20 @@ const dev = async (api, options, devServerOptions = {}) => {
74
73
  printInstructions(hookRunners, appContext, normalizedConfig);
75
74
  });
76
75
  } else {
77
- const server = await createDevServer({
76
+ const { server, afterListen } = await createDevServer({
78
77
  ...serverOptions,
79
78
  builder: appContext.builder
80
- }, applyPlugins);
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();
89
+ });
81
90
  setServer(server);
82
91
  }
83
92
  };
@@ -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
  }
@@ -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,7 +1,8 @@
1
1
  import { PluginAPI } from '@modern-js/core';
2
+ import { ApplyPlugins } from '@modern-js/server';
2
3
  import { DevOptions } from '../utils/types';
3
4
  import type { AppTools } from '../types';
4
5
  export interface ExtraServerOptions {
5
- useSSRWorker?: boolean;
6
+ applyPlugins?: ApplyPlugins;
6
7
  }
7
8
  export declare const dev: (api: PluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import { CliPlugin } from '@modern-js/core';
2
2
  import { AppTools } from './types';
3
3
  export { dev } from './commands/dev';
4
+ export type { DevOptions } from './utils/types';
4
5
  export { mergeConfig } from '@modern-js/core';
5
6
  export * from './defineConfig';
6
7
  export * from './types';
@@ -1,5 +1,5 @@
1
1
  import type { ServerUserConfig, BffUserConfig } from '@modern-js/server-core';
2
- import type { UniBuilderPlugin } from '@modern-js/uni-builder';
2
+ import type { UniBuilderPlugin, LooseRsbuildPlugin } from '@modern-js/uni-builder';
3
3
  import type { RsbuildConfig } from '@rsbuild/core';
4
4
  import type { Bundler } from '../utils';
5
5
  import type { OutputUserConfig } from './output';
@@ -38,7 +38,7 @@ export interface AppToolsUserConfig<B extends Bundler> {
38
38
  tools?: ToolsUserConfig<B>;
39
39
  security?: SecurityUserConfig;
40
40
  testing?: TestingUserConfig;
41
- builderPlugins?: UniBuilderPlugin[];
41
+ builderPlugins?: Array<LooseRsbuildPlugin | UniBuilderPlugin>;
42
42
  performance?: PerformanceUserConfig;
43
43
  devtools?: any;
44
44
  environments?: RsbuildConfig['environments'];
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.56.2",
18
+ "version": "2.57.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -87,20 +87,20 @@
87
87
  "mlly": "^1.6.1",
88
88
  "pkg-types": "^1.1.0",
89
89
  "std-env": "^3.7.0",
90
- "@modern-js/core": "2.56.2",
91
- "@modern-js/node-bundle-require": "2.56.2",
92
- "@modern-js/plugin": "2.56.2",
93
- "@modern-js/plugin-data-loader": "2.56.2",
94
- "@modern-js/plugin-i18n": "2.56.2",
95
- "@modern-js/plugin-lint": "2.56.2",
96
- "@modern-js/prod-server": "2.56.2",
97
- "@modern-js/rsbuild-plugin-esbuild": "2.56.2",
98
- "@modern-js/server": "2.56.2",
99
- "@modern-js/server-core": "2.56.2",
100
- "@modern-js/server-utils": "2.56.2",
101
- "@modern-js/types": "2.56.2",
102
- "@modern-js/utils": "2.56.2",
103
- "@modern-js/uni-builder": "2.56.2"
90
+ "@modern-js/core": "2.57.0",
91
+ "@modern-js/node-bundle-require": "2.57.0",
92
+ "@modern-js/plugin": "2.57.0",
93
+ "@modern-js/plugin-data-loader": "2.57.0",
94
+ "@modern-js/plugin-i18n": "2.57.0",
95
+ "@modern-js/plugin-lint": "2.57.0",
96
+ "@modern-js/prod-server": "2.57.0",
97
+ "@modern-js/rsbuild-plugin-esbuild": "2.57.0",
98
+ "@modern-js/server-utils": "2.57.0",
99
+ "@modern-js/server": "2.57.0",
100
+ "@modern-js/server-core": "2.57.0",
101
+ "@modern-js/types": "2.57.0",
102
+ "@modern-js/uni-builder": "2.57.0",
103
+ "@modern-js/utils": "2.57.0"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@rsbuild/plugin-swc": "1.0.1-beta.3",
@@ -112,8 +112,8 @@
112
112
  "tsconfig-paths": "^4.2.0",
113
113
  "typescript": "^5",
114
114
  "webpack": "^5.93.0",
115
- "@scripts/build": "2.56.2",
116
- "@scripts/jest-config": "2.56.2"
115
+ "@scripts/jest-config": "2.57.0",
116
+ "@scripts/build": "2.57.0"
117
117
  },
118
118
  "sideEffects": false,
119
119
  "publishConfig": {