@reliverse/pathkit 1.2.8 → 1.2.9
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/bin/mod.d.ts +13 -23
- package/bin/mod.js +22 -14
- package/package.json +1 -1
package/bin/mod.d.ts
CHANGED
|
@@ -96,13 +96,14 @@ declare function convertStringAliasRelative({ importPath, importerFile, pathPatt
|
|
|
96
96
|
targetDir: string;
|
|
97
97
|
}): Promise<string>;
|
|
98
98
|
/**
|
|
99
|
-
* main function to convert import paths from aliases to relative paths
|
|
99
|
+
* main function to convert import/export paths from aliases to relative paths
|
|
100
100
|
*/
|
|
101
|
-
declare function convertImportsAliasToRelative({ targetDir, aliasToReplace, pathExtFilter, displayLogsOnlyFor, }: {
|
|
101
|
+
declare function convertImportsAliasToRelative({ targetDir, aliasToReplace, pathExtFilter, displayLogsOnlyFor, displayLogs, }: {
|
|
102
102
|
targetDir: string;
|
|
103
103
|
aliasToReplace: string;
|
|
104
104
|
pathExtFilter: PathExtFilter;
|
|
105
105
|
displayLogsOnlyFor?: string[];
|
|
106
|
+
displayLogs?: boolean;
|
|
106
107
|
}): Promise<{
|
|
107
108
|
file: string;
|
|
108
109
|
changes: {
|
|
@@ -111,13 +112,14 @@ declare function convertImportsAliasToRelative({ targetDir, aliasToReplace, path
|
|
|
111
112
|
}[];
|
|
112
113
|
}[]>;
|
|
113
114
|
/**
|
|
114
|
-
* converts extensions in import paths from one format to another
|
|
115
|
+
* converts extensions in import/export paths from one format to another
|
|
115
116
|
*/
|
|
116
|
-
declare function convertImportsExt({ targetDir, extFrom, extTo, alias, }: {
|
|
117
|
+
declare function convertImportsExt({ targetDir, extFrom, extTo, alias, displayLogs, }: {
|
|
117
118
|
targetDir: string;
|
|
118
119
|
extFrom: ImportExtType;
|
|
119
120
|
extTo: ImportExtType;
|
|
120
121
|
alias?: string;
|
|
122
|
+
displayLogs?: boolean;
|
|
121
123
|
}): Promise<{
|
|
122
124
|
file: string;
|
|
123
125
|
changes: {
|
|
@@ -141,11 +143,12 @@ declare function stripPathSegments(path: string, count?: number, alias?: string)
|
|
|
141
143
|
* @param extensionsToProcess - Array of file extensions to process (default: EXTENSIONS)
|
|
142
144
|
* @returns Array of processed files and their changes
|
|
143
145
|
*/
|
|
144
|
-
declare function stripPathSegmentsInDirectory({ targetDir, segmentsToStrip, alias, extensionsToProcess, }: {
|
|
146
|
+
declare function stripPathSegmentsInDirectory({ targetDir, segmentsToStrip, alias, extensionsToProcess, displayLogs, }: {
|
|
145
147
|
targetDir: string;
|
|
146
148
|
segmentsToStrip: number;
|
|
147
149
|
alias?: string;
|
|
148
150
|
extensionsToProcess?: string[];
|
|
151
|
+
displayLogs?: boolean;
|
|
149
152
|
}): Promise<{
|
|
150
153
|
file: string;
|
|
151
154
|
changes: {
|
|
@@ -168,18 +171,19 @@ declare function attachPathSegments(path: string, segments: string | string[], o
|
|
|
168
171
|
preserveAlias?: string;
|
|
169
172
|
}): string;
|
|
170
173
|
/**
|
|
171
|
-
* recursively processes files in a directory to attach path segments to import statements
|
|
174
|
+
* recursively processes files in a directory to attach path segments to import/export statements
|
|
172
175
|
* @param targetDir - The directory to process
|
|
173
176
|
* @param segments - The segments to attach
|
|
174
177
|
* @param options - Configuration options for path segment attachment
|
|
175
178
|
* @param extensionsToProcess - Array of file extensions to process (default: EXTENSIONS)
|
|
176
179
|
* @returns Array of processed files and their changes
|
|
177
180
|
*/
|
|
178
|
-
declare function attachPathSegmentsInDirectory({ targetDir, segments, options, extensionsToProcess, }: {
|
|
181
|
+
declare function attachPathSegmentsInDirectory({ targetDir, segments, options, extensionsToProcess, displayLogs, }: {
|
|
179
182
|
targetDir: string;
|
|
180
183
|
segments: string | string[];
|
|
181
184
|
options?: Parameters<typeof attachPathSegments>[2];
|
|
182
185
|
extensionsToProcess?: string[];
|
|
186
|
+
displayLogs?: boolean;
|
|
183
187
|
}): Promise<{
|
|
184
188
|
file: string;
|
|
185
189
|
changes: {
|
|
@@ -202,26 +206,12 @@ declare const _pathBase: {
|
|
|
202
206
|
relative: (from: string, to: string) => string;
|
|
203
207
|
filename: typeof filename;
|
|
204
208
|
};
|
|
205
|
-
declare const path: PlatformPath & {
|
|
206
|
-
sep: string;
|
|
207
|
-
normalize: (path: string) => string;
|
|
208
|
-
join: (...segments: string[]) => string;
|
|
209
|
-
resolve: (...args: string[]) => string;
|
|
210
|
-
isAbsolute: (p: string) => boolean;
|
|
211
|
-
dirname: (p: string) => string;
|
|
212
|
-
basename: (p: string, ext?: string) => string;
|
|
213
|
-
extname: (p: string) => string;
|
|
214
|
-
format: (p: FormatInputPathObject) => string;
|
|
215
|
-
parse: (p: string) => ParsedPath;
|
|
216
|
-
toNamespacedPath: (p: string) => string;
|
|
217
|
-
relative: (from: string, to: string) => string;
|
|
218
|
-
filename: typeof filename;
|
|
219
|
-
} & {
|
|
209
|
+
declare const path: PlatformPath & typeof _pathBase & {
|
|
220
210
|
posix: PlatformPath;
|
|
221
211
|
win32: PlatformPath;
|
|
222
212
|
};
|
|
223
213
|
declare const win32: PlatformPath;
|
|
224
|
-
declare const delimiter:
|
|
214
|
+
declare const delimiter: ";" | ":";
|
|
225
215
|
export type { PlatformPath, PathExtFilter, ImportExtType, ImportExportInfo, ImportExportSpecifier, GetFileImportsExportsOptions, };
|
|
226
216
|
export { _pathBase as posix, win32, basename, delimiter, dirname, extname, filename, format, isAbsolute, join, normalize, parse, relative, resolve, sep, toNamespacedPath, normalizeAliases, resolveAlias, reverseResolveAlias, normalizeWindowsPath, convertStringAliasRelative, convertImportsAliasToRelative, convertImportsExt, stripPathSegments, stripPathSegmentsInDirectory, attachPathSegments, attachPathSegmentsInDirectory, getFileImportsExports, };
|
|
227
217
|
export default path;
|
package/bin/mod.js
CHANGED
|
@@ -10,8 +10,8 @@ const filteredLogger = (msg) => {
|
|
|
10
10
|
const message = typeof msg === "function" ? msg() : msg;
|
|
11
11
|
console.log(`\x1B[36;2m${message}\x1B[0m`);
|
|
12
12
|
};
|
|
13
|
+
const DEBUG_MODE = false;
|
|
13
14
|
const logInternal = (msg) => {
|
|
14
|
-
const DEBUG_MODE = true;
|
|
15
15
|
if (DEBUG_MODE) {
|
|
16
16
|
const message = typeof msg === "function" ? msg() : msg;
|
|
17
17
|
console.log(`\x1B[36;2m${message}\x1B[0m`);
|
|
@@ -464,8 +464,8 @@ function replaceAllInString(original, searchValue, replaceValue) {
|
|
|
464
464
|
}
|
|
465
465
|
return result;
|
|
466
466
|
}
|
|
467
|
-
async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter, displayLogsOnlyFor) {
|
|
468
|
-
const shouldLog = !displayLogsOnlyFor || displayLogsOnlyFor.includes(filePath);
|
|
467
|
+
async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter, displayLogsOnlyFor, displayLogs = false) {
|
|
468
|
+
const shouldLog = displayLogs && (!displayLogsOnlyFor || displayLogsOnlyFor.includes(filePath));
|
|
469
469
|
const log = (msg) => shouldLog && filteredLogger(msg);
|
|
470
470
|
const content = await fs.readFile(filePath, "utf-8");
|
|
471
471
|
let updated = content;
|
|
@@ -483,7 +483,9 @@ async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter, d
|
|
|
483
483
|
if (!importPath) continue;
|
|
484
484
|
log(` Processing import: ${importPath}`);
|
|
485
485
|
if (!importPath.startsWith(baseAlias)) {
|
|
486
|
-
|
|
486
|
+
if (DEBUG_MODE) {
|
|
487
|
+
log(` - skipping: import/export doesn't start with ${baseAlias}`);
|
|
488
|
+
}
|
|
487
489
|
continue;
|
|
488
490
|
}
|
|
489
491
|
const importExt = extname(importPath);
|
|
@@ -519,7 +521,9 @@ async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter, d
|
|
|
519
521
|
await fs.writeFile(filePath, updated);
|
|
520
522
|
log(`\u2713 processed: ${filePath}`);
|
|
521
523
|
} else {
|
|
522
|
-
|
|
524
|
+
if (DEBUG_MODE) {
|
|
525
|
+
log(` - no changes made to file: ${filePath}`);
|
|
526
|
+
}
|
|
523
527
|
}
|
|
524
528
|
return changes;
|
|
525
529
|
}
|
|
@@ -575,7 +579,8 @@ async function convertImportsAliasToRelative({
|
|
|
575
579
|
targetDir,
|
|
576
580
|
aliasToReplace,
|
|
577
581
|
pathExtFilter,
|
|
578
|
-
displayLogsOnlyFor
|
|
582
|
+
displayLogsOnlyFor,
|
|
583
|
+
displayLogs = false
|
|
579
584
|
}) {
|
|
580
585
|
const normalizedAlias = aliasToReplace.endsWith("/*") ? aliasToReplace : `${aliasToReplace}/*`;
|
|
581
586
|
regularLogger(
|
|
@@ -592,7 +597,7 @@ async function convertImportsAliasToRelative({
|
|
|
592
597
|
pathExtFilter,
|
|
593
598
|
displayLogsOnlyFor
|
|
594
599
|
});
|
|
595
|
-
if (results.length > 0) {
|
|
600
|
+
if (results.length > 0 && displayLogs) {
|
|
596
601
|
regularLogger("\n[convertImportsAliasToRelative] Summary of changes:");
|
|
597
602
|
for (const { file, changes } of results) {
|
|
598
603
|
const displayPath = relative(targetDir, file) || basename(file);
|
|
@@ -602,14 +607,15 @@ async function convertImportsAliasToRelative({
|
|
|
602
607
|
}
|
|
603
608
|
}
|
|
604
609
|
}
|
|
605
|
-
regularLogger("Import path conversion process complete.");
|
|
610
|
+
regularLogger("Import/export path conversion process complete.");
|
|
606
611
|
return results;
|
|
607
612
|
}
|
|
608
613
|
async function convertImportsExt({
|
|
609
614
|
targetDir,
|
|
610
615
|
extFrom,
|
|
611
616
|
extTo,
|
|
612
|
-
alias
|
|
617
|
+
alias,
|
|
618
|
+
displayLogs = false
|
|
613
619
|
}) {
|
|
614
620
|
const fromExtStr = extFrom === "none" ? "" : `.${extFrom}`;
|
|
615
621
|
const toExtStr = extTo === "none" ? "" : `.${extTo}`;
|
|
@@ -691,7 +697,7 @@ async function convertImportsExt({
|
|
|
691
697
|
}
|
|
692
698
|
})
|
|
693
699
|
);
|
|
694
|
-
if (results.length > 0) {
|
|
700
|
+
if (results.length > 0 && displayLogs) {
|
|
695
701
|
regularLogger("\n[convertImportsExt] Summary of changes:");
|
|
696
702
|
for (const { file, changes } of results) {
|
|
697
703
|
const displayPath = relative(targetDir, file) || basename(file);
|
|
@@ -760,7 +766,8 @@ async function stripPathSegmentsInDirectory({
|
|
|
760
766
|
targetDir,
|
|
761
767
|
segmentsToStrip,
|
|
762
768
|
alias = "",
|
|
763
|
-
extensionsToProcess = EXTENSIONS
|
|
769
|
+
extensionsToProcess = EXTENSIONS,
|
|
770
|
+
displayLogs = false
|
|
764
771
|
}) {
|
|
765
772
|
regularLogger(
|
|
766
773
|
() => `[stripPathSegmentsInDirectory] Processing directory: ${targetDir}`
|
|
@@ -822,7 +829,7 @@ async function stripPathSegmentsInDirectory({
|
|
|
822
829
|
}
|
|
823
830
|
})
|
|
824
831
|
);
|
|
825
|
-
if (results.length > 0) {
|
|
832
|
+
if (results.length > 0 && displayLogs) {
|
|
826
833
|
regularLogger(() => "[stripPathSegmentsInDirectory] Summary of changes:");
|
|
827
834
|
for (const { file, changes } of results) {
|
|
828
835
|
const displayPath = relative(targetDir, file) || basename(file);
|
|
@@ -881,7 +888,8 @@ async function attachPathSegmentsInDirectory({
|
|
|
881
888
|
targetDir,
|
|
882
889
|
segments,
|
|
883
890
|
options = {},
|
|
884
|
-
extensionsToProcess = EXTENSIONS
|
|
891
|
+
extensionsToProcess = EXTENSIONS,
|
|
892
|
+
displayLogs = false
|
|
885
893
|
}) {
|
|
886
894
|
try {
|
|
887
895
|
const entries = await fs.readdir(targetDir, { withFileTypes: true });
|
|
@@ -929,7 +937,7 @@ async function attachPathSegmentsInDirectory({
|
|
|
929
937
|
}
|
|
930
938
|
})
|
|
931
939
|
);
|
|
932
|
-
if (results.length > 0) {
|
|
940
|
+
if (results.length > 0 && displayLogs) {
|
|
933
941
|
regularLogger(
|
|
934
942
|
() => "\n[attachPathSegmentsInDirectory] Summary of changes:"
|
|
935
943
|
);
|