@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/xy/xy.mjs
CHANGED
|
@@ -681,7 +681,7 @@ function getBasePackageName(importName) {
|
|
|
681
681
|
}
|
|
682
682
|
return importName.split("/")[0];
|
|
683
683
|
}
|
|
684
|
-
function getImportsFromFile(filePath, importPaths) {
|
|
684
|
+
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
685
685
|
const sourceCode = fs2.readFileSync(filePath, "utf8");
|
|
686
686
|
const sourceFile = ts.createSourceFile(
|
|
687
687
|
path3.basename(filePath),
|
|
@@ -690,24 +690,41 @@ function getImportsFromFile(filePath, importPaths) {
|
|
|
690
690
|
true
|
|
691
691
|
);
|
|
692
692
|
const imports = [];
|
|
693
|
+
const typeImports = [];
|
|
693
694
|
function visit(node) {
|
|
694
695
|
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
695
696
|
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
697
|
+
const isTypeImport = ts.isImportDeclaration(node) ? node.importClause?.isTypeOnly ?? false : false;
|
|
696
698
|
if (moduleSpecifier) {
|
|
697
699
|
const trimmed = moduleSpecifier.split("'").at(1) ?? moduleSpecifier;
|
|
700
|
+
if (isTypeImport) {
|
|
701
|
+
typeImports.push(trimmed);
|
|
702
|
+
} else {
|
|
703
|
+
imports.push(trimmed);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
} else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
707
|
+
const [arg] = node.arguments;
|
|
708
|
+
if (ts.isStringLiteral(arg)) {
|
|
709
|
+
const trimmed = arg.text;
|
|
698
710
|
imports.push(trimmed);
|
|
699
711
|
}
|
|
700
712
|
}
|
|
701
713
|
ts.forEachChild(node, visit);
|
|
702
714
|
}
|
|
703
715
|
visit(sourceFile);
|
|
704
|
-
const importsStartsWithExcludes = [".", "#", "node:"
|
|
716
|
+
const importsStartsWithExcludes = [".", "#", "node:"];
|
|
705
717
|
const cleanedImports = imports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
718
|
+
const cleanedTypeImports = typeImports.filter((imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc))).map(getBasePackageName);
|
|
706
719
|
for (const imp of cleanedImports) {
|
|
707
720
|
importPaths[imp] = importPaths[imp] || [];
|
|
708
721
|
importPaths[imp].push(filePath);
|
|
709
722
|
}
|
|
710
|
-
|
|
723
|
+
for (const imp of cleanedTypeImports) {
|
|
724
|
+
typeImportPaths[imp] = typeImportPaths[imp] || [];
|
|
725
|
+
typeImportPaths[imp].push(filePath);
|
|
726
|
+
}
|
|
727
|
+
return [cleanedImports, cleanedTypeImports];
|
|
711
728
|
}
|
|
712
729
|
function findFilesByGlob(cwd, pattern) {
|
|
713
730
|
return globSync(pattern, { cwd, absolute: true });
|
|
@@ -727,10 +744,17 @@ function findFiles(path4) {
|
|
|
727
744
|
}
|
|
728
745
|
function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
729
746
|
const prodImportPaths = {};
|
|
730
|
-
const
|
|
747
|
+
const prodTypeImportPaths = {};
|
|
748
|
+
const prodImportPairs = prodSourceFiles.map((path4) => getImportsFromFile(path4, prodImportPaths, prodTypeImportPaths));
|
|
749
|
+
const prodImports = prodImportPairs.flatMap((pair) => pair[0]);
|
|
750
|
+
const prodTypeImports = prodImportPairs.flatMap((pair) => pair[1]);
|
|
731
751
|
const devImportPaths = {};
|
|
732
|
-
const
|
|
752
|
+
const devTypeImportPaths = {};
|
|
753
|
+
const devImportPairs = devSourceFiles.map((path4) => getImportsFromFile(path4, devImportPaths, devTypeImportPaths));
|
|
754
|
+
const devImports = devImportPairs.flatMap((pair) => pair[0]);
|
|
755
|
+
const devTypeImports = devImportPairs.flatMap((pair) => pair[1]);
|
|
733
756
|
const externalProdImports = prodImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
757
|
+
const externalProdTypeImports = prodTypeImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
734
758
|
const externalDevImports = devImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
735
759
|
return {
|
|
736
760
|
prodImports,
|
|
@@ -738,7 +762,10 @@ function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
|
738
762
|
prodImportPaths,
|
|
739
763
|
devImportPaths,
|
|
740
764
|
externalProdImports,
|
|
741
|
-
externalDevImports
|
|
765
|
+
externalDevImports,
|
|
766
|
+
prodTypeImports,
|
|
767
|
+
devTypeImports,
|
|
768
|
+
externalProdTypeImports
|
|
742
769
|
};
|
|
743
770
|
}
|
|
744
771
|
function check({
|
|
@@ -750,6 +777,7 @@ function check({
|
|
|
750
777
|
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
751
778
|
const {
|
|
752
779
|
prodImportPaths,
|
|
780
|
+
externalProdTypeImports,
|
|
753
781
|
devImportPaths,
|
|
754
782
|
externalProdImports,
|
|
755
783
|
externalDevImports
|
|
@@ -762,6 +790,15 @@ function check({
|
|
|
762
790
|
let unlistedDependencies = 0;
|
|
763
791
|
let unlistedDevDependencies = 0;
|
|
764
792
|
let unusedDependencies = 0;
|
|
793
|
+
let typesInDependencies = 0;
|
|
794
|
+
for (const imp of externalProdTypeImports) {
|
|
795
|
+
if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`)) {
|
|
796
|
+
unlistedDependencies++;
|
|
797
|
+
console.log(`[${chalk12.blue(name)}] Missing dependency in package.json: ${chalk12.red(imp)}`);
|
|
798
|
+
console.log(` ${prodImportPaths[imp].join("\n")}`);
|
|
799
|
+
console.log("");
|
|
800
|
+
}
|
|
801
|
+
}
|
|
765
802
|
for (const imp of externalProdImports) {
|
|
766
803
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
767
804
|
unlistedDependencies++;
|
|
@@ -771,6 +808,13 @@ function check({
|
|
|
771
808
|
}
|
|
772
809
|
}
|
|
773
810
|
for (const dep of dependencies) {
|
|
811
|
+
if (dep.startsWith("@types/")) {
|
|
812
|
+
typesInDependencies++;
|
|
813
|
+
console.log(`[${chalk12.blue(name)}] @types in dependencies in package.json: ${chalk12.red(dep)}`);
|
|
814
|
+
console.log(` ${location}/package.json
|
|
815
|
+
`);
|
|
816
|
+
console.log("");
|
|
817
|
+
}
|
|
774
818
|
if (!externalProdImports.includes(dep)) {
|
|
775
819
|
unusedDependencies++;
|
|
776
820
|
console.log(`[${chalk12.blue(name)}] Unused dependency in package.json: ${chalk12.red(dep)}`);
|
|
@@ -799,7 +843,7 @@ function check({
|
|
|
799
843
|
}
|
|
800
844
|
}
|
|
801
845
|
}
|
|
802
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies;
|
|
846
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies;
|
|
803
847
|
return totalErrors;
|
|
804
848
|
}
|
|
805
849
|
var deplint = ({ pkg }) => {
|