Skip to content

Commit 2341079

Browse files
committed
preserve html extension for static files
1 parent 3f76a9f commit 2341079

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/adapter/static-assets.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cp } from 'node:fs/promises'
2-
import { join } from 'node:path/posix'
2+
import { extname, join } from 'node:path/posix'
33

44
import type { FrameworksAPIConfig, OnBuildCompleteContext } from './types.js'
55

@@ -11,11 +11,19 @@ export async function onBuildComplete(
1111

1212
for (const staticFile of ctx.outputs.staticFiles) {
1313
try {
14-
await cp(staticFile.filePath, join('./.netlify/static', staticFile.pathname), {
14+
let distPathname = staticFile.pathname
15+
if (extname(distPathname) === '' && extname(staticFile.filePath) === '.html') {
16+
// if pathname is extension-less, but source file has an .html extension, preserve it
17+
distPathname += '.html'
18+
}
19+
20+
await cp(staticFile.filePath, join('./.netlify/static', distPathname), {
1521
recursive: true,
1622
})
1723
} catch (error) {
18-
throw new Error(`Failed copying static assets`, { cause: error })
24+
throw new Error(`Failed copying static asset.\n\n${JSON.stringify(staticFile, null, 2)}`, {
25+
cause: error,
26+
})
1927
}
2028
}
2129

0 commit comments

Comments
 (0)