@modern-js/server 2.65.5 → 2.66.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.
@@ -59,6 +59,7 @@ async function createDevServer(options, applyPlugins) {
59
59
  } else {
60
60
  nodeServer = await (0, import_node.createNodeServer)(server.handle.bind(server));
61
61
  }
62
+ const promise = (0, import_helpers.getDevAssetPrefix)(builder);
62
63
  const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
63
64
  runCompile: options.runCompile,
64
65
  compiler: options.compilier
@@ -69,6 +70,10 @@ async function createDevServer(options, applyPlugins) {
69
70
  builderDevServer
70
71
  })
71
72
  ]);
73
+ const assetPrefix = await promise;
74
+ if (assetPrefix) {
75
+ prodServerOptions.config.output.assetPrefix = assetPrefix;
76
+ }
72
77
  await applyPlugins(server, prodServerOptions, nodeServer);
73
78
  await server.init();
74
79
  const afterListen = async () => {
package/dist/cjs/dev.js CHANGED
@@ -39,12 +39,12 @@ const devPlugin = (options) => ({
39
39
  connectWebSocket && nodeServer && connectWebSocket({
40
40
  server: nodeServer
41
41
  });
42
- const runner = api.useHookRunners();
42
+ const hooks = api.getHooks();
43
43
  builder === null || builder === void 0 ? void 0 : builder.onDevCompileDone(({ stats }) => {
44
44
  if (stats.toJson({
45
45
  all: false
46
46
  }).name !== "server") {
47
- (0, import_helpers.onRepack)(distDirectory, runner);
47
+ (0, import_helpers.onRepack)(distDirectory, hooks);
48
48
  }
49
49
  });
50
50
  if (dev.watch) {
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var devOptions_exports = {};
20
20
  __export(devOptions_exports, {
21
+ getDevAssetPrefix: () => getDevAssetPrefix,
21
22
  getDevOptions: () => getDevOptions
22
23
  });
23
24
  module.exports = __toCommonJS(devOptions_exports);
@@ -28,7 +29,31 @@ const getDevOptions = (options) => {
28
29
  const defaultOptions = (0, import_constants.getDefaultDevOptions)();
29
30
  return (0, import_lodash.merge)(defaultOptions, devOptions);
30
31
  };
32
+ const getDevAssetPrefix = (builder) => {
33
+ return new Promise((resolve) => {
34
+ if (!builder) {
35
+ return resolve("");
36
+ }
37
+ builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler((params) => {
38
+ let webCompiler;
39
+ if ("compilers" in params.compiler) {
40
+ webCompiler = params.compiler.compilers.find((c) => {
41
+ return c.name === "web" || c.name === "client";
42
+ });
43
+ } else {
44
+ webCompiler = params.compiler;
45
+ }
46
+ const publicPath = webCompiler.options.output.publicPath;
47
+ if (publicPath && typeof publicPath === "string") {
48
+ const formatPublicPath = publicPath.replace(/^https?:\/\/[^/]+/, "");
49
+ return resolve(formatPublicPath);
50
+ }
51
+ return resolve("");
52
+ });
53
+ });
54
+ };
31
55
  // Annotate the CommonJS export names for ESM import in node:
32
56
  0 && (module.exports = {
57
+ getDevAssetPrefix,
33
58
  getDevOptions
34
59
  });
@@ -45,7 +45,7 @@ __reExport(helpers_exports, require("./mock"), module.exports);
45
45
  async function onServerChange({ pwd, filepath, event, server }) {
46
46
  const { mock } = import_server_core.AGGRED_DIR;
47
47
  const mockPath = import_path.default.normalize(import_path.default.join(pwd, mock));
48
- const { runner } = server;
48
+ const { hooks } = server;
49
49
  if (filepath.startsWith(mockPath)) {
50
50
  await (0, import_mock.initOrUpdateMockMiddlewares)(pwd);
51
51
  import_utils.logger.info("Finish update the mock handlers");
@@ -60,7 +60,7 @@ async function onServerChange({ pwd, filepath, event, server }) {
60
60
  }
61
61
  ]
62
62
  };
63
- await runner.reset({
63
+ await hooks.onReset.call({
64
64
  event: fileChangeEvent
65
65
  });
66
66
  (0, import_utils2.debug)(`Finish reload server, trigger by ${filepath} ${event}`);
@@ -29,10 +29,10 @@ const cleanSSRCache = (distDir) => {
29
29
  }
30
30
  });
31
31
  };
32
- const onRepack = (distDir, runner) => {
32
+ const onRepack = (distDir, hooks) => {
33
33
  cleanSSRCache(distDir);
34
34
  import_fileReader.fileReader.reset();
35
- runner.reset({
35
+ hooks.onReset.call({
36
36
  event: {
37
37
  type: "repack"
38
38
  }
@@ -7,13 +7,13 @@ import path from "node:path";
7
7
  import { createServerBase } from "@modern-js/server-core";
8
8
  import { createNodeServer, loadServerRuntimeConfig } from "@modern-js/server-core/node";
9
9
  import { devPlugin } from "./dev";
10
- import { getDevOptions } from "./helpers";
10
+ import { getDevAssetPrefix, getDevOptions } from "./helpers";
11
11
  function createDevServer(options, applyPlugins) {
12
12
  return _createDevServer.apply(this, arguments);
13
13
  }
14
14
  function _createDevServer() {
15
15
  _createDevServer = _async_to_generator(function(options, applyPlugins) {
16
- var _config_output_distPath, config, pwd, serverConfigFile, serverConfigPath, builder, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, nodeServer, genHttpsOptions, httpsOptions, builderDevServer, afterListen;
16
+ var _config_output_distPath, config, pwd, serverConfigFile, serverConfigPath, builder, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, nodeServer, genHttpsOptions, httpsOptions, promise, builderDevServer, assetPrefix, afterListen;
17
17
  return _ts_generator(this, function(_state) {
18
18
  switch (_state.label) {
19
19
  case 0:
@@ -70,6 +70,7 @@ function _createDevServer() {
70
70
  nodeServer = _state.sent();
71
71
  _state.label = 7;
72
72
  case 7:
73
+ promise = getDevAssetPrefix(builder);
73
74
  return [
74
75
  4,
75
76
  builder === null || builder === void 0 ? void 0 : builder.createDevServer({
@@ -86,15 +87,24 @@ function _createDevServer() {
86
87
  ]);
87
88
  return [
88
89
  4,
89
- applyPlugins(server, prodServerOptions, nodeServer)
90
+ promise
90
91
  ];
91
92
  case 9:
93
+ assetPrefix = _state.sent();
94
+ if (assetPrefix) {
95
+ prodServerOptions.config.output.assetPrefix = assetPrefix;
96
+ }
97
+ return [
98
+ 4,
99
+ applyPlugins(server, prodServerOptions, nodeServer)
100
+ ];
101
+ case 10:
92
102
  _state.sent();
93
103
  return [
94
104
  4,
95
105
  server.init()
96
106
  ];
97
- case 10:
107
+ case 11:
98
108
  _state.sent();
99
109
  afterListen = function() {
100
110
  var _ref = _async_to_generator(function() {
package/dist/esm/dev.js CHANGED
@@ -14,7 +14,7 @@ var devPlugin = function(options) {
14
14
  return {
15
15
  prepare: function prepare() {
16
16
  return _async_to_generator(function() {
17
- var _dev_after, _dev_before, _ref, builderMiddlewares, close, connectWebSocket, _api_useAppContext, middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase, runner, watchOptions, watcher, before, after, _dev_setupMiddlewares, setupMiddlewares, mockMiddleware;
17
+ var _dev_after, _dev_before, _ref, builderMiddlewares, close, connectWebSocket, _api_useAppContext, middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase, hooks, watchOptions, watcher, before, after, _dev_setupMiddlewares, setupMiddlewares, mockMiddleware;
18
18
  return _ts_generator(this, function(_state) {
19
19
  switch (_state.label) {
20
20
  case 0:
@@ -24,13 +24,13 @@ var devPlugin = function(options) {
24
24
  connectWebSocket && nodeServer && connectWebSocket({
25
25
  server: nodeServer
26
26
  });
27
- runner = api.useHookRunners();
27
+ hooks = api.getHooks();
28
28
  builder === null || builder === void 0 ? void 0 : builder.onDevCompileDone(function(param) {
29
29
  var stats = param.stats;
30
30
  if (stats.toJson({
31
31
  all: false
32
32
  }).name !== "server") {
33
- onRepack(distDirectory, runner);
33
+ onRepack(distDirectory, hooks);
34
34
  }
35
35
  });
36
36
  if (dev.watch) {
@@ -5,6 +5,30 @@ var getDevOptions = function(options) {
5
5
  var defaultOptions = getDefaultDevOptions();
6
6
  return merge(defaultOptions, devOptions);
7
7
  };
8
+ var getDevAssetPrefix = function(builder) {
9
+ return new Promise(function(resolve) {
10
+ if (!builder) {
11
+ return resolve("");
12
+ }
13
+ builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler(function(params) {
14
+ var webCompiler;
15
+ if ("compilers" in params.compiler) {
16
+ webCompiler = params.compiler.compilers.find(function(c) {
17
+ return c.name === "web" || c.name === "client";
18
+ });
19
+ } else {
20
+ webCompiler = params.compiler;
21
+ }
22
+ var publicPath = webCompiler.options.output.publicPath;
23
+ if (publicPath && typeof publicPath === "string") {
24
+ var formatPublicPath = publicPath.replace(/^https?:\/\/[^/]+/, "");
25
+ return resolve(formatPublicPath);
26
+ }
27
+ return resolve("");
28
+ });
29
+ });
30
+ };
8
31
  export {
32
+ getDevAssetPrefix,
9
33
  getDevOptions
10
34
  };
@@ -15,14 +15,14 @@ function onServerChange(_) {
15
15
  }
16
16
  function _onServerChange() {
17
17
  _onServerChange = _async_to_generator(function(param) {
18
- var pwd, filepath, event, server, mock, mockPath, runner, fileChangeEvent, e;
18
+ var pwd, filepath, event, server, mock, mockPath, hooks, fileChangeEvent, e;
19
19
  return _ts_generator(this, function(_state) {
20
20
  switch (_state.label) {
21
21
  case 0:
22
22
  pwd = param.pwd, filepath = param.filepath, event = param.event, server = param.server;
23
23
  mock = AGGRED_DIR.mock;
24
24
  mockPath = path.normalize(path.join(pwd, mock));
25
- runner = server.runner;
25
+ hooks = server.hooks;
26
26
  if (!filepath.startsWith(mockPath))
27
27
  return [
28
28
  3,
@@ -57,7 +57,7 @@ function _onServerChange() {
57
57
  };
58
58
  return [
59
59
  4,
60
- runner.reset({
60
+ hooks.onReset.call({
61
61
  event: fileChangeEvent
62
62
  })
63
63
  ];
@@ -6,10 +6,10 @@ var cleanSSRCache = function(distDir) {
6
6
  }
7
7
  });
8
8
  };
9
- var onRepack = function(distDir, runner) {
9
+ var onRepack = function(distDir, hooks) {
10
10
  cleanSSRCache(distDir);
11
11
  fileReader.reset();
12
- runner.reset({
12
+ hooks.onReset.call({
13
13
  event: {
14
14
  type: "repack"
15
15
  }
@@ -2,7 +2,7 @@ import path from "node:path";
2
2
  import { createServerBase } from "@modern-js/server-core";
3
3
  import { createNodeServer, loadServerRuntimeConfig } from "@modern-js/server-core/node";
4
4
  import { devPlugin } from "./dev";
5
- import { getDevOptions } from "./helpers";
5
+ import { getDevAssetPrefix, getDevOptions } from "./helpers";
6
6
  async function createDevServer(options, applyPlugins) {
7
7
  var _config_output_distPath;
8
8
  const { config, pwd, serverConfigFile, serverConfigPath, builder } = options;
@@ -26,6 +26,7 @@ async function createDevServer(options, applyPlugins) {
26
26
  } else {
27
27
  nodeServer = await createNodeServer(server.handle.bind(server));
28
28
  }
29
+ const promise = getDevAssetPrefix(builder);
29
30
  const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
30
31
  runCompile: options.runCompile,
31
32
  compiler: options.compilier
@@ -36,6 +37,10 @@ async function createDevServer(options, applyPlugins) {
36
37
  builderDevServer
37
38
  })
38
39
  ]);
40
+ const assetPrefix = await promise;
41
+ if (assetPrefix) {
42
+ prodServerOptions.config.output.assetPrefix = assetPrefix;
43
+ }
39
44
  await applyPlugins(server, prodServerOptions, nodeServer);
40
45
  await server.init();
41
46
  const afterListen = async () => {
@@ -16,12 +16,12 @@ const devPlugin = (options) => ({
16
16
  connectWebSocket && nodeServer && connectWebSocket({
17
17
  server: nodeServer
18
18
  });
19
- const runner = api.useHookRunners();
19
+ const hooks = api.getHooks();
20
20
  builder === null || builder === void 0 ? void 0 : builder.onDevCompileDone(({ stats }) => {
21
21
  if (stats.toJson({
22
22
  all: false
23
23
  }).name !== "server") {
24
- onRepack(distDirectory, runner);
24
+ onRepack(distDirectory, hooks);
25
25
  }
26
26
  });
27
27
  if (dev.watch) {
@@ -5,6 +5,30 @@ const getDevOptions = (options) => {
5
5
  const defaultOptions = getDefaultDevOptions();
6
6
  return merge(defaultOptions, devOptions);
7
7
  };
8
+ const getDevAssetPrefix = (builder) => {
9
+ return new Promise((resolve) => {
10
+ if (!builder) {
11
+ return resolve("");
12
+ }
13
+ builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler((params) => {
14
+ let webCompiler;
15
+ if ("compilers" in params.compiler) {
16
+ webCompiler = params.compiler.compilers.find((c) => {
17
+ return c.name === "web" || c.name === "client";
18
+ });
19
+ } else {
20
+ webCompiler = params.compiler;
21
+ }
22
+ const publicPath = webCompiler.options.output.publicPath;
23
+ if (publicPath && typeof publicPath === "string") {
24
+ const formatPublicPath = publicPath.replace(/^https?:\/\/[^/]+/, "");
25
+ return resolve(formatPublicPath);
26
+ }
27
+ return resolve("");
28
+ });
29
+ });
30
+ };
8
31
  export {
32
+ getDevAssetPrefix,
9
33
  getDevOptions
10
34
  };
@@ -11,7 +11,7 @@ export * from "./mock";
11
11
  async function onServerChange({ pwd, filepath, event, server }) {
12
12
  const { mock } = AGGRED_DIR;
13
13
  const mockPath = path.normalize(path.join(pwd, mock));
14
- const { runner } = server;
14
+ const { hooks } = server;
15
15
  if (filepath.startsWith(mockPath)) {
16
16
  await initOrUpdateMockMiddlewares(pwd);
17
17
  logger.info("Finish update the mock handlers");
@@ -26,7 +26,7 @@ async function onServerChange({ pwd, filepath, event, server }) {
26
26
  }
27
27
  ]
28
28
  };
29
- await runner.reset({
29
+ await hooks.onReset.call({
30
30
  event: fileChangeEvent
31
31
  });
32
32
  debug(`Finish reload server, trigger by ${filepath} ${event}`);
@@ -6,10 +6,10 @@ const cleanSSRCache = (distDir) => {
6
6
  }
7
7
  });
8
8
  };
9
- const onRepack = (distDir, runner) => {
9
+ const onRepack = (distDir, hooks) => {
10
10
  cleanSSRCache(distDir);
11
11
  fileReader.reset();
12
- runner.reset({
12
+ hooks.onReset.call({
13
13
  event: {
14
14
  type: "repack"
15
15
  }
@@ -1,9 +1,7 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { ApplyPlugins, ModernDevServerOptions } from './types';
4
2
  export declare function createDevServer(options: ModernDevServerOptions, applyPlugins: ApplyPlugins): Promise<{
5
3
  server: (import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>) & {
6
- getRequestListener: () => (req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>;
4
+ getRequestListener: () => ReturnType<(handler: import("@modern-js/server-core/dist/types/types").RequestHandler) => (req: import("@modern-js/server-core/dist/types/types").NodeRequest, res: import("@modern-js/server-core/dist/types/types").NodeResponse) => Promise<void>>;
7
5
  getRequestHandler: () => import("@modern-js/server-core/dist/types/types").RequestHandler;
8
6
  };
9
7
  afterListen: () => Promise<void>;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- import type Buffer from 'buffer';
3
1
  import type { DevServerHttpsOptions } from '../../types';
4
2
  export declare const genHttpsOptions: (userOptions: DevServerHttpsOptions, pwd: string) => Promise<{
5
3
  key?: Buffer | string;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export declare const defaultIgnores: string[];
3
2
  export interface DependencyTreeOptions {
4
3
  root: string;
@@ -1,9 +1,9 @@
1
- import type { ServerBaseOptions, ServerPlugin } from '@modern-js/server-core';
1
+ import type { ServerBaseOptions, ServerPluginLegacy } from '@modern-js/server-core';
2
2
  import type { 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) => ServerPlugin;
8
+ export declare const devPlugin: (options: DevPluginOptions) => ServerPluginLegacy;
9
9
  export {};
@@ -1,5 +1,7 @@
1
+ import type { UniBuilderInstance } from '@modern-js/uni-builder';
1
2
  import type { ModernDevServerOptions } from '../types';
2
3
  export declare const getDevOptions: (options: ModernDevServerOptions) => import("@modern-js/types/server/devServer").DevServerOptions & Pick<import("@modern-js/types/server/devServer").DevServerOptions, "watch" | "https"> & {
3
- port?: number | undefined;
4
- host?: string | undefined;
4
+ port?: number;
5
+ host?: string;
5
6
  };
7
+ export declare const getDevAssetPrefix: (builder?: UniBuilderInstance) => Promise<string>;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage, ServerResponse } from 'node:http';
3
2
  import { type InternalRequest, type Middleware } from '@modern-js/server-core';
4
3
  import type { NextFunction } from '@modern-js/types';
@@ -1,2 +1,2 @@
1
- import type { ServerHookRunner } from '@modern-js/server-core';
2
- export declare const onRepack: (distDir: string, runner: ServerHookRunner) => void;
1
+ import type { ServerPluginHooks } from '@modern-js/server-core';
2
+ export declare const onRepack: (distDir: string, hooks: ServerPluginHooks) => void;
@@ -1,7 +1,7 @@
1
- /// <reference types="node" />
1
+ import type { Server as NodeServer } from 'node:http';
2
2
  import type { DevServerHttpsOptions, DevServerOptions } from '@modern-js/types';
3
3
  import type { Rspack, UniBuilderInstance } from '@modern-js/uni-builder';
4
- import type { NodeServer, ServerBase, ServerBaseOptions } from '@modern-js/server-core';
4
+ import type { ServerBase, ServerBaseOptions } from '@modern-js/server-core';
5
5
  export type { DevServerOptions, DevServerHttpsOptions };
6
6
  export type ExtraOptions = {
7
7
  dev: Pick<DevServerOptions, 'watch' | 'https'> & {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.65.5",
18
+ "version": "2.66.0",
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.0.4",
49
49
  "path-to-regexp": "^6.2.0",
50
50
  "ws": "^8.13.0",
51
- "@modern-js/server-core": "2.65.5",
52
- "@modern-js/server-utils": "2.65.5",
53
- "@modern-js/types": "2.65.5",
54
- "@modern-js/runtime-utils": "2.65.5",
55
- "@modern-js/utils": "2.65.5"
51
+ "@modern-js/runtime-utils": "2.66.0",
52
+ "@modern-js/server-core": "2.66.0",
53
+ "@modern-js/server-utils": "2.66.0",
54
+ "@modern-js/types": "2.66.0",
55
+ "@modern-js/utils": "2.66.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/connect-history-api-fallback": "^1.3.5",
@@ -67,9 +67,9 @@
67
67
  "typescript": "^5",
68
68
  "webpack": "^5.98.0",
69
69
  "websocket": "^1",
70
- "@scripts/jest-config": "2.65.5",
71
- "@scripts/build": "2.65.5",
72
- "@modern-js/uni-builder": "2.65.5"
70
+ "@modern-js/uni-builder": "2.66.0",
71
+ "@scripts/jest-config": "2.66.0",
72
+ "@scripts/build": "2.66.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "devcert": "^1.2.2",