@shuvi/platform-web 1.0.14 → 1.0.16

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.
@@ -110,6 +110,11 @@ function onFastRefresh(hasUpdates) {
110
110
  const endLatency = Date.now();
111
111
  const latency = endLatency - startLatency;
112
112
  console.log(`[Fast Refresh] done in ${latency}ms`);
113
+ sendMessage(JSON.stringify({
114
+ event: 'client-hmr-latency',
115
+ startTime: startLatency,
116
+ endTime: endLatency
117
+ }));
113
118
  }
114
119
  }
115
120
  // Successful compilation.
@@ -36,7 +36,9 @@ export function connectHMR(options) {
36
36
  source.close();
37
37
  const { hostname, port } = window.location;
38
38
  const protocol = getSocketProtocol(options.assetPublicPath);
39
- const assetPublicPath = options.assetPublicPath.replace(/^\/+/, '');
39
+ const assetPublicPath = options.assetPublicPath
40
+ .replace(/^\/+/, '')
41
+ .replace(/\/+$/, '');
40
42
  let url = `${protocol}://${hostname}:${port}${assetPublicPath ? `/${assetPublicPath}` : ''}`;
41
43
  if (assetPublicPath.startsWith('http')) {
42
44
  url = `${protocol}://${assetPublicPath.split('://')[1]}`;
@@ -2,7 +2,8 @@ import { ShuviRequestHandler, IServerPluginContext } from '@shuvi/service';
2
2
  import { DevMiddleware } from '@shuvi/service/lib/server/middlewares/dev';
3
3
  export default class OnDemandRouteManager {
4
4
  devMiddleware: DevMiddleware | null;
5
- _serverPluginContext: IServerPluginContext;
5
+ private _serverPluginContext;
6
+ private _assetPathPrefix;
6
7
  constructor(serverPluginContext: IServerPluginContext);
7
8
  getServerMiddleware(): ShuviRequestHandler;
8
9
  ensureRoutesMiddleware(): ShuviRequestHandler;
@@ -27,17 +27,25 @@ class OnDemandRouteManager {
27
27
  constructor(serverPluginContext) {
28
28
  this.devMiddleware = null;
29
29
  this._serverPluginContext = serverPluginContext;
30
+ const { assetPublicPath } = this._serverPluginContext;
31
+ if (assetPublicPath.startsWith('http')) {
32
+ const url = new URL(assetPublicPath);
33
+ this._assetPathPrefix = url.pathname;
34
+ }
35
+ else {
36
+ this._assetPathPrefix = assetPublicPath;
37
+ }
30
38
  }
31
39
  getServerMiddleware() {
32
40
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
33
41
  const pathname = req.pathname;
34
- if (!pathname.startsWith(this._serverPluginContext.assetPublicPath)) {
42
+ if (!pathname.startsWith(this._assetPathPrefix)) {
35
43
  return next();
36
44
  }
37
45
  if (!this.devMiddleware) {
38
46
  return next();
39
47
  }
40
- const chunkName = pathname.replace(this._serverPluginContext.assetPublicPath, '');
48
+ const chunkName = pathname.replace(this._assetPathPrefix, '');
41
49
  const chunkInitiatorModule = resources_1.default.clientManifest.chunkRequest[chunkName];
42
50
  if (!chunkInitiatorModule) {
43
51
  return next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -72,17 +72,17 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@next/react-refresh-utils": "12.1.6",
75
- "@shuvi/error-overlay": "1.0.14",
76
- "@shuvi/hook": "1.0.14",
77
- "@shuvi/platform-shared": "1.0.14",
75
+ "@shuvi/error-overlay": "1.0.16",
76
+ "@shuvi/hook": "1.0.16",
77
+ "@shuvi/platform-shared": "1.0.16",
78
78
  "doura": "0.0.7",
79
79
  "react-doura": "0.0.7",
80
- "@shuvi/router": "1.0.14",
81
- "@shuvi/router-react": "1.0.14",
82
- "@shuvi/runtime": "1.0.14",
83
- "@shuvi/shared": "1.0.14",
84
- "@shuvi/toolpack": "1.0.14",
85
- "@shuvi/utils": "1.0.14",
80
+ "@shuvi/router": "1.0.16",
81
+ "@shuvi/router-react": "1.0.16",
82
+ "@shuvi/runtime": "1.0.16",
83
+ "@shuvi/shared": "1.0.16",
84
+ "@shuvi/toolpack": "1.0.16",
85
+ "@shuvi/utils": "1.0.16",
86
86
  "content-type": "1.0.4",
87
87
  "core-js": "3.6.5",
88
88
  "ejs": "3.1.5",
@@ -98,7 +98,7 @@
98
98
  "whatwg-fetch": "3.0.0"
99
99
  },
100
100
  "peerDependencies": {
101
- "@shuvi/service": "1.0.14"
101
+ "@shuvi/service": "1.0.16"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@shuvi/service": "workspace:*",