@modern-js/plugin-garfish 1.5.3 → 1.6.1

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 43bf23361: fix: 修复 bootstrap 函数第二个参数不支持传入 dom 节点
8
+ feat: '@modern-js/plugin-garfish' 支持 '@modern-js/runtime/garfish' scope 导出 garfish plugin 内置函数
9
+
10
+ ### Patch Changes
11
+
12
+ - 209d0a927: release: hot fix garfish error
13
+ - 996b91d9d: fix: optimize garfish plugin render function
14
+ - 43bf23361: fix(garfish-plugin): app static properties missing
15
+ - Updated dependencies [9377d2d9d]
16
+ - Updated dependencies [8c9ad1749]
17
+ - @modern-js/utils@1.7.7
18
+ - @modern-js/plugin-router@1.2.15
19
+
3
20
  ## 1.5.2
4
21
 
5
22
  ### Patch Changes
@@ -1,13 +1,8 @@
1
1
  export const makeProvider = () => `
2
2
  export const provider = function ({basename, dom}) {
3
3
  return {
4
- render({basename, dom, props}) {
5
- const SubApp = render({ props, basename });
6
- const node = dom.querySelector('#' + MOUNT_ID) || dom;
7
- const App = function () {
8
- return React.createElement(SubApp, props)
9
- };
10
- bootstrap(hoistNonReactStatics(App,SubApp), node);
4
+ render({basename, dom, props, appName}) {
5
+ render({ props, basename, dom, appName });
11
6
  },
12
7
  destroy({ dom }) {
13
8
  const node = dom.querySelector('#' + MOUNT_ID) || dom;
@@ -33,38 +28,60 @@ if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
33
28
  __GARFISH_EXPORTS__.provider = provider;
34
29
  }
35
30
 
36
- function renderInGarfish () {
37
- if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) return true;
38
- if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) return true;
39
- if (typeof __GARFISH_EXPORTS__ !== 'undefined') return true;
40
- return false;
31
+ function canContinueRender ({ dom, appName }) {
32
+ var renderByGarfish =
33
+ typeof __GARFISH_EXPORTS__ !== 'undefined'
34
+ || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);
35
+ let renderByProvider = dom || appName;
36
+ if (renderByGarfish) {
37
+ // Runs in the Garfish environment and is rendered by the provider
38
+ if (renderByProvider) {
39
+ return true;
40
+ } else {
41
+ // Runs in the Garfish environment and is not rendered by the provider
42
+ return false;
43
+ }
44
+ } else {
45
+ // Running in a non-Garfish environment
46
+ return true;
47
+ }
41
48
  }
42
- `;
43
- export const makeRenderFunction = code => {
44
- const inGarfishToRender = `
45
- const { basename, props } = arguments[0] || {};
46
- let renderByGarfish = renderInGarfish();
47
- const renderByProvider = !!basename;
48
-
49
- if (renderByGarfish && !renderByProvider) return null;
50
49
 
51
- function RouterPlugin (routerConfig) {
52
- if (basename) {
53
- routerConfig.basename = basename;
54
- if (routerConfig.supportHtml5History !== false) {
55
- if (!routerConfig.historyOptions) {
56
- routerConfig.historyOptions = {
57
- basename: basename
58
- };
59
- } else {
60
- routerConfig.historyOptions.basename = basename;
61
- }
50
+ function generateRouterPlugin (basename,routerConfig) {
51
+ if (basename) {
52
+ routerConfig.basename = basename;
53
+ if (routerConfig.supportHtml5History !== false) {
54
+ if (!routerConfig.historyOptions) {
55
+ routerConfig.historyOptions = {
56
+ basename: basename
57
+ };
58
+ } else {
59
+ routerConfig.historyOptions.basename = basename;
62
60
  }
63
61
  }
64
- return router(routerConfig);
65
62
  }
63
+ return router(routerConfig);
64
+ }
65
+
66
+ function generateAppWrapperAndRootDom ({ App, props, dom }) {
67
+ let AppWrapper = App;
68
+ if (props) {
69
+ AppWrapper = function () {
70
+ return React.createElement(App, props);
71
+ };
72
+ AppWrapper = hoistNonReactStatics(AppWrapper, App);
73
+ }
74
+ const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : MOUNT_ID;
75
+ return { AppWrapper, mountNode }
76
+ }
77
+ `;
78
+ export const makeRenderFunction = code => {
79
+ const inGarfishToRender = `
80
+ const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
81
+ if (!canContinueRender({ dom, appName })) return null;
82
+ let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
66
83
  `;
67
- return inGarfishToRender + code.replace(`router(`, `RouterPlugin(`).replace('IS_BROWSER', `IS_BROWSER && !renderByGarfish`);
84
+ return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace('(App)', `(AppWrapper)`).replace('MOUNT_ID', 'mountNode');
68
85
  }; // support legacy config
69
86
 
70
87
  export function getRuntimeConfig(config) {
@@ -10,13 +10,8 @@ exports.setRuntimeConfig = setRuntimeConfig;
10
10
  const makeProvider = () => `
11
11
  export const provider = function ({basename, dom}) {
12
12
  return {
13
- render({basename, dom, props}) {
14
- const SubApp = render({ props, basename });
15
- const node = dom.querySelector('#' + MOUNT_ID) || dom;
16
- const App = function () {
17
- return React.createElement(SubApp, props)
18
- };
19
- bootstrap(hoistNonReactStatics(App,SubApp), node);
13
+ render({basename, dom, props, appName}) {
14
+ render({ props, basename, dom, appName });
20
15
  },
21
16
  destroy({ dom }) {
22
17
  const node = dom.querySelector('#' + MOUNT_ID) || dom;
@@ -42,11 +37,51 @@ if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
42
37
  __GARFISH_EXPORTS__.provider = provider;
43
38
  }
44
39
 
45
- function renderInGarfish () {
46
- if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) return true;
47
- if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) return true;
48
- if (typeof __GARFISH_EXPORTS__ !== 'undefined') return true;
49
- return false;
40
+ function canContinueRender ({ dom, appName }) {
41
+ var renderByGarfish =
42
+ typeof __GARFISH_EXPORTS__ !== 'undefined'
43
+ || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);
44
+ let renderByProvider = dom || appName;
45
+ if (renderByGarfish) {
46
+ // Runs in the Garfish environment and is rendered by the provider
47
+ if (renderByProvider) {
48
+ return true;
49
+ } else {
50
+ // Runs in the Garfish environment and is not rendered by the provider
51
+ return false;
52
+ }
53
+ } else {
54
+ // Running in a non-Garfish environment
55
+ return true;
56
+ }
57
+ }
58
+
59
+ function generateRouterPlugin (basename,routerConfig) {
60
+ if (basename) {
61
+ routerConfig.basename = basename;
62
+ if (routerConfig.supportHtml5History !== false) {
63
+ if (!routerConfig.historyOptions) {
64
+ routerConfig.historyOptions = {
65
+ basename: basename
66
+ };
67
+ } else {
68
+ routerConfig.historyOptions.basename = basename;
69
+ }
70
+ }
71
+ }
72
+ return router(routerConfig);
73
+ }
74
+
75
+ function generateAppWrapperAndRootDom ({ App, props, dom }) {
76
+ let AppWrapper = App;
77
+ if (props) {
78
+ AppWrapper = function () {
79
+ return React.createElement(App, props);
80
+ };
81
+ AppWrapper = hoistNonReactStatics(AppWrapper, App);
82
+ }
83
+ const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : MOUNT_ID;
84
+ return { AppWrapper, mountNode }
50
85
  }
51
86
  `;
52
87
 
@@ -54,29 +89,11 @@ exports.makeProvider = makeProvider;
54
89
 
55
90
  const makeRenderFunction = code => {
56
91
  const inGarfishToRender = `
57
- const { basename, props } = arguments[0] || {};
58
- let renderByGarfish = renderInGarfish();
59
- const renderByProvider = !!basename;
60
-
61
- if (renderByGarfish && !renderByProvider) return null;
62
-
63
- function RouterPlugin (routerConfig) {
64
- if (basename) {
65
- routerConfig.basename = basename;
66
- if (routerConfig.supportHtml5History !== false) {
67
- if (!routerConfig.historyOptions) {
68
- routerConfig.historyOptions = {
69
- basename: basename
70
- };
71
- } else {
72
- routerConfig.historyOptions.basename = basename;
73
- }
74
- }
75
- }
76
- return router(routerConfig);
77
- }
92
+ const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
93
+ if (!canContinueRender({ dom, appName })) return null;
94
+ let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
78
95
  `;
79
- return inGarfishToRender + code.replace(`router(`, `RouterPlugin(`).replace('IS_BROWSER', `IS_BROWSER && !renderByGarfish`);
96
+ return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace('(App)', `(AppWrapper)`).replace('MOUNT_ID', 'mountNode');
80
97
  }; // support legacy config
81
98
 
82
99
 
@@ -1,9 +1,9 @@
1
1
  export var makeProvider = function makeProvider() {
2
- return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props}) {\n const SubApp = render({ props, basename });\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n const App = function () {\n return React.createElement(SubApp, props)\n };\n bootstrap(hoistNonReactStatics(App,SubApp), node);\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n unmountComponentAtNode(node);\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction renderInGarfish () {\n if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) return true;\n if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) return true;\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') return true;\n return false;\n}\n";
2
+ return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props, appName}) {\n render({ props, basename, dom, appName });\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n unmountComponentAtNode(node);\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction canContinueRender ({ dom, appName }) {\n var renderByGarfish =\n typeof __GARFISH_EXPORTS__ !== 'undefined'\n || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);\n let renderByProvider = dom || appName;\n if (renderByGarfish) {\n // Runs in the Garfish environment and is rendered by the provider\n if (renderByProvider) {\n return true;\n } else {\n // Runs in the Garfish environment and is not rendered by the provider\n return false;\n }\n } else {\n // Running in a non-Garfish environment\n return true;\n }\n}\n\nfunction generateRouterPlugin (basename,routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n}\n\nfunction generateAppWrapperAndRootDom ({ App, props, dom }) {\n let AppWrapper = App;\n if (props) {\n AppWrapper = function () {\n return React.createElement(App, props);\n };\n AppWrapper = hoistNonReactStatics(AppWrapper, App);\n }\n const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : MOUNT_ID;\n return { AppWrapper, mountNode }\n}\n";
3
3
  };
4
4
  export var makeRenderFunction = function makeRenderFunction(code) {
5
- var inGarfishToRender = "\n const { basename, props } = arguments[0] || {};\n let renderByGarfish = renderInGarfish();\n const renderByProvider = !!basename;\n\n if (renderByGarfish && !renderByProvider) return null;\n\n function RouterPlugin (routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n }\n ";
6
- return inGarfishToRender + code.replace("router(", "RouterPlugin(").replace('IS_BROWSER', "IS_BROWSER && !renderByGarfish");
5
+ var inGarfishToRender = "\n const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});\n ";
6
+ return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace('(App)', "(AppWrapper)").replace('MOUNT_ID', 'mountNode');
7
7
  }; // support legacy config
8
8
 
9
9
  export function getRuntimeConfig(config) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.5.3",
14
+ "version": "1.6.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/runtime/index.d.ts",
17
17
  "typesVersions": {
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@babel/runtime": "^7",
53
- "@modern-js/utils": "^1.7.5",
53
+ "@modern-js/utils": "^1.7.7",
54
54
  "@types/debug": "^4.1.7",
55
55
  "@types/react-loadable": "^5.5.6",
56
56
  "debug": "^4.3.2",
@@ -67,9 +67,9 @@
67
67
  }
68
68
  },
69
69
  "devDependencies": {
70
- "@modern-js/core": "1.11.2",
70
+ "@modern-js/core": "1.12.0",
71
71
  "@modern-js/plugin-router": "1.2.15",
72
- "@modern-js/runtime-core": "1.4.10",
72
+ "@modern-js/runtime-core": "1.5.0",
73
73
  "@modern-js/types": "1.5.4",
74
74
  "@scripts/build": "0.0.0",
75
75
  "@scripts/jest-config": "0.0.0",
package/type.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- declare module '@modern-js/runtime/garfish' {
1
+ declare module '@modern-js/runtime' {
2
2
  export const useModuleApp: typeof import('./dist/types/runtime').useModuleApp;
3
3
  export const useModuleApps: typeof import('./dist/types/runtime').useModuleApps;
4
- export const Garfish: typeof import('./dist/types/runtime').Garfish;
5
- export const garfish: typeof import('./dist/types/runtime').garfish;
6
4
  }