Skip to content

Commit 8cb2877

Browse files
committed
fix #1660; getWatchPath needs findModule
1 parent 6845ea8 commit 8cb2877

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/loader.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,8 @@ export class LoaderResolver {
255255
const exactPath = join(this.root, path);
256256
if (existsSync(exactPath)) return exactPath;
257257
if (exactPath.endsWith(".js")) {
258-
const basePath = exactPath.slice(0, -".js".length);
259-
for (const ext of [".ts", ".jsx", ".tsx"]) {
260-
const extPath = basePath + ext;
261-
if (existsSync(extPath)) return extPath;
262-
}
263-
return; // loaders aren’t supported for .js
258+
const module = findModule(this.root, path);
259+
return module && join(this.root, module.path);
264260
}
265261
const foundPath = this.find(path)?.path;
266262
if (foundPath) return join(this.root, foundPath);

test/loader-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,10 @@ describe("LoaderResolver.get{Source,Output}Info(path)", () => {
170170
assert.deepStrictEqual(loaders.getOutputInfo("input/loader/not-cached.txt"), undefined);
171171
});
172172
});
173+
174+
describe("LoaderResolver.getWatchPath(path)", () => {
175+
it("returns the path to a parameterized module", async () => {
176+
const loaders = new LoaderResolver({root: "test/input/params"});
177+
assert.deepStrictEqual(loaders.getWatchPath("prefix-test.js"), "test/input/params/prefix-[file].js");
178+
});
179+
});

0 commit comments

Comments
 (0)