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