@bleedingdev/modern-js-server 3.5.0-ultramodern.97 → 3.5.0-ultramodern.99

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.
package/dist/esm/dev.mjs CHANGED
@@ -1,40 +1,14 @@
1
1
  import { connectMid2HonoMid } from "@modern-js/server-core/node";
2
- import { API_DIR, SHARED_DIR } from "@modern-js/utils";
3
- import { getDevOptions, getMockMiddleware, initFileReader, onRepack, startWatcher } from "./helpers/index.mjs";
4
- const devPlugin = (options, compiler)=>({
2
+ import { API_DIR, SHARED_DIR, logger } from "@modern-js/utils";
3
+ import { getDevOptions, getMockMiddleware, initFileReader, isPathInsideDirectory, onRepack, resolveMockDirectory, startWatcher } from "./helpers/index.mjs";
4
+ const devRuntimeMiddlewarePlugin = (options, compiler)=>({
5
5
  name: '@modern-js/plugin-dev',
6
6
  setup (api) {
7
- const { config, pwd, builder, builderDevServer } = options;
8
- const closeCb = [];
7
+ const { pwd, builderDevServer } = options;
9
8
  const dev = getDevOptions(options.dev);
10
9
  api.onPrepare(async ()=>{
11
- const { middlewares: builderMiddlewares, close, connectWebSocket } = builderDevServer || {};
12
- close && closeCb.push(close);
13
- const { middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase } = api.getServerContext();
14
- connectWebSocket && nodeServer && connectWebSocket({
15
- server: nodeServer
16
- });
17
- const hooks = api.getHooks();
18
- builder?.onDevCompileDone(({ stats })=>{
19
- if ('server' !== stats.toJson({
20
- all: false
21
- }).name) onRepack(distDirectory, hooks);
22
- });
23
- const { watchOptions } = config.server;
24
- const watcher = startWatcher({
25
- pwd,
26
- distDir: distDirectory,
27
- apiDir: apiDirectory || API_DIR,
28
- sharedDir: sharedDirectory || SHARED_DIR,
29
- watchOptions,
30
- server: serverBase
31
- });
32
- closeCb.push(watcher.close.bind(watcher));
33
- closeCb.length > 0 && nodeServer?.on('close', ()=>{
34
- closeCb.forEach((cb)=>{
35
- cb();
36
- });
37
- });
10
+ const { middlewares: builderMiddlewares } = builderDevServer || {};
11
+ const { middlewares } = api.getServerContext();
38
12
  const before = [];
39
13
  const after = [];
40
14
  const { setupMiddlewares = [] } = dev;
@@ -52,7 +26,7 @@ const devPlugin = (options, compiler)=>({
52
26
  handler: connectMid2HonoMid(middleware)
53
27
  });
54
28
  });
55
- const mockMiddleware = await getMockMiddleware(pwd);
29
+ const mockMiddleware = await getMockMiddleware(pwd, options.config?.dev?.mockDir);
56
30
  middlewares.push({
57
31
  name: 'mock-dev',
58
32
  handler: mockMiddleware
@@ -74,4 +48,60 @@ const devPlugin = (options, compiler)=>({
74
48
  });
75
49
  }
76
50
  });
77
- export { devPlugin };
51
+ function setupDevInfra({ config, pwd, distDir, apiDir, sharedDir, builder, builderDevServer, getRuntimeServer, onFileChange, onClose, nodeServer }) {
52
+ const { close, connectWebSocket } = builderDevServer || {};
53
+ const closeCb = [];
54
+ close && closeCb.push(close);
55
+ connectWebSocket && nodeServer && connectWebSocket({
56
+ server: nodeServer
57
+ });
58
+ builder?.onDevCompileDone(({ stats })=>{
59
+ if ('server' !== stats.toJson({
60
+ all: false
61
+ }).name) {
62
+ const runtimeServer = getRuntimeServer();
63
+ if (runtimeServer) onRepack(distDir, runtimeServer.hooks);
64
+ }
65
+ });
66
+ const { watchOptions } = config.server;
67
+ const mockDir = config.dev?.mockDir;
68
+ const mockPath = resolveMockDirectory(pwd, mockDir);
69
+ const watcher = startWatcher({
70
+ pwd,
71
+ distDir,
72
+ apiDir: apiDir || API_DIR,
73
+ sharedDir: sharedDir || SHARED_DIR,
74
+ mockDir,
75
+ watchOptions,
76
+ onChange: (filepath, event)=>{
77
+ const runtimeServer = getRuntimeServer();
78
+ if (runtimeServer && !isPathInsideDirectory(filepath, mockPath)) {
79
+ const fileChangeEvent = {
80
+ type: 'file-change',
81
+ payload: [
82
+ {
83
+ filename: filepath,
84
+ event
85
+ }
86
+ ]
87
+ };
88
+ Promise.resolve(runtimeServer.hooks.onReset.call({
89
+ event: fileChangeEvent
90
+ })).catch((error)=>logger.error(error));
91
+ }
92
+ onFileChange(filepath, event);
93
+ }
94
+ });
95
+ closeCb.push(watcher.close.bind(watcher));
96
+ onClose && closeCb.push(onClose);
97
+ const close$ = ()=>{
98
+ closeCb.forEach((cb)=>{
99
+ cb();
100
+ });
101
+ };
102
+ closeCb.length > 0 && nodeServer?.on('close', close$);
103
+ return {
104
+ close: close$
105
+ };
106
+ }
107
+ export { devRuntimeMiddlewarePlugin, setupDevInfra };
@@ -1,42 +1,14 @@
1
- import { AGGRED_DIR } from "@modern-js/server-core";
2
- import { SERVER_BUNDLE_DIRECTORY, SERVER_DIR, logger } from "@modern-js/utils";
1
+ import { SERVER_BUNDLE_DIRECTORY, SERVER_DIR } from "@modern-js/utils";
3
2
  import path from "path";
4
3
  import dev_tools_watcher, { mergeWatchOptions } from "../dev-tools/watcher/index.mjs";
5
- import { initOrUpdateMockMiddlewares } from "./mock.mjs";
6
- import { debug } from "./utils.mjs";
4
+ import { resolveMockDirectory } from "./mock.mjs";
7
5
  export * from "./devOptions.mjs";
8
6
  export * from "./fileReader.mjs";
9
7
  export * from "./mock.mjs";
10
8
  export * from "./repack.mjs";
11
- async function onServerChange({ pwd, filepath, event, server }) {
12
- const { mock } = AGGRED_DIR;
13
- const mockPath = path.normalize(path.join(pwd, mock));
14
- const { hooks } = server;
15
- if (filepath.startsWith(mockPath)) {
16
- await initOrUpdateMockMiddlewares(pwd);
17
- logger.info('Finish update the mock handlers');
18
- } else try {
19
- const fileChangeEvent = {
20
- type: 'file-change',
21
- payload: [
22
- {
23
- filename: filepath,
24
- event
25
- }
26
- ]
27
- };
28
- await hooks.onReset.call({
29
- event: fileChangeEvent
30
- });
31
- debug(`Finish reload server, trigger by ${filepath} ${event}`);
32
- } catch (e) {
33
- logger.error(e);
34
- }
35
- }
36
- function startWatcher({ pwd, distDir, apiDir, sharedDir, watchOptions, server }) {
37
- const { mock } = AGGRED_DIR;
9
+ function startWatcher({ pwd, distDir, apiDir, sharedDir, mockDir, watchOptions, onChange }) {
38
10
  const defaultWatched = [
39
- `${mock}/**/*`,
11
+ path.join(resolveMockDirectory(pwd, mockDir), '**/*'),
40
12
  `${SERVER_DIR}/**/*`,
41
13
  `${apiDir}/**`,
42
14
  `${sharedDir}/**/*`,
@@ -53,12 +25,7 @@ function startWatcher({ pwd, distDir, apiDir, sharedDir, watchOptions, server })
53
25
  if (filepath.includes('-server-loaders.js')) return void delete require.cache[filepath];
54
26
  watcher.updateDepTree();
55
27
  watcher.cleanDepCache(filepath);
56
- onServerChange({
57
- pwd,
58
- filepath,
59
- event,
60
- server
61
- });
28
+ onChange(filepath, event);
62
29
  });
63
30
  return watcher;
64
31
  }
@@ -1,10 +1,15 @@
1
1
  import node_path from "node:path";
2
2
  import { AGGRED_DIR } from "@modern-js/server-core";
3
3
  import { connectMockMid2HonoMid } from "@modern-js/server-core/node";
4
- import { fs } from "@modern-js/utils";
4
+ import { compatibleRequire, fs } from "@modern-js/utils";
5
5
  import { match } from "path-to-regexp";
6
6
  let mockAPIs = [];
7
7
  let mockConfig;
8
+ const resolveMockDirectory = (pwd, mockDir = AGGRED_DIR.mock)=>node_path.resolve(pwd, mockDir);
9
+ const isPathInsideDirectory = (filepath, directory)=>{
10
+ const relativePath = node_path.relative(directory, node_path.resolve(filepath));
11
+ return '' === relativePath || '..' !== relativePath && !relativePath.startsWith(`..${node_path.sep}`) && !node_path.isAbsolute(relativePath);
12
+ };
8
13
  const parseKey = (key)=>{
9
14
  const _blank = ' ';
10
15
  const splitted = key.split(_blank).filter(Boolean);
@@ -20,21 +25,22 @@ const parseKey = (key)=>{
20
25
  path: key
21
26
  };
22
27
  };
23
- const getMockModule = async (pwd)=>{
28
+ const getMockModule = async (pwd, mockDir)=>{
24
29
  const exts = [
25
30
  '.ts',
26
31
  '.js'
27
32
  ];
28
33
  let mockFilePath = '';
34
+ const mockDirectory = resolveMockDirectory(pwd, mockDir);
29
35
  for (const ext of exts){
30
- const maybeMatch = node_path.join(pwd, `${AGGRED_DIR.mock}/index${ext}`);
36
+ const maybeMatch = node_path.join(mockDirectory, `index${ext}`);
31
37
  if (await fs.pathExists(maybeMatch)) {
32
38
  mockFilePath = maybeMatch;
33
39
  break;
34
40
  }
35
41
  }
36
42
  if (!mockFilePath) return;
37
- const { default: mockHandlers, config } = await import(mockFilePath);
43
+ const { default: mockHandlers, config } = await compatibleRequire(mockFilePath, false);
38
44
  const enable = config?.enable;
39
45
  if (false === enable) return;
40
46
  if (!mockHandlers) throw new Error(`Mock file ${mockFilePath} parsed failed!`);
@@ -54,8 +60,8 @@ const getMatched = (request, mockApis)=>{
54
60
  });
55
61
  return matched;
56
62
  };
57
- async function initOrUpdateMockMiddlewares(pwd) {
58
- const mockModule = await getMockModule(pwd);
63
+ async function initOrUpdateMockMiddlewares(pwd, mockDir) {
64
+ const mockModule = await getMockModule(pwd, mockDir);
59
65
  mockConfig = mockModule?.config;
60
66
  mockAPIs = Object.entries(mockModule?.mockHandlers || {}).map(([key, handler])=>{
61
67
  const { method, path } = parseKey(key);
@@ -66,8 +72,8 @@ async function initOrUpdateMockMiddlewares(pwd) {
66
72
  };
67
73
  });
68
74
  }
69
- async function getMockMiddleware(pwd) {
70
- await initOrUpdateMockMiddlewares(pwd);
75
+ async function getMockMiddleware(pwd, mockDir) {
76
+ await initOrUpdateMockMiddlewares(pwd, mockDir);
71
77
  const mockMiddleware = async (c, next)=>{
72
78
  if ('function' == typeof mockConfig?.enable) {
73
79
  const isEnabled = mockConfig.enable(c.env.node.req, c.env.node.res);
@@ -83,4 +89,4 @@ async function getMockMiddleware(pwd) {
83
89
  };
84
90
  return mockMiddleware;
85
91
  }
86
- export { getMatched, getMockMiddleware, initOrUpdateMockMiddlewares };
92
+ export { getMatched, getMockMiddleware, initOrUpdateMockMiddlewares, isPathInsideDirectory, resolveMockDirectory };
@@ -2,7 +2,10 @@ import "node:module";
2
2
  import node_path from "node:path";
3
3
  import { createServerBase } from "@modern-js/server-core";
4
4
  import { createNodeServer, loadServerRuntimeConfig } from "@modern-js/server-core/node";
5
- import { devPlugin } from "./dev.mjs";
5
+ import { logger } from "@modern-js/utils";
6
+ import { devRuntimeMiddlewarePlugin, setupDevInfra } from "./dev.mjs";
7
+ import { createReloadManager } from "./dev-tools/reloadManager.mjs";
8
+ import { createRuntimeServerOptions } from "./dev-tools/runtimeOptions.mjs";
6
9
  import { getDevAssetPrefix, getDevOptions } from "./helpers/index.mjs";
7
10
  async function createDevServer(options, applyPlugins) {
8
11
  const { config, pwd, serverConfigPath, builder } = options;
@@ -21,33 +24,76 @@ async function createDevServer(options, applyPlugins) {
21
24
  ...options.plugins || []
22
25
  ]
23
26
  };
24
- const server = createServerBase(prodServerOptions);
25
- const devHttpsOption = 'object' == typeof dev && dev.https;
26
- const isHttp2 = !!devHttpsOption;
27
- let nodeServer;
28
- if (devHttpsOption) {
29
- const { genHttpsOptions } = await import("./dev-tools/https/index.mjs");
30
- const httpsOptions = await genHttpsOptions(devHttpsOption, pwd);
31
- nodeServer = await createNodeServer(server.handle.bind(server), httpsOptions, isHttp2);
32
- } else nodeServer = await createNodeServer(server.handle.bind(server));
33
- const promise = getDevAssetPrefix(builder);
34
27
  let compiler = null;
35
28
  builder?.onAfterCreateCompiler((context)=>{
36
29
  compiler = context.compiler;
37
30
  });
31
+ const assetPrefixPromise = getDevAssetPrefix(builder);
38
32
  const builderDevServer = await builder?.createDevServer({
39
33
  runCompile: options.runCompile
40
34
  });
41
- server.addPlugins([
42
- devPlugin({
43
- ...options,
44
- builderDevServer
45
- }, compiler)
46
- ]);
47
- const assetPrefix = await promise;
48
- if (assetPrefix) prodServerOptions.config.output.assetPrefix = assetPrefix;
49
- await applyPlugins(server, prodServerOptions, nodeServer);
50
- await server.init();
35
+ const assetPrefix = await assetPrefixPromise;
36
+ let currentRuntimeServer;
37
+ let nodeServer;
38
+ const buildRuntimeServer = async ()=>{
39
+ const freshServerConfig = await loadServerRuntimeConfig(serverConfigPath) || {};
40
+ const runtimeOptions = createRuntimeServerOptions({
41
+ ...prodServerOptions,
42
+ serverConfig: {
43
+ ...freshServerConfig,
44
+ ...options.serverConfig
45
+ },
46
+ plugins: [
47
+ ...freshServerConfig.plugins || [],
48
+ ...options.plugins || []
49
+ ]
50
+ }, assetPrefix);
51
+ const runtimeServer = createServerBase(runtimeOptions);
52
+ runtimeServer.addPlugins([
53
+ devRuntimeMiddlewarePlugin({
54
+ ...options,
55
+ builderDevServer
56
+ }, compiler)
57
+ ]);
58
+ await applyPlugins(runtimeServer, runtimeOptions, nodeServer);
59
+ await runtimeServer.init();
60
+ currentRuntimeServer = runtimeServer;
61
+ return runtimeServer.handle;
62
+ };
63
+ const pendingReloadFiles = new Set();
64
+ const reloadManager = createReloadManager({
65
+ build: buildRuntimeServer,
66
+ onReload: ()=>{
67
+ const files = Array.from(pendingReloadFiles);
68
+ pendingReloadFiles.clear();
69
+ logger.info(files.length > 0 ? `Server runtime reloaded (${files.join(', ')})` : 'Server runtime reloaded');
70
+ }
71
+ });
72
+ const devHttpsOption = 'object' == typeof dev && dev.https;
73
+ const isHttp2 = !!devHttpsOption;
74
+ if (devHttpsOption) {
75
+ const { genHttpsOptions } = await import("./dev-tools/https/index.mjs");
76
+ const httpsOptions = await genHttpsOptions(devHttpsOption, pwd);
77
+ nodeServer = await createNodeServer(reloadManager.handle, httpsOptions, isHttp2);
78
+ } else nodeServer = await createNodeServer(reloadManager.handle);
79
+ reloadManager.setHandle(await buildRuntimeServer());
80
+ setupDevInfra({
81
+ config,
82
+ pwd,
83
+ distDir,
84
+ apiDir: options.appContext?.apiDirectory,
85
+ sharedDir: options.appContext?.sharedDirectory,
86
+ builder,
87
+ builderDevServer,
88
+ compiler,
89
+ nodeServer,
90
+ getRuntimeServer: ()=>currentRuntimeServer,
91
+ onFileChange: (filepath)=>{
92
+ pendingReloadFiles.add(node_path.relative(pwd, filepath));
93
+ reloadManager.schedule();
94
+ },
95
+ onClose: ()=>reloadManager.close()
96
+ });
51
97
  const afterListen = async ()=>{
52
98
  await builderDevServer?.afterListen();
53
99
  };
@@ -0,0 +1,186 @@
1
+ import "node:module";
2
+ import { logger } from "@modern-js/utils";
3
+ function _check_private_redeclaration(obj, privateCollection) {
4
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
5
+ }
6
+ function _class_apply_descriptor_get(receiver, descriptor) {
7
+ if (descriptor.get) return descriptor.get.call(receiver);
8
+ return descriptor.value;
9
+ }
10
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
11
+ if (descriptor.set) descriptor.set.call(receiver, value);
12
+ else {
13
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
14
+ descriptor.value = value;
15
+ }
16
+ }
17
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
18
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
19
+ return privateMap.get(receiver);
20
+ }
21
+ function _class_private_field_get(receiver, privateMap) {
22
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
23
+ return _class_apply_descriptor_get(receiver, descriptor);
24
+ }
25
+ function _class_private_field_init(obj, privateMap, value) {
26
+ _check_private_redeclaration(obj, privateMap);
27
+ privateMap.set(obj, value);
28
+ }
29
+ function _class_private_field_set(receiver, privateMap, value) {
30
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
31
+ _class_apply_descriptor_set(receiver, descriptor, value);
32
+ return value;
33
+ }
34
+ function _class_private_method_get(receiver, privateSet, fn) {
35
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
36
+ return fn;
37
+ }
38
+ function _class_private_method_init(obj, privateSet) {
39
+ _check_private_redeclaration(obj, privateSet);
40
+ privateSet.add(obj);
41
+ }
42
+ const DEFAULT_DEBOUNCE_MS = 300;
43
+ const notReadyHandle = ()=>new Response('Dev server is starting…', {
44
+ status: 503,
45
+ headers: {
46
+ 'content-type': 'text/plain; charset=utf-8'
47
+ }
48
+ });
49
+ var _current = /*#__PURE__*/ new WeakMap(), _build = /*#__PURE__*/ new WeakMap(), _debounceMs = /*#__PURE__*/ new WeakMap(), _onReload = /*#__PURE__*/ new WeakMap(), _onError = /*#__PURE__*/ new WeakMap(), _onReloadError = /*#__PURE__*/ new WeakMap(), _debounceTimer = /*#__PURE__*/ new WeakMap(), _running = /*#__PURE__*/ new WeakMap(), _pending = /*#__PURE__*/ new WeakMap(), _runningPromise = /*#__PURE__*/ new WeakMap(), _closed = /*#__PURE__*/ new WeakMap(), _runLoop = /*#__PURE__*/ new WeakSet(), _reportBuildError = /*#__PURE__*/ new WeakSet(), _reportReloadCallbackError = /*#__PURE__*/ new WeakSet();
50
+ class ReloadManager {
51
+ setHandle(handle) {
52
+ _class_private_field_set(this, _current, handle);
53
+ }
54
+ get handle() {
55
+ return (request, ...args)=>_class_private_field_get(this, _current).call(this, request, ...args);
56
+ }
57
+ get currentHandle() {
58
+ return _class_private_field_get(this, _current);
59
+ }
60
+ get isReloading() {
61
+ return _class_private_field_get(this, _running);
62
+ }
63
+ schedule() {
64
+ if (_class_private_field_get(this, _closed)) return;
65
+ if (_class_private_field_get(this, _debounceTimer)) clearTimeout(_class_private_field_get(this, _debounceTimer));
66
+ _class_private_field_set(this, _debounceTimer, setTimeout(()=>{
67
+ _class_private_field_set(this, _debounceTimer, null);
68
+ this.reloadNow();
69
+ }, _class_private_field_get(this, _debounceMs)));
70
+ }
71
+ async reloadNow() {
72
+ if (_class_private_field_get(this, _closed)) return;
73
+ if (_class_private_field_get(this, _running)) {
74
+ _class_private_field_set(this, _pending, true);
75
+ return _class_private_field_get(this, _runningPromise) ?? Promise.resolve();
76
+ }
77
+ _class_private_field_set(this, _running, true);
78
+ _class_private_field_set(this, _runningPromise, _class_private_method_get(this, _runLoop, runLoop).call(this));
79
+ try {
80
+ await _class_private_field_get(this, _runningPromise);
81
+ } finally{
82
+ _class_private_field_set(this, _running, false);
83
+ _class_private_field_set(this, _runningPromise, null);
84
+ }
85
+ }
86
+ close() {
87
+ _class_private_field_set(this, _closed, true);
88
+ _class_private_field_set(this, _pending, false);
89
+ if (_class_private_field_get(this, _debounceTimer)) {
90
+ clearTimeout(_class_private_field_get(this, _debounceTimer));
91
+ _class_private_field_set(this, _debounceTimer, null);
92
+ }
93
+ }
94
+ constructor(options){
95
+ _class_private_method_init(this, _runLoop);
96
+ _class_private_method_init(this, _reportBuildError);
97
+ _class_private_method_init(this, _reportReloadCallbackError);
98
+ _class_private_field_init(this, _current, {
99
+ writable: true,
100
+ value: void 0
101
+ });
102
+ _class_private_field_init(this, _build, {
103
+ writable: true,
104
+ value: void 0
105
+ });
106
+ _class_private_field_init(this, _debounceMs, {
107
+ writable: true,
108
+ value: void 0
109
+ });
110
+ _class_private_field_init(this, _onReload, {
111
+ writable: true,
112
+ value: void 0
113
+ });
114
+ _class_private_field_init(this, _onError, {
115
+ writable: true,
116
+ value: void 0
117
+ });
118
+ _class_private_field_init(this, _onReloadError, {
119
+ writable: true,
120
+ value: void 0
121
+ });
122
+ _class_private_field_init(this, _debounceTimer, {
123
+ writable: true,
124
+ value: void 0
125
+ });
126
+ _class_private_field_init(this, _running, {
127
+ writable: true,
128
+ value: void 0
129
+ });
130
+ _class_private_field_init(this, _pending, {
131
+ writable: true,
132
+ value: void 0
133
+ });
134
+ _class_private_field_init(this, _runningPromise, {
135
+ writable: true,
136
+ value: void 0
137
+ });
138
+ _class_private_field_init(this, _closed, {
139
+ writable: true,
140
+ value: void 0
141
+ });
142
+ _class_private_field_set(this, _debounceTimer, null);
143
+ _class_private_field_set(this, _running, false);
144
+ _class_private_field_set(this, _pending, false);
145
+ _class_private_field_set(this, _runningPromise, null);
146
+ _class_private_field_set(this, _closed, false);
147
+ _class_private_field_set(this, _current, options.initialHandle ?? notReadyHandle);
148
+ _class_private_field_set(this, _build, options.build);
149
+ _class_private_field_set(this, _debounceMs, options.debounceMs ?? DEFAULT_DEBOUNCE_MS);
150
+ _class_private_field_set(this, _onReload, options.onReload);
151
+ _class_private_field_set(this, _onError, options.onError);
152
+ _class_private_field_set(this, _onReloadError, options.onReloadError);
153
+ }
154
+ }
155
+ async function runLoop() {
156
+ var _this, _this1;
157
+ do {
158
+ _class_private_field_set(this, _pending, false);
159
+ let next;
160
+ try {
161
+ next = await _class_private_field_get(this, _build).call(this);
162
+ } catch (error) {
163
+ _class_private_method_get(this, _reportBuildError, reportBuildError).call(this, error);
164
+ continue;
165
+ }
166
+ if (_class_private_field_get(this, _closed)) return;
167
+ _class_private_field_set(this, _current, next);
168
+ try {
169
+ null == (_this = _class_private_field_get(_this1 = this, _onReload)) || _this.call(_this1, next);
170
+ } catch (callbackError) {
171
+ _class_private_method_get(this, _reportReloadCallbackError, reportReloadCallbackError).call(this, callbackError);
172
+ }
173
+ }while (_class_private_field_get(this, _pending) && !_class_private_field_get(this, _closed));
174
+ }
175
+ function reportBuildError(error) {
176
+ if (_class_private_field_get(this, _onError)) _class_private_field_get(this, _onError).call(this, error);
177
+ else logger.error(`[dev-server] runtime reload build failed, keep serving previous handle:\n${error instanceof Error ? error.stack ?? error.message : error}`);
178
+ }
179
+ function reportReloadCallbackError(error) {
180
+ if (_class_private_field_get(this, _onReloadError)) _class_private_field_get(this, _onReloadError).call(this, error);
181
+ else logger.warn(`[dev-server] onReload callback failed after a successful swap (handle is already active):\n${error instanceof Error ? error.stack ?? error.message : error}`);
182
+ }
183
+ function createReloadManager(options) {
184
+ return new ReloadManager(options);
185
+ }
186
+ export { ReloadManager, createReloadManager };
@@ -0,0 +1,36 @@
1
+ import "node:module";
2
+ function createRuntimeServerOptions(base, assetPrefix) {
3
+ const baseConfig = base.config ?? {};
4
+ const baseOutput = baseConfig.output ?? {};
5
+ const baseServerConfig = base.serverConfig ?? {};
6
+ return {
7
+ ...base,
8
+ config: {
9
+ ...baseConfig,
10
+ output: {
11
+ ...baseOutput,
12
+ ...assetPrefix ? {
13
+ assetPrefix
14
+ } : {}
15
+ }
16
+ },
17
+ serverConfig: {
18
+ ...baseServerConfig,
19
+ middlewares: [
20
+ ...baseServerConfig.middlewares ?? []
21
+ ],
22
+ renderMiddlewares: [
23
+ ...baseServerConfig.renderMiddlewares ?? []
24
+ ],
25
+ ...baseServerConfig.plugins ? {
26
+ plugins: [
27
+ ...baseServerConfig.plugins
28
+ ]
29
+ } : {}
30
+ },
31
+ plugins: [
32
+ ...base.plugins ?? []
33
+ ]
34
+ };
35
+ }
36
+ export { createRuntimeServerOptions };
@@ -1,4 +1,5 @@
1
1
  import "node:module";
2
+ import node_path from "node:path";
2
3
  import * as __rspack_external_minimatch from "minimatch";
3
4
  const defaultIgnores = [
4
5
  '**/coverage/**',
@@ -42,8 +43,9 @@ class DependencyTree {
42
43
  }
43
44
  }
44
45
  shouldIgnore(path) {
45
- return !path || Boolean(this.ignore.find((rule)=>__rspack_external_minimatch.match([
46
- path
46
+ const matchPath = path && node_path.isAbsolute(path) ? node_path.relative(process.cwd(), path) : path;
47
+ return !matchPath || Boolean(this.ignore.find((rule)=>__rspack_external_minimatch.match([
48
+ matchPath
47
49
  ], rule, {
48
50
  dot: true
49
51
  }).length > 0));