From 862e2c3a83acba3b4020f886f51733f77a9d03a9 Mon Sep 17 00:00:00 2001 From: Ben Merckx Date: Mon, 18 Nov 2024 14:54:09 +0100 Subject: [PATCH] Update withAlinea function and export to work better across Node versions and cjs/esm --- src/adapter/next/with-alinea.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/adapter/next/with-alinea.ts b/src/adapter/next/with-alinea.ts index 4a3c6526..52a0a0e0 100644 --- a/src/adapter/next/with-alinea.ts +++ b/src/adapter/next/with-alinea.ts @@ -1,7 +1,14 @@ -import {NextConfig} from 'next/dist/types.js' -import pkg from 'next/package.json' +import type {NextConfig} from 'next/dist/types.js' +import {readFileSync} from 'node:fs' +import {createRequire} from 'node:module' +import {resolve} from 'path' export function withAlinea(config: NextConfig): NextConfig { + // Ducktape this together so we can get the package.json contents regardless + // of .cjs, .mjs, compiled .ts or Node version + const require = createRequire(resolve('.')) + const pkgLocation = require.resolve('next/package.json') + const pkg = JSON.parse(readFileSync(pkgLocation, 'utf-8')) const majorVersion = Number(pkg.version.split('.')[0]) if (majorVersion < 15) return { @@ -11,7 +18,15 @@ export function withAlinea(config: NextConfig): NextConfig { serverComponentsExternalPackages: [ ...(config.experimental?.serverComponentsExternalPackages ?? []), '@alinea/generated' - ] + ], + turbo: { + ...config.experimental?.turbo, + resolveAlias: { + ...config.experimental?.turbo?.resolveAlias, + 'next/dist/server/app-render/work-unit-async-storage.external.js': + 'next/dist/client/components/request-async-storage.external.js' + } + } } } return {