Skip to content

Commit 0c24a46

Browse files
committed
testing out static file copying
1 parent 6c46c9d commit 0c24a46

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

adapters-notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@
3030
- Can we export build time otel spans from adapter similarly how we do that now in a build plugin?
3131
- Expose some constants from build plugin to adapter - what's best way to do that? (things like
3232
packagePath, publishDir etc)
33+
- Looking forward - Platform change to accept a list of files to upload to cdn (avoids file system
34+
operations such as `cp`)

src/adapter/adapter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
modifyConfig as modifyConfigForImageCDN,
99
onBuildComplete as onBuildCompleteForImageCDN,
1010
} from './image-cdn.js'
11+
import { onBuildComplete as onBuildCompleteForStaticFiles } from './static.js'
1112
import { FrameworksAPIConfig } from './types.js'
1213

1314
const NETLIFY_FRAMEWORKS_API_CONFIG_PATH = '.netlify/v1/config.json'
@@ -30,6 +31,10 @@ const adapter: NextAdapter = {
3031
let frameworksAPIConfig: FrameworksAPIConfig = null
3132

3233
frameworksAPIConfig = onBuildCompleteForImageCDN(nextAdapterContext, frameworksAPIConfig)
34+
frameworksAPIConfig = await onBuildCompleteForStaticFiles(
35+
nextAdapterContext,
36+
frameworksAPIConfig,
37+
)
3338
frameworksAPIConfig = onBuildCompleteForHeaders(nextAdapterContext, frameworksAPIConfig)
3439

3540
if (frameworksAPIConfig) {

src/adapter/static.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { cp } from 'node:fs/promises'
2+
import { join } from 'node:path/posix'
3+
4+
import type { FrameworksAPIConfig, OnBuildCompleteContext } from './types.js'
5+
6+
export async function onBuildComplete(
7+
ctx: OnBuildCompleteContext,
8+
frameworksAPIConfigArg: FrameworksAPIConfig,
9+
) {
10+
const frameworksAPIConfig: FrameworksAPIConfig = frameworksAPIConfigArg ?? {}
11+
12+
for (const staticFile of ctx.outputs.staticFiles) {
13+
try {
14+
await cp(staticFile.filePath, join('./.netlify/static', staticFile.pathname), {
15+
recursive: true,
16+
})
17+
} catch (error) {
18+
throw new Error(`Failed copying static assets`, { cause: error })
19+
}
20+
}
21+
22+
return frameworksAPIConfig
23+
}

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { wrapTracer } from '@opentelemetry/api/experimental'
88
import { restoreBuildCache, saveBuildCache } from './build/cache.js'
99
import { copyPrerenderedContent } from './build/content/prerendered.js'
1010
import {
11-
copyStaticAssets,
1211
copyStaticContent,
1312
copyStaticExport,
1413
publishStaticDir,
@@ -94,7 +93,6 @@ export const onBuild = async (options: NetlifyPluginOptions) => {
9493
await verifyNetlifyFormsWorkaround(ctx)
9594

9695
await Promise.all([
97-
copyStaticAssets(ctx), // this
9896
copyStaticContent(ctx), // this
9997
copyPrerenderedContent(ctx), // maybe this
10098
createServerHandler(ctx), // not this while we use standalone

0 commit comments

Comments
 (0)