@shijiu/jsview 2.3.0 → 3.0.0-next-vue.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/dom/bin/jsview-dom-browser-engine-core.min.js +1 -1
- package/dom/bin/jsview-dom-browser-engine-modules.min.js +1 -1
- package/dom/bin/{jsview-dom-browser-forge.1436.54c9.wasm → jsview-dom-browser-forge.1760.0e35.wasm} +0 -0
- package/dom/bin/jsview-dom-browser-forge.min.js +1 -1
- package/dom/bin/jsview-dom-browser-forge.worker.min.js +1 -1
- package/dom/bin/jsview-dom-browser.min.js +1 -1
- package/dom/bin/jsview-dom-native.min.js +1 -1
- package/dom/bin/jsview-engine-js-native.min.js +1 -1
- package/dom/target_core_revision.mjs +2 -2
- package/loader/jsv-core-api/jsview-core-api-glue.js +10 -1
- package/loader/jsv-core-api/wasm/core-api.js +87 -1
- package/loader/jsv-core-api/wasm/wasm-extension.js +5 -0
- package/loader/jsview-loader.js +7 -0
- package/loader/jsview-main.mjs +2 -1
- package/loader/jsview.config.default.js +4 -0
- package/package.json +7 -5
- package/patches/@vitejs+plugin-vue+4.0.0.patch +51 -0
- package/patches/@vitejs+plugin-vue+6.0.6.patch +54 -0
- package/patches/@vue+compiler-dom+3.2.45.patch +22 -0
- package/patches/@vue+compiler-dom+3.6.0-beta.10.patch +22 -0
- package/patches/@vue+compiler-sfc+3.2.45.patch +1986 -0
- package/patches/@vue+compiler-sfc+3.6.0-beta.10.patch +69 -0
- package/patches/@vue+runtime-core+3.2.45.patch +353 -0
- package/patches/@vue+runtime-core+3.6.0-beta.10.patch +196 -0
- package/patches/@vue+runtime-dom+3.2.45.patch +81 -0
- package/patches/@vue+runtime-dom+3.6.0-beta.10.patch +47 -0
- package/patches/postcss-js+5.1.0.patch +20 -0
- package/patches/vite+4.0.0.patch +117 -0
- package/patches/vite+8.0.9.patch +77 -0
- package/patches/vue-router+4.1.6.patch +17 -0
- package/patches/vue-router+5.0.6.patch +0 -0
- package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js → thirdparty/@vue/compiler-sfc/jsview-css-to-js.cjs} +15 -10
- package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-checker.js → thirdparty/@vue/compiler-sfc/jsview-style-checker.cjs} +6 -1
- package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-formator.cjs.js → thirdparty/@vue/compiler-sfc/jsview-style-formator.cjs} +3 -0
- package/thirdparty/@vue/runtime-core/jsview-render-break.mjs +189 -0
- package/thirdparty/vite/jsview-vite-extension.mjs +336 -0
- package/tools/jsview-build-zip.mjs +7 -2
- package/tools/jsview-common.mjs +18 -4
- package/tools/{jsview-logger.js → jsview-logger.cjs} +1 -1
- package/tools/jsview-post-build.mjs +88 -6
- package/tools/jsview-post-install.mjs +110 -103
- package/tools/jsview-run-tool.mjs +3 -6
- package/tools/jsview-vue-devtools.mjs +1 -1
- package/loader/jsview-react-main.js +0 -37
- package/loader/jsview-react-script-loader.js +0 -134
- package/patches/node_modules/@vitejs/plugin-react/dist/index.cjs +0 -520
- package/patches/node_modules/@vitejs/plugin-react/package.json +0 -55
- package/patches/node_modules/@vitejs/plugin-vue/dist/index.mjs +0 -2756
- package/patches/node_modules/@vitejs/plugin-vue/package.json +0 -51
- package/patches/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js +0 -3152
- package/patches/node_modules/@vue/compiler-dom/package.json +0 -43
- package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -17730
- package/patches/node_modules/@vue/compiler-sfc/package.json +0 -59
- package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +0 -8154
- package/patches/node_modules/@vue/runtime-core/package.json +0 -38
- package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.d.ts +0 -1531
- package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1740
- package/patches/node_modules/@vue/runtime-dom/package.json +0 -42
- package/patches/node_modules/postcss-js/objectifier.js +0 -94
- package/patches/node_modules/postcss-js/package.json +0 -42
- package/patches/node_modules/react-dev-utils/WebpackDevServerUtils.js +0 -450
- package/patches/node_modules/react-dev-utils/package.json +0 -88
- package/patches/node_modules/react-dom/cjs/react-dom.development.js +0 -29868
- package/patches/node_modules/react-dom/cjs/react-dom.production.min.js +0 -323
- package/patches/node_modules/react-dom/package.json +0 -62
- package/patches/node_modules/react-scripts/config/paths.js +0 -179
- package/patches/node_modules/react-scripts/config/webpack.config.js +0 -858
- package/patches/node_modules/react-scripts/package.json +0 -108
- package/patches/node_modules/vite/dist/node/chunks/dep-ed9cb113.js +0 -63182
- package/patches/node_modules/vite/dist/node/constants.js +0 -125
- package/patches/node_modules/vite/dist/node/jsview-vite-extension.js +0 -245
- package/patches/node_modules/vite/package.json +0 -153
- package/patches/node_modules/vue-router/dist/vue-router.mjs +0 -3613
- package/patches/node_modules/vue-router/package.json +0 -114
- package/patches/node_modules/webpack-dev-server/client/utils/reloadApp.js +0 -76
- package/patches/node_modules/webpack-dev-server/client/utils/sendMessage.js +0 -21
- package/patches/node_modules/webpack-dev-server/package.json +0 -141
- /package/patches/{node_modules/@originjs/vite-plugin-federation/1.3.4/@originjs+vite-plugin-federation+1.3.4.patch → @originjs+vite-plugin-federation+1.3.4.patch} +0 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
// import fullReload from 'vite-plugin-full-reload';
|
|
4
|
+
// import wasm from "vite-plugin-wasm";
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
const jsviewConfig = {
|
|
8
|
+
assetsInclude: ['**/*.bmp'],
|
|
9
|
+
base: './', // index.html 使用相对路径
|
|
10
|
+
build: {
|
|
11
|
+
assetsInlineLimit: 0,
|
|
12
|
+
//cssTarget: 'css/', // 未生效
|
|
13
|
+
commonjsOptions: getCommonjsOptions(),
|
|
14
|
+
emptyOutDir: true,
|
|
15
|
+
minify: useMinify(),
|
|
16
|
+
// jsvMinifyExclude: process.env['JSVIEW_MINIFY_EXCLUDE'],
|
|
17
|
+
modulePreload: {
|
|
18
|
+
polyfill: false
|
|
19
|
+
},
|
|
20
|
+
rolldownOptions: {
|
|
21
|
+
onwarn: onRolldownWarning,
|
|
22
|
+
output: {
|
|
23
|
+
assetFileNames: getAssetFileName,
|
|
24
|
+
chunkFileNames: getChunkFileName,
|
|
25
|
+
entryFileNames: 'js/main.jsv.[hash].js',
|
|
26
|
+
format: 'esm',
|
|
27
|
+
hashCharacters: 'hex',
|
|
28
|
+
manualChunks: getManualChunks,
|
|
29
|
+
},
|
|
30
|
+
plugins: [
|
|
31
|
+
rolldownRemoveBangsPlugin(),
|
|
32
|
+
rolldownMinifyExcludePlugin(),
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
sourcemap: true,
|
|
36
|
+
target: 'es2022', // 不转译async/await
|
|
37
|
+
},
|
|
38
|
+
isCustomElement: isCustomElement,
|
|
39
|
+
optimizeDeps: getOptimizeDeps(),
|
|
40
|
+
plugins: [
|
|
41
|
+
// fullReload('node_modules/@shijiu/**/*'),
|
|
42
|
+
// wasm(),
|
|
43
|
+
],
|
|
44
|
+
resolve: {
|
|
45
|
+
alias: getResolveAlias(),
|
|
46
|
+
preserveSymlinks: true
|
|
47
|
+
},
|
|
48
|
+
server: {
|
|
49
|
+
headers: { // 启用浏览器SharedArrayBuffer,webassmbly的thread用
|
|
50
|
+
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
51
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
52
|
+
},
|
|
53
|
+
host: true,
|
|
54
|
+
https: process.env['JSVIEW_ENABLE_HTTPS'] ? getHttpsConfig() : false,
|
|
55
|
+
open: !process.env['JSVIEW_DISABLE_OPEN_BROWSER'] && process.platform === "darwin",
|
|
56
|
+
watch: {
|
|
57
|
+
ignored: [
|
|
58
|
+
'!**/node_modules/@shijiu/**',
|
|
59
|
+
],
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
worker: {
|
|
63
|
+
format: 'esm',
|
|
64
|
+
rolldownOptions: {
|
|
65
|
+
output: {
|
|
66
|
+
assetFileNames: getAssetFileName,
|
|
67
|
+
chunkFileNames: getChunkFileName,
|
|
68
|
+
entryFileNames: getChunkFileName,
|
|
69
|
+
format: 'esm',
|
|
70
|
+
hashCharacters: 'hex',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function ensureFramework(originConfig) {
|
|
77
|
+
const checkFramework = function (name) {
|
|
78
|
+
if (name.indexOf('vue') >= 0) {
|
|
79
|
+
return 'vue';
|
|
80
|
+
// } else if (name.indexOf('react') >= 0) {
|
|
81
|
+
// return 'react';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let framework = 'unknown';
|
|
89
|
+
for (const plugins of originConfig.plugins) {
|
|
90
|
+
if (Array.isArray(plugins)) {
|
|
91
|
+
for (const plugin of plugins) {
|
|
92
|
+
framework = checkFramework(plugin.name);
|
|
93
|
+
if (framework) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
const plugin = plugins;
|
|
99
|
+
framework = checkFramework(plugin.name);
|
|
100
|
+
}
|
|
101
|
+
if (framework) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return framework;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getAssetFileName(chunkInfo) {
|
|
110
|
+
if(chunkInfo.name?.endsWith('.css')) {
|
|
111
|
+
return 'css/[name].[hash].css';
|
|
112
|
+
} else if(chunkInfo.name?.endsWith('.ttf')) {
|
|
113
|
+
return 'assets/[name].ttf';
|
|
114
|
+
} else if(chunkInfo.name?.endsWith('.wasm')) {
|
|
115
|
+
return 'js/[name].wasm';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// return 'assets/[name].[hash].[ext]'
|
|
119
|
+
return 'assets/[name].[hash][extname]'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getChunkFileName(chunkInfo) {
|
|
123
|
+
return (process.env['JSVIEW_KEEP_CHUNKNAME'] ? 'js/[name].[hash].js' : 'js/chunk.jsv2.[hash].js');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getCommonjsOptions() {
|
|
127
|
+
return {
|
|
128
|
+
'gifuct-js': true,
|
|
129
|
+
'js-binary-schema-parser': true,
|
|
130
|
+
'mockjs': true,
|
|
131
|
+
'qr.js': true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getHttpsConfig() {
|
|
136
|
+
const configDir = path.resolve(getModuleDir(), '@shijiu/jsview/tools/https-server-config');
|
|
137
|
+
const certFilePath = path.resolve(configDir, 'cert.pem');
|
|
138
|
+
const keyFilePath = path.resolve(configDir, 'key.pem');
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
cert: fs.readFileSync(certFilePath),
|
|
142
|
+
key: fs.readFileSync(keyFilePath),
|
|
143
|
+
maxVersion: 'TLSv1.2',
|
|
144
|
+
minVersion: 'TLSv1',
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function getManualChunks(moduleId) {
|
|
149
|
+
const manualChunks = {
|
|
150
|
+
'export-sfc': ['\0plugin-vue:export-helper', '@shijiu/jsview-vue/bin/export-sfc.mjs'], // 将_export_sfc独立出来,防止被集成在jsview-vue中导致import deadloop.
|
|
151
|
+
'vue': ['vue'], // 将vue独立出来,防止被集成在main.js中导致import deadloop.
|
|
152
|
+
// 将dom-entry和forge-define分割出来,防止被集成在main.js中导致import deadloop.
|
|
153
|
+
'jsview-forge-define': ['@shijiu/jsview/dom/jsv-forge-define.mjs'],
|
|
154
|
+
'jsview-dom-entry': ['@shijiu/jsview/dom/index.mjs'],
|
|
155
|
+
'jsview-vue-entry': ['@shijiu/jsview-vue/index.js'],
|
|
156
|
+
'jsview-vue-common': ['@shijiu/jsview-vue/bin/jsview-vue-common.mjs'],
|
|
157
|
+
// 'jsview-vue-export-sfc': [], // 将jsview-vue中的export-sfc,防止被集成在jsview-vue-entry中导致import deadloop.
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
for(const [key, valueList] of Object.entries(manualChunks)) {
|
|
161
|
+
for(const value of valueList) {
|
|
162
|
+
if(moduleId.endsWith(value)) {
|
|
163
|
+
return key;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function getModuleDir() {
|
|
170
|
+
const moduleDir = path.resolve(process.cwd(), 'node_modules');
|
|
171
|
+
return moduleDir;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getOptimizeDeps() {
|
|
175
|
+
return {
|
|
176
|
+
include: [
|
|
177
|
+
'gifuct-js',
|
|
178
|
+
// 'mockjs',
|
|
179
|
+
'qr.js'
|
|
180
|
+
],
|
|
181
|
+
exclude: [
|
|
182
|
+
'@shijiu/jsview/loader/jsview-main.mjs', // 解决windows上出现解析异常的问题。
|
|
183
|
+
'@shijiu/jsview',
|
|
184
|
+
'@shijiu/jsview-vue',
|
|
185
|
+
'@shijiu/jsview-vue-samples',
|
|
186
|
+
'jsview',
|
|
187
|
+
'jsview-vue',
|
|
188
|
+
'jsview-vue-samples',
|
|
189
|
+
],
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function getResolveAlias() {
|
|
194
|
+
return {
|
|
195
|
+
// 'jsview': path.resolve(process.cwd(), 'node_modules/@shijiu/jsview'),
|
|
196
|
+
'jsview-vue': path.resolve(process.cwd(), 'node_modules/@shijiu/jsview-vue'),
|
|
197
|
+
'jsview-vue-samples': path.resolve(process.cwd(), 'node_modules/@shijiu/jsview-vue-samples'),
|
|
198
|
+
// 'jsview-react': path.resolve(process.cwd(), 'node_modules/@shijiu/jsview-react'),
|
|
199
|
+
// 'jsview-react-samples': path.resolve(process.cwd(), 'node_modules/@shijiu/jsview-react-samples'),
|
|
200
|
+
'/js/main.jsv.mjs': path.resolve(process.cwd(), 'node_modules/@shijiu/jsview/loader/jsview-main.mjs'),
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function isCustomElement(tag) {
|
|
205
|
+
return tag == 'fdiv' || tag.startsWith('jsv-')
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function onRolldownWarning(warning, defaultHandler) {
|
|
209
|
+
if (warning.message?.includes('externalized for browser compatibility')
|
|
210
|
+
&& warning.message?.includes('jsview-dom-browser-forge')) {
|
|
211
|
+
// console.info('\nJsView Info: Ignore warning', warning.message)
|
|
212
|
+
return;
|
|
213
|
+
} else if (warning.code === 'FILE_NAME_CONFLICT') {
|
|
214
|
+
if(warning.message.includes('jsview-dom-browser-forge')
|
|
215
|
+
&& warning.message.includes('.wasm')) {
|
|
216
|
+
console.info('\nJsView Info: Ignore warning', warning.message)
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
} else if (warning.code === 'EVAL') {
|
|
220
|
+
if(warning.message.includes('mock.js')) {
|
|
221
|
+
console.info('\nJsView Info: Ignore warning', warning.message)
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
defaultHandler(warning);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function rolldownMinifyExcludePlugin() {
|
|
230
|
+
const jsvMinifyExclude = process.env['JSVIEW_MINIFY_EXCLUDE'];
|
|
231
|
+
const minifyExcludeChunkCodes = new Map();
|
|
232
|
+
let minifyExcludeRegex = null;
|
|
233
|
+
|
|
234
|
+
minifyExcludeRegex = new RegExp(jsvMinifyExclude?.trim() ?? '');
|
|
235
|
+
function isExcludeChunk(chunk) {
|
|
236
|
+
const name = chunk.name ?? chunk.fileName;
|
|
237
|
+
return minifyExcludeRegex.test(name);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function minifyExcludeRenderChunk(code, chunk, _options) {
|
|
241
|
+
if(isExcludeChunk(chunk)) {
|
|
242
|
+
const name = chunk.name ?? chunk.fileName;
|
|
243
|
+
// renderChunk 发生在 minify 之前,先缓存原始代码,稍后在 generateBundle 覆盖回来
|
|
244
|
+
minifyExcludeChunkCodes.set(name, code);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 统一交给 Rolldown 构建链路;命中项会在 generateBundle 阶段恢复原始代码
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function minifyExcludeGenerateBundle(_options, bundle) {
|
|
252
|
+
for(const item of Object.values(bundle)) {
|
|
253
|
+
if(item.type !== 'chunk') {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if(!isExcludeChunk(item)) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const originalCode = minifyExcludeChunkCodes.get(item.name || item.fileName);
|
|
261
|
+
if(typeof originalCode === 'string') {
|
|
262
|
+
item.code = originalCode;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
name: 'rolldown-plugin-minify-exclude',
|
|
269
|
+
renderChunk: jsvMinifyExclude ? minifyExcludeRenderChunk : null,
|
|
270
|
+
generateBundle: jsvMinifyExclude ? minifyExcludeGenerateBundle : null,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function rolldownRemoveBangsPlugin() {
|
|
275
|
+
return {
|
|
276
|
+
name: 'rolldown-plugin-remove-bangs',
|
|
277
|
+
renderChunk(code, _chunk, _options) {
|
|
278
|
+
return {
|
|
279
|
+
code: code.replace(/^\/\/!/g, '//').replace(/^\/\*!/g, '/*'),
|
|
280
|
+
map: null,
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function useMinify() {
|
|
287
|
+
return process.env['JSVIEW_DISABLE_MINIFY'] ? false : true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function jsvCreateJsViewViteConfig(originConfig) {
|
|
291
|
+
let aliasJsView;
|
|
292
|
+
|
|
293
|
+
const moduleDir = getModuleDir();
|
|
294
|
+
const framework = ensureFramework(originConfig);
|
|
295
|
+
switch (framework) {
|
|
296
|
+
case 'vue':
|
|
297
|
+
aliasJsView = path.resolve(moduleDir, '@shijiu/jsview-vue');
|
|
298
|
+
break;
|
|
299
|
+
// case 'react':
|
|
300
|
+
// aliasJsView = path.resolve(moduleDir, '@shijiu/jsview-react');
|
|
301
|
+
// break;
|
|
302
|
+
default:
|
|
303
|
+
throw new Error('JsView Error: Failed to support framework: ' + framework);
|
|
304
|
+
}
|
|
305
|
+
jsviewConfig.resolve.alias['jsview'] = aliasJsView;
|
|
306
|
+
|
|
307
|
+
if(process.env['JSVIEW_DISABLE_MANUALCHUNKS']) {
|
|
308
|
+
delete jsviewConfig.build.rolldownOptions.output.manualChunks
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 解决templete工程中没有mockjs导致的报错。
|
|
312
|
+
const mockjs = path.resolve(moduleDir, 'mockjs');
|
|
313
|
+
if(fs.existsSync(mockjs)) {
|
|
314
|
+
jsviewConfig.optimizeDeps.include.push('mockjs');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return jsviewConfig;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function jsvSaveUrlToCache(urls) {
|
|
321
|
+
if ((urls?.network?.length ?? -1 )<= 0) {
|
|
322
|
+
console.error("JsView Error: Failed to find network info.");
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const moduleDir = getModuleDir();
|
|
327
|
+
const urlCacheDir = path.resolve(moduleDir, '.vite', 'jsview')
|
|
328
|
+
const urlCacheFilePath = path.resolve(urlCacheDir, 'network.mjs')
|
|
329
|
+
fs.mkdirSync(urlCacheDir, { recursive: true });
|
|
330
|
+
fs.writeFileSync(urlCacheFilePath, `export default "${urls.network[0]}"`)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export {
|
|
334
|
+
jsvCreateJsViewViteConfig,
|
|
335
|
+
jsvSaveUrlToCache,
|
|
336
|
+
}
|
|
@@ -21,12 +21,16 @@ async function main(argv)
|
|
|
21
21
|
const zipName = 'dist.dat';
|
|
22
22
|
const zipPath = path.resolve(options.distDir, zipName);
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
let password = argv.password ?? 'jsview.shijiu.com';
|
|
25
|
+
if(argv.noPassword) {
|
|
26
|
+
password = null;
|
|
27
|
+
}
|
|
25
28
|
|
|
26
29
|
execCommand('npm run build');
|
|
27
30
|
|
|
28
31
|
let childFileNames = fs.readdirSync(options.distDir);
|
|
29
32
|
childFileNames = childFileNames.filter(it => it !== zipName);
|
|
33
|
+
childFileNames = childFileNames.filter(it => it !== 'debug');
|
|
30
34
|
childFileNames = childFileNames.map(it => path.resolve(options.distDir, it));
|
|
31
35
|
|
|
32
36
|
makeZip(zipPath, password, ...childFileNames)
|
|
@@ -37,7 +41,8 @@ async function main(argv)
|
|
|
37
41
|
const requiredUsages = {
|
|
38
42
|
};
|
|
39
43
|
const optionalUsages = {
|
|
40
|
-
'--password': 'Input
|
|
44
|
+
'--password': 'Input password',
|
|
45
|
+
'--no-password': 'Ignore password',
|
|
41
46
|
};
|
|
42
47
|
const argv = parseArguments(requiredUsages, optionalUsages);
|
|
43
48
|
main(argv);
|
package/tools/jsview-common.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import fs from 'node:fs';
|
|
|
6
6
|
import https from 'node:https';
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
-
import { Logger } from "./jsview-logger.
|
|
9
|
+
import { Logger } from "./jsview-logger.cjs";
|
|
10
10
|
|
|
11
11
|
function printArgumentsUsages(requiredUsages, optionalUsages, helpUsages)
|
|
12
12
|
{
|
|
@@ -180,6 +180,7 @@ function parseArguments(requiredUsages = {},
|
|
|
180
180
|
* jsview-test-project
|
|
181
181
|
* ├── dist
|
|
182
182
|
* │ ├── assets
|
|
183
|
+
* │ ├── css
|
|
183
184
|
* │ ├── debug
|
|
184
185
|
* │ │ └── map
|
|
185
186
|
* │ └── js
|
|
@@ -212,12 +213,11 @@ function getOptions(framework)
|
|
|
212
213
|
options.jsviewDomDir = path.resolve(options.jsviewDir, 'dom');
|
|
213
214
|
options.jsviewDomBinDir = path.resolve(options.jsviewDomDir, 'bin');
|
|
214
215
|
options.jsviewPatchesDir = path.resolve(options.jsviewDir, 'patches');
|
|
215
|
-
options.jsviewPatchModulesDir = path.resolve(options.jsviewPatchesDir, 'node_modules');
|
|
216
216
|
options.jsviewToolsDir = path.resolve(options.jsviewDir, 'tools');
|
|
217
217
|
options.jsviewDomRevisionFile = path.resolve(options.jsviewDir, 'dom', 'target_core_revision.mjs');
|
|
218
218
|
|
|
219
219
|
options.jsviewVueDir = path.resolve(options.modulesDir, '@shijiu', 'jsview-vue');
|
|
220
|
-
options.jsviewReactDir = path.resolve(options.modulesDir, '@shijiu', 'jsview-react');
|
|
220
|
+
// options.jsviewReactDir = path.resolve(options.modulesDir, '@shijiu', 'jsview-react');
|
|
221
221
|
if (framework) {
|
|
222
222
|
options.jsviewFrameworkDir = path.resolve(options.modulesDir, '@shijiu', 'jsview-' + framework);
|
|
223
223
|
}
|
|
@@ -240,10 +240,12 @@ function getOptions(framework)
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
+
options.distJsvConfigFile = path.resolve(options.distDir, 'jsv-config.json');
|
|
243
244
|
options.distJsvListFile = path.resolve(options.distDir, 'jsv-list.json');
|
|
244
245
|
options.distJsvInfoFile = path.resolve(options.distDir, 'jsv-info.json');
|
|
245
246
|
options.distJsIndexFile = path.resolve(options.distDir, 'index.html');
|
|
246
247
|
options.distAssetsDir = path.resolve(options.distDir, 'assets');
|
|
248
|
+
options.distCssDir = path.resolve(options.distDir, 'css');
|
|
247
249
|
options.distJsDir = path.resolve(options.distDir, 'js');
|
|
248
250
|
options.distDebugDir = path.resolve(options.distDir, 'debug');
|
|
249
251
|
options.distDebugMapDir = path.resolve(options.distDebugDir, 'map');
|
|
@@ -426,7 +428,7 @@ function execCommandWithLiveLog(cmdline)
|
|
|
426
428
|
}
|
|
427
429
|
|
|
428
430
|
|
|
429
|
-
function checkNodeVersion(minMajorVersion =
|
|
431
|
+
function checkNodeVersion(minMajorVersion = 20)
|
|
430
432
|
{
|
|
431
433
|
const versions = process.version.replace('v', '').split('.');
|
|
432
434
|
const [majorVersion, minorVersion, patchVersion] = versions;
|
|
@@ -437,6 +439,17 @@ function checkNodeVersion(minMajorVersion = 16)
|
|
|
437
439
|
}
|
|
438
440
|
}
|
|
439
441
|
|
|
442
|
+
function getNodeVersion()
|
|
443
|
+
{
|
|
444
|
+
const versions = process.version.replace('v', '').split('.');
|
|
445
|
+
const [major, minor, patch] = versions;
|
|
446
|
+
return {
|
|
447
|
+
major,
|
|
448
|
+
minor,
|
|
449
|
+
patch,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
440
453
|
function askAndAnswer(question)
|
|
441
454
|
{
|
|
442
455
|
process.stdout.write(question)
|
|
@@ -587,6 +600,7 @@ export {
|
|
|
587
600
|
getExportPrefix,
|
|
588
601
|
getJsViewBurdenDefaultBaseUrl,
|
|
589
602
|
getNetworkIpv4Addresses,
|
|
603
|
+
getNodeVersion,
|
|
590
604
|
getNpmRegistry,
|
|
591
605
|
getOptions,
|
|
592
606
|
isCommandAvailable,
|
|
@@ -95,6 +95,7 @@ function updateOptions(options)
|
|
|
95
95
|
options.appPrivKey = privKey;
|
|
96
96
|
options.appPubKey = pubKey;
|
|
97
97
|
options.appEntryMd5 = appEntryMd5;
|
|
98
|
+
options.appEntryFileName = `main.jsv.${options.appEntryMd5.slice(0, 8)}.js`;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
function getOtherSignVerifyKeys(options)
|
|
@@ -191,6 +192,22 @@ async function prepareMainAppData(options)
|
|
|
191
192
|
preloadBurdenResources.push(fileName);
|
|
192
193
|
}
|
|
193
194
|
|
|
195
|
+
const aesKeyFilePath = path.resolve(options.appConfigDir, 'fingerprint_aes_key.mjs');
|
|
196
|
+
if (fs.existsSync(aesKeyFilePath)) {
|
|
197
|
+
const aesKeyFileUrl = url.pathToFileURL(aesKeyFilePath);
|
|
198
|
+
const { default: aesKeyConfig } = await import (aesKeyFileUrl);
|
|
199
|
+
const aesKey = aesKeyConfig.aes_key;
|
|
200
|
+
const aesIv = aesKeyConfig.iv;
|
|
201
|
+
|
|
202
|
+
// 对appConfig.AppName进行aes加密并赋值给EncryptCode2
|
|
203
|
+
if (aesKey && aesIv) {
|
|
204
|
+
const cipher = crypto.createCipheriv('aes-128-cbc', Buffer.from(aesKey, 'utf8'), Buffer.from(aesIv, 'utf8'));
|
|
205
|
+
let encrypted = cipher.update(appConfig.AppName, 'utf8', 'base64');
|
|
206
|
+
encrypted += cipher.final('base64');
|
|
207
|
+
appConfig.EncryptCode2 = encrypted;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
194
211
|
// 组装AppData
|
|
195
212
|
appConfig.PublicKeys = publicKeys; // 使用签名数组,支持后续追加签名
|
|
196
213
|
appConfig.EncryptCodes = [encryptBase64]; // 同样使用数组,支持后续追加
|
|
@@ -199,10 +216,32 @@ async function prepareMainAppData(options)
|
|
|
199
216
|
BaseUrl: bunderBaseUrl,
|
|
200
217
|
Resources: preloadBurdenResources,
|
|
201
218
|
};
|
|
219
|
+
if (appConfig.FingerPrint) {
|
|
220
|
+
// 删除FingerPrint的存储,节省信息字节数
|
|
221
|
+
delete appConfig.FingerPrint;
|
|
222
|
+
}
|
|
202
223
|
|
|
203
224
|
return JSON.stringify(appConfig);
|
|
204
225
|
}
|
|
205
226
|
|
|
227
|
+
async function checkCssFileSize(options)
|
|
228
|
+
{
|
|
229
|
+
if(fs.existsSync(options.distCssDir) == false) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const cssFileNames = fs.readdirSync(options.distCssDir);
|
|
234
|
+
for(const fileName of cssFileNames) {
|
|
235
|
+
const filePath = path.resolve(options.distCssDir, fileName)
|
|
236
|
+
const fileStats = await fs.statSync(filePath);
|
|
237
|
+
if (fileStats.size > 0) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
fs.writeFileSync(filePath, ' ', 'utf8'); // 防止空文件。
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
206
245
|
async function checkAppConfig(options)
|
|
207
246
|
{
|
|
208
247
|
const appConfigFilePath = path.resolve(options.appConfigDir, 'app.config.mjs');
|
|
@@ -333,7 +372,8 @@ function redirectBurdenResource(options)
|
|
|
333
372
|
let sourceContent = fs.readFileSync(filePath, 'utf8');
|
|
334
373
|
|
|
335
374
|
for(const burdenFilePath of burdenFilePathList) {
|
|
336
|
-
|
|
375
|
+
let relativeBurdenFilePath = path.relative(options.distJsDir, burdenFilePath);
|
|
376
|
+
relativeBurdenFilePath = relativeBurdenFilePath.replaceAll('\\', '/'); // 更正windows分隔符
|
|
337
377
|
if(!sourceContent.includes(relativeBurdenFilePath)) {
|
|
338
378
|
continue;
|
|
339
379
|
}
|
|
@@ -395,14 +435,13 @@ function makeMainJsvMjs(options, framework)
|
|
|
395
435
|
|
|
396
436
|
// 更新entry hash
|
|
397
437
|
const jsEntryFilePath = getEntryFilePath(options);
|
|
398
|
-
const
|
|
399
|
-
const newEntryFilePath = path.resolve(path.dirname(jsEntryFilePath), newEntryFileName);
|
|
438
|
+
const newEntryFilePath = path.resolve(options.distJsDir, options.appEntryFileName);
|
|
400
439
|
Logger.Info(' -> ' + path.relative(options.projectDir, newEntryFilePath));
|
|
401
440
|
fs.renameSync(jsEntryFilePath, newEntryFilePath);
|
|
402
441
|
|
|
403
442
|
// 更新index.html hash
|
|
404
443
|
var indexContent = fs.readFileSync(options.distJsIndexFile, 'utf8');
|
|
405
|
-
indexContent = indexContent.replace(path.basename(jsEntryFilePath),
|
|
444
|
+
indexContent = indexContent.replace(path.basename(jsEntryFilePath), options.appEntryFileName);
|
|
406
445
|
Logger.Info(' -> ' + path.relative(options.projectDir, options.distJsIndexFile));
|
|
407
446
|
fs.writeFileSync(options.distJsIndexFile, indexContent, 'utf8');
|
|
408
447
|
|
|
@@ -478,6 +517,38 @@ function makeDebugMap(options, framework)
|
|
|
478
517
|
fs.copyFileSync(jsmapServePath, to);
|
|
479
518
|
}
|
|
480
519
|
|
|
520
|
+
async function makeJsvConfig(options)
|
|
521
|
+
{
|
|
522
|
+
const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
|
|
523
|
+
const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
|
|
524
|
+
const appEntryFilePath = path.resolve(options.distJsDir, options.appEntryFileName);
|
|
525
|
+
let appEntryFileName = `./${path.relative(options.distDir, appEntryFilePath)}`;
|
|
526
|
+
// appEntryFileName = appEntryFileName.replace(/\.js$/, '.mjs'); // deprecated
|
|
527
|
+
appEntryFileName = appEntryFileName.replaceAll('\\', '/'); // windows平台适配
|
|
528
|
+
|
|
529
|
+
const appConfigFilePath = path.resolve(options.appConfigDir, 'app.config.mjs');
|
|
530
|
+
if (!fs.existsSync(appConfigFilePath)) {
|
|
531
|
+
Logger.ErrorAndExit('Failed to open app config file from ' + appConfigFilePath);
|
|
532
|
+
}
|
|
533
|
+
const appConfigFileUrl = url.pathToFileURL(appConfigFilePath);
|
|
534
|
+
const { default: appConfig } = await import(appConfigFileUrl);
|
|
535
|
+
|
|
536
|
+
const jsvConfig = {
|
|
537
|
+
"COREVERSIONRANGE": jsviewTargetVersion.CoreRevisionAndBranch,
|
|
538
|
+
"ENGINE": jsviewTargetVersion.JseUrl,
|
|
539
|
+
"URL": appEntryFileName,
|
|
540
|
+
"MINIAPPNAME": appConfig.AppName,
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// 启动图
|
|
544
|
+
if (appConfig.StartImageUrl && appConfig.StartImageUrl.length != 0) {
|
|
545
|
+
jsvConfig.STARTIMG = appConfig.StartImageUrl;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const content = JSON.stringify(jsvConfig, null, 2);
|
|
549
|
+
fs.writeFileSync(options.distJsvConfigFile, content, 'utf8');
|
|
550
|
+
}
|
|
551
|
+
|
|
481
552
|
function makeJsvList(options)
|
|
482
553
|
{
|
|
483
554
|
let jsvList = makeFileListRecusive(options.distDir);
|
|
@@ -551,6 +622,10 @@ async function main(argv)
|
|
|
551
622
|
await checkDomDebugDisabled(options);
|
|
552
623
|
|
|
553
624
|
Logger.Info();
|
|
625
|
+
const jsviewPkgJson = loadPackageObject(options.jsviewDir);
|
|
626
|
+
Logger.Info(`JsView version: ${jsviewPkgJson.version}`);
|
|
627
|
+
Logger.Info();
|
|
628
|
+
|
|
554
629
|
Logger.Info('Redirecting JsView burden resource...');
|
|
555
630
|
redirectBurdenResource(options)
|
|
556
631
|
Logger.Info('Redirected JsView burden resource...');
|
|
@@ -562,6 +637,10 @@ async function main(argv)
|
|
|
562
637
|
// EntryMd5 要放在sourcemap更新之后
|
|
563
638
|
updateOptions(options);
|
|
564
639
|
|
|
640
|
+
Logger.Info('Checking JsView css file size...');
|
|
641
|
+
await checkCssFileSize(options);
|
|
642
|
+
Logger.Info('Checked JsView css file size...');
|
|
643
|
+
|
|
565
644
|
Logger.Info('Checking JsView app config...');
|
|
566
645
|
await checkAppConfig(options);
|
|
567
646
|
Logger.Info('Checked JsView app config...');
|
|
@@ -578,13 +657,16 @@ async function main(argv)
|
|
|
578
657
|
makeDebugMap(options, argv.framework);
|
|
579
658
|
Logger.Info('Made JsView Debug map.');
|
|
580
659
|
|
|
660
|
+
Logger.Info('Cleaning JsView Burden Resource...');
|
|
661
|
+
cleanupBurdenResource(options);
|
|
662
|
+
Logger.Info('Cleaned JsView Burden Resource...');
|
|
663
|
+
|
|
581
664
|
Logger.Info('Making JsView info...');
|
|
665
|
+
await makeJsvConfig(options);
|
|
582
666
|
makeJsvList(options);
|
|
583
667
|
await makeJsvInfo(options);
|
|
584
668
|
Logger.Info('Made JsView info...');
|
|
585
669
|
|
|
586
|
-
cleanupBurdenResource(options);
|
|
587
|
-
|
|
588
670
|
Logger.Info('Done...');
|
|
589
671
|
}
|
|
590
672
|
|