@xylabs/ts-scripts-yarn3 6.5.5 → 6.5.7
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/dist/actions/deplint/checkPackage/checkPackage.mjs +81 -99
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +8 -17
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +14 -5
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +13 -7
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +12 -6
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/index.mjs +81 -99
- package/dist/actions/deplint/checkPackage/index.mjs.map +1 -1
- package/dist/actions/deplint/deplint.mjs +81 -99
- package/dist/actions/deplint/deplint.mjs.map +1 -1
- package/dist/actions/deplint/findFiles.mjs +4 -14
- package/dist/actions/deplint/findFiles.mjs.map +1 -1
- package/dist/actions/deplint/getBasePackageName.mjs +5 -4
- package/dist/actions/deplint/getBasePackageName.mjs.map +1 -1
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs +27 -38
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +1 -1
- package/dist/actions/deplint/getImportsFromFile.mjs +12 -9
- package/dist/actions/deplint/getImportsFromFile.mjs.map +1 -1
- package/dist/actions/deplint/index.mjs +81 -99
- package/dist/actions/deplint/index.mjs.map +1 -1
- package/dist/actions/index.mjs +81 -99
- package/dist/actions/index.mjs.map +1 -1
- package/dist/bin/xy.mjs +81 -99
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +81 -99
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +81 -99
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +81 -99
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +81 -99
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/actions/deplint/checkPackage/getTypesInDependencies.mjs +0 -19
- package/dist/actions/deplint/checkPackage/getTypesInDependencies.mjs.map +0 -1
package/dist/xy/xy.mjs
CHANGED
|
@@ -667,20 +667,10 @@ function findFilesByGlob(cwd, pattern) {
|
|
|
667
667
|
// src/actions/deplint/findFiles.ts
|
|
668
668
|
function findFiles(path5) {
|
|
669
669
|
const allSourceInclude = ["./src/**/*.{ts,tsx}"];
|
|
670
|
-
const allDistInclude = ["./dist/**/*.d.ts"];
|
|
671
|
-
const
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
const allDistFiles = allDistInclude.flatMap((pattern) => findFilesByGlob(path5, pattern));
|
|
675
|
-
const prodSourceFiles = allSourceFiles.filter((file) => !prodExcludeEndswith.some((ext) => file.endsWith(ext)) && !prodExcludeIncludes.some((excl) => file.includes(excl)));
|
|
676
|
-
const prodDistFiles = allDistFiles.filter((file) => !prodExcludeEndswith.some((ext) => file.endsWith(ext)) && !prodExcludeIncludes.some((excl) => file.includes(excl)));
|
|
677
|
-
const devSourceFiles = allSourceFiles.filter((file) => !prodSourceFiles.includes(file));
|
|
678
|
-
return {
|
|
679
|
-
allSourceFiles,
|
|
680
|
-
prodSourceFiles,
|
|
681
|
-
devSourceFiles,
|
|
682
|
-
prodDistFiles
|
|
683
|
-
};
|
|
670
|
+
const allDistInclude = ["./dist/**/*.d.ts", "./dist/**/*.{mjs,js,cjs}"];
|
|
671
|
+
const srcFiles = allSourceInclude.flatMap((pattern) => findFilesByGlob(path5, pattern));
|
|
672
|
+
const distFiles = allDistInclude.flatMap((pattern) => findFilesByGlob(path5, pattern));
|
|
673
|
+
return { srcFiles, distFiles };
|
|
684
674
|
}
|
|
685
675
|
|
|
686
676
|
// src/actions/deplint/getDependenciesFromPackageJson.ts
|
|
@@ -707,21 +697,24 @@ import ts from "typescript";
|
|
|
707
697
|
|
|
708
698
|
// src/actions/deplint/getBasePackageName.ts
|
|
709
699
|
function getBasePackageName(importName) {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
700
|
+
const importNameScrubbed = importName.replaceAll('"', "").trim();
|
|
701
|
+
if (importNameScrubbed.startsWith("@")) {
|
|
702
|
+
const parts = importNameScrubbed.split("/");
|
|
703
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
|
|
713
704
|
}
|
|
714
|
-
return
|
|
705
|
+
return importNameScrubbed.split("/")[0];
|
|
715
706
|
}
|
|
716
707
|
|
|
717
708
|
// src/actions/deplint/getImportsFromFile.ts
|
|
718
709
|
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
719
710
|
const sourceCode = fs3.readFileSync(filePath, "utf8");
|
|
711
|
+
const isMjsFile = filePath.endsWith(".mjs");
|
|
720
712
|
const sourceFile = ts.createSourceFile(
|
|
721
713
|
path4.basename(filePath),
|
|
722
714
|
sourceCode,
|
|
723
715
|
ts.ScriptTarget.Latest,
|
|
724
|
-
true
|
|
716
|
+
true,
|
|
717
|
+
isMjsFile ? ts.ScriptKind.JS : void 0
|
|
725
718
|
);
|
|
726
719
|
const imports = [];
|
|
727
720
|
const typeImports = [];
|
|
@@ -730,8 +723,8 @@ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
|
730
723
|
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
731
724
|
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
732
725
|
const isTypeImport = ts.isImportDeclaration(node) ? node.importClause?.isTypeOnly ?? false : false;
|
|
733
|
-
if (moduleSpecifier) {
|
|
734
|
-
const trimmed = moduleSpecifier.
|
|
726
|
+
if (typeof moduleSpecifier === "string") {
|
|
727
|
+
const trimmed = moduleSpecifier.replaceAll("'", "").replaceAll('"', "").trim();
|
|
735
728
|
if (isTypeImport || isDeclarationFile) {
|
|
736
729
|
typeImports.push(trimmed);
|
|
737
730
|
} else {
|
|
@@ -752,11 +745,11 @@ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
|
752
745
|
const cleanedImports = imports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
753
746
|
const cleanedTypeImports = typeImports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
754
747
|
for (const imp of cleanedImports) {
|
|
755
|
-
importPaths[imp] = importPaths[imp]
|
|
748
|
+
importPaths[imp] = importPaths[imp] ?? [];
|
|
756
749
|
importPaths[imp].push(filePath);
|
|
757
750
|
}
|
|
758
751
|
for (const imp of cleanedTypeImports) {
|
|
759
|
-
typeImportPaths[imp] = typeImportPaths[imp]
|
|
752
|
+
typeImportPaths[imp] = typeImportPaths[imp] ?? [];
|
|
760
753
|
typeImportPaths[imp].push(filePath);
|
|
761
754
|
}
|
|
762
755
|
return [cleanedImports, cleanedTypeImports];
|
|
@@ -767,117 +760,115 @@ var internalImportPrefixes = [".", "#", "node:"];
|
|
|
767
760
|
var removeInternalImports = (imports) => {
|
|
768
761
|
return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
|
|
769
762
|
};
|
|
770
|
-
function getExternalImportsFromFiles({
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const
|
|
776
|
-
const
|
|
777
|
-
const
|
|
778
|
-
const
|
|
779
|
-
const prodImports = prodImportPairs.flatMap((pair) => pair[0]);
|
|
780
|
-
const prodDistImports = prodDistImportPairs.flatMap((pair) => pair[1]);
|
|
781
|
-
const devImportPaths = {};
|
|
782
|
-
const devTypeImportPaths = {};
|
|
783
|
-
const devImportPairs = devSourceFiles.map((path5) => getImportsFromFile(path5, devImportPaths, devTypeImportPaths));
|
|
784
|
-
const devImports = devImportPairs.flatMap((pair) => pair[0]);
|
|
785
|
-
const devTypeImports = devImportPairs.flatMap((pair) => pair[1]);
|
|
786
|
-
const externalProdImports = removeInternalImports(prodImports);
|
|
787
|
-
const externalProdTypeImports = removeInternalImports(prodDistImports);
|
|
788
|
-
const externalDevImports = removeInternalImports(devImports);
|
|
763
|
+
function getExternalImportsFromFiles({ srcFiles, distFiles }) {
|
|
764
|
+
const srcImportPaths = {};
|
|
765
|
+
const distImportPaths = {};
|
|
766
|
+
for (const path5 of srcFiles) getImportsFromFile(path5, srcImportPaths, srcImportPaths).flat();
|
|
767
|
+
for (const path5 of distFiles) getImportsFromFile(path5, distImportPaths, distImportPaths).flat();
|
|
768
|
+
const srcImports = Object.keys(srcImportPaths);
|
|
769
|
+
const distImports = Object.keys(distImportPaths);
|
|
770
|
+
const externalSrcImports = removeInternalImports(srcImports);
|
|
771
|
+
const externalDistImports = removeInternalImports(distImports);
|
|
789
772
|
return {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
externalDevImports,
|
|
797
|
-
prodDistImports,
|
|
798
|
-
devTypeImports,
|
|
799
|
-
externalProdTypeImports
|
|
773
|
+
srcImports,
|
|
774
|
+
srcImportPaths,
|
|
775
|
+
externalSrcImports,
|
|
776
|
+
distImports,
|
|
777
|
+
distImportPaths,
|
|
778
|
+
externalDistImports
|
|
800
779
|
};
|
|
801
780
|
}
|
|
802
781
|
|
|
803
782
|
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
804
783
|
import chalk12 from "chalk";
|
|
805
|
-
function getUnlistedDependencies({ name }, { dependencies, peerDependencies }, {
|
|
806
|
-
externalProdTypeImports,
|
|
807
|
-
prodTypeImportPaths,
|
|
808
|
-
externalProdImports,
|
|
809
|
-
prodImportPaths
|
|
810
|
-
}) {
|
|
784
|
+
function getUnlistedDependencies({ name, location }, { dependencies, peerDependencies }, { externalDistImports, distImportPaths }) {
|
|
811
785
|
let unlistedDependencies = 0;
|
|
812
|
-
for (const imp of
|
|
813
|
-
if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(`@types/${imp}`)) {
|
|
814
|
-
unlistedDependencies++;
|
|
815
|
-
console.log(`[${chalk12.blue(name)}] Missing dependency in package.json: ${chalk12.red(imp)}`);
|
|
816
|
-
console.log(` ${prodTypeImportPaths[imp].join("\n")}`);
|
|
817
|
-
console.log("");
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
for (const imp of externalProdImports) {
|
|
786
|
+
for (const imp of externalDistImports) {
|
|
821
787
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
822
788
|
unlistedDependencies++;
|
|
823
789
|
console.log(`[${chalk12.blue(name)}] Missing dependency in package.json: ${chalk12.red(imp)}`);
|
|
824
|
-
console.log(` ${
|
|
825
|
-
console.log("");
|
|
790
|
+
console.log(` ${distImportPaths[imp].join("\n ")}`);
|
|
826
791
|
}
|
|
827
792
|
}
|
|
793
|
+
if (unlistedDependencies > 0) {
|
|
794
|
+
const packageLocation = `${location}/package.json`;
|
|
795
|
+
console.log(` ${chalk12.yellow(packageLocation)}
|
|
796
|
+
`);
|
|
797
|
+
}
|
|
828
798
|
return unlistedDependencies;
|
|
829
799
|
}
|
|
830
800
|
|
|
831
801
|
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
832
802
|
import chalk13 from "chalk";
|
|
833
|
-
function getUnlistedDevDependencies({ name }, {
|
|
803
|
+
function getUnlistedDevDependencies({ name, location }, {
|
|
834
804
|
devDependencies,
|
|
835
805
|
dependencies,
|
|
836
806
|
peerDependencies
|
|
837
|
-
}, {
|
|
807
|
+
}, {
|
|
808
|
+
srcImportPaths,
|
|
809
|
+
externalSrcImports,
|
|
810
|
+
distImports
|
|
811
|
+
}) {
|
|
838
812
|
let unlistedDevDependencies = 0;
|
|
839
|
-
for (const imp of
|
|
840
|
-
if (!
|
|
813
|
+
for (const imp of externalSrcImports) {
|
|
814
|
+
if (!distImports.includes(imp) && !dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp)) {
|
|
841
815
|
unlistedDevDependencies++;
|
|
842
816
|
console.log(`[${chalk13.blue(name)}] Missing devDependency in package.json: ${chalk13.red(imp)}`);
|
|
843
|
-
console.log(`
|
|
817
|
+
console.log(` ${srcImportPaths[imp].join("\n ")}`);
|
|
844
818
|
}
|
|
845
819
|
}
|
|
820
|
+
if (unlistedDevDependencies > 0) {
|
|
821
|
+
const packageLocation = `${location}/package.json`;
|
|
822
|
+
console.log(` ${chalk13.yellow(packageLocation)}
|
|
823
|
+
`);
|
|
824
|
+
}
|
|
846
825
|
return unlistedDevDependencies;
|
|
847
826
|
}
|
|
848
827
|
|
|
849
828
|
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
850
829
|
import chalk14 from "chalk";
|
|
851
830
|
function getUnusedDependencies({ name, location }, { dependencies }, {
|
|
852
|
-
|
|
853
|
-
|
|
831
|
+
externalDistImports,
|
|
832
|
+
externalSrcImports
|
|
854
833
|
}) {
|
|
855
834
|
let unusedDependencies = 0;
|
|
856
835
|
for (const dep of dependencies) {
|
|
857
|
-
if (!
|
|
836
|
+
if (!externalDistImports.includes(dep)) {
|
|
858
837
|
unusedDependencies++;
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
838
|
+
if (externalSrcImports.includes(dep)) {
|
|
839
|
+
console.log(`[${chalk14.blue(name)}] dependency should be devDependency in package.json: ${chalk14.red(dep)}`);
|
|
840
|
+
} else {
|
|
841
|
+
console.log(`[${chalk14.blue(name)}] Unused dependency in package.json: ${chalk14.red(dep)}`);
|
|
842
|
+
}
|
|
863
843
|
}
|
|
864
844
|
}
|
|
845
|
+
if (unusedDependencies > 0) {
|
|
846
|
+
const packageLocation = `${location}/package.json`;
|
|
847
|
+
console.log(` ${chalk14.yellow(packageLocation)}
|
|
848
|
+
`);
|
|
849
|
+
}
|
|
865
850
|
return unusedDependencies;
|
|
866
851
|
}
|
|
867
852
|
|
|
868
853
|
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
869
854
|
import chalk15 from "chalk";
|
|
870
|
-
function getUnusedPeerDependencies({ name, location }, { peerDependencies }, {
|
|
855
|
+
function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports }) {
|
|
871
856
|
let unusedDependencies = 0;
|
|
872
857
|
for (const dep of peerDependencies) {
|
|
873
|
-
if (!
|
|
858
|
+
if (!externalDistImports.includes(dep)) {
|
|
874
859
|
unusedDependencies++;
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
860
|
+
if (dependencies.includes(dep)) {
|
|
861
|
+
console.log(`[${chalk15.blue(name)}] Unused peerDependency [already a dependency] in package.json: ${chalk15.red(dep)}`);
|
|
862
|
+
} else {
|
|
863
|
+
console.log(`[${chalk15.blue(name)}] Unused peerDependency in package.json: ${chalk15.red(dep)}`);
|
|
864
|
+
}
|
|
879
865
|
}
|
|
880
866
|
}
|
|
867
|
+
if (unusedDependencies > 0) {
|
|
868
|
+
const packageLocation = `${location}/package.json`;
|
|
869
|
+
console.log(` ${chalk15.yellow(packageLocation)}
|
|
870
|
+
`);
|
|
871
|
+
}
|
|
881
872
|
return unusedDependencies;
|
|
882
873
|
}
|
|
883
874
|
|
|
@@ -889,26 +880,17 @@ function checkPackage({
|
|
|
889
880
|
devDeps = false,
|
|
890
881
|
peerDeps = false
|
|
891
882
|
}) {
|
|
892
|
-
const {
|
|
893
|
-
prodSourceFiles,
|
|
894
|
-
devSourceFiles,
|
|
895
|
-
prodDistFiles
|
|
896
|
-
} = findFiles(location);
|
|
883
|
+
const { srcFiles, distFiles } = findFiles(location);
|
|
897
884
|
const checkDeps = deps || !(deps || devDeps || peerDeps);
|
|
898
885
|
const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
|
|
899
886
|
const checkPeerDeps = peerDeps;
|
|
900
|
-
const sourceParams = getExternalImportsFromFiles({
|
|
901
|
-
prodSourceFiles,
|
|
902
|
-
devSourceFiles,
|
|
903
|
-
prodDistFiles
|
|
904
|
-
});
|
|
887
|
+
const sourceParams = getExternalImportsFromFiles({ srcFiles, distFiles });
|
|
905
888
|
const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
906
889
|
const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
907
890
|
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
908
|
-
const typesInDependencies = 0;
|
|
909
891
|
const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
910
892
|
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
911
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies +
|
|
893
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedPeerDependencies;
|
|
912
894
|
return totalErrors;
|
|
913
895
|
}
|
|
914
896
|
|