ohos-router 1.1.4 → 1.1.6
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/package.json +1 -1
- package/router.ts +51 -28
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -167,6 +167,12 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
|
|
|
167
167
|
"RouterConfig } from '" + item + "';\n"
|
|
168
168
|
}
|
|
169
169
|
})
|
|
170
|
+
|
|
171
|
+
if(importHaveConfig.indexOf(name + "RouterConfig")==-1){
|
|
172
|
+
//证明没导入,那就手动再导入一次
|
|
173
|
+
importHaveConfig = importHaveConfig + "\nimport { " + name +
|
|
174
|
+
"RouterConfig } from '" + name.toLowerCase() + "';\n";
|
|
175
|
+
}
|
|
170
176
|
}
|
|
171
177
|
})
|
|
172
178
|
|
|
@@ -217,21 +223,34 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
|
|
|
217
223
|
|
|
218
224
|
}
|
|
219
225
|
|
|
226
|
+
function hasTwoOccurrencesIndexOf(str: string, target: string): boolean {
|
|
227
|
+
const firstIndex = str.indexOf(target);
|
|
228
|
+
if (firstIndex === -1) return false;
|
|
220
229
|
|
|
221
|
-
|
|
230
|
+
const secondIndex = str.indexOf(target, firstIndex + target.length);
|
|
231
|
+
return secondIndex !== -1;
|
|
232
|
+
}
|
|
222
233
|
|
|
234
|
+
let moduleSrcEntry: string
|
|
223
235
|
function moduleJson5JSONParse(moduleJson5Data: string) {
|
|
224
236
|
try {
|
|
225
237
|
let moduleJsonBean = JSON.parse(moduleJson5Data)
|
|
226
238
|
let module = moduleJsonBean.module
|
|
227
239
|
moduleSrcEntry = module.srcEntry
|
|
228
240
|
} catch (error) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
241
|
+
// 尝试修复常见的 JSON 错误
|
|
242
|
+
const repairedJson = moduleJson5Data
|
|
243
|
+
// 修复单引号
|
|
244
|
+
.replace(/'/g, '"')
|
|
245
|
+
// 修复未加引号的键名
|
|
246
|
+
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
247
|
+
// 修复尾随逗号
|
|
248
|
+
.replace(/,\s*}/g, '}')
|
|
249
|
+
.replace(/,\s*]/g, ']')
|
|
250
|
+
// 修复注释(移除单行和多行注释)
|
|
251
|
+
.replace(/\/\/.*$/gm, '')
|
|
252
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
253
|
+
moduleJson5JSONParse(repairedJson)
|
|
235
254
|
}
|
|
236
255
|
}
|
|
237
256
|
|
|
@@ -344,12 +363,19 @@ function dependenciesJSONParse(ohPackageData: string) {
|
|
|
344
363
|
}
|
|
345
364
|
}
|
|
346
365
|
} catch (error) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
366
|
+
// 尝试修复常见的 JSON 错误
|
|
367
|
+
const repairedJson = ohPackageData
|
|
368
|
+
// 修复单引号
|
|
369
|
+
.replace(/'/g, '"')
|
|
370
|
+
// 修复未加引号的键名
|
|
371
|
+
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
372
|
+
// 修复尾随逗号
|
|
373
|
+
.replace(/,\s*}/g, '}')
|
|
374
|
+
.replace(/,\s*]/g, ']')
|
|
375
|
+
// 修复注释(移除单行和多行注释)
|
|
376
|
+
.replace(/\/\/.*$/gm, '')
|
|
377
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
378
|
+
dependenciesJSONParse(repairedJson)
|
|
353
379
|
}
|
|
354
380
|
}
|
|
355
381
|
|
|
@@ -376,12 +402,18 @@ function buildProfileJSONParse(buildProfileData: string) {
|
|
|
376
402
|
}
|
|
377
403
|
}
|
|
378
404
|
} catch (error) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
405
|
+
const repairedJson = buildProfileData
|
|
406
|
+
// 修复单引号
|
|
407
|
+
.replace(/'/g, '"')
|
|
408
|
+
// 修复未加引号的键名
|
|
409
|
+
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
410
|
+
// 修复尾随逗号
|
|
411
|
+
.replace(/,\s*}/g, '}')
|
|
412
|
+
.replace(/,\s*]/g, ']')
|
|
413
|
+
// 修复注释(移除单行和多行注释)
|
|
414
|
+
.replace(/\/\/.*$/gm, '')
|
|
415
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
416
|
+
buildProfileJSONParse(repairedJson)
|
|
385
417
|
}
|
|
386
418
|
}
|
|
387
419
|
|
|
@@ -484,12 +516,3 @@ function replaceCharUsingSubstring(str: string, index: number, newChar: string)
|
|
|
484
516
|
}
|
|
485
517
|
return str.substring(0, index) + newChar + str.substring(index + 1);
|
|
486
518
|
}
|
|
487
|
-
|
|
488
|
-
function addPropertyToBeginning<T extends object, K extends string, V>(
|
|
489
|
-
obj: T,
|
|
490
|
-
key: K,
|
|
491
|
-
value: V
|
|
492
|
-
): T & { [P in K]: V } {
|
|
493
|
-
const newObj = {[key]: value, ...obj} as T & { [P in K]: V };
|
|
494
|
-
return newObj;
|
|
495
|
-
}
|