Skip to content

Commit

Permalink
fix #1660; getWatchPath needs findModule
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Sep 13, 2024
1 parent 6845ea8 commit 8cb2877
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,8 @@ export class LoaderResolver {
const exactPath = join(this.root, path);
if (existsSync(exactPath)) return exactPath;
if (exactPath.endsWith(".js")) {
const basePath = exactPath.slice(0, -".js".length);
for (const ext of [".ts", ".jsx", ".tsx"]) {
const extPath = basePath + ext;
if (existsSync(extPath)) return extPath;
}
return; // loaders aren’t supported for .js
const module = findModule(this.root, path);
return module && join(this.root, module.path);
}
const foundPath = this.find(path)?.path;
if (foundPath) return join(this.root, foundPath);
Expand Down
7 changes: 7 additions & 0 deletions test/loader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,10 @@ describe("LoaderResolver.get{Source,Output}Info(path)", () => {
assert.deepStrictEqual(loaders.getOutputInfo("input/loader/not-cached.txt"), undefined);
});
});

describe("LoaderResolver.getWatchPath(path)", () => {
it("returns the path to a parameterized module", async () => {
const loaders = new LoaderResolver({root: "test/input/params"});
assert.deepStrictEqual(loaders.getWatchPath("prefix-test.js"), "test/input/params/prefix-[file].js");
});
});

0 comments on commit 8cb2877

Please sign in to comment.