@adamhl8/configs 0.16.2 → 0.16.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/ts-import-fix +11 -6
- 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,13 @@ async function cli() {
|
|
|
2690
2691
|
const exclude = [
|
|
2691
2692
|
"node_modules/",
|
|
2692
2693
|
"dist/",
|
|
2693
|
-
|
|
2694
|
+
"astro.config.ts",
|
|
2695
|
+
...parseResult.fileIgnorePatterns
|
|
2694
2696
|
];
|
|
2697
|
+
const filePaths = await Array.fromAsync(fs.glob(FILES_GLOB, { exclude }));
|
|
2695
2698
|
return {
|
|
2696
|
-
|
|
2697
|
-
|
|
2699
|
+
parseResult,
|
|
2700
|
+
filePaths
|
|
2698
2701
|
};
|
|
2699
2702
|
}
|
|
2700
2703
|
function getPathsMap() {
|
|
@@ -2737,7 +2740,8 @@ function transformRelativeImport(filePath, importPath, pathsMap) {
|
|
|
2737
2740
|
TRANSFORM_ERRORS.push(`❌ (${filePath}) could not find alias for '${importPath}'`);
|
|
2738
2741
|
}
|
|
2739
2742
|
async function tsImportFix() {
|
|
2740
|
-
const { filePaths,
|
|
2743
|
+
const { filePaths, parseResult } = await cli();
|
|
2744
|
+
const { write, importIgnoreStrings } = parseResult;
|
|
2741
2745
|
const pathsMap = getPathsMap();
|
|
2742
2746
|
if (isErr(pathsMap)) return pathsMap;
|
|
2743
2747
|
const importFixResult = await attempt(() => {
|
|
@@ -2747,6 +2751,7 @@ async function tsImportFix() {
|
|
|
2747
2751
|
const isRelativeImport = importPath.startsWith("./") || importPath.startsWith("../");
|
|
2748
2752
|
const isAliasImport = Object.keys(pathsMap).some((alias) => importPath.startsWith(alias));
|
|
2749
2753
|
if (!(isRelativeImport || isAliasImport)) return match;
|
|
2754
|
+
if (importIgnoreStrings.some((ignoreString) => importPath.includes(ignoreString))) return match;
|
|
2750
2755
|
let newImportPath = transformExtension(importPath);
|
|
2751
2756
|
if (isRelativeImport) newImportPath = transformRelativeImport(filePath, newImportPath, pathsMap) ?? newImportPath;
|
|
2752
2757
|
if (newImportPath === importPath) return match;
|