fix: improve path handling for .d.ts file emission
- Fix leading slash in relative path - Use .d.ts extension instead of .csv.d.ts - Support typesOutputDir option properly - Use ./ prefix for module declaration path Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -152,16 +152,26 @@ export default function csvLoader(
|
||||
});
|
||||
|
||||
const json = JSON.stringify(objects, null, 2);
|
||||
|
||||
|
||||
// Emit type definition file if enabled
|
||||
if (emitTypes) {
|
||||
const relativePath = this.resourcePath.replace(this.context, '').replace(/\\/g, '/');
|
||||
const dtsFileName = relativePath.replace(/\.csv$/, '.d.ts');
|
||||
const outputPath = path.join(typesOutputDir, dtsFileName);
|
||||
const dtsContent = generateTypeDefinition(this.resourcePath, propertyConfigs, relativePath);
|
||||
const context = this.context || '';
|
||||
// Get relative path from context, normalize to forward slashes
|
||||
let relativePath = this.resourcePath.replace(context, '');
|
||||
if (relativePath.startsWith('\\') || relativePath.startsWith('/')) {
|
||||
relativePath = relativePath.substring(1);
|
||||
}
|
||||
relativePath = relativePath.replace(/\\/g, '/');
|
||||
|
||||
// Replace .csv with .d.ts for the output filename
|
||||
const dtsFileName = relativePath.replace(/\.csv$/, '.d.ts');
|
||||
const outputPath = typesOutputDir
|
||||
? path.join(typesOutputDir, dtsFileName)
|
||||
: dtsFileName;
|
||||
const dtsContent = generateTypeDefinition(this.resourcePath, propertyConfigs, `./${relativePath}`);
|
||||
|
||||
this.emitFile?.(outputPath, dtsContent);
|
||||
}
|
||||
|
||||
|
||||
return `export default ${json};`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user