@shijiu/jsview 2.1.367-test.0 → 2.1.435
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.min.js +1 -1
- package/dom/bin/jsview-dom-native.min.js +1 -1
- package/dom/bin/jsview-engine-js-browser.min.js +1 -1
- package/dom/jsv-forge-define.d.ts +1 -0
- package/dom/target_core_revision.mjs +5 -5
- package/package.json +1 -1
- package/tools/jsview-common.mjs +15 -72
- package/tools/jsview-post-build.mjs +18 -7
- package/tools/jsview-post-install.mjs +6 -88
- package/tools/jsview-retrieve-sourcemap.mjs +194 -0
- package/tools/jsview-run-tool.mjs +7 -45
- package/patches/node_modules/@originjs/vite-plugin-federation/1.3.4/@originjs+vite-plugin-federation+1.3.4.patch +0 -70
- package/tools/jsview-config-app.mjs +0 -47
- package/tools/jsview-module-federation.mjs +0 -354
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '@shijiu/jsview/dom/jsv-forge-define.mjs';
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const TargetRevision = {
|
|
6
|
-
"CoreRevision":
|
|
7
|
-
"CoreRevisionAndBranch": "
|
|
8
|
-
"JseRevision": "1.0.
|
|
6
|
+
"CoreRevision": 1021746,
|
|
7
|
+
"CoreRevisionAndBranch": "1021746",
|
|
8
|
+
"JseRevision": "1.0.950",
|
|
9
9
|
"JseUrl":
|
|
10
|
-
"http://cdn.release.qcast.cn/forge_js/master/
|
|
11
|
-
"JseName": "
|
|
10
|
+
"http://cdn.release.qcast.cn/forge_js/master/JsViewES6_js2c_r950.jsv.33b8f0af.js",
|
|
11
|
+
"JseName": "JsViewES6_js2c_r950.jsv.33b8f0af.js",
|
|
12
12
|
"JsidtName": "libjsidt.102.7.so",
|
|
13
13
|
};
|
|
14
14
|
|
package/package.json
CHANGED
package/tools/jsview-common.mjs
CHANGED
|
@@ -3,18 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import childProcess from 'node:child_process';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import
|
|
6
|
+
import os from 'node:os';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { Logger } from "./jsview-logger.js";
|
|
9
9
|
|
|
10
10
|
function printArgumentsUsages(requiredUsages, optionalUsages, helpUsages)
|
|
11
11
|
{
|
|
12
|
-
if(!helpUsages) {
|
|
13
|
-
helpUsages = {
|
|
14
|
-
'-h | --help': 'Print help usages.',
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
12
|
let maxLength = 0;
|
|
19
13
|
for (const usage in requiredUsages) {
|
|
20
14
|
maxLength = (maxLength > usage.length ? maxLength : usage.length);
|
|
@@ -47,9 +41,7 @@ function printArgumentsUsages(requiredUsages, optionalUsages, helpUsages)
|
|
|
47
41
|
|
|
48
42
|
function parseArguments(requiredUsages = {},
|
|
49
43
|
optionalUsages = {},
|
|
50
|
-
withoutUnparsed = true
|
|
51
|
-
ignoreUnknown = false,
|
|
52
|
-
ignoreHelpUsage = false)
|
|
44
|
+
withoutUnparsed = true)
|
|
53
45
|
{
|
|
54
46
|
const keySeparator = '|';
|
|
55
47
|
const formatKey = (key) => {
|
|
@@ -118,8 +110,7 @@ function parseArguments(requiredUsages = {},
|
|
|
118
110
|
}
|
|
119
111
|
|
|
120
112
|
let options = {
|
|
121
|
-
unparsed: []
|
|
122
|
-
argumentsLine: '',
|
|
113
|
+
unparsed: []
|
|
123
114
|
};
|
|
124
115
|
|
|
125
116
|
// arg0: node
|
|
@@ -139,8 +130,7 @@ function parseArguments(requiredUsages = {},
|
|
|
139
130
|
}
|
|
140
131
|
}
|
|
141
132
|
|
|
142
|
-
if (
|
|
143
|
-
&& hasKey(helpUsages, key) == false
|
|
133
|
+
if (hasKey(helpUsages, key) == false
|
|
144
134
|
&& hasKey(requiredUsages, key) == false
|
|
145
135
|
&& hasKey(optionalUsages, key) == false) {
|
|
146
136
|
Logger.ErrorAndExitNoException('Failed to parse usage: ' + argu);
|
|
@@ -149,13 +139,11 @@ function parseArguments(requiredUsages = {},
|
|
|
149
139
|
let formattedKey = formatKey(key);
|
|
150
140
|
let formattedValue = formatValue(value);
|
|
151
141
|
options[formattedKey] = formattedValue;
|
|
152
|
-
|
|
153
|
-
options.argumentsLine += ' ' + argu;
|
|
154
142
|
}
|
|
155
143
|
|
|
156
144
|
for (const checker in helpUsages) {
|
|
157
145
|
const aliasedOptions = checkAliases(checker, options);
|
|
158
|
-
if (aliasedOptions
|
|
146
|
+
if (aliasedOptions) {
|
|
159
147
|
printArgumentsUsages(requiredUsages, optionalUsages, helpUsages);
|
|
160
148
|
process.exit(0);
|
|
161
149
|
}
|
|
@@ -220,8 +208,6 @@ function getOptions(framework)
|
|
|
220
208
|
}
|
|
221
209
|
|
|
222
210
|
options.appConfigDir = path.resolve(options.projectDir, 'src', 'appConfig');
|
|
223
|
-
options.appConfigFile = path.resolve(options.appConfigDir, 'app.config.mjs');
|
|
224
|
-
options.appJsviewConfigFile = path.resolve(options.appConfigDir, 'jsview.config.mjs');
|
|
225
211
|
options.appPrivKeyFile = path.resolve(options.appConfigDir, 'app_sign_private_key.crt');
|
|
226
212
|
options.appPubKeyFile = path.resolve(options.appConfigDir, 'app_sign_public_key.pem');
|
|
227
213
|
|
|
@@ -238,19 +224,19 @@ function getOptions(framework)
|
|
|
238
224
|
}
|
|
239
225
|
options.distJsvListFile = path.resolve(options.distDir, 'jsv-list.json');
|
|
240
226
|
options.distJsvInfoFile = path.resolve(options.distDir, 'jsv-info.json');
|
|
227
|
+
options.distJsIndexFile = path.resolve(options.distDir, 'index.html');
|
|
241
228
|
options.distJsDir = path.resolve(options.distDir, 'js');
|
|
242
229
|
options.distDebugDir = path.resolve(options.distDir, 'debug');
|
|
243
230
|
options.distDebugMapDir = path.resolve(options.distDebugDir, 'map');
|
|
244
231
|
|
|
245
232
|
const cacheName = (framework == 'vue' ? '.vite' : '.cache');
|
|
246
233
|
options.cacheDir = path.resolve(options.modulesDir, cacheName);
|
|
247
|
-
options.
|
|
248
|
-
options.baseUrlFile = path.resolve(options.cacheJsViewDir, 'network.mjs');
|
|
234
|
+
options.baseUrlFile = path.resolve(options.cacheDir, 'jsview', 'network.mjs');
|
|
249
235
|
|
|
250
236
|
return options;
|
|
251
237
|
}
|
|
252
238
|
|
|
253
|
-
function
|
|
239
|
+
function getPackageObject(modulePath)
|
|
254
240
|
{
|
|
255
241
|
const pkgFullFile = path.resolve(modulePath, 'package.json');
|
|
256
242
|
if (!fs.existsSync(pkgFullFile)) {
|
|
@@ -262,16 +248,6 @@ function loadPackageObject(modulePath)
|
|
|
262
248
|
return pkgObj;
|
|
263
249
|
}
|
|
264
250
|
|
|
265
|
-
function savePackageObject(modulePath, pkgObj)
|
|
266
|
-
{
|
|
267
|
-
const pkgFullFile = path.resolve(modulePath, 'package.json');
|
|
268
|
-
const pkgContent = JSON.stringify(pkgObj, null, 2);
|
|
269
|
-
|
|
270
|
-
fs.writeFileSync(pkgFullFile, pkgContent, 'utf8');
|
|
271
|
-
|
|
272
|
-
return pkgObj;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
251
|
function cpSync(workDir, srcPath, destPath, ignore=[])
|
|
276
252
|
{
|
|
277
253
|
const exists = fs.existsSync(srcPath);
|
|
@@ -409,44 +385,14 @@ function makeZip(zipFilePath, password, ...args)
|
|
|
409
385
|
}
|
|
410
386
|
}
|
|
411
387
|
|
|
412
|
-
function
|
|
388
|
+
function convertHomeDirectory(filePath)
|
|
413
389
|
{
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const file = fs.createWriteStream(localPath);
|
|
418
|
-
|
|
419
|
-
return new Promise((resolve, reject) => {
|
|
420
|
-
const request = https.get(url, (response) => {
|
|
421
|
-
response.pipe(file);
|
|
422
|
-
|
|
423
|
-
file.on('finish', () => {
|
|
424
|
-
file.close(() => {
|
|
425
|
-
Logger.Info('Success to download file to ' + relativePath);
|
|
426
|
-
resolve();
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
request.on('error', (err) => {
|
|
432
|
-
fs.unlink(localPath, () => {
|
|
433
|
-
Logger.ErrorAndExit('Failed to download file from ' + url);
|
|
434
|
-
reject(err);
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function unzipFile(zipFilePath, toDir, workDir)
|
|
441
|
-
{
|
|
442
|
-
var relativePath = path.relative(workDir, toDir);
|
|
443
|
-
if(!relativePath) {
|
|
444
|
-
relativePath = './'
|
|
390
|
+
if(!filePath) {
|
|
391
|
+
return null;
|
|
445
392
|
}
|
|
446
|
-
Logger.Info('Unzipping ' + zipFilePath + ' => ' + relativePath);
|
|
447
393
|
|
|
448
|
-
const
|
|
449
|
-
|
|
394
|
+
const homeDir = os.homedir();
|
|
395
|
+
return filePath.replace(/^~\//, homeDir + '/');
|
|
450
396
|
}
|
|
451
397
|
|
|
452
398
|
function getNpmRegistry()
|
|
@@ -457,20 +403,17 @@ function getNpmRegistry()
|
|
|
457
403
|
export {
|
|
458
404
|
askAndAnswer,
|
|
459
405
|
checkNodeVersion,
|
|
406
|
+
convertHomeDirectory,
|
|
460
407
|
cpSync,
|
|
461
|
-
downloadFileAsync,
|
|
462
408
|
execCommand,
|
|
463
409
|
getOptions,
|
|
410
|
+
getPackageObject,
|
|
464
411
|
getNpmRegistry,
|
|
465
412
|
isSymlinkSync,
|
|
466
|
-
loadPackageObject,
|
|
467
413
|
makeZip,
|
|
468
414
|
parseArguments,
|
|
469
|
-
printArgumentsUsages,
|
|
470
415
|
readJsonFile,
|
|
471
416
|
rmSync,
|
|
472
|
-
savePackageObject,
|
|
473
417
|
symlinkSync,
|
|
474
|
-
unzipFile,
|
|
475
418
|
Logger,
|
|
476
419
|
}
|
|
@@ -8,7 +8,7 @@ import url from 'node:url'
|
|
|
8
8
|
import {
|
|
9
9
|
checkNodeVersion,
|
|
10
10
|
getOptions,
|
|
11
|
-
|
|
11
|
+
getPackageObject,
|
|
12
12
|
parseArguments,
|
|
13
13
|
Logger,
|
|
14
14
|
} from './jsview-common.mjs';
|
|
@@ -181,9 +181,20 @@ function makeMainJsvMjs(options, framework)
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
const sourceContent = fs.readFileSync(jsEntryFilePath, 'utf8');
|
|
185
|
+
const hash = sourceContent.replace(/\n/g, '').replace(/.*\/\*jsvmd5:([a-fA-F0-9]{8})[a-fA-F0-9]*\*\/.*/, '$1');
|
|
186
|
+
const newEntryFileName = `main.jsv.${hash}.js`;
|
|
187
|
+
const newEntryFilePath = path.resolve(path.dirname(jsEntryFilePath), newEntryFileName);
|
|
188
|
+
Logger.Info(' -> ' + path.relative(options.projectDir, newEntryFilePath));
|
|
189
|
+
fs.renameSync(jsEntryFilePath, newEntryFilePath);
|
|
190
|
+
|
|
191
|
+
var indexContent = fs.readFileSync(options.distJsIndexFile, 'utf8');
|
|
192
|
+
indexContent = indexContent.replace(path.basename(jsEntryFilePath), newEntryFileName);
|
|
193
|
+
Logger.Info(' -> ' + path.relative(options.projectDir, options.distJsIndexFile));
|
|
194
|
+
fs.writeFileSync(options.distJsIndexFile, indexContent, 'utf8');
|
|
195
|
+
|
|
196
|
+
const moduleEntryFilePath = newEntryFilePath.replace(/\.js$/, '.mjs');
|
|
197
|
+
fs.copyFileSync(newEntryFilePath, moduleEntryFilePath);
|
|
187
198
|
}
|
|
188
199
|
|
|
189
200
|
function makeDebugMap(options, framework)
|
|
@@ -193,7 +204,7 @@ function makeDebugMap(options, framework)
|
|
|
193
204
|
let jsEntryFilePath;
|
|
194
205
|
const jsFileNames = fs.readdirSync(options.distJsDir);
|
|
195
206
|
for(const fileName of jsFileNames) {
|
|
196
|
-
if (fileName.startsWith('main.jsv') && fileName.endsWith('.
|
|
207
|
+
if (fileName.startsWith('main.jsv') && fileName.endsWith('.mjs')) {
|
|
197
208
|
jsEntryFilePath = path.resolve(options.distJsDir, fileName);
|
|
198
209
|
}
|
|
199
210
|
if (!fileName.endsWith('.map')) {
|
|
@@ -202,7 +213,7 @@ function makeDebugMap(options, framework)
|
|
|
202
213
|
|
|
203
214
|
const from = path.resolve(options.distJsDir, fileName);
|
|
204
215
|
const to = path.resolve(options.distDebugMapDir, fileName);
|
|
205
|
-
|
|
216
|
+
Logger.Info(' -> ' + path.relative(options.projectDir, to));
|
|
206
217
|
fs.renameSync(from, to);
|
|
207
218
|
};
|
|
208
219
|
|
|
@@ -241,7 +252,7 @@ function makeJsvList(options)
|
|
|
241
252
|
|
|
242
253
|
async function makeJsvInfo(options)
|
|
243
254
|
{
|
|
244
|
-
const jsviewPkgJson =
|
|
255
|
+
const jsviewPkgJson = getPackageObject(options.jsviewDir);
|
|
245
256
|
|
|
246
257
|
const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
|
|
247
258
|
const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
cpSync,
|
|
10
10
|
execCommand,
|
|
11
11
|
getOptions,
|
|
12
|
-
|
|
12
|
+
getPackageObject,
|
|
13
13
|
isSymlinkSync,
|
|
14
14
|
parseArguments,
|
|
15
15
|
symlinkSync,
|
|
@@ -33,7 +33,7 @@ function checkNpmCommand()
|
|
|
33
33
|
|
|
34
34
|
function checkNpmLinkForDebug(options, linkablePkgNames)
|
|
35
35
|
{
|
|
36
|
-
const pkgObj =
|
|
36
|
+
const pkgObj = getPackageObject(options.projectDir);
|
|
37
37
|
|
|
38
38
|
// node 16 不会安装本地包的二次依赖, 需要手动安装。
|
|
39
39
|
let missingDepPkgs = '';
|
|
@@ -46,7 +46,7 @@ function checkNpmLinkForDebug(options, linkablePkgNames)
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const linkablePath = path.resolve(options.modulesDir, linkableName);
|
|
49
|
-
const linkablePkgObj =
|
|
49
|
+
const linkablePkgObj = getPackageObject(linkablePath);
|
|
50
50
|
|
|
51
51
|
for (const dep in linkablePkgObj.dependencies ?? {}) {
|
|
52
52
|
const depPath = path.resolve(options.modulesDir, dep);
|
|
@@ -98,11 +98,11 @@ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
|
|
|
98
98
|
for (const pkgName of pkgNeedPatch) {
|
|
99
99
|
if (skipCheckVersion !== true) {
|
|
100
100
|
const patchPkgDir = path.resolve(options.jsviewPatchModulesDir, pkgName);
|
|
101
|
-
const patchPkgObj =
|
|
101
|
+
const patchPkgObj = getPackageObject(patchPkgDir);
|
|
102
102
|
Logger.Info(' ' + pkgName + ': ' + patchPkgObj.version);
|
|
103
103
|
|
|
104
104
|
const modulePkgDir = path.resolve(options.modulesDir, pkgName);
|
|
105
|
-
const modulePkgObj =
|
|
105
|
+
const modulePkgObj = getPackageObject(modulePkgDir);
|
|
106
106
|
if (modulePkgObj.version != patchPkgObj.version) {
|
|
107
107
|
Logger.ErrorAndExit(pkgName + '@' + modulePkgObj.version + ' is not supported, required version is ' + patchPkgObj.version);
|
|
108
108
|
}
|
|
@@ -114,7 +114,7 @@ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
|
|
|
114
114
|
|
|
115
115
|
function installPatches(options, pkgNeedPatch)
|
|
116
116
|
{
|
|
117
|
-
Logger.Info('
|
|
117
|
+
Logger.Info('Patching JsView:');
|
|
118
118
|
for (const pkgName of pkgNeedPatch) {
|
|
119
119
|
const patchSrc = path.resolve(options.jsviewPatchModulesDir, pkgName);
|
|
120
120
|
const patchDest = path.resolve(options.modulesDir, pkgName);
|
|
@@ -126,86 +126,6 @@ function installPatches(options, pkgNeedPatch)
|
|
|
126
126
|
rmSync(options.projectDir, options.cacheDir);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
function getPatchListRecursive(patchDir)
|
|
130
|
-
{
|
|
131
|
-
var patchList = [];
|
|
132
|
-
|
|
133
|
-
const pkgNameArray = fs.readdirSync(patchDir);
|
|
134
|
-
for (const pkgName of pkgNameArray) {
|
|
135
|
-
const pkgFullPath = path.resolve(patchDir, pkgName);
|
|
136
|
-
|
|
137
|
-
const isDirectory = fs.statSync(pkgFullPath).isDirectory();
|
|
138
|
-
if(isDirectory) {
|
|
139
|
-
const subPatchList = getPatchListRecursive(pkgFullPath);
|
|
140
|
-
patchList = [...patchList, ...subPatchList];
|
|
141
|
-
} else {
|
|
142
|
-
if(pkgFullPath.endsWith('.patch') == false) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
patchList.push(pkgFullPath);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return patchList;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function autoPatchPackages(options)
|
|
154
|
-
{
|
|
155
|
-
Logger.Info('Stage 2: Auto patching packages:');
|
|
156
|
-
|
|
157
|
-
const patchCacheDir = path.resolve(options.cacheJsViewDir, 'patches');
|
|
158
|
-
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.');
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
|
|
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
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const hasPatches = fs.readdirSync(patchCacheDir);
|
|
202
|
-
if(hasPatches && hasPatches.length > 0) {
|
|
203
|
-
execCommand('npx patch-package --patch-dir ' + path.relative(options.projectDir, patchCacheDir));
|
|
204
|
-
} else {
|
|
205
|
-
Logger.Info(' No patch files found.');
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
129
|
async function printRevision(options)
|
|
210
130
|
{
|
|
211
131
|
const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
|
|
@@ -268,8 +188,6 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion)
|
|
|
268
188
|
|
|
269
189
|
installPatches(options, pkgNeedPatch);
|
|
270
190
|
|
|
271
|
-
autoPatchPackages(options);
|
|
272
|
-
|
|
273
191
|
printRevision(options);
|
|
274
192
|
}
|
|
275
193
|
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
askAndAnswer,
|
|
8
|
+
checkNodeVersion,
|
|
9
|
+
convertHomeDirectory,
|
|
10
|
+
execCommand,
|
|
11
|
+
getOptions,
|
|
12
|
+
parseArguments,
|
|
13
|
+
Logger,
|
|
14
|
+
} from './jsview-common.mjs';
|
|
15
|
+
|
|
16
|
+
function getDefaultSourceMapDir() {
|
|
17
|
+
return './dist/debug/map';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getExtraOptions(argv)
|
|
21
|
+
{
|
|
22
|
+
const options = getOptions(argv.framework);
|
|
23
|
+
|
|
24
|
+
options.inputFile = convertHomeDirectory(argv.inputFile);
|
|
25
|
+
options.outputFile = convertHomeDirectory(argv.outputFile);
|
|
26
|
+
options.sourcemapDir = convertHomeDirectory(argv.sourcemapDir) ?? getDefaultSourceMapDir();
|
|
27
|
+
options.sourceMapMoudulePath = path.resolve(options.modulesDir, 'source-map', 'source-map.js');
|
|
28
|
+
|
|
29
|
+
if(!argv.sourcemapDir) {
|
|
30
|
+
Logger.Warn('Use default source map dir: ' + options.sourcemapDir);
|
|
31
|
+
}
|
|
32
|
+
if(fs.existsSync(options.sourcemapDir) == false) {
|
|
33
|
+
Logger.ErrorAndExit('Source map dir is not exists. Please check dir: ' + options.sourcemapDir);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return options;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function ensureSourceMapModule(options)
|
|
40
|
+
{
|
|
41
|
+
if (fs.existsSync(options.sourceMapMoudulePath)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Logger.Warn('node module "source-map" is not found.')
|
|
46
|
+
Logger.Warn(' Do you want to install it?');
|
|
47
|
+
const answer = askAndAnswer('(Y/n) ');
|
|
48
|
+
if (answer && answer.substring(0, 1) != 'y' && answer.substring(0, 3) != 'yes') {
|
|
49
|
+
Logger.ErrorAndExitNoException('User cancelled.')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let cmdline = 'npm install --package-lock-only --save-exact --save-dev source-map';
|
|
53
|
+
execCommand(cmdline);
|
|
54
|
+
cmdline = 'npm ci'
|
|
55
|
+
execCommand(cmdline);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function parseConsoleLog(options)
|
|
59
|
+
{
|
|
60
|
+
options.sourceMapModule = await import(options.sourceMapMoudulePath);
|
|
61
|
+
options.sourceMapConsumerMap = { };
|
|
62
|
+
|
|
63
|
+
const content = fs.readFileSync(options.inputFile, 'utf-8');
|
|
64
|
+
const contentLines = content.split('\n');
|
|
65
|
+
|
|
66
|
+
const regexCharAt = /^\s+at\s+(\S+)?\s?\(?(.*):(\d+):(\d+)\)?$/;
|
|
67
|
+
const regexSymbolAt = /^(\S+) @ (.*?):(\d+)(?::(\d+))?$/;
|
|
68
|
+
|
|
69
|
+
var resultLines = [];
|
|
70
|
+
for(const line of contentLines) {
|
|
71
|
+
var recovered = line.replace(/.*?:\d+ /, '');
|
|
72
|
+
|
|
73
|
+
if(regexCharAt.test(recovered)) {
|
|
74
|
+
recovered = await recoverCharAt(options, recovered, regexCharAt);
|
|
75
|
+
} else if(regexSymbolAt.test(recovered)) {
|
|
76
|
+
recovered = await recoverSymbolAt(options, recovered, regexSymbolAt);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(!options.outputFile) {
|
|
80
|
+
console.log(recovered);
|
|
81
|
+
} else {
|
|
82
|
+
resultLines.push(recovered);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const result = resultLines.join('\n');
|
|
87
|
+
if(options.outputFile) {
|
|
88
|
+
fs.writeFileSync(options.outputFile, result, 'utf-8');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function recoverCharAt(options, content, regex)
|
|
93
|
+
{
|
|
94
|
+
const matchResult = regex.exec(content);
|
|
95
|
+
var funcName = matchResult?.[1];
|
|
96
|
+
var fileName = matchResult?.[2];
|
|
97
|
+
var fileRow = matchResult?.[3];
|
|
98
|
+
var fileColumn = matchResult?.[4];
|
|
99
|
+
|
|
100
|
+
// at file.js:row:column
|
|
101
|
+
if(!fileName) {
|
|
102
|
+
fileName = funcName;
|
|
103
|
+
funcName = "";
|
|
104
|
+
} else { // at func (file.js:row:column)
|
|
105
|
+
// do nothing
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const origPos = await getOriginalPosition(options, fileName, fileRow, fileColumn);
|
|
109
|
+
if(!origPos) {
|
|
110
|
+
return content;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
funcName = (origPos.name ?? funcName);
|
|
114
|
+
content = ' at ';
|
|
115
|
+
content += funcName
|
|
116
|
+
content += (funcName ? ' (' : '');
|
|
117
|
+
content += (origPos.source + ':' + origPos.line + ':' + origPos.column);
|
|
118
|
+
content += (funcName ? ') ' : '');
|
|
119
|
+
|
|
120
|
+
return content;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function recoverSymbolAt(options, content, regex)
|
|
124
|
+
{
|
|
125
|
+
// 忽略,拿不到column,不能解析出结果
|
|
126
|
+
// const matchResult = regex.exec(content);
|
|
127
|
+
// var funcName = matchResult?.[1];
|
|
128
|
+
// var fileName = matchResult?.[2];
|
|
129
|
+
// var fileRow = matchResult?.[3];
|
|
130
|
+
// var fileColumn = matchResult?.[4];
|
|
131
|
+
|
|
132
|
+
// const origPos = await getOriginalPosition(options, fileName, fileRow, fileColumn);
|
|
133
|
+
// if(!origPos) {
|
|
134
|
+
// return content;
|
|
135
|
+
// }
|
|
136
|
+
|
|
137
|
+
// funcName = (origPos.name ?? funcName);
|
|
138
|
+
// content = funcName
|
|
139
|
+
// content += ' @ '
|
|
140
|
+
// content += (origPos.source + ':' + origPos.line + ':' + origPos.column);
|
|
141
|
+
|
|
142
|
+
return content;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function getOriginalPosition(options, fileName, fileRow, fileColumn)
|
|
146
|
+
{
|
|
147
|
+
if(!fileName || !fileRow || !fileColumn) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const sourceMapFilePath = path.resolve(options.sourcemapDir, fileName + '.map');
|
|
152
|
+
if(fs.existsSync(sourceMapFilePath) == false) {
|
|
153
|
+
Logger.Warn('Source map file is not found: ' + sourceMapFilePath)
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var sourceMapConsumer = options.sourceMapConsumerMap[sourceMapFilePath];
|
|
158
|
+
if(!sourceMapConsumer) {
|
|
159
|
+
const sourceMapContent = fs.readFileSync(sourceMapFilePath, 'utf-8');
|
|
160
|
+
sourceMapConsumer = new options.sourceMapModule.SourceMapConsumer(sourceMapContent);
|
|
161
|
+
if(sourceMapConsumer instanceof Promise) {
|
|
162
|
+
sourceMapConsumer = await sourceMapConsumer ;
|
|
163
|
+
}
|
|
164
|
+
options.sourceMapConsumerMap[sourceMapFilePath] = sourceMapConsumer;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const originalPosition = sourceMapConsumer.originalPositionFor({
|
|
168
|
+
line: Number(fileRow),
|
|
169
|
+
column: Number(fileColumn),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return originalPosition;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function main(argv)
|
|
176
|
+
{
|
|
177
|
+
checkNodeVersion();
|
|
178
|
+
|
|
179
|
+
const options = getExtraOptions(argv);
|
|
180
|
+
|
|
181
|
+
await ensureSourceMapModule(options);
|
|
182
|
+
|
|
183
|
+
await parseConsoleLog(options);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const requiredUsages = {
|
|
187
|
+
'--input-file': 'Chromium console log file path.',
|
|
188
|
+
};
|
|
189
|
+
const optionalUsages = {
|
|
190
|
+
'-d | --sourcemap-dir': 'Source map dir. Default dir is: ' + getDefaultSourceMapDir(),
|
|
191
|
+
'-o | --output-file': 'Recovered console log file path.',
|
|
192
|
+
};
|
|
193
|
+
const argv = parseArguments(requiredUsages, optionalUsages, false);
|
|
194
|
+
main(argv)
|