@xylabs/ts-scripts-yarn3 6.4.1 → 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 +52 -7
- package/dist/actions/deplint.mjs.map +1 -1
- package/dist/actions/index.mjs +52 -7
- package/dist/actions/index.mjs.map +1 -1
- package/dist/bin/xy.mjs +52 -7
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +52 -7
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +52 -7
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +52 -7
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +52 -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,23 +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
|
|
808
|
+
const importsStartsWithExcludes = [".", "#", "node:"];
|
|
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);
|
|
797
811
|
for (const imp of cleanedImports) {
|
|
798
812
|
importPaths[imp] = importPaths[imp] || [];
|
|
799
813
|
importPaths[imp].push(filePath);
|
|
800
814
|
}
|
|
801
|
-
|
|
815
|
+
for (const imp of cleanedTypeImports) {
|
|
816
|
+
typeImportPaths[imp] = typeImportPaths[imp] || [];
|
|
817
|
+
typeImportPaths[imp].push(filePath);
|
|
818
|
+
}
|
|
819
|
+
return [cleanedImports, cleanedTypeImports];
|
|
802
820
|
}
|
|
803
821
|
function findFilesByGlob(cwd4, pattern) {
|
|
804
822
|
return globSync(pattern, { cwd: cwd4, absolute: true });
|
|
@@ -818,10 +836,17 @@ function findFiles(path9) {
|
|
|
818
836
|
}
|
|
819
837
|
function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
820
838
|
const prodImportPaths = {};
|
|
821
|
-
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]);
|
|
822
843
|
const devImportPaths = {};
|
|
823
|
-
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]);
|
|
824
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:"));
|
|
825
850
|
const externalDevImports = devImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
826
851
|
return {
|
|
827
852
|
prodImports,
|
|
@@ -829,7 +854,10 @@ function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
|
829
854
|
prodImportPaths,
|
|
830
855
|
devImportPaths,
|
|
831
856
|
externalProdImports,
|
|
832
|
-
externalDevImports
|
|
857
|
+
externalDevImports,
|
|
858
|
+
prodTypeImports,
|
|
859
|
+
devTypeImports,
|
|
860
|
+
externalProdTypeImports
|
|
833
861
|
};
|
|
834
862
|
}
|
|
835
863
|
function check({
|
|
@@ -841,6 +869,7 @@ function check({
|
|
|
841
869
|
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
842
870
|
const {
|
|
843
871
|
prodImportPaths,
|
|
872
|
+
externalProdTypeImports,
|
|
844
873
|
devImportPaths,
|
|
845
874
|
externalProdImports,
|
|
846
875
|
externalDevImports
|
|
@@ -853,6 +882,15 @@ function check({
|
|
|
853
882
|
let unlistedDependencies = 0;
|
|
854
883
|
let unlistedDevDependencies = 0;
|
|
855
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
|
+
}
|
|
856
894
|
for (const imp of externalProdImports) {
|
|
857
895
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
858
896
|
unlistedDependencies++;
|
|
@@ -862,6 +900,13 @@ function check({
|
|
|
862
900
|
}
|
|
863
901
|
}
|
|
864
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
|
+
}
|
|
865
910
|
if (!externalProdImports.includes(dep)) {
|
|
866
911
|
unusedDependencies++;
|
|
867
912
|
console.log(`[${chalk14.blue(name)}] Unused dependency in package.json: ${chalk14.red(dep)}`);
|
|
@@ -890,7 +935,7 @@ function check({
|
|
|
890
935
|
}
|
|
891
936
|
}
|
|
892
937
|
}
|
|
893
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies;
|
|
938
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies;
|
|
894
939
|
return totalErrors;
|
|
895
940
|
}
|
|
896
941
|
var deplint = ({ pkg }) => {
|