@xylabs/ts-scripts-yarn3 6.4.2 → 6.4.3
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 +51 -7
- package/dist/actions/deplint.mjs.map +1 -1
- package/dist/actions/index.mjs +51 -7
- package/dist/actions/index.mjs.map +1 -1
- package/dist/bin/xy.mjs +51 -7
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +51 -7
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +51 -7
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +51 -7
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +51 -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,10 +836,17 @@ 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,
|
|
@@ -830,7 +854,10 @@ function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
|
830
854
|
prodImportPaths,
|
|
831
855
|
devImportPaths,
|
|
832
856
|
externalProdImports,
|
|
833
|
-
externalDevImports
|
|
857
|
+
externalDevImports,
|
|
858
|
+
prodTypeImports,
|
|
859
|
+
devTypeImports,
|
|
860
|
+
externalProdTypeImports
|
|
834
861
|
};
|
|
835
862
|
}
|
|
836
863
|
function check({
|
|
@@ -842,6 +869,7 @@ function check({
|
|
|
842
869
|
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
843
870
|
const {
|
|
844
871
|
prodImportPaths,
|
|
872
|
+
externalProdTypeImports,
|
|
845
873
|
devImportPaths,
|
|
846
874
|
externalProdImports,
|
|
847
875
|
externalDevImports
|
|
@@ -854,6 +882,15 @@ function check({
|
|
|
854
882
|
let unlistedDependencies = 0;
|
|
855
883
|
let unlistedDevDependencies = 0;
|
|
856
884
|
let unusedDependencies = 0;
|
|
885
|
+
let typesInDependencies = 0;
|
|
886
|
+
for (const imp of externalProdTypeImports) {
|
|
887
|
+
if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`)) {
|
|
888
|
+
unlistedDependencies++;
|
|
889
|
+
console.log(`[${chalk14.blue(name)}] Missing dependency in package.json: ${chalk14.red(imp)}`);
|
|
890
|
+
console.log(` ${prodImportPaths[imp].join("\n")}`);
|
|
891
|
+
console.log("");
|
|
892
|
+
}
|
|
893
|
+
}
|
|
857
894
|
for (const imp of externalProdImports) {
|
|
858
895
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
859
896
|
unlistedDependencies++;
|
|
@@ -863,6 +900,13 @@ function check({
|
|
|
863
900
|
}
|
|
864
901
|
}
|
|
865
902
|
for (const dep of dependencies) {
|
|
903
|
+
if (dep.startsWith("@types/")) {
|
|
904
|
+
typesInDependencies++;
|
|
905
|
+
console.log(`[${chalk14.blue(name)}] @types in dependencies in package.json: ${chalk14.red(dep)}`);
|
|
906
|
+
console.log(` ${location}/package.json
|
|
907
|
+
`);
|
|
908
|
+
console.log("");
|
|
909
|
+
}
|
|
866
910
|
if (!externalProdImports.includes(dep)) {
|
|
867
911
|
unusedDependencies++;
|
|
868
912
|
console.log(`[${chalk14.blue(name)}] Unused dependency in package.json: ${chalk14.red(dep)}`);
|
|
@@ -891,7 +935,7 @@ function check({
|
|
|
891
935
|
}
|
|
892
936
|
}
|
|
893
937
|
}
|
|
894
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies;
|
|
938
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies;
|
|
895
939
|
return totalErrors;
|
|
896
940
|
}
|
|
897
941
|
var deplint = ({ pkg }) => {
|