@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/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,23 +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
|
|
716
|
+
const importsStartsWithExcludes = [".", "#", "node:"];
|
|
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);
|
|
705
719
|
for (const imp of cleanedImports) {
|
|
706
720
|
importPaths[imp] = importPaths[imp] || [];
|
|
707
721
|
importPaths[imp].push(filePath);
|
|
708
722
|
}
|
|
709
|
-
|
|
723
|
+
for (const imp of cleanedTypeImports) {
|
|
724
|
+
typeImportPaths[imp] = typeImportPaths[imp] || [];
|
|
725
|
+
typeImportPaths[imp].push(filePath);
|
|
726
|
+
}
|
|
727
|
+
return [cleanedImports, cleanedTypeImports];
|
|
710
728
|
}
|
|
711
729
|
function findFilesByGlob(cwd, pattern) {
|
|
712
730
|
return globSync(pattern, { cwd, absolute: true });
|
|
@@ -726,10 +744,17 @@ function findFiles(path4) {
|
|
|
726
744
|
}
|
|
727
745
|
function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
728
746
|
const prodImportPaths = {};
|
|
729
|
-
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]);
|
|
730
751
|
const devImportPaths = {};
|
|
731
|
-
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]);
|
|
732
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:"));
|
|
733
758
|
const externalDevImports = devImports.filter((imp) => !imp.startsWith(".") && !imp.startsWith("#") && !imp.startsWith("node:"));
|
|
734
759
|
return {
|
|
735
760
|
prodImports,
|
|
@@ -737,7 +762,10 @@ function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
|
737
762
|
prodImportPaths,
|
|
738
763
|
devImportPaths,
|
|
739
764
|
externalProdImports,
|
|
740
|
-
externalDevImports
|
|
765
|
+
externalDevImports,
|
|
766
|
+
prodTypeImports,
|
|
767
|
+
devTypeImports,
|
|
768
|
+
externalProdTypeImports
|
|
741
769
|
};
|
|
742
770
|
}
|
|
743
771
|
function check({
|
|
@@ -749,6 +777,7 @@ function check({
|
|
|
749
777
|
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
750
778
|
const {
|
|
751
779
|
prodImportPaths,
|
|
780
|
+
externalProdTypeImports,
|
|
752
781
|
devImportPaths,
|
|
753
782
|
externalProdImports,
|
|
754
783
|
externalDevImports
|
|
@@ -761,6 +790,15 @@ function check({
|
|
|
761
790
|
let unlistedDependencies = 0;
|
|
762
791
|
let unlistedDevDependencies = 0;
|
|
763
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
|
+
}
|
|
764
802
|
for (const imp of externalProdImports) {
|
|
765
803
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
766
804
|
unlistedDependencies++;
|
|
@@ -770,6 +808,13 @@ function check({
|
|
|
770
808
|
}
|
|
771
809
|
}
|
|
772
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
|
+
}
|
|
773
818
|
if (!externalProdImports.includes(dep)) {
|
|
774
819
|
unusedDependencies++;
|
|
775
820
|
console.log(`[${chalk12.blue(name)}] Unused dependency in package.json: ${chalk12.red(dep)}`);
|
|
@@ -798,7 +843,7 @@ function check({
|
|
|
798
843
|
}
|
|
799
844
|
}
|
|
800
845
|
}
|
|
801
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies;
|
|
846
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies;
|
|
802
847
|
return totalErrors;
|
|
803
848
|
}
|
|
804
849
|
var deplint = ({ pkg }) => {
|