@modern-js/prod-server 1.0.5 → 1.0.6
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/CHANGELOG.md +11 -0
- package/dist/js/modern/libs/render/cache/index.js +2 -4
- package/dist/js/modern/libs/render/cache/spr.js +1 -2
- package/dist/js/modern/libs/render/cache/util.js +2 -5
- package/dist/js/modern/server/modern-server.js +1 -2
- package/dist/js/node/libs/render/cache/index.js +2 -4
- package/dist/js/node/libs/render/cache/spr.js +1 -2
- package/dist/js/node/libs/render/cache/util.js +2 -5
- package/dist/js/node/server/modern-server.js +1 -2
- package/dist/types/libs/proxy.d.ts +3 -3
- package/dist/types/type.d.ts +0 -7
- package/jest.config.js +0 -1
- package/package.json +5 -5
- package/src/libs/proxy.ts +3 -3
- package/src/libs/render/cache/index.ts +0 -2
- package/src/libs/render/cache/spr.ts +0 -1
- package/src/libs/render/cache/util.ts +0 -3
- package/src/server/modern-server.ts +2 -3
- package/src/type.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @modern-js/prod-server
|
|
2
2
|
|
|
3
|
+
## 1.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bebb39b6: chore: improve devDependencies and peerDependencies
|
|
8
|
+
- 132f7b53: feat: move config declarations to @modern-js/core
|
|
9
|
+
- Updated dependencies [bebb39b6]
|
|
10
|
+
- Updated dependencies [132f7b53]
|
|
11
|
+
- @modern-js/server-core@1.2.5
|
|
12
|
+
- @modern-js/utils@1.3.7
|
|
13
|
+
|
|
3
14
|
## 1.0.5
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -46,8 +46,7 @@ export default ((renderFn, ctx) => {
|
|
|
46
46
|
} else if (cacheFile.isStale) {
|
|
47
47
|
// if file is stale, request async
|
|
48
48
|
const render = withCoalescedInvoke(() => renderFn(context)).bind(null, namespaceHash('render', cacheFile.hash), []);
|
|
49
|
-
render()
|
|
50
|
-
.then(res => {
|
|
49
|
+
render().then(res => {
|
|
51
50
|
if (res.value && res.isOrigin) {
|
|
52
51
|
const {
|
|
53
52
|
cacheConfig
|
|
@@ -59,8 +58,7 @@ export default ((renderFn, ctx) => {
|
|
|
59
58
|
sprCache.del(cacheContext, cacheHash);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
})
|
|
63
|
-
.catch(e => {
|
|
61
|
+
}).catch(e => {
|
|
64
62
|
sprCache.del(cacheContext, cacheHash);
|
|
65
63
|
ctx.error(ERROR_DIGEST.ERENDER, e);
|
|
66
64
|
});
|
|
@@ -221,8 +221,7 @@ class CacheManager {
|
|
|
221
221
|
let data = this.cache.get(cacheKey);
|
|
222
222
|
|
|
223
223
|
if (!data) {
|
|
224
|
-
const caches = await createPageCaches(MAX_CACHE_EACH_REQ);
|
|
225
|
-
|
|
224
|
+
const caches = await createPageCaches(MAX_CACHE_EACH_REQ);
|
|
226
225
|
data = this.createCacheContent(cacheConfig, caches);
|
|
227
226
|
}
|
|
228
227
|
|
|
@@ -39,7 +39,6 @@ export function withCoalescedInvoke(func) {
|
|
|
39
39
|
const entry = globalInvokeCache.get(key);
|
|
40
40
|
|
|
41
41
|
if (entry) {
|
|
42
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
43
42
|
return entry.then(res => ({
|
|
44
43
|
isOrigin: false,
|
|
45
44
|
value: res.value
|
|
@@ -50,15 +49,13 @@ export function withCoalescedInvoke(func) {
|
|
|
50
49
|
return func(...args);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
const future = __wrapper()
|
|
54
|
-
.then(res => {
|
|
52
|
+
const future = __wrapper().then(res => {
|
|
55
53
|
globalInvokeCache.delete(key);
|
|
56
54
|
return {
|
|
57
55
|
isOrigin: true,
|
|
58
56
|
value: res
|
|
59
57
|
};
|
|
60
|
-
})
|
|
61
|
-
.catch(err => {
|
|
58
|
+
}).catch(err => {
|
|
62
59
|
globalInvokeCache.delete(key);
|
|
63
60
|
throw err;
|
|
64
61
|
});
|
|
@@ -56,8 +56,7 @@ var _default = (renderFn, ctx) => {
|
|
|
56
56
|
} else if (cacheFile.isStale) {
|
|
57
57
|
// if file is stale, request async
|
|
58
58
|
const render = (0, _util.withCoalescedInvoke)(() => renderFn(context)).bind(null, (0, _util.namespaceHash)('render', cacheFile.hash), []);
|
|
59
|
-
render()
|
|
60
|
-
.then(res => {
|
|
59
|
+
render().then(res => {
|
|
61
60
|
if (res.value && res.isOrigin) {
|
|
62
61
|
const {
|
|
63
62
|
cacheConfig
|
|
@@ -69,8 +68,7 @@ var _default = (renderFn, ctx) => {
|
|
|
69
68
|
sprCache.del(cacheContext, cacheHash);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
})
|
|
73
|
-
.catch(e => {
|
|
71
|
+
}).catch(e => {
|
|
74
72
|
sprCache.del(cacheContext, cacheHash);
|
|
75
73
|
ctx.error(_constants.ERROR_DIGEST.ERENDER, e);
|
|
76
74
|
});
|
|
@@ -237,8 +237,7 @@ class CacheManager {
|
|
|
237
237
|
let data = this.cache.get(cacheKey);
|
|
238
238
|
|
|
239
239
|
if (!data) {
|
|
240
|
-
const caches = await (0, _pageCaches.createPageCaches)(MAX_CACHE_EACH_REQ);
|
|
241
|
-
|
|
240
|
+
const caches = await (0, _pageCaches.createPageCaches)(MAX_CACHE_EACH_REQ);
|
|
242
241
|
data = this.createCacheContent(cacheConfig, caches);
|
|
243
242
|
}
|
|
244
243
|
|
|
@@ -64,7 +64,6 @@ function withCoalescedInvoke(func) {
|
|
|
64
64
|
const entry = globalInvokeCache.get(key);
|
|
65
65
|
|
|
66
66
|
if (entry) {
|
|
67
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
68
67
|
return entry.then(res => ({
|
|
69
68
|
isOrigin: false,
|
|
70
69
|
value: res.value
|
|
@@ -75,15 +74,13 @@ function withCoalescedInvoke(func) {
|
|
|
75
74
|
return func(...args);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
const future = __wrapper()
|
|
79
|
-
.then(res => {
|
|
77
|
+
const future = __wrapper().then(res => {
|
|
80
78
|
globalInvokeCache.delete(key);
|
|
81
79
|
return {
|
|
82
80
|
isOrigin: true,
|
|
83
81
|
value: res
|
|
84
82
|
};
|
|
85
|
-
})
|
|
86
|
-
.catch(err => {
|
|
83
|
+
}).catch(err => {
|
|
87
84
|
globalInvokeCache.delete(key);
|
|
88
85
|
throw err;
|
|
89
86
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextFunction,
|
|
1
|
+
import { NextFunction, BffProxyOptions } from '@modern-js/types';
|
|
2
2
|
import { ModernServerContext } from './context';
|
|
3
|
-
export type {
|
|
4
|
-
export declare const createProxyHandler: (proxyOptions?:
|
|
3
|
+
export type { BffProxyOptions };
|
|
4
|
+
export declare const createProxyHandler: (proxyOptions?: BffProxyOptions | undefined) => ((ctx: ModernServerContext, next: NextFunction) => Promise<void>)[] | null;
|
package/dist/types/type.d.ts
CHANGED
|
@@ -10,13 +10,6 @@ declare module 'http' {
|
|
|
10
10
|
metrics: Metrics;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
declare module '@modern-js/core' {
|
|
14
|
-
interface UserConfig {
|
|
15
|
-
bff?: {
|
|
16
|
-
proxy: Record<string, any>;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
13
|
declare type Plugin = string | [string, any] | ServerPlugin;
|
|
21
14
|
export declare type ModernServerOptions = {
|
|
22
15
|
pwd: string;
|
package/jest.config.js
CHANGED
|
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
|
|
|
2
2
|
|
|
3
3
|
/** @type {import('@jest/types').Config.InitialOptions} */
|
|
4
4
|
module.exports = {
|
|
5
|
-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
6
5
|
...sharedConfig,
|
|
7
6
|
testEnvironment: 'node',
|
|
8
7
|
rootDir: __dirname,
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.0.
|
|
14
|
+
"version": "1.0.6",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@modern-js/utils": "^1.3.
|
|
31
|
+
"@modern-js/utils": "^1.3.7",
|
|
32
32
|
"@babel/compat-data": "^7.17.0",
|
|
33
|
-
"@modern-js/server-core": "^1.2.
|
|
33
|
+
"@modern-js/server-core": "^1.2.5",
|
|
34
34
|
"axios": "^0.24.0",
|
|
35
35
|
"compare-versions": "^3.6.0",
|
|
36
36
|
"http-proxy-middleware": "^2.0.1",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"cookie": "^0.4.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@modern-js/types": "^1.3.
|
|
48
|
-
"@modern-js/core": "
|
|
47
|
+
"@modern-js/types": "^1.3.6",
|
|
48
|
+
"@modern-js/core": "1.6.1",
|
|
49
49
|
"@scripts/jest-config": "0.0.0",
|
|
50
50
|
"@scripts/build": "0.0.0",
|
|
51
51
|
"del-cli": "^4.0.1",
|
package/src/libs/proxy.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
2
|
-
import { NextFunction,
|
|
2
|
+
import { NextFunction, BffProxyOptions } from '@modern-js/types';
|
|
3
3
|
import { formatProxyOptions } from '@modern-js/utils';
|
|
4
4
|
import { ModernServerContext } from './context';
|
|
5
5
|
|
|
6
|
-
export type {
|
|
6
|
+
export type { BffProxyOptions };
|
|
7
7
|
|
|
8
|
-
export const createProxyHandler = (proxyOptions?:
|
|
8
|
+
export const createProxyHandler = (proxyOptions?: BffProxyOptions) => {
|
|
9
9
|
if (!proxyOptions) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
@@ -49,7 +49,6 @@ export default (renderFn: RenderFunction, ctx: ModernServerContext) => {
|
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
render()
|
|
52
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
53
52
|
.then(res => {
|
|
54
53
|
if (res.value && res.isOrigin) {
|
|
55
54
|
const { cacheConfig } = context;
|
|
@@ -60,7 +59,6 @@ export default (renderFn: RenderFunction, ctx: ModernServerContext) => {
|
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
})
|
|
63
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
64
62
|
.catch(e => {
|
|
65
63
|
sprCache.del(cacheContext, cacheHash);
|
|
66
64
|
ctx.error(ERROR_DIGEST.ERENDER, e);
|
|
@@ -236,7 +236,6 @@ class CacheManager {
|
|
|
236
236
|
let data = this.cache.get(cacheKey);
|
|
237
237
|
if (!data) {
|
|
238
238
|
const caches = await createPageCaches(MAX_CACHE_EACH_REQ);
|
|
239
|
-
// eslint-disable-next-line require-atomic-updates
|
|
240
239
|
data = this.createCacheContent(cacheConfig, caches);
|
|
241
240
|
}
|
|
242
241
|
|
|
@@ -58,7 +58,6 @@ export function withCoalescedInvoke<F extends (...args: any[]) => Promise<any>>(
|
|
|
58
58
|
return async function (key: string, args: Parameters<F>) {
|
|
59
59
|
const entry = globalInvokeCache.get(key);
|
|
60
60
|
if (entry) {
|
|
61
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
62
61
|
return entry.then(res => ({
|
|
63
62
|
isOrigin: false,
|
|
64
63
|
value: res.value as UnwrapPromise<ReturnType<F>>,
|
|
@@ -70,12 +69,10 @@ export function withCoalescedInvoke<F extends (...args: any[]) => Promise<any>>(
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
const future = __wrapper()
|
|
73
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
74
72
|
.then(res => {
|
|
75
73
|
globalInvokeCache.delete(key);
|
|
76
74
|
return { isOrigin: true, value: res as UnwrapPromise<ReturnType<F>> };
|
|
77
75
|
})
|
|
78
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
79
76
|
.catch(err => {
|
|
80
77
|
globalInvokeCache.delete(key);
|
|
81
78
|
throw err;
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
noop,
|
|
36
36
|
} from '../utils';
|
|
37
37
|
import * as reader from '../libs/render/reader';
|
|
38
|
-
import { createProxyHandler,
|
|
38
|
+
import { createProxyHandler, BffProxyOptions } from '../libs/proxy';
|
|
39
39
|
import { createContext, ModernServerContext } from '../libs/context';
|
|
40
40
|
import {
|
|
41
41
|
AGGRED_DIR,
|
|
@@ -144,7 +144,7 @@ export class ModernServer implements ModernServerInterface {
|
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
// proxy handler, each proxy has own handler
|
|
147
|
-
this.proxyHandler = createProxyHandler(conf.bff?.proxy as
|
|
147
|
+
this.proxyHandler = createProxyHandler(conf.bff?.proxy as BffProxyOptions);
|
|
148
148
|
if (this.proxyHandler) {
|
|
149
149
|
this.proxyHandler.forEach(handler => {
|
|
150
150
|
this.addHandler(handler);
|
|
@@ -547,7 +547,6 @@ export class ModernServer implements ModernServerInterface {
|
|
|
547
547
|
return next();
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
551
550
|
return handler(context, dispatch as NextFunction).catch(onError);
|
|
552
551
|
};
|
|
553
552
|
|
package/src/type.ts
CHANGED
|
@@ -12,14 +12,6 @@ declare module 'http' {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
declare module '@modern-js/core' {
|
|
16
|
-
interface UserConfig {
|
|
17
|
-
bff?: {
|
|
18
|
-
proxy: Record<string, any>;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
15
|
type Plugin = string | [string, any] | ServerPlugin;
|
|
24
16
|
export type ModernServerOptions = {
|
|
25
17
|
pwd: string;
|