Skip to content

Commit 6ab3ee5

Browse files
committed
fix(dev-server-rollup): ensure correct imports in pages without extension
1 parent b180a2e commit 6ab3ee5

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

.changeset/friendly-ads-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/dev-server-rollup': patch
3+
---
4+
5+
fix: ensure imports are resolved correctly in pages without extension

packages/dev-server-rollup/src/rollupAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export function rollupAdapter(
317317
const importPath = toBrowserPath(relativePath.substring(lastDirUpIndex));
318318
resolvedImportPath = `/__wds-outside-root__/${dirUpStrings.length - 1}/${importPath}`;
319319
} else {
320-
const resolveRelativeTo = path.extname(filePath) ? path.dirname(filePath) : filePath;
320+
const resolveRelativeTo = path.dirname(filePath);
321321
const relativeImportFilePath = path.relative(resolveRelativeTo, resolvedImportPath);
322322
resolvedImportPath = `./${toBrowserPath(relativeImportFilePath)}`;
323323
}

packages/dev-server-rollup/test/node/plugins/node-resolve.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ describe('@rollup/plugin-node-resolve', () => {
2424
}
2525
});
2626

27+
it('can resolve imports in extensionless pages', async () => {
28+
const { server, host } = await createTestServer({
29+
plugins: [
30+
nodeResolve(),
31+
{
32+
name: 'test',
33+
serve(ctx) {
34+
if (ctx.path === '/index') {
35+
return { body: '<script type="module">import \'module-a\';</script>', type: 'html' };
36+
}
37+
},
38+
},
39+
],
40+
});
41+
42+
try {
43+
const text = await fetchText(`${host}/index`);
44+
expectIncludes(text, "import './node_modules/module-a/index.js'");
45+
} finally {
46+
server.stop();
47+
}
48+
});
49+
2750
it('can resolve imports in inline scripts', async () => {
2851
const { server, host } = await createTestServer({
2952
plugins: [nodeResolve()],

0 commit comments

Comments
 (0)