@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/index.mjs
CHANGED
|
@@ -759,20 +759,10 @@ function findFilesByGlob(cwd4, pattern) {
|
|
|
759
759
|
// src/actions/deplint/findFiles.ts
|
|
760
760
|
function findFiles(path10) {
|
|
761
761
|
const allSourceInclude = ["./src/**/*.{ts,tsx}"];
|
|
762
|
-
const allDistInclude = ["./dist/**/*.d.ts"];
|
|
763
|
-
const
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
const allDistFiles = allDistInclude.flatMap((pattern) => findFilesByGlob(path10, pattern));
|
|
767
|
-
const prodSourceFiles = allSourceFiles.filter((file) => !prodExcludeEndswith.some((ext) => file.endsWith(ext)) && !prodExcludeIncludes.some((excl) => file.includes(excl)));
|
|
768
|
-
const prodDistFiles = allDistFiles.filter((file) => !prodExcludeEndswith.some((ext) => file.endsWith(ext)) && !prodExcludeIncludes.some((excl) => file.includes(excl)));
|
|
769
|
-
const devSourceFiles = allSourceFiles.filter((file) => !prodSourceFiles.includes(file));
|
|
770
|
-
return {
|
|
771
|
-
allSourceFiles,
|
|
772
|
-
prodSourceFiles,
|
|
773
|
-
devSourceFiles,
|
|
774
|
-
prodDistFiles
|
|
775
|
-
};
|
|
762
|
+
const allDistInclude = ["./dist/**/*.d.ts", "./dist/**/*.{mjs,js,cjs}"];
|
|
763
|
+
const srcFiles = allSourceInclude.flatMap((pattern) => findFilesByGlob(path10, pattern));
|
|
764
|
+
const distFiles = allDistInclude.flatMap((pattern) => findFilesByGlob(path10, pattern));
|
|
765
|
+
return { srcFiles, distFiles };
|
|
776
766
|
}
|
|
777
767
|
|
|
778
768
|
// src/actions/deplint/getDependenciesFromPackageJson.ts
|
|
@@ -799,21 +789,24 @@ import ts from "typescript";
|
|
|
799
789
|
|
|
800
790
|
// src/actions/deplint/getBasePackageName.ts
|
|
801
791
|
function getBasePackageName(importName) {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
792
|
+
const importNameScrubbed = importName.replaceAll('"', "").trim();
|
|
793
|
+
if (importNameScrubbed.startsWith("@")) {
|
|
794
|
+
const parts = importNameScrubbed.split("/");
|
|
795
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
|
|
805
796
|
}
|
|
806
|
-
return
|
|
797
|
+
return importNameScrubbed.split("/")[0];
|
|
807
798
|
}
|
|
808
799
|
|
|
809
800
|
// src/actions/deplint/getImportsFromFile.ts
|
|
810
801
|
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
811
802
|
const sourceCode = fs3.readFileSync(filePath, "utf8");
|
|
803
|
+
const isMjsFile = filePath.endsWith(".mjs");
|
|
812
804
|
const sourceFile = ts.createSourceFile(
|
|
813
805
|
path4.basename(filePath),
|
|
814
806
|
sourceCode,
|
|
815
807
|
ts.ScriptTarget.Latest,
|
|
816
|
-
true
|
|
808
|
+
true,
|
|
809
|
+
isMjsFile ? ts.ScriptKind.JS : void 0
|
|
817
810
|
);
|
|
818
811
|
const imports = [];
|
|
819
812
|
const typeImports = [];
|
|
@@ -822,8 +815,8 @@ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
|
822
815
|
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
823
816
|
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
824
817
|
const isTypeImport = ts.isImportDeclaration(node) ? node.importClause?.isTypeOnly ?? false : false;
|
|
825
|
-
if (moduleSpecifier) {
|
|
826
|
-
const trimmed = moduleSpecifier.
|
|
818
|
+
if (typeof moduleSpecifier === "string") {
|
|
819
|
+
const trimmed = moduleSpecifier.replaceAll("'", "").replaceAll('"', "").trim();
|
|
827
820
|
if (isTypeImport || isDeclarationFile) {
|
|
828
821
|
typeImports.push(trimmed);
|
|
829
822
|
} else {
|
|
@@ -844,11 +837,11 @@ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
|
844
837
|
const cleanedImports = imports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
845
838
|
const cleanedTypeImports = typeImports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
846
839
|
for (const imp of cleanedImports) {
|
|
847
|
-
importPaths[imp] = importPaths[imp]
|
|
840
|
+
importPaths[imp] = importPaths[imp] ?? [];
|
|
848
841
|
importPaths[imp].push(filePath);
|
|
849
842
|
}
|
|
850
843
|
for (const imp of cleanedTypeImports) {
|
|
851
|
-
typeImportPaths[imp] = typeImportPaths[imp]
|
|
844
|
+
typeImportPaths[imp] = typeImportPaths[imp] ?? [];
|
|
852
845
|
typeImportPaths[imp].push(filePath);
|
|
853
846
|
}
|
|
854
847
|
return [cleanedImports, cleanedTypeImports];
|
|
@@ -859,117 +852,115 @@ var internalImportPrefixes = [".", "#", "node:"];
|
|
|
859
852
|
var removeInternalImports = (imports) => {
|
|
860
853
|
return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
|
|
861
854
|
};
|
|
862
|
-
function getExternalImportsFromFiles({
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
const
|
|
868
|
-
const
|
|
869
|
-
const
|
|
870
|
-
const
|
|
871
|
-
const prodImports = prodImportPairs.flatMap((pair) => pair[0]);
|
|
872
|
-
const prodDistImports = prodDistImportPairs.flatMap((pair) => pair[1]);
|
|
873
|
-
const devImportPaths = {};
|
|
874
|
-
const devTypeImportPaths = {};
|
|
875
|
-
const devImportPairs = devSourceFiles.map((path10) => getImportsFromFile(path10, devImportPaths, devTypeImportPaths));
|
|
876
|
-
const devImports = devImportPairs.flatMap((pair) => pair[0]);
|
|
877
|
-
const devTypeImports = devImportPairs.flatMap((pair) => pair[1]);
|
|
878
|
-
const externalProdImports = removeInternalImports(prodImports);
|
|
879
|
-
const externalProdTypeImports = removeInternalImports(prodDistImports);
|
|
880
|
-
const externalDevImports = removeInternalImports(devImports);
|
|
855
|
+
function getExternalImportsFromFiles({ srcFiles, distFiles }) {
|
|
856
|
+
const srcImportPaths = {};
|
|
857
|
+
const distImportPaths = {};
|
|
858
|
+
for (const path10 of srcFiles) getImportsFromFile(path10, srcImportPaths, srcImportPaths).flat();
|
|
859
|
+
for (const path10 of distFiles) getImportsFromFile(path10, distImportPaths, distImportPaths).flat();
|
|
860
|
+
const srcImports = Object.keys(srcImportPaths);
|
|
861
|
+
const distImports = Object.keys(distImportPaths);
|
|
862
|
+
const externalSrcImports = removeInternalImports(srcImports);
|
|
863
|
+
const externalDistImports = removeInternalImports(distImports);
|
|
881
864
|
return {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
externalDevImports,
|
|
889
|
-
prodDistImports,
|
|
890
|
-
devTypeImports,
|
|
891
|
-
externalProdTypeImports
|
|
865
|
+
srcImports,
|
|
866
|
+
srcImportPaths,
|
|
867
|
+
externalSrcImports,
|
|
868
|
+
distImports,
|
|
869
|
+
distImportPaths,
|
|
870
|
+
externalDistImports
|
|
892
871
|
};
|
|
893
872
|
}
|
|
894
873
|
|
|
895
874
|
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
896
875
|
import chalk14 from "chalk";
|
|
897
|
-
function getUnlistedDependencies({ name }, { dependencies, peerDependencies }, {
|
|
898
|
-
externalProdTypeImports,
|
|
899
|
-
prodTypeImportPaths,
|
|
900
|
-
externalProdImports,
|
|
901
|
-
prodImportPaths
|
|
902
|
-
}) {
|
|
876
|
+
function getUnlistedDependencies({ name, location }, { dependencies, peerDependencies }, { externalDistImports, distImportPaths }) {
|
|
903
877
|
let unlistedDependencies = 0;
|
|
904
|
-
for (const imp of
|
|
905
|
-
if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(`@types/${imp}`)) {
|
|
906
|
-
unlistedDependencies++;
|
|
907
|
-
console.log(`[${chalk14.blue(name)}] Missing dependency in package.json: ${chalk14.red(imp)}`);
|
|
908
|
-
console.log(` ${prodTypeImportPaths[imp].join("\n")}`);
|
|
909
|
-
console.log("");
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
for (const imp of externalProdImports) {
|
|
878
|
+
for (const imp of externalDistImports) {
|
|
913
879
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
914
880
|
unlistedDependencies++;
|
|
915
881
|
console.log(`[${chalk14.blue(name)}] Missing dependency in package.json: ${chalk14.red(imp)}`);
|
|
916
|
-
console.log(` ${
|
|
917
|
-
console.log("");
|
|
882
|
+
console.log(` ${distImportPaths[imp].join("\n ")}`);
|
|
918
883
|
}
|
|
919
884
|
}
|
|
885
|
+
if (unlistedDependencies > 0) {
|
|
886
|
+
const packageLocation = `${location}/package.json`;
|
|
887
|
+
console.log(` ${chalk14.yellow(packageLocation)}
|
|
888
|
+
`);
|
|
889
|
+
}
|
|
920
890
|
return unlistedDependencies;
|
|
921
891
|
}
|
|
922
892
|
|
|
923
893
|
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
924
894
|
import chalk15 from "chalk";
|
|
925
|
-
function getUnlistedDevDependencies({ name }, {
|
|
895
|
+
function getUnlistedDevDependencies({ name, location }, {
|
|
926
896
|
devDependencies,
|
|
927
897
|
dependencies,
|
|
928
898
|
peerDependencies
|
|
929
|
-
}, {
|
|
899
|
+
}, {
|
|
900
|
+
srcImportPaths,
|
|
901
|
+
externalSrcImports,
|
|
902
|
+
distImports
|
|
903
|
+
}) {
|
|
930
904
|
let unlistedDevDependencies = 0;
|
|
931
|
-
for (const imp of
|
|
932
|
-
if (!
|
|
905
|
+
for (const imp of externalSrcImports) {
|
|
906
|
+
if (!distImports.includes(imp) && !dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp)) {
|
|
933
907
|
unlistedDevDependencies++;
|
|
934
908
|
console.log(`[${chalk15.blue(name)}] Missing devDependency in package.json: ${chalk15.red(imp)}`);
|
|
935
|
-
console.log(`
|
|
909
|
+
console.log(` ${srcImportPaths[imp].join("\n ")}`);
|
|
936
910
|
}
|
|
937
911
|
}
|
|
912
|
+
if (unlistedDevDependencies > 0) {
|
|
913
|
+
const packageLocation = `${location}/package.json`;
|
|
914
|
+
console.log(` ${chalk15.yellow(packageLocation)}
|
|
915
|
+
`);
|
|
916
|
+
}
|
|
938
917
|
return unlistedDevDependencies;
|
|
939
918
|
}
|
|
940
919
|
|
|
941
920
|
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
942
921
|
import chalk16 from "chalk";
|
|
943
922
|
function getUnusedDependencies({ name, location }, { dependencies }, {
|
|
944
|
-
|
|
945
|
-
|
|
923
|
+
externalDistImports,
|
|
924
|
+
externalSrcImports
|
|
946
925
|
}) {
|
|
947
926
|
let unusedDependencies = 0;
|
|
948
927
|
for (const dep of dependencies) {
|
|
949
|
-
if (!
|
|
928
|
+
if (!externalDistImports.includes(dep)) {
|
|
950
929
|
unusedDependencies++;
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
930
|
+
if (externalSrcImports.includes(dep)) {
|
|
931
|
+
console.log(`[${chalk16.blue(name)}] dependency should be devDependency in package.json: ${chalk16.red(dep)}`);
|
|
932
|
+
} else {
|
|
933
|
+
console.log(`[${chalk16.blue(name)}] Unused dependency in package.json: ${chalk16.red(dep)}`);
|
|
934
|
+
}
|
|
955
935
|
}
|
|
956
936
|
}
|
|
937
|
+
if (unusedDependencies > 0) {
|
|
938
|
+
const packageLocation = `${location}/package.json`;
|
|
939
|
+
console.log(` ${chalk16.yellow(packageLocation)}
|
|
940
|
+
`);
|
|
941
|
+
}
|
|
957
942
|
return unusedDependencies;
|
|
958
943
|
}
|
|
959
944
|
|
|
960
945
|
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
961
946
|
import chalk17 from "chalk";
|
|
962
|
-
function getUnusedPeerDependencies({ name, location }, { peerDependencies }, {
|
|
947
|
+
function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports }) {
|
|
963
948
|
let unusedDependencies = 0;
|
|
964
949
|
for (const dep of peerDependencies) {
|
|
965
|
-
if (!
|
|
950
|
+
if (!externalDistImports.includes(dep)) {
|
|
966
951
|
unusedDependencies++;
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
952
|
+
if (dependencies.includes(dep)) {
|
|
953
|
+
console.log(`[${chalk17.blue(name)}] Unused peerDependency [already a dependency] in package.json: ${chalk17.red(dep)}`);
|
|
954
|
+
} else {
|
|
955
|
+
console.log(`[${chalk17.blue(name)}] Unused peerDependency in package.json: ${chalk17.red(dep)}`);
|
|
956
|
+
}
|
|
971
957
|
}
|
|
972
958
|
}
|
|
959
|
+
if (unusedDependencies > 0) {
|
|
960
|
+
const packageLocation = `${location}/package.json`;
|
|
961
|
+
console.log(` ${chalk17.yellow(packageLocation)}
|
|
962
|
+
`);
|
|
963
|
+
}
|
|
973
964
|
return unusedDependencies;
|
|
974
965
|
}
|
|
975
966
|
|
|
@@ -981,26 +972,17 @@ function checkPackage({
|
|
|
981
972
|
devDeps = false,
|
|
982
973
|
peerDeps = false
|
|
983
974
|
}) {
|
|
984
|
-
const {
|
|
985
|
-
prodSourceFiles,
|
|
986
|
-
devSourceFiles,
|
|
987
|
-
prodDistFiles
|
|
988
|
-
} = findFiles(location);
|
|
975
|
+
const { srcFiles, distFiles } = findFiles(location);
|
|
989
976
|
const checkDeps = deps || !(deps || devDeps || peerDeps);
|
|
990
977
|
const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
|
|
991
978
|
const checkPeerDeps = peerDeps;
|
|
992
|
-
const sourceParams = getExternalImportsFromFiles({
|
|
993
|
-
prodSourceFiles,
|
|
994
|
-
devSourceFiles,
|
|
995
|
-
prodDistFiles
|
|
996
|
-
});
|
|
979
|
+
const sourceParams = getExternalImportsFromFiles({ srcFiles, distFiles });
|
|
997
980
|
const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
998
981
|
const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
999
982
|
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
1000
|
-
const typesInDependencies = 0;
|
|
1001
983
|
const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
1002
984
|
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
1003
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies +
|
|
985
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedPeerDependencies;
|
|
1004
986
|
return totalErrors;
|
|
1005
987
|
}
|
|
1006
988
|
|