@shuvi/platform-web 1.0.13 → 1.0.15

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.
@@ -7,6 +7,7 @@ export interface PlatformWebCustomConfig {
7
7
  router: IRouterConfig;
8
8
  routes?: IPageRouteConfig[];
9
9
  conventionRoutes: {
10
+ include?: string[];
10
11
  exclude?: string[];
11
12
  };
12
13
  }
@@ -28,5 +28,5 @@ export declare type HotDevClient = {
28
28
  export default function connect(options: {
29
29
  launchEditorEndpoint: string;
30
30
  path: string;
31
- location: Location;
31
+ assetPublicPath: string;
32
32
  }): HotDevClient;
@@ -1,4 +1,5 @@
1
1
  import { DEV_SOCKET_TIMEOUT_MS, DEV_HOT_MIDDLEWARE_PATH, DEV_HOT_LAUNCH_EDITOR_ENDPOINT } from '@shuvi/shared/constants';
2
+ import { getPublicPath } from '@shuvi/platform-shared/shared/helper/getPublicPath';
2
3
  import connect from './hotDevClient';
3
4
  let devClient;
4
5
  export const initHMRAndDevClient = (app) => {
@@ -8,7 +9,7 @@ export const initHMRAndDevClient = (app) => {
8
9
  devClient = connect({
9
10
  launchEditorEndpoint: DEV_HOT_LAUNCH_EDITOR_ENDPOINT,
10
11
  path: DEV_HOT_MIDDLEWARE_PATH,
11
- location
12
+ assetPublicPath: getPublicPath()
12
13
  });
13
14
  setInterval(() => {
14
15
  devClient.sendMessage(JSON.stringify({
@@ -8,9 +8,5 @@ export declare function connectHMR(options: {
8
8
  path: string;
9
9
  timeout: number;
10
10
  log?: boolean;
11
- location: {
12
- protocol: string;
13
- hostname: string;
14
- port?: string;
15
- };
11
+ assetPublicPath: string;
16
12
  }): void;
@@ -2,7 +2,13 @@ let source;
2
2
  const eventCallbacks = [];
3
3
  let lastActivity = Date.now();
4
4
  let initDataBeforeWsOnline = [];
5
- function getSocketProtocol(protocol) {
5
+ function getSocketProtocol(assetPublicPath) {
6
+ let protocol = window.location.protocol;
7
+ try {
8
+ // assetPublicPath is a url
9
+ protocol = new URL(assetPublicPath).protocol;
10
+ }
11
+ catch (_) { }
6
12
  return protocol === 'http:' ? 'ws' : 'wss';
7
13
  }
8
14
  export function addMessageListener(cb) {
@@ -28,9 +34,15 @@ export function connectHMR(options) {
28
34
  function init() {
29
35
  if (source)
30
36
  source.close();
31
- let { protocol, hostname, port } = options.location;
32
- protocol = getSocketProtocol(protocol);
33
- let url = `${protocol}://${hostname}:${port}`;
37
+ const { hostname, port } = window.location;
38
+ const protocol = getSocketProtocol(options.assetPublicPath);
39
+ const assetPublicPath = options.assetPublicPath
40
+ .replace(/^\/+/, '')
41
+ .replace(/\/+$/, '');
42
+ let url = `${protocol}://${hostname}:${port}${assetPublicPath ? `/${assetPublicPath}` : ''}`;
43
+ if (assetPublicPath.startsWith('http')) {
44
+ url = `${protocol}://${assetPublicPath.split('://')[1]}`;
45
+ }
34
46
  source = new WebSocket(`${url}${options.path}`);
35
47
  source.onopen = handleOnline;
36
48
  source.onerror = handleDisconnect;
@@ -37,7 +37,10 @@ const plugin = (0, service_1.createPlugin)({
37
37
  name: 'virtual-raw-routes.js',
38
38
  virtual: true,
39
39
  content: () => __awaiter(void 0, void 0, void 0, function* () {
40
- const rawRoutes = yield (0, node_1.getRawRoutesFromDir)(paths.routesDir, conventionRoutes.exclude);
40
+ const rawRoutes = yield (0, node_1.getRawRoutesFromDir)(paths.routesDir, {
41
+ includes: conventionRoutes.include,
42
+ excludes: conventionRoutes.exclude
43
+ });
41
44
  return rawRoutes;
42
45
  }),
43
46
  dependencies: [paths.routesDir],
@@ -54,7 +57,10 @@ const plugin = (0, service_1.createPlugin)({
54
57
  routes = pageRoutes;
55
58
  }
56
59
  else {
57
- const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
60
+ const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(getContent(rawRoutes), {
61
+ includes: conventionRoutes.include,
62
+ excludes: conventionRoutes.exclude
63
+ });
58
64
  if (isBuildPhase) {
59
65
  warnings.forEach(warning => {
60
66
  logger_1.default.warn(warning.msg);
@@ -77,7 +83,10 @@ const plugin = (0, service_1.createPlugin)({
77
83
  const apiRoutesFile = defineFile({
78
84
  name: 'apiRoutes.js',
79
85
  content: () => __awaiter(void 0, void 0, void 0, function* () {
80
- const { routes: fsRoutes, warnings } = yield (0, node_1.getApiRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
86
+ const { routes: fsRoutes, warnings } = yield (0, node_1.getApiRoutes)(getContent(rawRoutes), {
87
+ includes: conventionRoutes.include,
88
+ excludes: conventionRoutes.exclude
89
+ });
81
90
  if (isBuildPhase) {
82
91
  warnings.forEach(warning => {
83
92
  logger_1.default.warn(warning);
@@ -94,7 +103,10 @@ const plugin = (0, service_1.createPlugin)({
94
103
  // Remove the 'middleware' file convention first, and deal with it in a future major update.
95
104
  // const { routes: _routes, warnings } = await getMiddlewareRoutes(
96
105
  // getContent(rawRoutes),
97
- // conventionRoutes.exclude
106
+ // {
107
+ // includes: conventionRoutes.include,
108
+ // excludes: conventionRoutes.exclude
109
+ // }
98
110
  // );
99
111
  // if (isBuildPhase) {
100
112
  // warnings.forEach(warning => {
@@ -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();
@@ -7,6 +7,7 @@ export interface PlatformWebCustomConfig {
7
7
  router: IRouterConfig;
8
8
  routes?: IPageRouteConfig[];
9
9
  conventionRoutes: {
10
+ include?: string[];
10
11
  exclude?: string[];
11
12
  };
12
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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.13",
76
- "@shuvi/hook": "1.0.13",
77
- "@shuvi/platform-shared": "1.0.13",
75
+ "@shuvi/error-overlay": "1.0.15",
76
+ "@shuvi/hook": "1.0.15",
77
+ "@shuvi/platform-shared": "1.0.15",
78
78
  "doura": "0.0.7",
79
79
  "react-doura": "0.0.7",
80
- "@shuvi/router": "1.0.13",
81
- "@shuvi/router-react": "1.0.13",
82
- "@shuvi/runtime": "1.0.13",
83
- "@shuvi/shared": "1.0.13",
84
- "@shuvi/toolpack": "1.0.13",
85
- "@shuvi/utils": "1.0.13",
80
+ "@shuvi/router": "1.0.15",
81
+ "@shuvi/router-react": "1.0.15",
82
+ "@shuvi/runtime": "1.0.15",
83
+ "@shuvi/shared": "1.0.15",
84
+ "@shuvi/toolpack": "1.0.15",
85
+ "@shuvi/utils": "1.0.15",
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.13"
101
+ "@shuvi/service": "1.0.15"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@shuvi/service": "workspace:*",