fix(exports): Fixed duplicate file compilation in compileGlobStringObject, fixes #1
This commit is contained in:
@ -25,35 +25,52 @@ export let compileFileArray = (
|
||||
* }
|
||||
*/
|
||||
export let compileGlobStringObject = async (
|
||||
globStringObjectArg: any,
|
||||
globStringObjectArg: Record<string, string>,
|
||||
tsOptionsArg: CompilerOptions = {},
|
||||
cwdArg: string = process.cwd(),
|
||||
argvArg?: any
|
||||
) => {
|
||||
let compiledFiles: plugins.smartfile.SmartFile[] = [];
|
||||
let compiledFiles: any[] = [];
|
||||
|
||||
for (const keyArg in globStringObjectArg) {
|
||||
if (globStringObjectArg[keyArg]) {
|
||||
// Type safety check for key
|
||||
if (keyArg && typeof keyArg === 'string' && globStringObjectArg[keyArg]) {
|
||||
console.log(
|
||||
`TypeScript assignment: transpile from ${keyArg} to ${globStringObjectArg[keyArg]}`
|
||||
);
|
||||
|
||||
// Get files matching the glob pattern
|
||||
const fileTreeArray = await plugins.smartfile.fs.listFileTree(cwdArg, keyArg);
|
||||
const absoluteFilePathArray: string[] = plugins.smartpath.transform.toAbsolute(
|
||||
fileTreeArray,
|
||||
|
||||
// Ensure fileTreeArray contains only strings before transforming
|
||||
const stringFileTreeArray = Array.isArray(fileTreeArray)
|
||||
? fileTreeArray.filter((item): item is string => typeof item === 'string')
|
||||
: [];
|
||||
|
||||
// Transform to absolute paths
|
||||
const absoluteFilePathArray = plugins.smartpath.transform.toAbsolute(
|
||||
stringFileTreeArray,
|
||||
cwdArg
|
||||
) as string[];
|
||||
|
||||
// Get destination directory as absolute path
|
||||
const destDir: string = plugins.smartpath.transform.toAbsolute(
|
||||
globStringObjectArg[keyArg],
|
||||
cwdArg
|
||||
) as string;
|
||||
tsOptionsArg = {
|
||||
|
||||
// Update compiler options with the output directory
|
||||
const updatedTsOptions: CompilerOptions = {
|
||||
...tsOptionsArg,
|
||||
outDir: destDir,
|
||||
};
|
||||
compiledFiles = compiledFiles.concat(
|
||||
compiledFiles,
|
||||
await compileFileArray(absoluteFilePathArray, tsOptionsArg, argvArg)
|
||||
);
|
||||
|
||||
// Compile the files and correctly concat the results
|
||||
// Fixed: removed duplicating compiledFiles in the concat operation
|
||||
const newlyCompiledFiles = await compileFileArray(absoluteFilePathArray, updatedTsOptions, argvArg);
|
||||
compiledFiles = compiledFiles.concat(newlyCompiledFiles);
|
||||
}
|
||||
}
|
||||
|
||||
return compiledFiles;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user