Skip to content

Commit 34d7276

Browse files
dfranklandnicknisi
andauthored
fix ESM import extensions (#249)
Co-authored-by: Nick Nisi <[email protected]>
1 parent 4daa96f commit 34d7276

18 files changed

+2397
-114
lines changed

.eslintrc.cjs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
module.exports = {
22
root: true,
33
extends: [
4-
'eslint:recommended',
5-
'prettier',
4+
'eslint:recommended',
5+
'prettier',
66
'plugin:@typescript-eslint/recommended',
7-
'plugin:require-extensions/recommended',
7+
'plugin:import/recommended',
8+
'plugin:import/typescript',
89
],
9-
plugins: ['require-extensions'],
10+
settings: {
11+
'import/resolver': {
12+
typescript: {
13+
extensions: ['.js'],
14+
},
15+
node: {
16+
extensions: ['.js'],
17+
},
18+
},
19+
},
20+
rules: {
21+
'import/extensions': [
22+
'error',
23+
'always',
24+
{
25+
ts: 'never',
26+
tsx: 'never',
27+
},
28+
],
29+
},
1030
};

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
169169
For pages where you want to display a signed-in and signed-out view, use `withAuth` to retrieve the user session from WorkOS.
170170

171171
```jsx
172-
import Link from 'next/link';
172+
import Link from 'next/link.js';
173173
import { getSignInUrl, getSignUpUrl, withAuth, signOut } from '@workos-inc/authkit-nextjs';
174174

175175
export default async function HomePage() {

__tests__/auth.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import { describe, it, expect, beforeEach, jest } from '@jest/globals';
22

33
import { getSignInUrl, getSignUpUrl, signOut, switchToOrganization } from '../src/auth.js';
44
import * as session from '../src/session.js';
5-
import * as cache from 'next/cache';
5+
import * as cache from 'next/cache.js';
66
import * as workosModule from '../src/workos.js';
77

88
// These are mocked in jest.setup.ts
9-
import { cookies, headers } from 'next/headers';
10-
import { redirect } from 'next/navigation';
9+
import { cookies, headers } from 'next/headers.js';
10+
import { redirect } from 'next/navigation.js';
1111
import { generateSession, generateTestToken } from './test-helpers.js';
1212
import { sealData } from 'iron-session';
1313
import { getWorkOS } from '../src/workos.js';
1414

1515
const workos = getWorkOS();
1616

17-
jest.mock('next/cache', () => {
18-
const actual = jest.requireActual<typeof cache>('next/cache');
17+
jest.mock('next/cache.js', () => {
18+
const actual = jest.requireActual<typeof cache>('next/cache.js');
1919
return {
2020
...actual,
2121
revalidateTag: jest.fn(),

__tests__/authkit-callback-route.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getWorkOS } from '../src/workos.js';
22
import { handleAuth } from '../src/authkit-callback-route.js';
3-
import { NextRequest, NextResponse } from 'next/server';
3+
import { NextRequest, NextResponse } from 'next/server.js';
44

55
// Mocked in jest.setup.ts
6-
import { cookies, headers } from 'next/headers';
6+
import { cookies, headers } from 'next/headers.js';
77

88
// Mock dependencies
99
const fakeWorkosInstance = {

__tests__/get-authorization-url.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { describe, it, expect, beforeEach, jest } from '@jest/globals';
22
import { getAuthorizationUrl } from '../src/get-authorization-url.js';
3-
import { headers } from 'next/headers';
3+
import { headers } from 'next/headers.js';
44
import { getWorkOS } from '../src/workos.js';
55

6-
jest.mock('next/headers');
6+
jest.mock('next/headers.js');
77

88
// Mock dependencies
99
const fakeWorkosInstance = {

__tests__/session.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { NextRequest, NextResponse } from 'next/server';
2-
import { cookies, headers } from 'next/headers';
3-
import { redirect } from 'next/navigation';
1+
import { NextRequest, NextResponse } from 'next/server.js';
2+
import { cookies, headers } from 'next/headers.js';
3+
import { redirect } from 'next/navigation.js';
44
import { generateTestToken } from './test-helpers.js';
55
import { withAuth, updateSession, refreshSession, updateSessionMiddleware, getCustomClaims } from '../src/session.js';
66
import { getWorkOS } from '../src/workos.js';

__tests__/test-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { sealData } from 'iron-session';
44
import { SignJWT } from 'jose';
55
import { WORKOS_COOKIE_NAME, WORKOS_COOKIE_PASSWORD } from '../src/env-variables.js';
6-
import { cookies } from 'next/headers';
6+
import { cookies } from 'next/headers.js';
77
import { User } from '@workos-inc/node';
88

99
export async function generateTestToken(payload = {}, expired = false) {

__tests__/utils.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextResponse } from 'next/server.js';
22
import { redirectWithFallback, errorResponseWithFallback } from '../src/utils.js';
33

44
describe('utils', () => {
@@ -37,7 +37,7 @@ describe('utils', () => {
3737

3838
jest.resetModules();
3939

40-
jest.mock('next/server', () => ({
40+
jest.mock('next/server.js', () => ({
4141
NextResponse: {
4242
// exists but has no redirect method
4343
},
@@ -58,7 +58,7 @@ describe('utils', () => {
5858
jest.resetModules();
5959

6060
// Mock with undefined NextResponse
61-
jest.mock('next/server', () => ({
61+
jest.mock('next/server.js', () => ({
6262
NextResponse: undefined,
6363
}));
6464

@@ -108,7 +108,7 @@ describe('utils', () => {
108108
it('falls back to standard Response when NextResponse exists but json is undefined', async () => {
109109
jest.resetModules();
110110

111-
jest.mock('next/server', () => ({
111+
jest.mock('next/server.js', () => ({
112112
NextResponse: {
113113
// exists but has no json method
114114
},
@@ -126,7 +126,7 @@ describe('utils', () => {
126126
it('falls back to standard Response when NextResponse is undefined', async () => {
127127
jest.resetModules();
128128

129-
jest.mock('next/server', () => ({
129+
jest.mock('next/server.js', () => ({
130130
NextResponse: undefined,
131131
}));
132132

jest.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ process.env.NEXT_PUBLIC_WORKOS_REDIRECT_URI = 'http://localhost:3000/callback';
55
process.env.WORKOS_COOKIE_DOMAIN = 'example.com';
66

77
// Mock the next/headers module
8-
jest.mock('next/headers', () => {
8+
jest.mock('next/headers.js', () => {
99
const cookieStore = new Map();
1010
const headersStore = new Map();
1111

@@ -38,6 +38,6 @@ jest.mock('next/headers', () => {
3838
};
3939
});
4040

41-
jest.mock('next/navigation', () => ({
41+
jest.mock('next/navigation.js', () => ({
4242
redirect: jest.fn(),
4343
}));

0 commit comments

Comments
 (0)