Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 28 additions & 1 deletion src/build/content/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
}
const src = join(ctx.standaloneDir, entry)
const dest = join(ctx.serverHandlerDir, entry)
await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true })
const filter = ctx.constants.IS_LOCAL ? undefined : nodeModulesFilter
await cp(src, dest, {
recursive: true,
verbatimSymlinks: true,
force: true,
filter,
})

if (entry === 'node_modules') {
await recreateNodeModuleSymlinks(ctx.resolveFromSiteDir('node_modules'), dest)
Expand Down Expand Up @@ -438,3 +444,24 @@ export const verifyHandlerDirStructure = async (ctx: PluginContext) => {
)
}
}

// This is a workaround for Next.js installations in a pnpm+glibc context
// Patch required due to an intermittent upstream issue in the npm/pnpm ecosystem
// https://github.com/pnpm/pnpm/issues/9654
// https://github.com/pnpm/pnpm/issues/5928
// https://github.com/pnpm/pnpm/issues/7362 (persisting even though ticket is closed)
const nodeModulesFilter = async (sourcePath: string) => {
// Filtering rule for the following packages:
// - @rspack+binding-linux-x64-musl
// - @swc+core-linux-x64-musl
// - @img+sharp-linuxmusl-x64
// - @img+sharp-libvips-linuxmusl-x64
if (
sourcePath.includes('.pnpm') &&
(sourcePath.includes('linuxmusl-x64') || sourcePath.includes('linux-x64-musl'))
) {
return false
}

return true
}
12 changes: 3 additions & 9 deletions src/build/functions/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,11 @@ const buildHandlerDefinition = (
ctx: PluginContext,
def: EdgeOrNodeMiddlewareDefinition,
): Array<ManifestFunction> => {
const functionHandlerName = getHandlerName({ name: def.name })
const functionName = 'Next.js Middleware Handler'
const cache = def.name.endsWith('middleware') ? undefined : ('manual' as const)
const generator = `${ctx.pluginName}@${ctx.pluginVersion}`

return augmentMatchers(def.matchers, ctx).map((matcher) => ({
function: functionHandlerName,
name: functionName,
function: getHandlerName({ name: def.name }),
name: 'Next.js Middleware Handler',
pattern: matcher.regexp,
cache,
generator,
generator: `${ctx.pluginName}@${ctx.pluginVersion}`,
}))
}

Expand Down
2 changes: 1 addition & 1 deletion src/build/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export interface ExportDetail {
}

export class PluginContext {
constants: NetlifyPluginConstants
featureFlags: NetlifyPluginOptions['featureFlags']
netlifyConfig: NetlifyPluginOptions['netlifyConfig']
pluginName: string
pluginVersion: string
utils: NetlifyPluginUtils

private constants: NetlifyPluginConstants
private packageJSON: { name: string; version: string } & Record<string, unknown>

/** Absolute path of the next runtime plugin directory */
Expand Down
Loading