@xylabs/ts-scripts-yarn3 6.4.2 → 6.4.4
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.mjs +53 -7
- package/dist/actions/deplint.mjs.map +1 -1
- package/dist/actions/index.mjs +53 -7
- package/dist/actions/index.mjs.map +1 -1
- package/dist/bin/xy.mjs +53 -7
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +53 -7
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +53 -7
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +53 -7
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +53 -7
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +4 -5
package/dist/index.mjs
CHANGED
|
@@ -773,7 +773,7 @@ function getBasePackageName(importName) {
|
|
|
773
773
|
}
|
|
774
774
|
return importName.split("/")[0];
|
|
775
775
|
}
|
|
776
|
-
function getImportsFromFile(filePath, importPaths) {
|
|
776
|
+
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
777
777
|
const sourceCode = fs2.readFileSync(filePath, "utf8");
|
|
778
778
|
const sourceFile = ts.createSourceFile(
|
|
779
779
|
path3.basename(filePath),
|
|
@@ -782,24 +782,41 @@ function getImportsFromFile(filePath, importPaths) {
|
|
|
782
782
|
true
|
|
783
783
|
);
|
|
784
784
|
const imports = [];
|
|
785
|
+
const typeImports = [];
|
|
785
786
|
function visit(node) {
|
|
786
787
|
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
787
788
|
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
789
|
+
const isTypeImport = ts.isImportDeclaration(node) ? node.importClause?.isTypeOnly ?? false : false;
|
|
788
790
|
if (moduleSpecifier) {
|
|
789
791
|
const trimmed = moduleSpecifier.split("'").at(1) ?? moduleSpecifier;
|
|
792
|
+
if (isTypeImport) {
|
|
793
|
+
typeImports.push(trimmed);
|
|
794
|
+
} else {
|
|
795
|
+
imports.push(trimmed);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
} else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
799
|
+
const [arg] = node.arguments;
|
|
800
|
+
if (ts.isStringLiteral(arg)) {
|
|
801
|
+
const trimmed = arg.text;
|
|
790
802
|
imports.push(trimmed);
|
|
791
803
|
}
|
|
792
804
|
}
|
|
793
805
|
ts.forEachChild(node, visit);
|
|
794
806
|
}
|
|
795
807
|
visit(sourceFile);
|
|
796
|
-
const importsStartsWithExcludes = [".", "#", "node:"
|
|
808
|
+
const importsStartsWithExcludes = [".", "#", "node:"];
|
|
797
809
|
const cleanedImports = imports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
810
|
+
const cleanedTypeImports = typeImports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
798
811
|
for (const imp of cleanedImports) {
|
|
799
812
|
importPaths[imp] = importPaths[imp] || [];
|
|
800
813
|
importPaths[imp].push(filePath);
|
|
801
814
|
}
|
|
802
|
-
|
|
815
|
+
for (const imp of cleanedTypeImports) {
|
|
816
|
+
typeImportPaths[imp] = typeImportPaths[imp] || [];
|
|
817
|
+
typeImportPaths[imp].push(filePath);
|
|
818
|
+
}
|
|
819
|
+
return [cleanedImports, cleanedTypeImports];
|
|
803
820
|
}
|
|
804
821
|
function findFilesByGlob(cwd4, pattern) {
|
|
805
822
|
return globSync(pattern, { cwd: cwd4, absolute: true });
|
|
@@ -819,18 +836,29 @@ function findFiles(path9) {
|
|
|
819
836
|
}
|
|
820
837
|
function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
821
838
|
const prodImportPaths = {};
|
|
822
|
-
const
|
|
839
|
+
const prodTypeImportPaths = {};
|
|
840
|
+
const prodImportPairs = prodSourceFiles.map((path9) => getImportsFromFile(path9, prodImportPaths, prodTypeImportPaths));
|
|
841
|
+
const prodImports = prodImportPairs.flatMap((pair) => pair[0]);
|
|
842
|
+
const prodTypeImports = prodImportPairs.flatMap((pair) => pair[1]);
|
|
823
843
|
const devImportPaths = {};
|
|
824
|
-
const
|
|
844
|
+
const devTypeImportPaths = {};
|
|
845
|
+
const devImportPairs = devSourceFiles.map((path9) => getImportsFromFile(path9, devImportPaths, devTypeImportPaths));
|
|
846
|
+
const devImports = devImportPairs.flatMap((pair) => pair[0]);
|
|
847
|
+
const devTypeImports = devImportPairs.flatMap((pair) => pair[1]);
|
|
825
848
|
const externalProdImports = prodImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
849
|
+
const externalProdTypeImports = prodTypeImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
826
850
|
const externalDevImports = devImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
827
851
|
return {
|
|
828
852
|
prodImports,
|
|
829
853
|
devImports,
|
|
830
854
|
prodImportPaths,
|
|
855
|
+
prodTypeImportPaths,
|
|
831
856
|
devImportPaths,
|
|
832
857
|
externalProdImports,
|
|
833
|
-
externalDevImports
|
|
858
|
+
externalDevImports,
|
|
859
|
+
prodTypeImports,
|
|
860
|
+
devTypeImports,
|
|
861
|
+
externalProdTypeImports
|
|
834
862
|
};
|
|
835
863
|
}
|
|
836
864
|
function check({
|
|
@@ -841,7 +869,9 @@ function check({
|
|
|
841
869
|
}) {
|
|
842
870
|
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
843
871
|
const {
|
|
872
|
+
prodTypeImportPaths,
|
|
844
873
|
prodImportPaths,
|
|
874
|
+
externalProdTypeImports,
|
|
845
875
|
devImportPaths,
|
|
846
876
|
externalProdImports,
|
|
847
877
|
externalDevImports
|
|
@@ -854,6 +884,15 @@ function check({
|
|
|
854
884
|
let unlistedDependencies = 0;
|
|
855
885
|
let unlistedDevDependencies = 0;
|
|
856
886
|
let unusedDependencies = 0;
|
|
887
|
+
let typesInDependencies = 0;
|
|
888
|
+
for (const imp of externalProdTypeImports) {
|
|
889
|
+
if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`)) {
|
|
890
|
+
unlistedDependencies++;
|
|
891
|
+
console.log(`[${chalk14.blue(name)}] Missing dependency in package.json: ${chalk14.red(imp)}`);
|
|
892
|
+
console.log(` ${prodTypeImportPaths[imp].join("\n")}`);
|
|
893
|
+
console.log("");
|
|
894
|
+
}
|
|
895
|
+
}
|
|
857
896
|
for (const imp of externalProdImports) {
|
|
858
897
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
859
898
|
unlistedDependencies++;
|
|
@@ -863,6 +902,13 @@ function check({
|
|
|
863
902
|
}
|
|
864
903
|
}
|
|
865
904
|
for (const dep of dependencies) {
|
|
905
|
+
if (dep.startsWith("@types/")) {
|
|
906
|
+
typesInDependencies++;
|
|
907
|
+
console.log(`[${chalk14.blue(name)}] @types in dependencies in package.json: ${chalk14.red(dep)}`);
|
|
908
|
+
console.log(` ${location}/package.json
|
|
909
|
+
`);
|
|
910
|
+
console.log("");
|
|
911
|
+
}
|
|
866
912
|
if (!externalProdImports.includes(dep)) {
|
|
867
913
|
unusedDependencies++;
|
|
868
914
|
console.log(`[${chalk14.blue(name)}] Unused dependency in package.json: ${chalk14.red(dep)}`);
|
|
@@ -891,7 +937,7 @@ function check({
|
|
|
891
937
|
}
|
|
892
938
|
}
|
|
893
939
|
}
|
|
894
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies;
|
|
940
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies;
|
|
895
941
|
return totalErrors;
|
|
896
942
|
}
|
|
897
943
|
var deplint = ({ pkg }) => {
|