Skip to content

Commit 88da4a5

Browse files
committed
feat(build): move completely to esm within typescript
1 parent 5125590 commit 88da4a5

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

Diff for: .eslintrc.cjs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@labdigital/eslint-config-node'],
4+
parserOptions: {
5+
project: 'tsconfig.json',
6+
tsconfigRootDir: __dirname,
7+
extraFileExtensions: ['.cjs'],
8+
},
9+
}

Diff for: .eslintrc.js

-4
This file was deleted.

Diff for: jest.config.js renamed to jest.config.cjs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const customJestConfig = {
77
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.tsx'],
88
verbose: true,
99
transformIgnorePatterns: ['/next[/\\\\]dist/', '/\\.next/'],
10+
extensionsToTreatAsEsm: ['.ts'],
11+
moduleNameMapper: {
12+
'^(\\.{1,2}/.*)\\.js$': '$1',
13+
},
1014
}
1115

1216
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js config which is async

Diff for: src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
export { createNextAuthMiddleware, nextBasicAuthMiddleware } from './middleware'
1+
export {
2+
createNextAuthMiddleware,
3+
nextBasicAuthMiddleware,
4+
} from './middleware.js'
25
export type { MiddlewareOptions } from './types'

Diff for: src/lib/credentials.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BasicAuthResult } from './auth'
2-
import { safeCompare } from './compare'
1+
import { BasicAuthResult } from './auth.js'
2+
import { safeCompare } from './compare.js'
33

44
// This contains all the logic for parsing and checking credentials
55
type AuthCredentialsObject = {
@@ -12,7 +12,7 @@ export type AuthCredentials = AuthCredentialsObject[]
1212
export const parseCredentials = (credentials: string): AuthCredentials => {
1313
const authCredentials: AuthCredentials = []
1414

15-
credentials.split('|').forEach(item => {
15+
credentials.split('|').forEach((item) => {
1616
if (item.length < 3) {
1717
throw new Error(
1818
`Received incorrect basic auth syntax, use <username>:<password>, received ${item}`
@@ -46,7 +46,7 @@ export const compareCredentials = (
4646
requiredCredentials: AuthCredentials
4747
): boolean =>
4848
requiredCredentials.some(
49-
item =>
49+
(item) =>
5050
safeCompare(input.user, item.name) &&
5151
safeCompare(input.pass, item.password)
5252
)

Diff for: src/middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextRequest } from 'next/server'
22
// eslint-disable-next-line no-duplicate-imports
33
import { NextResponse } from 'next/server'
4-
import { basicAuthentication } from './lib/auth'
4+
import { basicAuthentication } from './lib/auth.js'
55
import {
66
AuthCredentials,
77
compareCredentials,

Diff for: tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"include": ["src", "jest.config.js"],
2+
"include": ["src", "jest.config.cjs", ".eslintrc.cjs"],
33
"compilerOptions": {
44
"target": "es2022",
5-
"module": "esnext",
5+
"module": "nodenext",
66
"lib": ["dom", "esnext"],
77
"importHelpers": true,
88
"declaration": true,

0 commit comments

Comments
 (0)