@shijiu/jsview 2.3.151-test.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.
Files changed (78) hide show
  1. package/dom/bin/jsview-dom-browser-engine-core.min.js +1 -1
  2. package/dom/bin/jsview-dom-browser-engine-modules.min.js +1 -1
  3. package/dom/bin/{jsview-dom-browser-forge.1493.9a36.wasm → jsview-dom-browser-forge.1760.0e35.wasm} +0 -0
  4. package/dom/bin/jsview-dom-browser-forge.min.js +1 -1
  5. package/dom/bin/jsview-dom-browser-forge.worker.min.js +1 -1
  6. package/dom/bin/jsview-dom-browser.min.js +1 -1
  7. package/dom/bin/jsview-dom-native.min.js +1 -1
  8. package/dom/bin/jsview-engine-js-native.min.js +1 -1
  9. package/dom/target_core_revision.mjs +2 -2
  10. package/loader/jsv-core-api/jsview-core-api-glue.js +10 -1
  11. package/loader/jsv-core-api/wasm/core-api.js +87 -2
  12. package/loader/jsv-core-api/wasm/wasm-extension.js +5 -0
  13. package/loader/jsview-loader.js +7 -0
  14. package/loader/jsview-main.mjs +2 -1
  15. package/loader/jsview.config.default.js +4 -0
  16. package/package.json +7 -5
  17. package/patches/@vitejs+plugin-vue+4.0.0.patch +51 -0
  18. package/patches/@vitejs+plugin-vue+6.0.6.patch +54 -0
  19. package/patches/@vue+compiler-dom+3.2.45.patch +22 -0
  20. package/patches/@vue+compiler-dom+3.6.0-beta.10.patch +22 -0
  21. package/patches/@vue+compiler-sfc+3.2.45.patch +1986 -0
  22. package/patches/@vue+compiler-sfc+3.6.0-beta.10.patch +69 -0
  23. package/patches/@vue+runtime-core+3.2.45.patch +353 -0
  24. package/patches/@vue+runtime-core+3.6.0-beta.10.patch +196 -0
  25. package/patches/@vue+runtime-dom+3.2.45.patch +81 -0
  26. package/patches/@vue+runtime-dom+3.6.0-beta.10.patch +47 -0
  27. package/patches/postcss-js+5.1.0.patch +20 -0
  28. package/patches/vite+4.0.0.patch +117 -0
  29. package/patches/vite+8.0.9.patch +77 -0
  30. package/patches/vue-router+4.1.6.patch +17 -0
  31. package/patches/vue-router+5.0.6.patch +0 -0
  32. package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js → thirdparty/@vue/compiler-sfc/jsview-css-to-js.cjs} +15 -10
  33. package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-checker.js → thirdparty/@vue/compiler-sfc/jsview-style-checker.cjs} +6 -1
  34. package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-formator.cjs.js → thirdparty/@vue/compiler-sfc/jsview-style-formator.cjs} +3 -0
  35. package/thirdparty/@vue/runtime-core/jsview-render-break.mjs +189 -0
  36. package/thirdparty/vite/jsview-vite-extension.mjs +336 -0
  37. package/tools/jsview-build-zip.mjs +7 -2
  38. package/tools/jsview-common.mjs +17 -4
  39. package/tools/{jsview-logger.js → jsview-logger.cjs} +1 -1
  40. package/tools/jsview-post-build.mjs +55 -0
  41. package/tools/jsview-post-install.mjs +105 -103
  42. package/tools/jsview-run-tool.mjs +3 -6
  43. package/tools/jsview-vue-devtools.mjs +1 -1
  44. package/loader/jsview-react-main.js +0 -37
  45. package/loader/jsview-react-script-loader.js +0 -134
  46. package/patches/node_modules/@vitejs/plugin-react/dist/index.cjs +0 -520
  47. package/patches/node_modules/@vitejs/plugin-react/package.json +0 -55
  48. package/patches/node_modules/@vitejs/plugin-vue/dist/index.mjs +0 -2756
  49. package/patches/node_modules/@vitejs/plugin-vue/package.json +0 -51
  50. package/patches/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js +0 -3152
  51. package/patches/node_modules/@vue/compiler-dom/package.json +0 -43
  52. package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -17730
  53. package/patches/node_modules/@vue/compiler-sfc/package.json +0 -59
  54. package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +0 -8154
  55. package/patches/node_modules/@vue/runtime-core/package.json +0 -38
  56. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.d.ts +0 -1531
  57. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1740
  58. package/patches/node_modules/@vue/runtime-dom/package.json +0 -42
  59. package/patches/node_modules/postcss-js/objectifier.js +0 -94
  60. package/patches/node_modules/postcss-js/package.json +0 -42
  61. package/patches/node_modules/react-dev-utils/WebpackDevServerUtils.js +0 -450
  62. package/patches/node_modules/react-dev-utils/package.json +0 -88
  63. package/patches/node_modules/react-dom/cjs/react-dom.development.js +0 -29868
  64. package/patches/node_modules/react-dom/cjs/react-dom.production.min.js +0 -323
  65. package/patches/node_modules/react-dom/package.json +0 -62
  66. package/patches/node_modules/react-scripts/config/paths.js +0 -179
  67. package/patches/node_modules/react-scripts/config/webpack.config.js +0 -858
  68. package/patches/node_modules/react-scripts/package.json +0 -108
  69. package/patches/node_modules/vite/dist/node/chunks/dep-ed9cb113.js +0 -63182
  70. package/patches/node_modules/vite/dist/node/constants.js +0 -125
  71. package/patches/node_modules/vite/dist/node/jsview-vite-extension.js +0 -245
  72. package/patches/node_modules/vite/package.json +0 -153
  73. package/patches/node_modules/vue-router/dist/vue-router.mjs +0 -3613
  74. package/patches/node_modules/vue-router/package.json +0 -114
  75. package/patches/node_modules/webpack-dev-server/client/utils/reloadApp.js +0 -76
  76. package/patches/node_modules/webpack-dev-server/client/utils/sendMessage.js +0 -21
  77. package/patches/node_modules/webpack-dev-server/package.json +0 -141
  78. /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
@@ -8,6 +8,7 @@ import {
8
8
  checkNodeVersion,
9
9
  cpSync,
10
10
  execCommand,
11
+ getNodeVersion,
11
12
  getOptions,
12
13
  loadPackageObject,
13
14
  isSymlinkSync,
@@ -31,11 +32,10 @@ function checkNpmCommand()
31
32
  Logger.Warn('Please use "npm ci" to install node modules.');
32
33
  }
33
34
 
34
- function checkNpmLinkForDebug(options, linkablePkgNames)
35
+ function checkNpmMissingDepPkgs(options, linkablePkgNames)
35
36
  {
36
37
  const pkgObj = loadPackageObject(options.projectDir);
37
38
 
38
- // node 16 不会安装本地包的二次依赖, 需要手动安装。
39
39
  let missingDepPkgs = '';
40
40
  for (const linkableName of linkablePkgNames) {
41
41
  let linkableTarget = pkgObj.dependencies?.[linkableName];
@@ -69,11 +69,14 @@ function checkNpmLinkForDebug(options, linkablePkgNames)
69
69
  }
70
70
  }
71
71
  if (missingDepPkgs !== '') {
72
- Logger.Info('Install missing dependencies')
73
72
  execCommand('npm install --force --no-save ' + missingDepPkgs);
74
73
  }
74
+ }
75
+
76
+ function checkNpmLinkableDepPkgs(options, linkablePkgNames)
77
+ {
78
+ const pkgObj = loadPackageObject(options.projectDir);
75
79
 
76
- // node 18 不会将本地依赖安装成链接,需要手动改成链接。
77
80
  for (const linkableName of linkablePkgNames) {
78
81
  let linkableTarget = pkgObj.dependencies?.[linkableName];
79
82
  if (!linkableTarget || !linkableTarget.startsWith('file:../../@shijiu/jsview')) {
@@ -89,43 +92,60 @@ function checkNpmLinkForDebug(options, linkablePkgNames)
89
92
  const linkablePath = path.resolve(options.modulesDir, linkableName);
90
93
  symlinkSync(options.projectDir, linkableTargetPath, linkablePath);
91
94
  }
92
-
93
95
  }
94
96
 
95
- function checkPatches(options, pkgNeedPatch, skipCheckVersion)
97
+ function checkNpmLinkForDebug(options, linkablePkgNames)
96
98
  {
97
- Logger.Info('Checking package:');
98
- for (const pkgName of pkgNeedPatch) {
99
- if (skipCheckVersion !== true) {
100
- const patchPkgDir = path.resolve(options.jsviewPatchModulesDir, pkgName);
101
- const patchPkgObj = loadPackageObject(patchPkgDir);
102
- Logger.Info(' ' + pkgName + ': ' + patchPkgObj.version);
103
-
104
- const modulePkgDir = path.resolve(options.modulesDir, pkgName);
105
- const modulePkgObj = loadPackageObject(modulePkgDir);
106
- if (modulePkgObj.version != patchPkgObj.version) {
107
- Logger.ErrorAndExit(pkgName + '@' + modulePkgObj.version + ' is not supported, required version is ' + patchPkgObj.version);
108
- }
109
- } else {
110
- Logger.Info(' Skip ', pkgName);
111
- }
112
- }
113
- }
99
+ const nodeVersion = getNodeVersion();
114
100
 
115
- function installPatches(options, pkgNeedPatch)
116
- {
117
- Logger.Info('Stage 1: Installing patches for JsView:');
118
- for (const pkgName of pkgNeedPatch) {
119
- const patchSrc = path.resolve(options.jsviewPatchModulesDir, pkgName);
120
- const patchDest = path.resolve(options.modulesDir, pkgName);
101
+ const pkgObj = loadPackageObject(options.projectDir);
121
102
 
122
- cpSync(options.projectDir, patchSrc, patchDest, ['package.json']);
123
- }
103
+ // node 不会安装本地包的二次依赖, 需要手动安装。
104
+ checkNpmMissingDepPkgs(options, linkablePkgNames);
124
105
 
125
- Logger.Info('Cleanup node_modules cache... ');
126
- rmSync(options.projectDir, options.cacheDir);
106
+ // node 18 不会将本地依赖安装成链接,需要手动改成链接。
107
+ if(nodeVersion.major == 18) {
108
+ checkNpmLinkableDepPkgs(options, linkablePkgNames);
109
+ }
127
110
  }
128
111
 
112
+ // function checkPatches(options, pkgNeedInstallModules, skipCheckVersion)
113
+ // {
114
+ // Logger.Info('Checking package:');
115
+ // for (const pkgName of pkgNeedInstallModules) {
116
+ // if (skipCheckVersion !== true) {
117
+ // const patchPkgDir = path.resolve(options.jsviewPatchInstallModulesDir, pkgName);
118
+ // const patchPkgObj = loadPackageObject(patchPkgDir);
119
+ // Logger.Info(' ' + pkgName + ': ' + patchPkgObj.version);
120
+
121
+ // const modulePkgDir = path.resolve(options.modulesDir, pkgName);
122
+ // const modulePkgObj = loadPackageObject(modulePkgDir);
123
+ // if (modulePkgObj.version != patchPkgObj.version) {
124
+ // Logger.ErrorAndExit(pkgName + '@' + modulePkgObj.version + ' is not supported, required version is ' + patchPkgObj.version);
125
+ // }
126
+ // } else {
127
+ // Logger.Info(' Skip ', pkgName);
128
+ // }
129
+ // }
130
+ // }
131
+
132
+ // function installPatches(options, pkgNeedInstallModules, skipCheckVersion)
133
+ // {
134
+ // Logger.Info('Stage 2: Installing patches for JsView:');
135
+
136
+ // checkPatches(options, pkgNeedInstallModules, skipCheckVersion);
137
+
138
+ // for (const pkgName of pkgNeedInstallModules) {
139
+ // const patchSrc = path.resolve(options.jsviewPatchInstallModulesDir, pkgName);
140
+ // const patchDest = path.resolve(options.modulesDir, pkgName);
141
+
142
+ // cpSync(options.projectDir, patchSrc, patchDest, ['package.json']);
143
+ // }
144
+
145
+ // Logger.Info('Cleanup node_modules cache... ');
146
+ // rmSync(options.projectDir, options.cacheDir);
147
+ // }
148
+
129
149
  function getPatchListRecursive(patchDir)
130
150
  {
131
151
  var patchList = [];
@@ -150,57 +170,23 @@ function getPatchListRecursive(patchDir)
150
170
  return patchList;
151
171
  }
152
172
 
153
- function autoPatchPackages(options)
173
+ function autoPatchPackages(options, pkgNeedPatchModules)
154
174
  {
155
- Logger.Info('Stage 2: Auto patching packages:');
156
-
157
175
  const patchCacheDir = path.resolve(options.cacheJsViewDir, 'patches');
158
176
  fs.mkdirSync(patchCacheDir, { recursive: true, force: true });
159
-
160
- const patchInfo = {};
161
- const patchList = getPatchListRecursive(options.jsviewPatchModulesDir);
162
- for (const patchFullPath of patchList) {
163
- const patchRelativePath = path.relative(options.jsviewPatchModulesDir, patchFullPath);
164
- const patchNameAndVersion = path.dirname(patchRelativePath);
165
- const patchVersion = path.basename(patchNameAndVersion);
166
- const patchName = path.dirname(patchNameAndVersion);
167
-
168
- if(!patchInfo[patchName]) {
169
- patchInfo[patchName] = [];
170
- }
171
- patchInfo[patchName].push(patchVersion);
172
- }
173
-
174
- for(const [patchName, patchVersions] of Object.entries(patchInfo)) {
175
- const pkgFullDir = path.resolve(options.modulesDir, patchName);
176
- const pkgJsonFullPath = path.resolve(pkgFullDir, 'package.json');
177
- if(fs.existsSync(pkgJsonFullPath) == false) {
178
- continue;
179
- }
180
-
181
- const pkgObj = loadPackageObject(pkgFullDir);
182
- const pkgVersion = pkgObj.version;
183
- if(patchVersions.includes(pkgVersion) == false) {
184
- Logger.Warn(' Patch file for ' + patchName + '@' + pkgVersion + ' is not found.');
177
+ for (const file of pkgNeedPatchModules) {
178
+ if(file.endsWith('.patch') == false) {
185
179
  continue;
186
180
  }
187
181
 
188
- const patchFullDir = path.resolve(options.jsviewPatchModulesDir, patchName, pkgVersion);
189
- const patchFiles = fs.readdirSync(patchFullDir);
190
- for (const file of patchFiles) {
191
- if(file.endsWith('.patch') == false) {
192
- continue;
193
- }
194
-
195
- const copyFromPath = path.resolve(patchFullDir, file);
196
- const copyToPath = path.resolve(patchCacheDir, file);
197
- cpSync(options.projectDir, copyFromPath, copyToPath);
198
- }
182
+ const copyFromPath = path.resolve(options.jsviewPatchesDir, file);
183
+ const copyToPath = path.resolve(patchCacheDir, file);
184
+ cpSync(options.projectDir, copyFromPath, copyToPath);
199
185
  }
200
186
 
201
187
  const hasPatches = fs.readdirSync(patchCacheDir);
202
188
  if(hasPatches && hasPatches.length > 0) {
203
- execCommand('npx patch-package --patch-dir ' + path.relative(options.projectDir, patchCacheDir));
189
+ execCommand('npx patch-package --error-on-fail --patch-dir ' + path.relative(options.projectDir, patchCacheDir));
204
190
  } else {
205
191
  Logger.Info(' No patch files found.');
206
192
  }
@@ -230,10 +216,10 @@ async function printRevision(options)
230
216
  let versionFilePath = path.resolve(pathname, 'version.mjs');
231
217
  if (fs.existsSync(versionFilePath)) {
232
218
  const versionFileURL = url.pathToFileURL(versionFilePath);
233
- const { default: targetVersion } = await import(versionFileURL);
234
- Logger.Info(`* [${path.basename
235
- (pathname)}] : ${targetVersion.packageName
236
- } : ${targetVersion.version}`);
219
+ const versionModule = await import(versionFileURL);
220
+ // 兼容 default 导出(JsvAudio/JsvPlayer)与命名导出 PluginInfo(JsvLatex)
221
+ const targetVersion = versionModule.PluginInfo ?? versionModule.default;
222
+ Logger.Info(`* [${path.basename(pathname)}] : ${targetVersion.packageName} : ${targetVersion.version}`);
237
223
  pluginCount++;
238
224
  }
239
225
  }
@@ -260,22 +246,22 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion, skipCheckNpmcm
260
246
  '@shijiu/jsview-vue',
261
247
  '@shijiu/jsview-vue-samples',
262
248
  '@shijiu/jsview-vue-extra-samples',
263
- '@shijiu/jsview-react',
264
- '@shijiu/jsview-react-samples',
265
- '@shijiu/jsview-react-extra-samples',
249
+ // '@shijiu/jsview-react',
250
+ // '@shijiu/jsview-react-samples',
251
+ // '@shijiu/jsview-react-extra-samples',
266
252
  ];
267
253
 
268
254
  if(!skipCheckNpmcmd) {
269
255
  checkNpmCommand();
270
256
  }
271
257
 
258
+ Logger.Tip('Stage 1: Check link and missing dependencies...')
272
259
  checkNpmLinkForDebug(options, linkablePkgNames);
273
260
 
274
- checkPatches(options, pkgNeedPatch, skipCheckVersion);
261
+ Logger.Tip('Stage 2: Auto patching packages...');
262
+ autoPatchPackages(options, pkgNeedPatch.patchModules);
275
263
 
276
- installPatches(options, pkgNeedPatch);
277
-
278
- autoPatchPackages(options);
264
+ // installPatches(options, pkgNeedPatch.installModules, skipCheckVersion);
279
265
 
280
266
  printRevision(options);
281
267
  }
@@ -288,29 +274,45 @@ function main(argv)
288
274
 
289
275
  switch (argv.framework) {
290
276
  case 'vue':
291
- pkgNeedPatch = [
292
- '@vitejs/plugin-vue',
293
- '@vue/compiler-dom',
294
- '@vue/compiler-sfc',
295
- '@vue/runtime-core',
296
- '@vue/runtime-dom',
297
- 'postcss-js',
298
- 'vite',
299
- 'vue-router',
300
- ];
301
- break;
302
- case 'react':
303
- pkgNeedPatch = [
304
- 'react-dev-utils',
305
- 'react-dom',
306
- 'react-scripts',
307
- 'webpack-dev-server',
308
- ];
277
+ pkgNeedPatch = {
278
+ installModules: [
279
+ // '@vitejs/plugin-vue',
280
+ // '@vue/compiler-dom',
281
+ // '@vue/compiler-sfc',
282
+ // '@vue/runtime-core',
283
+ // '@vue/runtime-dom',
284
+ // 'postcss-js',
285
+ 'vite',
286
+ // 'vue-router',
287
+ ],
288
+ patchModules: [
289
+ '@vitejs+plugin-vue+6.0.6.patch',
290
+ '@vue+compiler-dom+3.6.0-beta.10.patch',
291
+ '@vue+compiler-sfc+3.6.0-beta.10.patch',
292
+ '@vue+runtime-core+3.6.0-beta.10.patch',
293
+ '@vue+runtime-dom+3.6.0-beta.10.patch',
294
+ 'postcss-js+5.1.0.patch',
295
+ 'vite+8.0.9.patch',
296
+ 'vue-router+5.0.6.patch',
297
+ ]
298
+ };
309
299
  break;
300
+ // case 'react':
301
+ // pkgNeedPatch = [
302
+ // 'react-dev-utils',
303
+ // 'react-dom',
304
+ // 'react-scripts',
305
+ // 'webpack-dev-server',
306
+ // ];
307
+ // break;
310
308
  default:
311
309
  Logger.ErrorAndExit('Failed to support framework: ' + framework);
312
310
  }
313
311
 
312
+ if(!argv.skipCheckVersion) {
313
+ argv.skipCheckVersion = true;
314
+ }
315
+
314
316
  doPostInstall(argv.framework, pkgNeedPatch, argv.skipCheckVersion, argv.skipCheckNpmcmd);
315
317
  }
316
318
 
@@ -79,6 +79,7 @@ async function getExtraOptions(argv)
79
79
  options.genKeypair = argv.genKeypair;
80
80
  options.buildMinifyExclude = argv.buildMinifyExclude;
81
81
  options.buildZip = argv.buildZip;
82
+ options.noPassword = argv.noPassword;
82
83
  options.buildBurdenLocal = argv.buildBurdenLocal;
83
84
  options.buildBurdenBaseurl = argv.buildBurdenBaseurl;
84
85
  options.vueDevtools = argv.vueDevtools;
@@ -129,11 +130,7 @@ function doCommand(options, argv) {
129
130
  } else if(options.buildZip) {
130
131
  const defaultPassword = 'jsview.shijiu.com';
131
132
  const password = (typeof(options.buildZip) === 'string' ? options.buildZip : defaultPassword);
132
- if(password !== options.buildZip) {
133
- Logger.Warn(`Zip password is not set, use default value: ${defaultPassword}`);
134
- }
135
-
136
- command = `node node_modules/@shijiu/jsview/tools/jsview-build-zip.mjs --password=${password}`;
133
+ command = `node node_modules/@shijiu/jsview/tools/jsview-build-zip.mjs --password=${password} ${options.noPassword ? '--no-password' : ''}`;
137
134
  } else if(options.buildBurdenLocal) {
138
135
  command = 'JSVIEW_BURDEN_LOCAL=true npm run build';
139
136
  } else if(options.buildBurdenBaseurl) {
@@ -217,7 +214,7 @@ const optionalUsages = {
217
214
  '-c | --config-app': 'Config app, like: -c or --config-app=[AppName:AppTitle].',
218
215
  '-g | --gen-keypair': 'Generate sign keypair.',
219
216
  '-m | --build-minify-exclude': 'Build target with minify-exclude filter, like: -m or --build-minify-exclude=[filter], additional options: -s or --script=build:dev.',
220
- '-z | --build-zip': 'Build target to offline zip package, like: -z or --build-zip=[password].',
217
+ '-z | --build-zip': 'Build target to offline zip package, like: -z, --build-zip=[password] or --build-zip --no-password.',
221
218
  '-l | --build-burden-local': 'Build target with local burden files.',
222
219
  '-b | --build-burden-baseurl': 'Build target with custom burden base url.',
223
220
  '-d | --vue-devtools': 'Start vue dev server and vue-devtools standalone, like: -d or --vue-devtools=[port].',
@@ -64,7 +64,7 @@ async function runVueDevtoolsStandalone(options)
64
64
  console.log()
65
65
  console.log()
66
66
  Logger.Tip(" *** NOTICE ***:")
67
- Logger.Tip(" Don't forget to add the following code at the beginning of your source entry ['main.ts' or 'main.tsx']:")
67
+ Logger.Tip(" Don't forget to add the following code at the beginning of your source entry ['main.ts']:")
68
68
  console.log(" if (process.env.NODE_ENV === 'development') {")
69
69
  console.log(" window.requestAnimationFrame = (callback) => setTimeout(callback, 0)")
70
70
  console.log(" const devtools = await import('@vue/devtools')")
@@ -1,37 +0,0 @@
1
- import JsViewLoader from './jsview-loader'
2
- import AppData from '/src/appConfig/app.config'
3
- import JsViewVendorConfig from "/src/appConfig/jsview.config"
4
- import initHeaderScriptLoader from "./jsview-react-script-loader";
5
- import { PERMISSION } from '/src/appConfig/permission.js'
6
-
7
- function main() {
8
- const jsviewLoader = new JsViewLoader();
9
-
10
- // 使用vendor配置值覆盖默认配置。
11
- const config = jsviewLoader.mergeConfig(JsViewVendorConfig);
12
- console.log("JsView config: " + JSON.stringify(config));
13
-
14
- jsviewLoader.initForgeEnv();
15
-
16
- // Webpack 并不能直接运行import语法,需要一个Script加载器
17
- if (window.JsView) {
18
- initHeaderScriptLoader(config.jsviewConfig.jsSubPath);
19
- }
20
-
21
- // 初始化jsview运行环境。
22
- const onInitJsViewEnv = async function () {
23
- // workaround: 因为React的npm run build后,不能支持top-level-await,
24
- // 所以只能在这里加载 JsViewReactWidget/BrowserDebugWidget, 导致了反向依赖问题。
25
- // 期待下一个版本的Webpack能修复此问题。
26
- if (!window.JsView) {
27
- await import("../../jsview-react/utils/JsViewReactWidget/BrowserDebugWidget/WidgetLoader");
28
- }
29
-
30
- // JsView环境加载完毕后,加载vue/react的main.js文件。
31
- import('/src/main.tsx');
32
- };
33
- jsviewLoader.initJsViewEnv(AppData.AppName, onInitJsViewEnv, PERMISSION);
34
- }
35
-
36
- // webpack/vite运行入口
37
- main();
@@ -1,134 +0,0 @@
1
- /**
2
- * Created by ludl on 3/30/20.
3
- */
4
-
5
- function alterUrl(origin_url, js_sub_path) {
6
- console.log(`++++++++ origin_url=${origin_url} js_sub_path = ${js_sub_path}`);
7
- let schema_idx = origin_url.indexOf("://");
8
- if (schema_idx < 0 || schema_idx > 10) {
9
- // 非schema打头方式,认为是相对路径
10
- if (!origin_url.startsWith('./') && !origin_url.startsWith('/')) {
11
- origin_url = "./" + origin_url; // 补充相对路径头信息
12
- }
13
- }
14
-
15
- if (origin_url.startsWith('./') || origin_url.startsWith('/')) {
16
- const main_js_path = window.JsView.getAppUrl();
17
- let idx = main_js_path.indexOf('?');
18
- const host_path = (idx > 0 ? main_js_path.substring(0, idx) : main_js_path);
19
- idx = host_path.lastIndexOf(js_sub_path);
20
- const path_header = host_path.substring(0, idx);
21
-
22
- let ret;
23
- if (origin_url.startsWith('./')) {
24
- ret = path_header + origin_url.substring(1);
25
- } else {
26
- // start with '/'
27
- // remove protocal
28
- let host_parser = main_js_path;
29
- idx = host_parser.indexOf('://');
30
- const protocol = (idx > 0 ? host_parser.substring(0, idx) : "");
31
- host_parser = (idx > 1 ? host_parser.substring(idx + 3) : "");
32
-
33
- // Get host
34
- idx = host_parser.indexOf('/');
35
- const host = (idx > 0 ? host_parser.substring(0, idx) : "");
36
-
37
- ret = `${protocol}://${host}${origin_url}`;
38
- }
39
-
40
- return ret;
41
- }
42
- return origin_url;
43
- }
44
-
45
- class LoadingScriptElement {
46
- constructor(js_sub_path) {
47
- console.log(`++++++++ js_sub_path=${js_sub_path}`);
48
- this.src = null;
49
- this.onerror = null;
50
- this.onload = null;
51
- this.charset = null;
52
- this.timeout = 120;
53
- this._JsSubPath = js_sub_path;
54
- }
55
-
56
- setAttribute(name, value) {
57
- console.log(`ScriptElement.setAttribute() name=${name}, value=`, value);
58
- this[name] = value;
59
- }
60
-
61
- jsvActiveScript() {
62
- if (this.src !== null) {
63
- const url_href = alterUrl(this.src, this._JsSubPath);
64
- console.log(`load script with url=${url_href}`);
65
- const _this = this;
66
- window.JsView.runJsWithUrl(url_href, false, (is_success, err_code) => {
67
- _this.onLoadResult(is_success, err_code);
68
- });
69
- }
70
- }
71
-
72
- onLoadResult(is_success, err_code) {
73
- console.log(`[Head]onLoadResult ${is_success} ${err_code}`);
74
- if (is_success) {
75
- if (this.onload) {
76
- this.onload();
77
- }
78
- } else {
79
- if (this.onerror) {
80
- this.onerror({ type: `[Head]jsvErr_${err_code}`, target: this });
81
- }
82
- }
83
- }
84
- }
85
-
86
- class LoadingHeader {
87
- constructor() {
88
- console.log("Document header construct");
89
- }
90
-
91
- appendChild(node) {
92
- if (node instanceof LoadingScriptElement) {
93
- console.log("Found append script in head.");
94
- node.jsvActiveScript();
95
- }
96
- }
97
- }
98
-
99
- class LoadingDocument {
100
- constructor(js_sub_path) {
101
- this.head = new LoadingHeader();
102
- this._JsSubPath = js_sub_path;
103
- }
104
-
105
- createElement(name) {
106
- console.log(`HeaderDocument.createElement() name=${name}`);
107
- switch (name) {
108
- case "script":
109
- return new LoadingScriptElement(this._JsSubPath);
110
- default:
111
- console.warn(`HeaderDocument.createElement() name=${name}`);
112
- return null;
113
- }
114
- }
115
-
116
- getElementsByTagName(name) {
117
- if (name.toLowerCase() === "head") {
118
- return [this.head];
119
- }
120
- if (name.toLowerCase() === "link"
121
- || name.toLowerCase() === "script"
122
- || name.toLowerCase() === "style") {
123
- return [];
124
- }
125
-
126
- throw Error("LoadingDocument.getElementsByTagName() name=" + name + " is UNIMPLEMENTED.");
127
- }
128
- }
129
-
130
- function initHeaderScriptLoader(js_sub_path) {
131
- window.document = new LoadingDocument(js_sub_path);
132
- }
133
-
134
- export default initHeaderScriptLoader;