Skip to content

Commit

Permalink
fix: --file-paths with non-js resources
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Mar 26, 2024
1 parent 28d8604 commit ee03f2b
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/detectors/typeChecker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class TsProjectDetector extends ProjectBasedDetector {
const resourceContent = await resource.getString();
({source, messages} = await lintManifest(resourcePath, resourceContent));
} else if (resourcePath.endsWith(".html")) {
resourcePath = resourcePath.replace(/\.html$/, ".html.js");
resourcePath = resourcePath.replace(/\.html$/, ".js");
source = await resource.getString();
({messages} = await lintHtml(resourcePath, resource.getStream()));
} else {
Expand Down Expand Up @@ -217,11 +217,20 @@ export class TsProjectDetector extends ProjectBasedDetector {
});

// Rewrite fs-paths to virtual paths
resourcePaths = allResources.map((res: Resource) => {
resourcePaths = [...allResources, ...allTestResources].map((res: Resource) => {
if (absoluteFilePaths.includes(res.getSourceMetadata().fsPath)) {
return res.getPath();
}
}).filter(($: string | undefined) => $);
})
.filter(($: string | undefined) => $)
.map((res) => {
if (res && !res.endsWith(".js")) {
const chunks = res?.split(".");
chunks.splice(-1, 1, "js")
res = chunks.join(".");
}
return res;
});
} else {
resourcePaths = Array.from(resources.keys());
}
Expand Down Expand Up @@ -295,6 +304,14 @@ export class TsFileDetector extends FileBasedDetector {
}
internalfilePath = filePath.replace(/\.json$/, ".js");
transformationResult = await lintManifest(internalfilePath, fileContent);
} else if (filePath.endsWith(".html")) {
const fileContent = ts.sys.readFile(filePath);
if (!fileContent) {
throw new Error(`Failed to read file ${filePath}`);
}
internalfilePath = filePath.replace(/\.html$/, ".html.js");
transformationResult = await lintHtml(internalfilePath, fs.createReadStream(filePath));
transformationResult.source = fileContent;
} else {
throw new Error(`Unsupported file type for ${filePath}`);
}
Expand Down

0 comments on commit ee03f2b

Please sign in to comment.