@modern-js/app-tools 2.63.6 → 2.64.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.
@@ -115,6 +115,7 @@ const dev = async (api, options, devServerOptions) => {
115
115
  }, () => {
116
116
  (0, import_printInstructions.printInstructions)(hooks, appContext, normalizedConfig);
117
117
  });
118
+ (0, import_createServer.setServer)(server);
118
119
  } else {
119
120
  const { server, afterListen } = await (0, import_server.createDevServer)({
120
121
  ...serverOptions,
@@ -42,6 +42,7 @@ const start = async (api) => {
42
42
  const userConfig = api.getNormalizedConfig();
43
43
  const hooks = api.getHooks();
44
44
  const { distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
45
+ const { isCrossProjectServer } = (userConfig === null || userConfig === void 0 ? void 0 : userConfig.bff) || {};
45
46
  import_utils.logger.info(`Starting production server...`);
46
47
  const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
47
48
  let runMode;
@@ -71,8 +72,8 @@ const start = async (api) => {
71
72
  appDirectory,
72
73
  internalDirectory,
73
74
  sharedDirectory: (0, import_utils.getTargetDir)(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
74
- apiDirectory: (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
75
- lambdaDirectory: (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
75
+ apiDirectory: isCrossProjectServer ? appContext.apiDirectory : (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
76
+ lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
76
77
  },
77
78
  runMode
78
79
  });
@@ -122,7 +122,7 @@ function getHookRunners(context) {
122
122
  return hooks.onBeforeDev.call();
123
123
  },
124
124
  afterDev: async (params) => {
125
- return hooks.onAfterDev.call(params);
125
+ return hooks.onDevCompileDone.call(params);
126
126
  },
127
127
  beforeDeploy: async (options) => {
128
128
  return hooks.onBeforeDeploy.call(options);
@@ -56,7 +56,7 @@ function transformHookRunner(hookRunnerName) {
56
56
  case "beforeDev":
57
57
  return "onBeforeDev";
58
58
  case "afterDev":
59
- return "onAfterDev";
59
+ return "onDevCompileDone";
60
60
  case "beforeDeploy":
61
61
  return "onBeforeDeploy";
62
62
  case "afterDeploy":
package/dist/cjs/index.js CHANGED
@@ -34,10 +34,12 @@ __export(src_exports, {
34
34
  defineConfig: () => import_defineConfig.defineConfig,
35
35
  defineLegacyConfig: () => import_defineConfig.defineLegacyConfig,
36
36
  dev: () => import_dev.dev,
37
+ generateWatchFiles: () => import_generateWatchFiles2.generateWatchFiles,
37
38
  initAppContext: () => import_initAppContext.initAppContext,
38
39
  mergeConfig: () => import_core.mergeConfig
39
40
  });
40
41
  module.exports = __toCommonJS(src_exports);
42
+ var import_path = __toESM(require("path"));
41
43
  var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
42
44
  var import_plugin_v2 = require("@modern-js/plugin-v2");
43
45
  var import_uni_builder = require("@modern-js/uni-builder");
@@ -57,6 +59,7 @@ __reExport(src_exports, require("./defineConfig"), module.exports);
57
59
  var import_defineConfig = require("./defineConfig");
58
60
  var import_core = require("@modern-js/core");
59
61
  var import_dev = require("./commands/dev");
62
+ var import_generateWatchFiles2 = require("./utils/generateWatchFiles");
60
63
  __reExport(src_exports, require("./types"), module.exports);
61
64
  const appTools = (options = {
62
65
  // default webpack to be compatible with original projects
@@ -168,7 +171,10 @@ const appTools = (options = {
168
171
  });
169
172
  api.onFileChanged(async (e) => {
170
173
  const { filename, eventType, isPrivate } = e;
171
- if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
174
+ const { appDirectory, apiDirectory } = api.getAppContext();
175
+ const relativeApiPath = import_path.default.relative(appDirectory, apiDirectory);
176
+ const isApiProject = filename.startsWith(`${relativeApiPath}/`);
177
+ if (!isPrivate && (eventType === "change" || eventType === "unlink") && !isApiProject) {
172
178
  const { closeServer } = await import("./utils/createServer.js");
173
179
  await closeServer();
174
180
  await (0, import_restart.restart)(api.getHooks(), filename);
@@ -188,6 +194,7 @@ var src_default = appTools;
188
194
  defineConfig,
189
195
  defineLegacyConfig,
190
196
  dev,
197
+ generateWatchFiles,
191
198
  initAppContext,
192
199
  mergeConfig,
193
200
  ...require("./defineConfig"),
@@ -166,9 +166,11 @@ var analyze_default = ({ bundler }) => ({
166
166
  });
167
167
  await (0, import_config2.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
168
168
  });
169
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
170
- hooks.onAfterDev.call({
171
- isFirstCompile
169
+ builder.onDevCompileDone(async ({ isFirstCompile, stats, environments }) => {
170
+ hooks.onDevCompileDone.call({
171
+ isFirstCompile,
172
+ stats,
173
+ environments
172
174
  });
173
175
  if (isFirstCompile) {
174
176
  (0, import_printInstructions.printInstructions)(hooks, appContext, normalizedConfig);
@@ -186,6 +188,11 @@ var analyze_default = ({ bundler }) => ({
186
188
  compiler
187
189
  });
188
190
  });
191
+ builder.onAfterStartDevServer(async ({ port }) => {
192
+ await hooks.onAfterDev.call({
193
+ port
194
+ });
195
+ });
189
196
  builder.addPlugins(resolvedConfig.builderPlugins);
190
197
  api.updateAppContext({
191
198
  builder
@@ -134,6 +134,7 @@ var dev = function() {
134
134
  }, function() {
135
135
  printInstructions(hooks, appContext, normalizedConfig);
136
136
  });
137
+ setServer(server);
137
138
  return [
138
139
  3,
139
140
  12
@@ -9,7 +9,7 @@ import { loadServerPlugins } from "../utils/loadPlugins";
9
9
  import { printInstructions } from "../utils/printInstructions";
10
10
  var start = function() {
11
11
  var _ref = _async_to_generator(function(api) {
12
- var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hooks, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
12
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hooks, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, isCrossProjectServer, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
13
13
  return _ts_generator(this, function(_state) {
14
14
  switch (_state.label) {
15
15
  case 0:
@@ -17,6 +17,7 @@ var start = function() {
17
17
  userConfig = api.getNormalizedConfig();
18
18
  hooks = api.getHooks();
19
19
  distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, internalDirectory = appContext.internalDirectory, port = appContext.port, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes, serverConfigFile = appContext.serverConfigFile;
20
+ isCrossProjectServer = ((userConfig === null || userConfig === void 0 ? void 0 : userConfig.bff) || {}).isCrossProjectServer;
20
21
  logger.info("Starting production server...");
21
22
  return [
22
23
  4,
@@ -55,8 +56,8 @@ var start = function() {
55
56
  appDirectory,
56
57
  internalDirectory,
57
58
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
58
- apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
59
- lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
59
+ apiDirectory: isCrossProjectServer ? appContext.apiDirectory : getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
60
+ lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
60
61
  },
61
62
  runMode
62
63
  })
@@ -348,7 +348,7 @@ function getHookRunners(context) {
348
348
  return _ts_generator(this, function(_state) {
349
349
  return [
350
350
  2,
351
- hooks.onAfterDev.call(params)
351
+ hooks.onDevCompileDone.call(params)
352
352
  ];
353
353
  });
354
354
  });
@@ -31,7 +31,7 @@ function transformHookRunner(hookRunnerName) {
31
31
  case "beforeDev":
32
32
  return "onBeforeDev";
33
33
  case "afterDev":
34
- return "onAfterDev";
34
+ return "onDevCompileDone";
35
35
  case "beforeDeploy":
36
36
  return "onBeforeDeploy";
37
37
  case "afterDeploy":
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import path from "path";
4
5
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
5
6
  import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
6
7
  import { castArray } from "@modern-js/uni-builder";
@@ -194,12 +195,15 @@ var appTools = function() {
194
195
  }));
195
196
  api.onFileChanged(function() {
196
197
  var _ref = _async_to_generator(function(e) {
197
- var filename, eventType, isPrivate, closeServer;
198
+ var filename, eventType, isPrivate, _api_getAppContext, appDirectory, apiDirectory, relativeApiPath, isApiProject, closeServer;
198
199
  return _ts_generator(this, function(_state) {
199
200
  switch (_state.label) {
200
201
  case 0:
201
202
  filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
202
- if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
203
+ _api_getAppContext = api.getAppContext(), appDirectory = _api_getAppContext.appDirectory, apiDirectory = _api_getAppContext.apiDirectory;
204
+ relativeApiPath = path.relative(appDirectory, apiDirectory);
205
+ isApiProject = filename.startsWith("".concat(relativeApiPath, "/"));
206
+ if (!(!isPrivate && (eventType === "change" || eventType === "unlink") && !isApiProject))
203
207
  return [
204
208
  3,
205
209
  4
@@ -245,6 +249,7 @@ var appTools = function() {
245
249
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
246
250
  import { mergeConfig } from "@modern-js/core";
247
251
  import { dev } from "./commands/dev";
252
+ import { generateWatchFiles as generateWatchFiles2 } from "./utils/generateWatchFiles";
248
253
  export * from "./types";
249
254
  var src_default = appTools;
250
255
  export {
@@ -253,6 +258,7 @@ export {
253
258
  defineConfig,
254
259
  defineLegacyConfig,
255
260
  dev,
261
+ generateWatchFiles2 as generateWatchFiles,
256
262
  initAppContext,
257
263
  mergeConfig
258
264
  };
@@ -310,11 +310,13 @@ function analyze_default(param) {
310
310
  }());
311
311
  builder.onDevCompileDone(function() {
312
312
  var _ref5 = _async_to_generator(function(param2) {
313
- var isFirstCompile;
313
+ var isFirstCompile, stats, environments;
314
314
  return _ts_generator(this, function(_state2) {
315
- isFirstCompile = param2.isFirstCompile;
316
- hooks.onAfterDev.call({
317
- isFirstCompile
315
+ isFirstCompile = param2.isFirstCompile, stats = param2.stats, environments = param2.environments;
316
+ hooks.onDevCompileDone.call({
317
+ isFirstCompile,
318
+ stats,
319
+ environments
318
320
  });
319
321
  if (isFirstCompile) {
320
322
  printInstructions(hooks, appContext, normalizedConfig);
@@ -380,6 +382,31 @@ function analyze_default(param) {
380
382
  return _ref5.apply(this, arguments);
381
383
  };
382
384
  }());
385
+ builder.onAfterStartDevServer(function() {
386
+ var _ref5 = _async_to_generator(function(param2) {
387
+ var port;
388
+ return _ts_generator(this, function(_state2) {
389
+ switch (_state2.label) {
390
+ case 0:
391
+ port = param2.port;
392
+ return [
393
+ 4,
394
+ hooks.onAfterDev.call({
395
+ port
396
+ })
397
+ ];
398
+ case 1:
399
+ _state2.sent();
400
+ return [
401
+ 2
402
+ ];
403
+ }
404
+ });
405
+ });
406
+ return function(_2) {
407
+ return _ref5.apply(this, arguments);
408
+ };
409
+ }());
383
410
  builder.addPlugins(resolvedConfig.builderPlugins);
384
411
  api.updateAppContext({
385
412
  builder
@@ -82,6 +82,7 @@ const dev = async (api, options, devServerOptions) => {
82
82
  }, () => {
83
83
  printInstructions(hooks, appContext, normalizedConfig);
84
84
  });
85
+ setServer(server);
85
86
  } else {
86
87
  const { server, afterListen } = await createDevServer({
87
88
  ...serverOptions,
@@ -9,6 +9,7 @@ const start = async (api) => {
9
9
  const userConfig = api.getNormalizedConfig();
10
10
  const hooks = api.getHooks();
11
11
  const { distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
12
+ const { isCrossProjectServer } = (userConfig === null || userConfig === void 0 ? void 0 : userConfig.bff) || {};
12
13
  logger.info(`Starting production server...`);
13
14
  const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
14
15
  let runMode;
@@ -38,8 +39,8 @@ const start = async (api) => {
38
39
  appDirectory,
39
40
  internalDirectory,
40
41
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
41
- apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
42
- lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
42
+ apiDirectory: isCrossProjectServer ? appContext.apiDirectory : getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
43
+ lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
43
44
  },
44
45
  runMode
45
46
  });
@@ -98,7 +98,7 @@ function getHookRunners(context) {
98
98
  return hooks.onBeforeDev.call();
99
99
  },
100
100
  afterDev: async (params) => {
101
- return hooks.onAfterDev.call(params);
101
+ return hooks.onDevCompileDone.call(params);
102
102
  },
103
103
  beforeDeploy: async (options) => {
104
104
  return hooks.onBeforeDeploy.call(options);
@@ -31,7 +31,7 @@ function transformHookRunner(hookRunnerName) {
31
31
  case "beforeDev":
32
32
  return "onBeforeDev";
33
33
  case "afterDev":
34
- return "onAfterDev";
34
+ return "onDevCompileDone";
35
35
  case "beforeDeploy":
36
36
  return "onBeforeDeploy";
37
37
  case "afterDeploy":
@@ -1,3 +1,4 @@
1
+ import path from "path";
1
2
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
2
3
  import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
3
4
  import { castArray } from "@modern-js/uni-builder";
@@ -124,7 +125,10 @@ const appTools = (options = {
124
125
  });
125
126
  api.onFileChanged(async (e) => {
126
127
  const { filename, eventType, isPrivate } = e;
127
- if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
128
+ const { appDirectory, apiDirectory } = api.getAppContext();
129
+ const relativeApiPath = path.relative(appDirectory, apiDirectory);
130
+ const isApiProject = filename.startsWith(`${relativeApiPath}/`);
131
+ if (!isPrivate && (eventType === "change" || eventType === "unlink") && !isApiProject) {
128
132
  const { closeServer } = await import("./utils/createServer.js");
129
133
  await closeServer();
130
134
  await restart(api.getHooks(), filename);
@@ -140,6 +144,7 @@ const appTools = (options = {
140
144
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
141
145
  import { mergeConfig } from "@modern-js/core";
142
146
  import { dev } from "./commands/dev";
147
+ import { generateWatchFiles as generateWatchFiles2 } from "./utils/generateWatchFiles";
143
148
  export * from "./types";
144
149
  var src_default = appTools;
145
150
  export {
@@ -148,6 +153,7 @@ export {
148
153
  defineConfig,
149
154
  defineLegacyConfig,
150
155
  dev,
156
+ generateWatchFiles2 as generateWatchFiles,
151
157
  initAppContext,
152
158
  mergeConfig
153
159
  };
@@ -133,9 +133,11 @@ var analyze_default = ({ bundler }) => ({
133
133
  });
134
134
  await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
135
135
  });
136
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
137
- hooks.onAfterDev.call({
138
- isFirstCompile
136
+ builder.onDevCompileDone(async ({ isFirstCompile, stats, environments }) => {
137
+ hooks.onDevCompileDone.call({
138
+ isFirstCompile,
139
+ stats,
140
+ environments
139
141
  });
140
142
  if (isFirstCompile) {
141
143
  printInstructions(hooks, appContext, normalizedConfig);
@@ -153,6 +155,11 @@ var analyze_default = ({ bundler }) => ({
153
155
  compiler
154
156
  });
155
157
  });
158
+ builder.onAfterStartDevServer(async ({ port }) => {
159
+ await hooks.onAfterDev.call({
160
+ port
161
+ });
162
+ });
156
163
  builder.addPlugins(resolvedConfig.builderPlugins);
157
164
  api.updateAppContext({
158
165
  builder
@@ -7,6 +7,7 @@ export { mergeConfig } from '@modern-js/core';
7
7
  export type { RuntimeUserConfig } from './types/config';
8
8
  export { dev } from './commands/dev';
9
9
  export type { DevOptions } from './utils/types';
10
+ export { generateWatchFiles } from './utils/generateWatchFiles';
10
11
  export * from './types';
11
12
  export { initAppContext };
12
13
  export default appTools;
@@ -152,4 +152,4 @@ export interface AppToolsExtendContext<B extends Bundler = 'webpack'> {
152
152
  toolsType?: string;
153
153
  }
154
154
  export type AppToolsContext<B extends Bundler = 'webpack'> = AppContext<AppTools<B>> & AppToolsExtendContext<B>;
155
- export type AppToolsHooks<B extends Bundler = 'webpack'> = Hooks<AppToolsUserConfig<B>, AppToolsNormalizedConfig> & AppToolsExtendHooks;
155
+ export type AppToolsHooks<B extends Bundler = 'webpack'> = Hooks<AppToolsUserConfig<B>, AppToolsNormalizedConfig, {}> & AppToolsExtendHooks;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.6",
18
+ "version": "2.64.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -92,20 +92,20 @@
92
92
  "pkg-types": "^1.1.0",
93
93
  "ndepe": "0.1.5",
94
94
  "std-env": "^3.7.0",
95
- "@modern-js/core": "2.63.6",
96
- "@modern-js/node-bundle-require": "2.63.6",
97
- "@modern-js/plugin": "2.63.6",
98
- "@modern-js/plugin-data-loader": "2.63.6",
99
- "@modern-js/plugin-i18n": "2.63.6",
100
- "@modern-js/plugin-v2": "2.63.6",
101
- "@modern-js/prod-server": "2.63.6",
102
- "@modern-js/rsbuild-plugin-esbuild": "2.63.6",
103
- "@modern-js/server": "2.63.6",
104
- "@modern-js/server-core": "2.63.6",
105
- "@modern-js/server-utils": "2.63.6",
106
- "@modern-js/types": "2.63.6",
107
- "@modern-js/uni-builder": "2.63.6",
108
- "@modern-js/utils": "2.63.6"
95
+ "@modern-js/core": "2.64.0",
96
+ "@modern-js/node-bundle-require": "2.64.0",
97
+ "@modern-js/plugin-data-loader": "2.64.0",
98
+ "@modern-js/plugin": "2.64.0",
99
+ "@modern-js/plugin-i18n": "2.64.0",
100
+ "@modern-js/plugin-v2": "2.64.0",
101
+ "@modern-js/prod-server": "2.64.0",
102
+ "@modern-js/rsbuild-plugin-esbuild": "2.64.0",
103
+ "@modern-js/server": "2.64.0",
104
+ "@modern-js/server-core": "2.64.0",
105
+ "@modern-js/server-utils": "2.64.0",
106
+ "@modern-js/types": "2.64.0",
107
+ "@modern-js/uni-builder": "2.64.0",
108
+ "@modern-js/utils": "2.64.0"
109
109
  },
110
110
  "devDependencies": {
111
111
  "@rsbuild/plugin-webpack-swc": "1.0.9",
@@ -117,8 +117,8 @@
117
117
  "tsconfig-paths": "^4.2.0",
118
118
  "typescript": "^5",
119
119
  "webpack": "^5.97.1",
120
- "@scripts/build": "2.63.6",
121
- "@scripts/jest-config": "2.63.6"
120
+ "@scripts/jest-config": "2.64.0",
121
+ "@scripts/build": "2.64.0"
122
122
  },
123
123
  "peerDependencies": {
124
124
  "ts-node": "^10.7.0",