Skip to content

Commit

Permalink
fix: ensure compat with [email protected]
Browse files Browse the repository at this point in the history
Closes #887
  • Loading branch information
Xunnamius committed Oct 3, 2023
1 parent 3450b71 commit ca1da40
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 117 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type { NextApiHandler } from 'next';
import type { Server, IncomingMessage, ServerResponse } from 'http';
import type { RequestInit, Response as FetchReturnValue } from 'node-fetch';

// @ts-ignore: ignore this (conditional) import so bundlers don't choke and die
import type { apiResolver as NextApiResolver } from 'next/dist/server/api-utils/node';
import type { apiResolver as NextApiResolver } from 'next/dist/server/api-utils/node/api-resolver';

/**
* This function is responsible for adding the headers sent along with every
Expand Down Expand Up @@ -166,9 +165,10 @@ export async function testApiHandler<NextResponseJsonType = any>({

try {
if (!apiResolver) {
// ? The following is for next@>=12.1.0:
// @ts-ignore: conditional import for earlier next versions
({ apiResolver } = await import('next/dist/server/api-utils/node.js')
// ? The following is for next@>=12.5.4:
({ apiResolver } = await import('next/dist/server/api-utils/node/api-resolver.js')
// ? The following is for next@<12.5.4 >=12.1.0:
.catch(tryImport('next/dist/server/api-utils/node.js'))
// ? The following is for next@<12.1.0 >=11.1.0:
.catch(tryImport('next/dist/server/api-utils.js'))
// ? The following is for next@<11.1.0 >=9.0.6:
Expand Down
6 changes: 4 additions & 2 deletions test/integration-client-next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const NEXT_VERSIONS_UNDER_TEST = satisfiesRange(process.versions.node, '<15') ?
['next@^10', 'react@^17'],
['[email protected]', 'react@^17'],
['next@^11', 'react@^17'],
['[email protected]', 'react@^17'],
['next@latest', 'react@^17']
['[email protected]', 'react@^18'],
['[email protected]', 'react@^18'],
['next@latest', 'react@^18']
]
:
[
Expand All @@ -41,6 +42,7 @@ const NEXT_VERSIONS_UNDER_TEST = satisfiesRange(process.versions.node, '<15') ?
['[email protected]'], // ? See issue #295
['next@^11'], // ? Latest version 11 release
['next@^12.0.x'], // ? See issue #487
['next@^13.5.3'], // ? See issue #887
['next@latest'] // ? Latest release
];

Expand Down
Loading

1 comment on commit ca1da40

@Xunnamius
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, that should have said 13.5.4 instead of 12.1.0. Oops :)

Please sign in to comment.