@10yun/open-sdk 0.3.124 → 0.3.125

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.
@@ -1,122 +1,155 @@
1
- /*!
2
- * vite-plugin-qiankun.js v1.0.14
3
- * (c) 2021-2022 Teng Mao Qing
4
- * Released under the MIT License.
5
- */
6
- // import cheerio from 'cheerio';
7
- import * as cheerio from 'cheerio';
8
-
9
- /*! *****************************************************************************
10
- Copyright (c) Microsoft Corporation.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
- PERFORMANCE OF THIS SOFTWARE.
22
- ***************************************************************************** */
23
-
24
- function __spreadArray(to, from) {
25
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
26
- return to;
27
- }
28
-
29
- var createQiankunHelper = function (qiankunName) {
30
- return (
31
- "\n const createDeffer = (hookName) => {\n const d = new Promise((resolve, reject) => {\n window.proxy && (window.proxy[`vite${hookName}`] = resolve)\n })\n return props => d.then(fn => fn(props));\n }\n const bootstrap = createDeffer('bootstrap');\n const mount = createDeffer('mount');\n const unmount = createDeffer('unmount');\n const update = createDeffer('update');\n\n ;(global => {\n global.qiankunName = '" +
32
- qiankunName +
33
- "';\n global['" +
34
- qiankunName +
35
- "'] = {\n bootstrap,\n mount,\n unmount,\n update\n };\n })(window);\n"
36
- );
37
- };
38
- var createImportFinallyResolve = function (qiankunName) {
39
- return (
40
- "\n const qiankunLifeCycle = window.moudleQiankunAppLifeCycles && window.moudleQiankunAppLifeCycles['" +
41
- qiankunName +
42
- "'];\n if (qiankunLifeCycle) {\n window.proxy.vitemount((props) => qiankunLifeCycle.mount(props));\n window.proxy.viteunmount((props) => qiankunLifeCycle.unmount(props));\n window.proxy.vitebootstrap(() => qiankunLifeCycle.bootstrap());\n window.proxy.viteupdate((props) => qiankunLifeCycle.update(props));\n }\n "
43
- );
44
- };
45
- var htmlPlugin = function (qiankunName, microOption) {
46
- if (microOption === void 0) {
47
- microOption = {};
48
- }
49
- var isProduction;
50
- var base = '';
51
- var module2DynamicImport = function ($, scriptTag) {
52
- if (!scriptTag) {
53
- return;
54
- }
55
- var script$ = $(scriptTag);
56
- var moduleSrc = script$.attr('src');
57
- var appendBase = '';
58
- if (microOption.useDevMode && !isProduction) {
59
- appendBase = "(window.proxy ? (window.proxy.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ + '..') : '') + ";
60
- }
61
- script$.removeAttr('src');
62
- script$.removeAttr('type');
63
- script$.html('import(' + appendBase + "'" + moduleSrc + "')");
64
- return script$;
65
- };
66
- return {
67
- name: 'qiankun-html-transform',
68
- configResolved: function (config) {
69
- isProduction = config.command === 'build' || config.isProduction;
70
- base = config.base;
71
- },
72
- configureServer: function (server) {
73
- return function () {
74
- server.middlewares.use(function (req, res, next) {
75
- if (isProduction || !microOption.useDevMode) {
76
- next();
77
- return;
78
- }
79
- var end = res.end.bind(res);
80
- res.end = function () {
81
- var args = [];
82
- for (var _i = 0; _i < arguments.length; _i++) {
83
- args[_i] = arguments[_i];
84
- }
85
- var htmlStr = args[0],
86
- rest = args.slice(1);
87
- if (typeof htmlStr === 'string') {
88
- var $ = cheerio.load(htmlStr);
89
- module2DynamicImport($, $('script[src=' + base + '@vite/client]').get(0));
90
- htmlStr = $.html();
91
- }
92
- end.apply(void 0, __spreadArray([htmlStr], rest));
93
- };
94
- next();
95
- });
96
- };
97
- },
98
- transformIndexHtml: function (html) {
99
- var $ = cheerio.load(html);
100
- var moduleTags = $('body script[type=module], head script[crossorigin=""]');
101
- if (!moduleTags || !moduleTags.length) {
102
- return;
103
- }
104
- var len = moduleTags.length;
105
- moduleTags.each(function (i, moduleTag) {
106
- var script$ = module2DynamicImport($, moduleTag);
107
- if (len - 1 === i) {
108
- script$ === null || script$ === void 0
109
- ? void 0
110
- : script$.html(
111
- script$.html() + '.finally(() => {\n ' + createImportFinallyResolve(qiankunName) + '\n })'
112
- );
113
- }
114
- });
115
- $('body').append('<script>' + createQiankunHelper(qiankunName) + '</script>');
116
- var output = $.html();
117
- return output;
118
- }
119
- };
120
- };
121
-
122
- export default htmlPlugin;
1
+ /*!
2
+ * vite-plugin-qiankun.js v1.0.14 (no cheerio, equivalent)
3
+ * (c) 2021-2022 Teng Mao Qing
4
+ * MIT License
5
+ */
6
+
7
+ function __spreadArray(to, from) {
8
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
9
+ return to;
10
+ }
11
+
12
+ /* ---------------------------------- */
13
+ /* qiankun helpers(原样保留) */
14
+ /* ---------------------------------- */
15
+
16
+ var createQiankunHelper = function (qiankunName) {
17
+ return (
18
+ "\n const createDeffer = (hookName) => {\n const d = new Promise((resolve, reject) => {\n window.proxy && (window.proxy[`vite${hookName}`] = resolve)\n })\n return props => d.then(fn => fn(props));\n }\n const bootstrap = createDeffer('bootstrap');\n const mount = createDeffer('mount');\n const unmount = createDeffer('unmount');\n const update = createDeffer('update');\n\n ;(global => {\n global.qiankunName = '" +
19
+ qiankunName +
20
+ "';\n global['" +
21
+ qiankunName +
22
+ "'] = {\n bootstrap,\n mount,\n unmount,\n update\n };\n })(window);\n"
23
+ );
24
+ };
25
+
26
+ var createImportFinallyResolve = function (qiankunName) {
27
+ return (
28
+ "\n const qiankunLifeCycle = window.moudleQiankunAppLifeCycles && window.moudleQiankunAppLifeCycles['" +
29
+ qiankunName +
30
+ "'];\n if (qiankunLifeCycle) {\n window.proxy.vitemount((props) => qiankunLifeCycle.mount(props));\n window.proxy.viteunmount((props) => qiankunLifeCycle.unmount(props));\n window.proxy.vitebootstrap(() => qiankunLifeCycle.bootstrap());\n window.proxy.viteupdate((props) => qiankunLifeCycle.update(props));\n }\n "
31
+ );
32
+ };
33
+
34
+ /* ---------------------------------- */
35
+ /* 等价 DOM 操作(替代 cheerio) */
36
+ /* ---------------------------------- */
37
+
38
+ function replaceScriptTag(html, matcher, replacer) {
39
+ var match;
40
+ var result = html;
41
+ while ((match = matcher.exec(html))) {
42
+ var original = match[0];
43
+ var replaced = replacer(match);
44
+ result = result.replace(original, replaced);
45
+ }
46
+ return result;
47
+ }
48
+
49
+ function transformSingleScript(scriptHtml, appendBase) {
50
+ var srcMatch = scriptHtml.match(/src=["']([^"']+)["']/);
51
+ if (!srcMatch) return scriptHtml;
52
+
53
+ var src = srcMatch[1];
54
+ var importCode = 'import(' + appendBase + "'" + src + "')";
55
+
56
+ return '<script>' + importCode + '</script>';
57
+ }
58
+
59
+ /* ---------------------------------- */
60
+ /* 主插件(逻辑严格对齐原版) */
61
+ /* ---------------------------------- */
62
+
63
+ var htmlPlugin = function (qiankunName, microOption) {
64
+ if (microOption === void 0) microOption = {};
65
+
66
+ var isProduction;
67
+ var base = '';
68
+
69
+ return {
70
+ name: 'qiankun-html-transform',
71
+ configResolved: function (config) {
72
+ isProduction = config.command === 'build' || config.isProduction;
73
+ base = config.base;
74
+ },
75
+ configureServer: function (server) {
76
+ return function () {
77
+ server.middlewares.use(function (req, res, next) {
78
+ if (isProduction || !microOption.useDevMode) {
79
+ next();
80
+ return;
81
+ }
82
+ var end = res.end.bind(res);
83
+ res.end = function () {
84
+ var args = [];
85
+ for (var _i = 0; _i < arguments.length; _i++) {
86
+ args[_i] = arguments[_i];
87
+ }
88
+
89
+ var htmlStr = args[0];
90
+ var rest = args.slice(1);
91
+
92
+ if (typeof htmlStr === 'string') {
93
+ var appendBase = "(window.proxy ? (window.proxy.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ + '..') : '') + ";
94
+
95
+ var viteClientRE = new RegExp('<script[^>]*src=["\']' + base + '@vite/client["\'][^>]*></script>');
96
+
97
+ htmlStr = htmlStr.replace(viteClientRE, function (script) {
98
+ return transformSingleScript(script, appendBase);
99
+ });
100
+ }
101
+
102
+ end.apply(void 0, __spreadArray([htmlStr], rest));
103
+ };
104
+
105
+ next();
106
+ });
107
+ };
108
+ },
109
+
110
+ transformIndexHtml: function (html) {
111
+ var appendBase =
112
+ microOption.useDevMode && !isProduction
113
+ ? "(window.proxy ? (window.proxy.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ + '..') : '') + "
114
+ : '';
115
+
116
+ var scripts = [];
117
+
118
+ var scriptRE = /<(script)([^>]*?)>([\s\S]*?)<\/script>/gi;
119
+
120
+ var match;
121
+ while ((match = scriptRE.exec(html))) {
122
+ var full = match[0];
123
+ var attrs = match[2];
124
+
125
+ var isModule = /type=["']module["']/.test(attrs) || /crossorigin=["']["']/.test(attrs);
126
+
127
+ if (isModule && /src=["']/.test(attrs)) {
128
+ scripts.push({
129
+ original: full,
130
+ transformed: transformSingleScript(full, appendBase)
131
+ });
132
+ }
133
+ }
134
+
135
+ if (!scripts.length) return html;
136
+
137
+ scripts.forEach(function (item, index) {
138
+ var code = item.transformed;
139
+ if (index === scripts.length - 1) {
140
+ code = code.replace(
141
+ '</script>',
142
+ '.finally(() => {\n ' + createImportFinallyResolve(qiankunName) + '\n })</script>'
143
+ );
144
+ }
145
+ html = html.replace(item.original, code);
146
+ });
147
+
148
+ html = html.replace('</body>', '<script>' + createQiankunHelper(qiankunName) + '</script></body>');
149
+
150
+ return html;
151
+ }
152
+ };
153
+ };
154
+
155
+ export default htmlPlugin;
@@ -0,0 +1,3 @@
1
+ index-old 为原先的。
2
+
3
+ index 为 去除 cheerio
@@ -2,24 +2,7 @@ import { loadEnv } from 'vite';
2
2
  import path from 'path';
3
3
  import qiankun from './vite-plugin-qiankun/es/index.js';
4
4
  export { qiankunWindow } from './vite-plugin-qiankun/es/helper.js';
5
- // import { encryptStrEncode } from './common/encipher.js';
6
- import { buildRbac } from './common/buildRbac.js';
7
- /**
8
- * 使用 plugins: [shiyunInjectHtml({ key: 'value' })]
9
- * @param {*} data
10
- * @returns
11
- */
12
- export function shiyunInjectHtml(data) {
13
- return {
14
- name: 'vite-plugin-shiyun-inject-html',
15
- transformIndexHtml(html) {
16
- Object.keys(data).forEach((key) => {
17
- html = html.replace(`<!--%${key}%-->`, data[key]);
18
- });
19
- return html;
20
- }
21
- };
22
- }
5
+ import { shiyunReleaseCommon } from './build/plugin-common.js';
23
6
  /**
24
7
  *
25
8
  * @param {*} params
@@ -33,143 +16,18 @@ export function shiyunRelease(params = { menu_arr: [] }) {
33
16
  // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
34
17
  const ENV_ARR_VITE = loadEnv(ENV_MODE, PROCESS_CWD, 'VITE_');
35
18
  const ENV_ARR_CICD = loadEnv(ENV_MODE, PROCESS_CWD, 'CICD_');
36
- const { CICD_BUILD_DOMAIN_SCHEME, CICD_BUILD_DOMAIN_ALONE, CICD_BUILD_VERS_FULL, CICD_BUILD_VERS_CODE } = ENV_ARR_CICD;
37
- // proPublicPath = `${}/`;
38
- const {
39
- VITE_SY_PRODUCT_PORT,
40
- VITE_SY_PRODUCT_SIGN,
41
- VITE_SY_API_DEV,
42
- VITE_SY_APP_PROJECT_SIGN,
43
- VITE_SY_APP_CONNECT_ID,
44
- VITE_SY_APP_CONNECT_ROLE
45
- } = ENV_ARR_VITE;
46
- const LAST_PRODUCT_SIGN = VITE_SY_PRODUCT_SIGN || BASENAME_SIGN;
47
- const LAST_BUILD_DOMAIN = CICD_BUILD_DOMAIN_SCHEME || '';
48
- const LAST_BUILD_VERS_SIGN = CICD_BUILD_DOMAIN_ALONE == 'on' ? '' : LAST_PRODUCT_SIGN;
49
- const LAST_BUILD_VERS_FULL = CICD_BUILD_VERS_FULL || '';
50
- if (ENV_MODE == 'production') {
51
- buildRbac(params.menu_arr, PROCESS_CWD, {
52
- RBAC_BASE_SIGN: LAST_PRODUCT_SIGN
53
- });
54
- }
55
-
56
- // const sign_flag = `${VITE_SY_APP_PROJECT_SIGN}---${VITE_SY_APP_CONNECT_ID}---${VITE_SY_APP_CONNECT_ROLE}`;
57
- // const sign_param = encryptStrEncode(sign_flag);
58
- // const get_api = `${VITE_SY_API_DEV}/base.base_load/common`;
59
-
60
19
  /**
61
20
  * useDevMode 开启时与热更新插件冲突
62
21
  * useDevMode = true 时不开启热更新
63
22
  * 如果是在主应用中加载子应用vite,必须打开这个,否则vite加载不成功, 单独运行没影响
64
23
  */
24
+ console.log('--asd');
65
25
  const useDevMode = true;
66
-
67
26
  return [
68
27
  // 微应用名字,与主应用注册的微应用名字保持一致
69
- qiankun(LAST_PRODUCT_SIGN, {
28
+ qiankun(ENV_ARR_VITE.VITE_SY_PRODUCT_SIGN || BASENAME_SIGN, {
70
29
  useDevMode
71
30
  }),
72
- {
73
- name: 'vite-plugin-shiyun-release',
74
- // apply: 'build', // 'build' 或 'serve' ,在什么情况下使用
75
- config: (config, { mode, command }) => {
76
- let basePath = '/';
77
- if (mode == 'production') {
78
- let buildPath = `${LAST_BUILD_DOMAIN}/${LAST_BUILD_VERS_SIGN}/${LAST_BUILD_VERS_FULL}/`;
79
- /**
80
- * 使用正则表达式进行过滤
81
- * 过滤除了 https:// 和 http:// 以外的 // 和 ///
82
- */
83
- buildPath = buildPath.replace(/\/(undefined\/)+/g, '/');
84
- buildPath = buildPath.replace(/([^:]\/)\/+/g, '$1');
85
- basePath = buildPath;
86
- }
87
- return {
88
- base: basePath,
89
- server: {
90
- port: VITE_SY_PRODUCT_PORT
91
- },
92
- esbuild: {
93
- drop: ['console', 'debugger']
94
- },
95
- optimizeDeps: {
96
- esbuildOptions: {
97
- target: 'esnext'
98
- },
99
- // 确保 open-sdk 包在依赖优化中
100
- // include: ['@10yun/open-sdk']
101
- exclude: ['@10yun/open-sdk/uncompiled']
102
- /**
103
- * TODO
104
- * 确保 open-sdk 包不在依赖优化中,不然造成修改 【项目@/下的相关文件】,vite无法及时热更新响应
105
- * 添加下列 exclude 会爆 dayjs 问题
106
- */
107
- // exclude: ['@10yun/open-sdk']
108
- },
109
- build: {
110
- // target: ['chrome89', 'edge89', 'firefox89', 'safari15', 'chrome87', 'edge88', 'es2020', 'firefox78', 'safari14'],
111
- target: 'esnext',
112
- sourcemap: false,
113
- chunkSizeWarningLimit: 2000
114
- },
115
- output: {
116
- // 把子应用打包成 umd 库格式
117
- // library: `${子应用名}-[name]`,
118
- // libraryTarget: 'umd',
119
- // jsonpFunction: `webpackJsonp_${子应用名}`
120
- library: `${BASENAME_SIGN}-[name]`,
121
- libraryTarget: 'umd',
122
- jsonpFunction: `webpackJsonp_${BASENAME_SIGN}`
123
- }
124
- };
125
- },
126
- configResolved(config) {
127
- // console.log('---111---');
128
- // console.log('configResolved', config.base, config.mode, config.command, config.esbuild);
129
- // config.base = 'asdad';
130
- // isProduction = config.command === 'build' || config.isProduction;
131
- // base = config.base;
132
- },
133
- configureServer(server) {
134
- // 在开发服务器配置时可以执行的逻辑
135
- // console.log('开发的时候', server);
136
- },
137
- transformIndexHtml(html) {
138
- if (ENV_MODE == 'development') {
139
- // 删除带 mode="pro" 的标签
140
- html = html.replace(/<(script)\b[^>]*?mode="pro"[^>]*>[\s\S]*?<\/script>/gi, '');
141
- html = html.replace(/<(link|script)\b[^>]*?mode="pro"[^>]*>/gi, '');
142
- }
143
- if (ENV_MODE == 'production') {
144
- // 删除带 mode="dev" 的标签
145
- if (CICD_BUILD_DOMAIN_ALONE != 'on') {
146
- html = html.replace(/<(script)\b[^>]*?mode="dev"[^>]*>[\s\S]*?<\/script>/gi, '');
147
- html = html.replace(/<(link|script)\b[^>]*?mode="dev"[^>]*>/gi, '');
148
- }
149
- }
150
- /**
151
- * 新增十云相关信息
152
- */
153
- const copyrightInfo = 'saas软件,软件开发,软件制定,公众号,小程序,app,十云,十云科技,福州十云,ctocode,10yun.com';
154
- let shiyunInfo = `<meta name="description" content="${copyrightInfo}" />\n`;
155
- shiyunInfo += `<meta name="keywords" content="${copyrightInfo}" />\n`;
156
- shiyunInfo += `<meta name="author" content="十云_ctocode_技术支持_https://www.10yun.com" />\n`;
157
- if (CICD_BUILD_VERS_FULL) {
158
- shiyunInfo += `<meta name="version" content="${CICD_BUILD_VERS_FULL}_${CICD_BUILD_VERS_CODE}" />\n`;
159
- }
160
- // 将meta标签插入到head标签内(</head>闭合标签之前)
161
- html = html.replace('</head>', `\n${shiyunInfo}\n</head>`);
162
- // 删除空行
163
- html = html.replace(/\n\s*\n/g, '\n');
164
- return html;
165
- }
166
- // transform(code, id) {
167
- // // console.log('transform');
168
- // if (id.endsWith('.example')) {
169
- // // 对特定文件进行转换逻辑
170
- // return code + '\n// This is an example plugin transformation';
171
- // }
172
- // }
173
- }
31
+ shiyunReleaseCommon(ENV_ARR_VITE, ENV_ARR_CICD, ENV_MODE, params)
174
32
  ];
175
33
  }
package/common/common.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * 判断是否为有效字符串:
3
- * - 类型必须是 string
4
- * - 不能是空字符串或全是空格
5
- * - 不能是 'undefined' 这个字符串
6
- */
7
- export function isValidString(str) {
8
- return typeof str === 'string' && str.trim() !== '' && str !== 'undefined';
9
- }