@modern-js/server 2.68.16 → 2.68.18

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.
@@ -71,6 +71,10 @@ async function createDevServer(options, applyPlugins) {
71
71
  nodeServer = await (0, import_node.createNodeServer)(server.handle.bind(server));
72
72
  }
73
73
  const promise = (0, import_helpers.getDevAssetPrefix)(builder);
74
+ let compiler = null;
75
+ builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler((context) => {
76
+ compiler = context.compiler;
77
+ });
74
78
  const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
75
79
  runCompile: options.runCompile,
76
80
  compiler: options.compiler
@@ -79,7 +83,7 @@ async function createDevServer(options, applyPlugins) {
79
83
  (0, import_dev.devPlugin)({
80
84
  ...options,
81
85
  builderDevServer
82
- })
86
+ }, compiler)
83
87
  ]);
84
88
  const assetPrefix = await promise;
85
89
  if (assetPrefix) {
package/dist/cjs/dev.js CHANGED
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(dev_exports);
24
24
  var import_node = require("@modern-js/server-core/node");
25
25
  var import_utils = require("@modern-js/utils");
26
26
  var import_helpers = require("./helpers");
27
- const devPlugin = (options) => ({
27
+ const devPlugin = (options, compiler) => ({
28
28
  name: "@modern-js/plugin-dev",
29
29
  setup(api) {
30
30
  const { config, pwd, builder, builderDevServer } = options;
@@ -105,7 +105,7 @@ const devPlugin = (options) => ({
105
105
  });
106
106
  middlewares.push({
107
107
  name: "init-file-reader",
108
- handler: (0, import_helpers.initFileReader)()
108
+ handler: (0, import_helpers.initFileReader)(compiler)
109
109
  });
110
110
  }
111
111
  };
@@ -22,21 +22,18 @@ __export(fileReader_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(fileReader_exports);
24
24
  var import_fileReader = require("@modern-js/runtime-utils/fileReader");
25
- const initFileReader = () => {
25
+ const initFileReader = (compiler) => {
26
26
  let isInit = false;
27
27
  return async (ctx, next) => {
28
- var _res_locals;
29
28
  if (isInit) {
30
29
  return next();
31
30
  }
32
31
  isInit = true;
33
- const { res } = ctx.env.node;
34
- if (!((_res_locals = res.locals) === null || _res_locals === void 0 ? void 0 : _res_locals.webpack)) {
32
+ if (!compiler) {
35
33
  import_fileReader.fileReader.reset();
36
34
  return next();
37
35
  }
38
- const { devMiddleware: webpackDevMid } = res.locals.webpack;
39
- const { outputFileSystem } = webpackDevMid;
36
+ const { outputFileSystem } = "compilers" in compiler ? compiler.compilers[0] : compiler;
40
37
  if (outputFileSystem) {
41
38
  import_fileReader.fileReader.reset(outputFileSystem);
42
39
  } else {
@@ -14,7 +14,7 @@ function createDevServer(options, applyPlugins) {
14
14
  }
15
15
  function _createDevServer() {
16
16
  _createDevServer = _async_to_generator(function(options, applyPlugins) {
17
- var _config_output_distPath, config, pwd, serverConfigFile, serverConfigPath, builder, metaName, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, isHttp2, nodeServer, genHttpsOptions, httpsOptions, promise, builderDevServer, assetPrefix, afterListen;
17
+ var _config_output_distPath, config, pwd, serverConfigFile, serverConfigPath, builder, metaName, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, isHttp2, nodeServer, genHttpsOptions, httpsOptions, promise, compiler, builderDevServer, assetPrefix, afterListen;
18
18
  return _ts_generator(this, function(_state) {
19
19
  switch (_state.label) {
20
20
  case 0:
@@ -77,6 +77,10 @@ function _createDevServer() {
77
77
  _state.label = 7;
78
78
  case 7:
79
79
  promise = getDevAssetPrefix(builder);
80
+ compiler = null;
81
+ builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler(function(context) {
82
+ compiler = context.compiler;
83
+ });
80
84
  return [
81
85
  4,
82
86
  builder === null || builder === void 0 ? void 0 : builder.createDevServer({
@@ -89,7 +93,7 @@ function _createDevServer() {
89
93
  server.addPlugins([
90
94
  devPlugin(_object_spread_props(_object_spread({}, options), {
91
95
  builderDevServer
92
- }))
96
+ }), compiler)
93
97
  ]);
94
98
  return [
95
99
  4,
package/dist/esm/dev.js CHANGED
@@ -4,7 +4,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import { connectMid2HonoMid } from "@modern-js/server-core/node";
5
5
  import { API_DIR, SHARED_DIR } from "@modern-js/utils";
6
6
  import { getDevOptions, getMockMiddleware, initFileReader, onRepack, startWatcher } from "./helpers";
7
- var devPlugin = function(options) {
7
+ var devPlugin = function(options, compiler) {
8
8
  return {
9
9
  name: "@modern-js/plugin-dev",
10
10
  setup: function setup(api) {
@@ -108,7 +108,7 @@ var devPlugin = function(options) {
108
108
  });
109
109
  middlewares.push({
110
110
  name: "init-file-reader",
111
- handler: initFileReader()
111
+ handler: initFileReader(compiler)
112
112
  });
113
113
  return [
114
114
  2
@@ -1,11 +1,11 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
4
- var initFileReader = function() {
4
+ var initFileReader = function(compiler) {
5
5
  var isInit = false;
6
6
  return function() {
7
7
  var _ref = _async_to_generator(function(ctx, next) {
8
- var _res_locals, res, _res_locals_webpack, webpackDevMid, outputFileSystem;
8
+ var outputFileSystem;
9
9
  return _ts_generator(this, function(_state) {
10
10
  if (isInit) {
11
11
  return [
@@ -14,16 +14,14 @@ var initFileReader = function() {
14
14
  ];
15
15
  }
16
16
  isInit = true;
17
- res = ctx.env.node.res;
18
- if (!((_res_locals = res.locals) === null || _res_locals === void 0 ? void 0 : _res_locals.webpack)) {
17
+ if (!compiler) {
19
18
  fileReader.reset();
20
19
  return [
21
20
  2,
22
21
  next()
23
22
  ];
24
23
  }
25
- _res_locals_webpack = res.locals.webpack, webpackDevMid = _res_locals_webpack.devMiddleware;
26
- outputFileSystem = webpackDevMid.outputFileSystem;
24
+ outputFileSystem = ("compilers" in compiler ? compiler.compilers[0] : compiler).outputFileSystem;
27
25
  if (outputFileSystem) {
28
26
  fileReader.reset(outputFileSystem);
29
27
  } else {
@@ -38,6 +38,10 @@ async function createDevServer(options, applyPlugins) {
38
38
  nodeServer = await createNodeServer(server.handle.bind(server));
39
39
  }
40
40
  const promise = getDevAssetPrefix(builder);
41
+ let compiler = null;
42
+ builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler((context) => {
43
+ compiler = context.compiler;
44
+ });
41
45
  const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
42
46
  runCompile: options.runCompile,
43
47
  compiler: options.compiler
@@ -46,7 +50,7 @@ async function createDevServer(options, applyPlugins) {
46
50
  devPlugin({
47
51
  ...options,
48
52
  builderDevServer
49
- })
53
+ }, compiler)
50
54
  ]);
51
55
  const assetPrefix = await promise;
52
56
  if (assetPrefix) {
@@ -1,7 +1,7 @@
1
1
  import { connectMid2HonoMid } from "@modern-js/server-core/node";
2
2
  import { API_DIR, SHARED_DIR } from "@modern-js/utils";
3
3
  import { getDevOptions, getMockMiddleware, initFileReader, onRepack, startWatcher } from "./helpers";
4
- const devPlugin = (options) => ({
4
+ const devPlugin = (options, compiler) => ({
5
5
  name: "@modern-js/plugin-dev",
6
6
  setup(api) {
7
7
  const { config, pwd, builder, builderDevServer } = options;
@@ -82,7 +82,7 @@ const devPlugin = (options) => ({
82
82
  });
83
83
  middlewares.push({
84
84
  name: "init-file-reader",
85
- handler: initFileReader()
85
+ handler: initFileReader(compiler)
86
86
  });
87
87
  }
88
88
  };
@@ -1,19 +1,16 @@
1
1
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
2
- const initFileReader = () => {
2
+ const initFileReader = (compiler) => {
3
3
  let isInit = false;
4
4
  return async (ctx, next) => {
5
- var _res_locals;
6
5
  if (isInit) {
7
6
  return next();
8
7
  }
9
8
  isInit = true;
10
- const { res } = ctx.env.node;
11
- if (!((_res_locals = res.locals) === null || _res_locals === void 0 ? void 0 : _res_locals.webpack)) {
9
+ if (!compiler) {
12
10
  fileReader.reset();
13
11
  return next();
14
12
  }
15
- const { devMiddleware: webpackDevMid } = res.locals.webpack;
16
- const { outputFileSystem } = webpackDevMid;
13
+ const { outputFileSystem } = "compilers" in compiler ? compiler.compilers[0] : compiler;
17
14
  if (outputFileSystem) {
18
15
  fileReader.reset(outputFileSystem);
19
16
  } else {
@@ -1,9 +1,9 @@
1
1
  import type { ServerBaseOptions, ServerPluginLegacy } from '@modern-js/server-core';
2
- import type { UniBuilderInstance } from '@modern-js/uni-builder';
2
+ import type { Rspack, UniBuilderInstance } from '@modern-js/uni-builder';
3
3
  import type { ModernDevServerOptions } from './types';
4
4
  type BuilderDevServer = Awaited<ReturnType<UniBuilderInstance['createDevServer']>>;
5
5
  export type DevPluginOptions = ModernDevServerOptions<ServerBaseOptions> & {
6
6
  builderDevServer?: BuilderDevServer;
7
7
  };
8
- export declare const devPlugin: (options: DevPluginOptions) => ServerPluginLegacy;
8
+ export declare const devPlugin: (options: DevPluginOptions, compiler: Rspack.Compiler | Rspack.MultiCompiler | null) => ServerPluginLegacy;
9
9
  export {};
@@ -1,2 +1,3 @@
1
1
  import type { Middleware } from '@modern-js/server-core';
2
- export declare const initFileReader: () => Middleware;
2
+ import type { Rspack } from '@modern-js/uni-builder';
3
+ export declare const initFileReader: (compiler: Rspack.Compiler | Rspack.MultiCompiler | null) => Middleware;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.16",
18
+ "version": "2.68.18",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -48,11 +48,11 @@
48
48
  "minimatch": "^3.1.2",
49
49
  "path-to-regexp": "^6.3.0",
50
50
  "ws": "^8.13.0",
51
- "@modern-js/runtime-utils": "2.68.16",
52
- "@modern-js/server-core": "2.68.16",
53
- "@modern-js/server-utils": "2.68.16",
54
- "@modern-js/utils": "2.68.16",
55
- "@modern-js/types": "2.68.16"
51
+ "@modern-js/runtime-utils": "2.68.18",
52
+ "@modern-js/server-core": "2.68.18",
53
+ "@modern-js/server-utils": "2.68.18",
54
+ "@modern-js/types": "2.68.18",
55
+ "@modern-js/utils": "2.68.18"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/connect-history-api-fallback": "^1.3.5",
@@ -65,9 +65,9 @@
65
65
  "ts-node": "^10.9.1",
66
66
  "tsconfig-paths": "4.2.0",
67
67
  "typescript": "^5",
68
- "webpack": "^5.101.3",
68
+ "webpack": "^5.102.1",
69
69
  "websocket": "^1.0.35",
70
- "@modern-js/uni-builder": "2.68.16",
70
+ "@modern-js/uni-builder": "2.68.18",
71
71
  "@scripts/build": "2.66.0",
72
72
  "@scripts/jest-config": "2.66.0"
73
73
  },