@adamhl8/configs 0.16.1 → 0.16.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/ts-import-fix +11 -7
- package/package.json +1 -1
package/dist/ts-import-fix
CHANGED
|
@@ -2680,9 +2680,10 @@ const TRANSFORM_ERRORS = [];
|
|
|
2680
2680
|
async function cli() {
|
|
2681
2681
|
const options = object({
|
|
2682
2682
|
write: option("-w", "--write", { description: message`Write changes to files` }),
|
|
2683
|
-
|
|
2683
|
+
fileIgnorePatterns: multiple(option("-f", "--file-ignore", string({ metavar: "PATTERN" }), { description: message`Additional glob patterns for files to ignore` })),
|
|
2684
|
+
importIgnoreStrings: multiple(option("-i", "--import-ignore", string(), { description: message`An import path *containing* the given string will be ignored` }))
|
|
2684
2685
|
});
|
|
2685
|
-
const
|
|
2686
|
+
const parseResult = run(options, {
|
|
2686
2687
|
programName: "ts-import-fix",
|
|
2687
2688
|
help: "option",
|
|
2688
2689
|
showDefault: { prefix: " [default: " }
|
|
@@ -2690,11 +2691,12 @@ async function cli() {
|
|
|
2690
2691
|
const exclude = [
|
|
2691
2692
|
"node_modules/",
|
|
2692
2693
|
"dist/",
|
|
2693
|
-
...
|
|
2694
|
+
...parseResult.fileIgnorePatterns
|
|
2694
2695
|
];
|
|
2696
|
+
const filePaths = await Array.fromAsync(fs.glob(FILES_GLOB, { exclude }));
|
|
2695
2697
|
return {
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
+
parseResult,
|
|
2699
|
+
filePaths
|
|
2698
2700
|
};
|
|
2699
2701
|
}
|
|
2700
2702
|
function getPathsMap() {
|
|
@@ -2737,7 +2739,8 @@ function transformRelativeImport(filePath, importPath, pathsMap) {
|
|
|
2737
2739
|
TRANSFORM_ERRORS.push(`❌ (${filePath}) could not find alias for '${importPath}'`);
|
|
2738
2740
|
}
|
|
2739
2741
|
async function tsImportFix() {
|
|
2740
|
-
const { filePaths,
|
|
2742
|
+
const { filePaths, parseResult } = await cli();
|
|
2743
|
+
const { write, importIgnoreStrings } = parseResult;
|
|
2741
2744
|
const pathsMap = getPathsMap();
|
|
2742
2745
|
if (isErr(pathsMap)) return pathsMap;
|
|
2743
2746
|
const importFixResult = await attempt(() => {
|
|
@@ -2747,6 +2750,7 @@ async function tsImportFix() {
|
|
|
2747
2750
|
const isRelativeImport = importPath.startsWith("./") || importPath.startsWith("../");
|
|
2748
2751
|
const isAliasImport = Object.keys(pathsMap).some((alias) => importPath.startsWith(alias));
|
|
2749
2752
|
if (!(isRelativeImport || isAliasImport)) return match;
|
|
2753
|
+
if (importIgnoreStrings.some((ignoreString) => importPath.includes(ignoreString))) return match;
|
|
2750
2754
|
let newImportPath = transformExtension(importPath);
|
|
2751
2755
|
if (isRelativeImport) newImportPath = transformRelativeImport(filePath, newImportPath, pathsMap) ?? newImportPath;
|
|
2752
2756
|
if (newImportPath === importPath) return match;
|
|
@@ -2755,7 +2759,7 @@ async function tsImportFix() {
|
|
|
2755
2759
|
const { ext: newExt } = newPathParts;
|
|
2756
2760
|
let newImportPathString = newImportPath;
|
|
2757
2761
|
if (newExt !== originalExt) newImportPathString = `${path.format(changeExtension(newPathParts, ""))}${import_picocolors.default.greenBright(newExt)}`;
|
|
2758
|
-
console.log(`✅ (${filePath}) '${importPath}' -> ${newImportPathString}`);
|
|
2762
|
+
console.log(`✅ (${filePath}) '${importPath}' -> '${newImportPathString}'`);
|
|
2759
2763
|
return match.replace(importPath, newImportPath);
|
|
2760
2764
|
});
|
|
2761
2765
|
if (transformedContent === content) return;
|