Skip to content

fix: copy imageconfig into edge function dir #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions plugin/src/helpers/edge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable max-lines */
import { promises as fs, existsSync } from 'fs'
import { resolve, join } from 'path'

import type { NetlifyConfig } from '@netlify/build'
import { emptyDir, ensureDir, readJSON, readJson, writeJSON, writeJson } from 'fs-extra'
import { copyFile, emptyDir, ensureDir, readJSON, readJson, writeJSON, writeJson } from 'fs-extra'
import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middleware-plugin'

type EdgeFunctionDefinition = MiddlewareManifest['middleware']['name']
Expand Down Expand Up @@ -139,7 +140,13 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
'Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.',
)
}
await copyEdgeSourceFile({ edgeFunctionDir: edgeFunctionRoot, file: 'ipx.ts' })
const edgeFunctionDir = join(edgeFunctionRoot, 'ipx')
await ensureDir(edgeFunctionDir)
await copyEdgeSourceFile({ edgeFunctionDir, file: 'ipx.ts', target: 'index.ts' })
await copyFile(
join('.netlify', 'functions-internal', '_ipx', 'imageconfig.json'),
join(edgeFunctionDir, 'imageconfig.json'),
)
manifest.functions.push({
function: 'ipx',
path: '/_next/image*',
Expand Down Expand Up @@ -183,3 +190,4 @@ export const updateConfig = async (publish: string) => {
config.config.env.NEXT_USE_NETLIFY_EDGE = 'true'
await writeJSON(configFile, config)
}
/* eslint-enable max-lines */
2 changes: 1 addition & 1 deletion plugin/src/templates/edge/ipx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Accepts } from "https://deno.land/x/[email protected]/mod.ts";
import type { Context } from "netlify:edge";
// Available at build time
import imageconfig from "../functions-internal/_ipx/imageconfig.json" assert {
import imageconfig from "./imageconfig.json" assert {
type: "json",
};

Expand Down