xshell 1.3.42 → 1.3.44
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/xlint.js +20 -9
package/package.json
CHANGED
package/xlint.js
CHANGED
|
@@ -679,17 +679,18 @@ export const xlint_plugin = {
|
|
|
679
679
|
// 格式化 source, 收集 decl
|
|
680
680
|
ImportDeclaration(node) {
|
|
681
681
|
const source = node.source.value;
|
|
682
|
-
const [type, source_] = format_source(pkgs, aliases, cwd, context.filename.fp, source);
|
|
682
|
+
const [type, source_, ialias] = format_source(pkgs, aliases, cwd, context.filename.fp, source);
|
|
683
683
|
if (!source_ || source_ === source) {
|
|
684
684
|
imports.push({
|
|
685
685
|
node,
|
|
686
686
|
type,
|
|
687
|
-
style: style_fexts.has(source.fext)
|
|
687
|
+
style: style_fexts.has(source.fext),
|
|
688
|
+
ialias
|
|
688
689
|
});
|
|
689
690
|
return;
|
|
690
691
|
}
|
|
691
692
|
need_fix_source = true;
|
|
692
|
-
console.log(`自动修复 ${source} -> ${source_}`)
|
|
693
|
+
// console.log(`自动修复 ${source} -> ${source_}`)
|
|
693
694
|
context.report({
|
|
694
695
|
// @ts-ignore
|
|
695
696
|
message: `import source ${source} 应该改为 ${source_}`,
|
|
@@ -719,6 +720,8 @@ export const xlint_plugin = {
|
|
|
719
720
|
let imports_ = imports.toSorted((a, b) => {
|
|
720
721
|
if (a.style !== b.style)
|
|
721
722
|
return a.style ? -1 : 1;
|
|
723
|
+
if (a.type === 'alias' && b.type === 'alias')
|
|
724
|
+
return a.ialias - b.ialias;
|
|
722
725
|
return imtypes.indexOf(a.type) - imtypes.indexOf(b.type);
|
|
723
726
|
});
|
|
724
727
|
for (let i = 0; i < imports.length; i++) {
|
|
@@ -750,7 +753,7 @@ export const xlint_plugin = {
|
|
|
750
753
|
return text;
|
|
751
754
|
});
|
|
752
755
|
// 一次性替换所有 import
|
|
753
|
-
return fixer.replaceTextRange([_start, _end], texts.join_lines());
|
|
756
|
+
return fixer.replaceTextRange([_start, _end], texts.join_lines(false));
|
|
754
757
|
}
|
|
755
758
|
});
|
|
756
759
|
break;
|
|
@@ -1011,7 +1014,11 @@ function get_packages(cwd) {
|
|
|
1011
1014
|
if (cache_pkgs_cwd === cwd)
|
|
1012
1015
|
return cache_pkgs;
|
|
1013
1016
|
const { dependencies = {}, devDependencies = {} } = JSON.parse(fs.readFileSync(`${cwd}package.json`, 'utf-8'));
|
|
1014
|
-
const pkgs = [
|
|
1017
|
+
const pkgs = [
|
|
1018
|
+
...Object.keys(dependencies),
|
|
1019
|
+
...Object.keys(devDependencies)
|
|
1020
|
+
.map(pkg => pkg.startsWith('@types/') ? pkg.strip_start('@types/') : pkg),
|
|
1021
|
+
].unique();
|
|
1015
1022
|
cache_pkgs_cwd = cwd;
|
|
1016
1023
|
return cache_pkgs = pkgs;
|
|
1017
1024
|
}
|
|
@@ -1057,9 +1064,10 @@ function format_source(pkgs, aliases, cwd, fp, source) {
|
|
|
1057
1064
|
source = `${source}.${resolve_suffix(source)}`;
|
|
1058
1065
|
}
|
|
1059
1066
|
const relative = source.strip_start(cwd, true);
|
|
1060
|
-
const
|
|
1061
|
-
check(
|
|
1062
|
-
|
|
1067
|
+
const ialias = aliases.findIndex(({ fp }) => relative.startsWith(fp));
|
|
1068
|
+
check(ialias !== -1, '一定能找到匹配的 alias');
|
|
1069
|
+
const alias_ = aliases[ialias];
|
|
1070
|
+
return ['alias', alias_.alias + relative.strip_start(alias_.fp), ialias];
|
|
1063
1071
|
}
|
|
1064
1072
|
let cache_exists = new Map();
|
|
1065
1073
|
function resolve_suffix(fp_base) {
|
|
@@ -1067,7 +1075,10 @@ function resolve_suffix(fp_base) {
|
|
|
1067
1075
|
const fp = `${fp_base}.${suffix}`;
|
|
1068
1076
|
const c = cache_exists.get(fp);
|
|
1069
1077
|
if (c !== undefined)
|
|
1070
|
-
|
|
1078
|
+
if (c)
|
|
1079
|
+
return suffix;
|
|
1080
|
+
else
|
|
1081
|
+
continue;
|
|
1071
1082
|
const e = fs.existsSync(fp);
|
|
1072
1083
|
cache_exists.set(fp, e);
|
|
1073
1084
|
if (e)
|