@umijs/preset-umi 4.0.37 → 4.0.39

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.
@@ -327,24 +327,18 @@ PORT=8888 umi dev
327
327
  memo.ip = import_utils.address.ip();
328
328
  return memo;
329
329
  });
330
- const restartServer = () => {
331
- var _a;
332
- import_utils.logger.info(`Restart dev server with port ${api.appData.port}...`);
333
- (0, import_watch.unwatch)();
334
- (_a = process.send) == null ? void 0 : _a.call(process, {
335
- type: "RESTART",
336
- payload: {
337
- port: api.appData.port
338
- }
339
- });
340
- };
341
- process.on("UMI_RESTART_SERVER", () => {
342
- restartServer();
343
- });
344
330
  api.registerMethod({
345
331
  name: "restartServer",
346
332
  fn() {
347
- restartServer();
333
+ var _a;
334
+ import_utils.logger.info(`Restart dev server with port ${api.appData.port}...`);
335
+ (0, import_watch.unwatch)();
336
+ (_a = process.send) == null ? void 0 : _a.call(process, {
337
+ type: "RESTART",
338
+ payload: {
339
+ port: api.appData.port
340
+ }
341
+ });
348
342
  }
349
343
  });
350
344
  api.modifyViteConfig((viteConfig) => {
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { IncomingMessage } from 'http';
3
4
  import type { IRoute } from '../../types';
4
5
  declare class UmiApiRequest {
@@ -482,7 +482,7 @@ export default function EmptyRoute() {
482
482
  }
483
483
  }
484
484
  exports.push("// plugins types.d.ts");
485
- for (const plugin of plugins) {
485
+ for (const plugin of allPlugins) {
486
486
  const file = (0, import_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, plugin, "types.d.ts"));
487
487
  if ((0, import_fs.existsSync)(file)) {
488
488
  const noSuffixFile = file.replace(/\.ts$/, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.37",
3
+ "version": "4.0.39",
4
4
  "description": "@umijs/preset-umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -25,19 +25,19 @@
25
25
  "test": "umi-scripts jest-turbo"
26
26
  },
27
27
  "dependencies": {
28
- "@umijs/ast": "4.0.37",
29
- "@umijs/babel-preset-umi": "4.0.37",
30
- "@umijs/bundler-utils": "4.0.37",
31
- "@umijs/bundler-vite": "4.0.37",
32
- "@umijs/bundler-webpack": "4.0.37",
33
- "@umijs/core": "4.0.37",
28
+ "@umijs/ast": "4.0.39",
29
+ "@umijs/babel-preset-umi": "4.0.39",
30
+ "@umijs/bundler-utils": "4.0.39",
31
+ "@umijs/bundler-vite": "4.0.39",
32
+ "@umijs/bundler-webpack": "4.0.39",
33
+ "@umijs/core": "4.0.39",
34
34
  "@umijs/did-you-know": "^1.0.0",
35
35
  "@umijs/history": "5.3.1",
36
- "@umijs/mfsu": "4.0.37",
37
- "@umijs/plugin-run": "4.0.37",
38
- "@umijs/renderer-react": "4.0.37",
39
- "@umijs/server": "4.0.37",
40
- "@umijs/utils": "4.0.37",
36
+ "@umijs/mfsu": "4.0.39",
37
+ "@umijs/plugin-run": "4.0.39",
38
+ "@umijs/renderer-react": "4.0.39",
39
+ "@umijs/server": "4.0.39",
40
+ "@umijs/utils": "4.0.39",
41
41
  "babel-plugin-dynamic-import-node": "2.3.3",
42
42
  "click-to-react-component": "^1.0.8",
43
43
  "core-js": "3.22.4",
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import { createHashHistory, createMemoryHistory, createBrowserHistory, History } from '{{{ historyPath }}}';
2
3
 
3
4
  let history: History;
@@ -18,10 +19,10 @@ export function createHistory(opts: any) {
18
19
  history = {
19
20
  ...h,
20
21
  push(to, state) {
21
- h.push(patchTo(to, h), state);
22
+ h.push(patchTo(to, h, basename), state);
22
23
  },
23
24
  replace(to, state) {
24
- h.replace(patchTo(to, h), state);
25
+ h.replace(patchTo(to, h, basename), state);
25
26
  },
26
27
  get location() {
27
28
  return h.location;
@@ -38,16 +39,20 @@ export function createHistory(opts: any) {
38
39
  // Refs:
39
40
  // https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L484
40
41
  // https://github.com/remix-run/history/blob/dev/docs/api-reference.md#to
41
- function patchTo(to: any, h: History) {
42
+ function patchTo(to: any, h: History, basename: string) {
42
43
  if (typeof to === 'string') {
43
- return `${stripLastSlash(basename)}${to}`;
44
+ if (isAbsolute(to)) {
45
+ return `${stripLastSlash(basename)}${to}`;
46
+ } else {
47
+ return `${stripLastSlash(basename)}${resolvePath(to, h, basename)}`;
48
+ }
44
49
  } else if (typeof to === 'object') {
45
50
 
46
51
  const currentPathname = h.location.pathname;
47
52
 
48
53
  return {
49
54
  ...to,
50
- pathname: to.pathname? `${stripLastSlash(basename)}${to.pathname}` : currentPathname,
55
+ pathname: to.pathname ? `${stripLastSlash(basename)}${resolvePath(to.pathname, h, basename)}` : currentPathname,
51
56
  };
52
57
  } else {
53
58
  throw new Error(`Unexpected to: ${to}`);
@@ -57,5 +62,87 @@ function patchTo(to: any, h: History) {
57
62
  function stripLastSlash(path) {
58
63
  return path.slice(-1) === '/' ? path.slice(0, -1) : path;
59
64
  }
65
+ function resolvePath(pathname: string, h: History, basename:string ){
66
+ let fromPath= h.location.pathname
67
+
68
+ if(basename ==='/' || basename ===''){
69
+ }else{
70
+ fromPath = fromPath.replace(new RegExp(`^${stripLastSlash(basename)}`), '') || '/'
71
+ }
72
+
73
+ return resolvePathname(pathname, fromPath)
74
+ }
75
+
76
+ function isAbsolute(pathname:string): boolean {
77
+ return pathname.charAt(0) === '/';
78
+ }
79
+
80
+ // About 1.5x faster than the two-arg version of Array#splice()
81
+ function spliceOne(list: any[], index:number) {
82
+ for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
83
+ list[i] = list[k];
84
+ }
85
+
86
+ list.pop();
87
+ }
88
+
89
+ function resolvePathname(to: string, from :string = ''): string {
90
+
91
+ const toParts = (to && to.split('/')) || [];
92
+ let fromParts = (from && from.split('/')) || [];
93
+
94
+ const isToAbs = to && isAbsolute(to);
95
+ const isFromAbs = from && isAbsolute(from);
96
+ const mustEndAbs = isToAbs || isFromAbs;
97
+
98
+ if (to && isAbsolute(to)) {
99
+ // to is absolute
100
+ fromParts = toParts;
101
+ } else if (toParts.length) {
102
+ // to is relative, drop the filename
103
+ fromParts.pop();
104
+ fromParts = fromParts.concat(toParts);
105
+ }
106
+
107
+ if (!fromParts.length) return '/';
108
+
109
+ let hasTrailingSlash;
110
+ if (fromParts.length) {
111
+ const last = fromParts[fromParts.length - 1];
112
+ hasTrailingSlash = last === '.' || last === '..' || last === '';
113
+ } else {
114
+ hasTrailingSlash = false;
115
+ }
116
+
117
+ let up = 0;
118
+ for (let i = fromParts.length; i >= 0; i--) {
119
+ const part = fromParts[i];
120
+
121
+ if (part === '.') {
122
+ spliceOne(fromParts, i);
123
+ } else if (part === '..') {
124
+ spliceOne(fromParts, i);
125
+ up++;
126
+ } else if (up) {
127
+ spliceOne(fromParts, i);
128
+ up--;
129
+ }
130
+ }
131
+
132
+ if (!mustEndAbs) for (; up--; up) fromParts.unshift('..');
133
+
134
+ if (
135
+ mustEndAbs &&
136
+ fromParts[0] !== '' &&
137
+ (!fromParts[0] || !isAbsolute(fromParts[0]))
138
+ )
139
+ fromParts.unshift('');
140
+
141
+ let result = fromParts.join('/');
142
+
143
+ if (hasTrailingSlash && result.substr(-1) !== '/') result += '/';
144
+
145
+ return result;
146
+ }
60
147
 
61
148
  export { history };