@modern-js/runtime 1.3.4-alpha.0 → 1.4.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.
- package/CHANGELOG.md +77 -19
- package/dist/js/modern/cli/index.js +4 -4
- package/dist/js/modern/common.js +1 -0
- package/dist/js/modern/exports/model.js +2 -1
- package/dist/js/modern/exports/router.js +2 -1
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/exports/ssr.js +2 -1
- package/dist/js/modern/router/cli/index.js +106 -0
- package/dist/js/modern/router/index.js +2 -0
- package/dist/js/modern/router/runtime/DefaultNotFound.js +13 -0
- package/dist/js/modern/router/runtime/index.js +4 -0
- package/dist/js/modern/router/runtime/plugin.js +88 -0
- package/dist/js/modern/router/runtime/utils.js +108 -0
- package/dist/js/modern/ssr/cli/index.js +120 -0
- package/dist/js/modern/ssr/index.js +109 -0
- package/dist/js/modern/ssr/index.node.js +78 -0
- package/dist/js/modern/ssr/prefetch.js +58 -0
- package/dist/js/modern/ssr/react/index.js +2 -0
- package/dist/js/modern/ssr/react/nossr/index.js +13 -0
- package/dist/js/modern/ssr/react/prerender/index.js +104 -0
- package/dist/js/modern/ssr/react/prerender/type.js +0 -0
- package/dist/js/modern/ssr/react/prerender/util.js +99 -0
- package/dist/js/modern/ssr/serverRender/entry.js +179 -0
- package/dist/js/modern/ssr/serverRender/helmet.js +46 -0
- package/dist/js/modern/ssr/serverRender/index.js +29 -0
- package/dist/js/modern/ssr/serverRender/loadable.js +48 -0
- package/dist/js/modern/ssr/serverRender/measure.js +11 -0
- package/dist/js/modern/ssr/serverRender/reduce.js +7 -0
- package/dist/js/modern/ssr/serverRender/styledComponent.js +8 -0
- package/dist/js/modern/ssr/serverRender/template.js +90 -0
- package/dist/js/modern/ssr/serverRender/type.js +8 -0
- package/dist/js/modern/ssr/utils.js +51 -0
- package/dist/js/modern/state/cli/index.js +110 -0
- package/dist/js/modern/state/index.js +2 -0
- package/dist/js/modern/state/plugins.js +7 -0
- package/dist/js/modern/state/runtime/index.js +4 -0
- package/dist/js/modern/state/runtime/plugin.js +71 -0
- package/dist/js/modern/state/types.js +1 -0
- package/dist/js/node/cli/index.js +5 -5
- package/dist/js/node/common.js +10 -0
- package/dist/js/node/exports/model.js +19 -5
- package/dist/js/node/exports/router.js +19 -5
- package/dist/js/node/exports/server.js +0 -17
- package/dist/js/node/exports/ssr.js +19 -5
- package/dist/js/node/router/cli/index.js +122 -0
- package/dist/js/node/router/index.js +30 -0
- package/dist/js/node/router/runtime/DefaultNotFound.js +26 -0
- package/dist/js/node/router/runtime/index.js +39 -0
- package/dist/js/node/router/runtime/plugin.js +111 -0
- package/dist/js/node/router/runtime/utils.js +128 -0
- package/dist/js/node/ssr/cli/index.js +136 -0
- package/dist/js/node/ssr/index.js +138 -0
- package/dist/js/node/ssr/index.node.js +105 -0
- package/dist/js/node/ssr/prefetch.js +75 -0
- package/dist/js/node/ssr/react/index.js +21 -0
- package/dist/js/node/ssr/react/nossr/index.js +28 -0
- package/dist/js/node/ssr/react/prerender/index.js +121 -0
- package/dist/js/node/ssr/react/prerender/type.js +0 -0
- package/dist/js/node/ssr/react/prerender/util.js +119 -0
- package/dist/js/node/ssr/serverRender/entry.js +208 -0
- package/dist/js/node/ssr/serverRender/helmet.js +52 -0
- package/dist/js/node/ssr/serverRender/index.js +46 -0
- package/dist/js/node/ssr/serverRender/loadable.js +60 -0
- package/dist/js/node/ssr/serverRender/measure.js +20 -0
- package/dist/js/node/ssr/serverRender/reduce.js +14 -0
- package/dist/js/node/ssr/serverRender/styledComponent.js +18 -0
- package/dist/js/node/ssr/serverRender/template.js +103 -0
- package/dist/js/node/ssr/serverRender/type.js +15 -0
- package/dist/js/node/ssr/utils.js +65 -0
- package/dist/js/node/state/cli/index.js +127 -0
- package/dist/js/node/state/index.js +30 -0
- package/dist/js/node/state/plugins.js +35 -0
- package/dist/js/node/state/runtime/index.js +61 -0
- package/dist/js/node/state/runtime/plugin.js +101 -0
- package/dist/js/node/state/types.js +5 -0
- package/dist/js/treeshaking/cli/index.js +4 -4
- package/dist/js/treeshaking/common.js +3 -0
- package/dist/js/treeshaking/exports/model.js +2 -1
- package/dist/js/treeshaking/exports/router.js +2 -1
- package/dist/js/treeshaking/exports/server.js +0 -1
- package/dist/js/treeshaking/exports/ssr.js +2 -1
- package/dist/js/treeshaking/router/cli/index.js +100 -0
- package/dist/js/treeshaking/router/index.js +2 -0
- package/dist/js/treeshaking/router/runtime/DefaultNotFound.js +15 -0
- package/dist/js/treeshaking/router/runtime/index.js +4 -0
- package/dist/js/treeshaking/router/runtime/plugin.js +89 -0
- package/dist/js/treeshaking/router/runtime/utils.js +106 -0
- package/dist/js/treeshaking/ssr/cli/index.js +113 -0
- package/dist/js/treeshaking/ssr/index.js +129 -0
- package/dist/js/treeshaking/ssr/index.node.js +100 -0
- package/dist/js/treeshaking/ssr/prefetch.js +97 -0
- package/dist/js/treeshaking/ssr/react/index.js +2 -0
- package/dist/js/treeshaking/ssr/react/nossr/index.js +16 -0
- package/dist/js/treeshaking/ssr/react/prerender/index.js +119 -0
- package/dist/js/treeshaking/ssr/react/prerender/type.js +0 -0
- package/dist/js/treeshaking/ssr/react/prerender/util.js +115 -0
- package/dist/js/treeshaking/ssr/serverRender/entry.js +267 -0
- package/dist/js/treeshaking/ssr/serverRender/helmet.js +37 -0
- package/dist/js/treeshaking/ssr/serverRender/index.js +69 -0
- package/dist/js/treeshaking/ssr/serverRender/loadable.js +59 -0
- package/dist/js/treeshaking/ssr/serverRender/measure.js +17 -0
- package/dist/js/treeshaking/ssr/serverRender/reduce.js +11 -0
- package/dist/js/treeshaking/ssr/serverRender/styledComponent.js +8 -0
- package/dist/js/treeshaking/ssr/serverRender/template.js +111 -0
- package/dist/js/treeshaking/ssr/serverRender/type.js +8 -0
- package/dist/js/treeshaking/ssr/utils.js +53 -0
- package/dist/js/treeshaking/state/cli/index.js +100 -0
- package/dist/js/treeshaking/state/index.js +2 -0
- package/dist/js/treeshaking/state/plugins.js +13 -0
- package/dist/js/treeshaking/state/runtime/index.js +4 -0
- package/dist/js/treeshaking/state/runtime/plugin.js +63 -0
- package/dist/js/treeshaking/state/types.js +1 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/exports/model.d.ts +2 -1
- package/dist/types/exports/router.d.ts +2 -1
- package/dist/types/exports/server.d.ts +0 -1
- package/dist/types/exports/ssr.d.ts +2 -1
- package/dist/types/index.d.ts +8 -2
- package/dist/types/router/cli/index.d.ts +5 -0
- package/dist/types/router/index.d.ts +2 -0
- package/dist/types/router/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/router/runtime/index.d.ts +6 -0
- package/dist/types/router/runtime/plugin.d.ts +51 -0
- package/dist/types/router/runtime/utils.d.ts +6 -0
- package/dist/types/ssr/cli/index.d.ts +5 -0
- package/dist/types/ssr/index.d.ts +18 -0
- package/dist/types/ssr/index.node.d.ts +4 -0
- package/dist/types/ssr/prefetch.d.ts +13 -0
- package/dist/types/ssr/react/index.d.ts +2 -0
- package/dist/types/ssr/react/nossr/index.d.ts +2 -0
- package/dist/types/ssr/react/prerender/index.d.ts +1 -0
- package/dist/types/ssr/react/prerender/type.d.ts +29 -0
- package/dist/types/ssr/react/prerender/util.d.ts +6 -0
- package/dist/types/ssr/serverRender/entry.d.ts +20 -0
- package/dist/types/ssr/serverRender/helmet.d.ts +2 -0
- package/dist/types/ssr/serverRender/index.d.ts +8 -0
- package/dist/types/ssr/serverRender/loadable.d.ts +2 -0
- package/dist/types/ssr/serverRender/measure.d.ts +1 -0
- package/dist/types/ssr/serverRender/reduce.d.ts +3 -0
- package/dist/types/ssr/serverRender/styledComponent.d.ts +2 -0
- package/dist/types/ssr/serverRender/template.d.ts +14 -0
- package/dist/types/ssr/serverRender/type.d.ts +32 -0
- package/dist/types/ssr/utils.d.ts +8 -0
- package/dist/types/state/cli/index.d.ts +5 -0
- package/dist/types/state/index.d.ts +2 -0
- package/dist/types/state/plugins.d.ts +4 -0
- package/dist/types/state/runtime/index.d.ts +4 -0
- package/dist/types/state/runtime/plugin.d.ts +17 -0
- package/dist/types/state/types.d.ts +17 -0
- package/package.json +37 -20
- package/types/model.d.ts +1 -1
- package/types/state.d.ts +4 -0
- package/dist/js/modern/exports/request.js +0 -1
- package/dist/js/node/exports/request.js +0 -13
- package/dist/js/treeshaking/exports/request.js +0 -1
- package/dist/types/exports/request.d.ts +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
2
|
+
import { run } from '@modern-js/utils/ssr';
|
|
3
|
+
import { PreRender } from "../react/prerender";
|
|
4
|
+
import SSREntry from "./entry";
|
|
5
|
+
import { time } from "./measure";
|
|
6
|
+
export const render = async (ctx, _ = process.cwd(), App) => {
|
|
7
|
+
const {
|
|
8
|
+
ssrContext
|
|
9
|
+
} = ctx;
|
|
10
|
+
return run(ssrContext.request.headers, async () => {
|
|
11
|
+
const entry = new SSREntry({
|
|
12
|
+
ctx: ssrContext,
|
|
13
|
+
App
|
|
14
|
+
});
|
|
15
|
+
entry.metrics.emitCounter('app.visit.count', 1);
|
|
16
|
+
const end = time();
|
|
17
|
+
const html = await entry.renderToHtml(ctx);
|
|
18
|
+
const cost = end();
|
|
19
|
+
entry.logger.info('App Render Total cost = %d ms', cost);
|
|
20
|
+
entry.metrics.emitTimer('app.render.cost', cost);
|
|
21
|
+
const cacheConfig = PreRender.config();
|
|
22
|
+
|
|
23
|
+
if (cacheConfig) {
|
|
24
|
+
ctx.ssrContext.cacheConfig = cacheConfig;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return html;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { ChunkExtractor } from '@loadable/server';
|
|
3
|
+
|
|
4
|
+
function getLoadableScripts(extractor) {
|
|
5
|
+
const check = scripts => (scripts || '').includes('__LOADABLE_REQUIRED_CHUNKS___ext');
|
|
6
|
+
|
|
7
|
+
const scripts = extractor.getScriptTags();
|
|
8
|
+
|
|
9
|
+
if (!check(scripts)) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return scripts.split('</script>') // 前两个 script为 loadable 必须的 script
|
|
14
|
+
.slice(0, 2).map(i => `${i}</script>`).join('');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const toHtml = (jsx, renderer, next) => {
|
|
18
|
+
const {
|
|
19
|
+
loadableManifest,
|
|
20
|
+
result: {
|
|
21
|
+
chunksMap
|
|
22
|
+
}
|
|
23
|
+
} = renderer;
|
|
24
|
+
|
|
25
|
+
if (!loadableManifest || chunksMap.js) {
|
|
26
|
+
return next(jsx);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const extractor = new ChunkExtractor({
|
|
30
|
+
statsFile: loadableManifest,
|
|
31
|
+
entrypoints: [renderer.entryName]
|
|
32
|
+
});
|
|
33
|
+
const html = next(extractor.collectChunks(jsx));
|
|
34
|
+
const chunks = extractor.getChunkAssets(extractor.chunks);
|
|
35
|
+
chunksMap.js = (chunksMap.js || '') + getLoadableScripts(extractor);
|
|
36
|
+
|
|
37
|
+
for (const v of chunks) {
|
|
38
|
+
const fileType = path.extname(v.url).slice(1);
|
|
39
|
+
|
|
40
|
+
if (fileType === 'js') {
|
|
41
|
+
chunksMap[fileType] += `<script src="${v.url}"></script>`;
|
|
42
|
+
} else if (fileType === 'css') {
|
|
43
|
+
chunksMap[fileType] += `<link href="${v.url}" rel="stylesheet" />`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return html;
|
|
48
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ServerStyleSheet } from '@modern-js/runtime-core/styled';
|
|
2
|
+
export const toHtml = (jsx, renderer, next) => {
|
|
3
|
+
const sheet = new ServerStyleSheet();
|
|
4
|
+
const html = next(sheet.collectStyles(jsx));
|
|
5
|
+
const css = sheet.getStyleTags();
|
|
6
|
+
renderer.result.chunksMap.css += css;
|
|
7
|
+
return html;
|
|
8
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
const readFile = filepath => {
|
|
6
|
+
if (fs.existsSync(filepath)) {
|
|
7
|
+
return fs.readFileSync(filepath, 'utf-8');
|
|
8
|
+
} else {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const VARIABLE_REG_EXP = /<!--<\?([-=+])\s*(.*?)\s*\?>-->/;
|
|
14
|
+
const VARIABLE_SPLITTER = /(<!--<\?.*?\?>-->)/;
|
|
15
|
+
const ENCODE_HTML_RULES = {
|
|
16
|
+
'&': '&',
|
|
17
|
+
'<': '<',
|
|
18
|
+
'>': '>',
|
|
19
|
+
'"': '"',
|
|
20
|
+
"'": '''
|
|
21
|
+
};
|
|
22
|
+
const MATCH_HTML = /[&<>'"]/g;
|
|
23
|
+
|
|
24
|
+
function encodeChar(c) {
|
|
25
|
+
return ENCODE_HTML_RULES[c] || c;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function escape(str) {
|
|
29
|
+
return str.replace(MATCH_HTML, encodeChar);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Fragment {
|
|
33
|
+
constructor(template) {
|
|
34
|
+
_defineProperty(this, "isVariable", void 0);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "content", void 0);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "filters", void 0);
|
|
39
|
+
|
|
40
|
+
_defineProperty(this, "path", void 0);
|
|
41
|
+
|
|
42
|
+
const match = VARIABLE_REG_EXP.exec(template);
|
|
43
|
+
|
|
44
|
+
if (match) {
|
|
45
|
+
const [, filterFlag, content] = match;
|
|
46
|
+
this.isVariable = true;
|
|
47
|
+
this.content = content;
|
|
48
|
+
this.filters = [Fragment.filterMap[filterFlag]];
|
|
49
|
+
this.path = content.replace(/\[['"](.*?)['"]\]/g, '.$1').split('.');
|
|
50
|
+
} else {
|
|
51
|
+
this.isVariable = false;
|
|
52
|
+
this.content = template;
|
|
53
|
+
this.filters = [];
|
|
54
|
+
this.path = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getValue(data) {
|
|
59
|
+
if (this.isVariable) {
|
|
60
|
+
const value = this.path.reduce((p, n) => p != null ? p[n] : p, data);
|
|
61
|
+
return this.filters.reduce((p, n) => n(p), value != null ? value : '');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return this.content;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_defineProperty(Fragment, "filterMap", {
|
|
70
|
+
'=': escape,
|
|
71
|
+
'-': v => v
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const fragmentListMap = {};
|
|
75
|
+
export function toFragments(filename) {
|
|
76
|
+
if (fragmentListMap[filename]) {
|
|
77
|
+
return fragmentListMap[filename];
|
|
78
|
+
} // 未开启现代构建的项目无 -es6.html
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const template = readFile(filename);
|
|
82
|
+
|
|
83
|
+
if (!template) {
|
|
84
|
+
throw new Error(`Could not find template file: ${filename}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const fragmentList = template.split(VARIABLE_SPLITTER).filter(v => Boolean(v)).map(v => new Fragment(v));
|
|
88
|
+
fragmentListMap[filename] = fragmentList;
|
|
89
|
+
return fragmentList;
|
|
90
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// import { IncomingHttpHeaders } from 'http';
|
|
2
|
+
export let RenderLevel;
|
|
3
|
+
|
|
4
|
+
(function (RenderLevel) {
|
|
5
|
+
RenderLevel[RenderLevel["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
|
|
6
|
+
RenderLevel[RenderLevel["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
|
|
7
|
+
RenderLevel[RenderLevel["SERVER_RENDER"] = 2] = "SERVER_RENDER";
|
|
8
|
+
})(RenderLevel || (RenderLevel = {}));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
export const formatServer = request => {
|
|
8
|
+
const {
|
|
9
|
+
cookie = '',
|
|
10
|
+
'user-agent': userAgent = '',
|
|
11
|
+
referer
|
|
12
|
+
} = request.headers || {};
|
|
13
|
+
return _objectSpread({
|
|
14
|
+
cookie,
|
|
15
|
+
userAgent,
|
|
16
|
+
referer
|
|
17
|
+
}, request);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getQuery = () => window.location.search.substring(1).split('&').reduce((res, item) => {
|
|
21
|
+
const [key, value] = item.split('=');
|
|
22
|
+
res[key] = value;
|
|
23
|
+
return res;
|
|
24
|
+
}, {});
|
|
25
|
+
|
|
26
|
+
export const formatClient = request => {
|
|
27
|
+
return {
|
|
28
|
+
params: request.params || {},
|
|
29
|
+
host: request.host || location.host,
|
|
30
|
+
pathname: request.pathname || location.pathname,
|
|
31
|
+
headers: request.headers || {},
|
|
32
|
+
cookieMap: request.cookieMap || {},
|
|
33
|
+
cookie: request.headers.cookie || document.cookie,
|
|
34
|
+
userAgent: request.headers['user-agent'] || navigator.userAgent,
|
|
35
|
+
referer: request.referer || document.referrer,
|
|
36
|
+
query: request.query || getQuery(),
|
|
37
|
+
url: location.href
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const mockResponse = () => {
|
|
41
|
+
return {
|
|
42
|
+
setHeader() {
|
|
43
|
+
console.info('setHeader can only be used in the server side');
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
status() {
|
|
47
|
+
console.info('status can only be used in the server side');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
3
|
+
import "../types";
|
|
4
|
+
const PLUGIN_IDENTIFIER = 'state';
|
|
5
|
+
export default (() => ({
|
|
6
|
+
name: '@modern-js/plugin-state',
|
|
7
|
+
required: ['@modern-js/runtime'],
|
|
8
|
+
setup: api => {
|
|
9
|
+
const stateConfigMap = new Map();
|
|
10
|
+
let pluginsExportsUtils;
|
|
11
|
+
const stateModulePath = path.resolve(__dirname, '../');
|
|
12
|
+
return {
|
|
13
|
+
config() {
|
|
14
|
+
const appContext = api.useAppContext();
|
|
15
|
+
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'plugins');
|
|
16
|
+
return {
|
|
17
|
+
source: {
|
|
18
|
+
alias: {
|
|
19
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
modifyEntryImports({
|
|
26
|
+
entrypoint,
|
|
27
|
+
imports
|
|
28
|
+
}) {
|
|
29
|
+
var _getEntryOptions;
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
entryName
|
|
33
|
+
} = entrypoint;
|
|
34
|
+
const userConfig = api.useResolvedConfigContext();
|
|
35
|
+
const {
|
|
36
|
+
packageName
|
|
37
|
+
} = api.useAppContext();
|
|
38
|
+
const stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
39
|
+
stateConfigMap.set(entryName, stateConfig);
|
|
40
|
+
|
|
41
|
+
const getEnabledPlugins = () => {
|
|
42
|
+
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
43
|
+
return internalPlugins.filter(name => stateConfig[name] !== false);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (stateConfig) {
|
|
47
|
+
imports.push({
|
|
48
|
+
value: '@modern-js/runtime/plugins',
|
|
49
|
+
specifiers: [{
|
|
50
|
+
imported: PLUGIN_IDENTIFIER
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
53
|
+
imports.push({
|
|
54
|
+
value: '@modern-js/runtime/model',
|
|
55
|
+
specifiers: getEnabledPlugins().map(imported => ({
|
|
56
|
+
imported
|
|
57
|
+
})),
|
|
58
|
+
initialize: `
|
|
59
|
+
const createStatePlugins = (config) => {
|
|
60
|
+
const plugins = [];
|
|
61
|
+
|
|
62
|
+
${getEnabledPlugins().map(name => `
|
|
63
|
+
plugins.push(${name}(config['${name}']));
|
|
64
|
+
`).join('\n')}
|
|
65
|
+
|
|
66
|
+
return plugins;
|
|
67
|
+
}
|
|
68
|
+
`
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
entrypoint,
|
|
74
|
+
imports
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
modifyEntryRuntimePlugins({
|
|
79
|
+
entrypoint,
|
|
80
|
+
plugins
|
|
81
|
+
}) {
|
|
82
|
+
const stateOptions = stateConfigMap.get(entrypoint.entryName);
|
|
83
|
+
|
|
84
|
+
if (stateOptions) {
|
|
85
|
+
const isBoolean = typeof stateOptions === 'boolean';
|
|
86
|
+
let options = isBoolean ? '{}' : JSON.stringify(stateOptions);
|
|
87
|
+
options = `${options.substr(0, options.length - 1)}${isBoolean ? '' : ','}plugins: createStatePlugins(${JSON.stringify(stateConfigMap.get(entrypoint.entryName))})}`;
|
|
88
|
+
plugins.push({
|
|
89
|
+
name: PLUGIN_IDENTIFIER,
|
|
90
|
+
options
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
entrypoint,
|
|
96
|
+
plugins
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
validateSchema() {
|
|
101
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-state'];
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
addRuntimeExports() {
|
|
105
|
+
pluginsExportsUtils.addExport(`export { default as state } from '${stateModulePath}'`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { plugin as effectsPlugin } from '@modern-js-reduck/plugin-effects';
|
|
2
|
+
import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
|
|
3
|
+
import immerPlugin from '@modern-js-reduck/plugin-immutable';
|
|
4
|
+
export { default as devtools } from '@modern-js-reduck/plugin-devtools';
|
|
5
|
+
export const effects = () => effectsPlugin;
|
|
6
|
+
export const immer = () => immerPlugin;
|
|
7
|
+
export const autoActions = () => autoActionsPlugin;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import { useContext } from 'react';
|
|
8
|
+
import { RuntimeReactContext } from '@modern-js/runtime-core';
|
|
9
|
+
import { createStore } from '@modern-js-reduck/store';
|
|
10
|
+
import { Provider } from '@modern-js-reduck/react';
|
|
11
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
12
|
+
import { isBrowser } from "../../common";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
|
|
15
|
+
const state = config => ({
|
|
16
|
+
name: '@modern-js/plugin-state',
|
|
17
|
+
setup: () => {
|
|
18
|
+
return {
|
|
19
|
+
hoc({
|
|
20
|
+
App
|
|
21
|
+
}, next) {
|
|
22
|
+
const getStateApp = props => {
|
|
23
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
24
|
+
const context = useContext(RuntimeReactContext);
|
|
25
|
+
return /*#__PURE__*/_jsx(Provider, {
|
|
26
|
+
store: context.store,
|
|
27
|
+
config: config,
|
|
28
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return next({
|
|
33
|
+
App: hoistNonReactStatics(getStateApp, App)
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
init({
|
|
38
|
+
context
|
|
39
|
+
}, next) {
|
|
40
|
+
const storeConfig = config || {};
|
|
41
|
+
|
|
42
|
+
if (isBrowser()) {
|
|
43
|
+
var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
|
|
44
|
+
|
|
45
|
+
storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window$_SSR_DATA = _window._SSR_DATA) === null || _window$_SSR_DATA === void 0 ? void 0 : (_window$_SSR_DATA$dat = _window$_SSR_DATA.data) === null || _window$_SSR_DATA$dat === void 0 ? void 0 : _window$_SSR_DATA$dat.storeState) || {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
context.store = createStore(storeConfig);
|
|
49
|
+
next({
|
|
50
|
+
context
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
pickContext({
|
|
55
|
+
context,
|
|
56
|
+
pickedContext
|
|
57
|
+
}, next) {
|
|
58
|
+
return next({
|
|
59
|
+
context,
|
|
60
|
+
pickedContext: _objectSpread(_objectSpread({}, pickedContext), {}, {
|
|
61
|
+
store: context.store
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export default state;
|
|
71
|
+
export * from "../plugins";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,18 +9,18 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
-
var _cli = _interopRequireDefault(require("
|
|
12
|
+
var _cli = _interopRequireDefault(require("../state/cli"));
|
|
13
13
|
|
|
14
|
-
var _cli2 = _interopRequireDefault(require("
|
|
14
|
+
var _cli2 = _interopRequireDefault(require("../ssr/cli"));
|
|
15
15
|
|
|
16
|
-
var _cli3 = _interopRequireDefault(require("
|
|
16
|
+
var _cli3 = _interopRequireDefault(require("../router/cli"));
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
20
|
var _default = () => ({
|
|
21
21
|
name: '@modern-js/runtime',
|
|
22
22
|
post: ['@modern-js/plugin-router', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-design-token'],
|
|
23
|
-
usePlugins: [(0, _cli.default)(), (0,
|
|
23
|
+
usePlugins: [(0, _cli.default)(), (0, _cli3.default)(), (0, _cli2.default)()],
|
|
24
24
|
setup: api => {
|
|
25
25
|
let runtimeExportsUtils = {};
|
|
26
26
|
return {
|
|
@@ -58,7 +58,7 @@ var _default = () => ({
|
|
|
58
58
|
},
|
|
59
59
|
|
|
60
60
|
async beforeRestart() {
|
|
61
|
-
(0, _utils.cleanRequireCache)([require.resolve(
|
|
61
|
+
(0, _utils.cleanRequireCache)([require.resolve("../state/cli"), require.resolve("../router/cli"), require.resolve("../ssr/cli")]);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
};
|
|
@@ -3,16 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
state: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "state", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _state.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
|
|
7
|
-
var
|
|
16
|
+
var _state = _interopRequireWildcard(require("../state"));
|
|
8
17
|
|
|
9
|
-
Object.keys(
|
|
18
|
+
Object.keys(_state).forEach(function (key) {
|
|
10
19
|
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
21
|
+
if (key in exports && exports[key] === _state[key]) return;
|
|
12
22
|
Object.defineProperty(exports, key, {
|
|
13
23
|
enumerable: true,
|
|
14
24
|
get: function () {
|
|
15
|
-
return
|
|
25
|
+
return _state[key];
|
|
16
26
|
}
|
|
17
27
|
});
|
|
18
|
-
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -3,16 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
router: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "router", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _router.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
|
|
7
|
-
var
|
|
16
|
+
var _router = _interopRequireWildcard(require("../router"));
|
|
8
17
|
|
|
9
|
-
Object.keys(
|
|
18
|
+
Object.keys(_router).forEach(function (key) {
|
|
10
19
|
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
21
|
+
if (key in exports && exports[key] === _router[key]) return;
|
|
12
22
|
Object.defineProperty(exports, key, {
|
|
13
23
|
enumerable: true,
|
|
14
24
|
get: function () {
|
|
15
|
-
return
|
|
25
|
+
return _router[key];
|
|
16
26
|
}
|
|
17
27
|
});
|
|
18
|
-
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -3,25 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
hook: true
|
|
8
|
-
};
|
|
9
6
|
exports.hook = void 0;
|
|
10
7
|
|
|
11
|
-
var _bffRuntime = require("@modern-js/bff-runtime");
|
|
12
|
-
|
|
13
|
-
Object.keys(_bffRuntime).forEach(function (key) {
|
|
14
|
-
if (key === "default" || key === "__esModule") return;
|
|
15
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
16
|
-
if (key in exports && exports[key] === _bffRuntime[key]) return;
|
|
17
|
-
Object.defineProperty(exports, key, {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _bffRuntime[key];
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
8
|
const hook = attacher => attacher;
|
|
26
9
|
|
|
27
10
|
exports.hook = hook;
|
|
@@ -3,16 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
ssr: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "ssr", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _ssr.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
|
|
7
|
-
var
|
|
16
|
+
var _ssr = _interopRequireWildcard(require("../ssr"));
|
|
8
17
|
|
|
9
|
-
Object.keys(
|
|
18
|
+
Object.keys(_ssr).forEach(function (key) {
|
|
10
19
|
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
21
|
+
if (key in exports && exports[key] === _ssr[key]) return;
|
|
12
22
|
Object.defineProperty(exports, key, {
|
|
13
23
|
enumerable: true,
|
|
14
24
|
get: function () {
|
|
15
|
-
return
|
|
25
|
+
return _ssr[key];
|
|
16
26
|
}
|
|
17
27
|
});
|
|
18
|
-
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|