From 9528ed649b63a96e9e088003bf409394f220f324 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 4 Apr 2024 15:49:24 +0200 Subject: [PATCH 01/15] chore(auth): Convert to ESM+CJS dual build --- packages/auth/build.ts | 24 +++++++++++++++ packages/auth/package.json | 14 ++++++--- .../auth/src/AuthProvider/AuthProvider.tsx | 30 +++++++++---------- .../src/AuthProvider/AuthProviderState.ts | 2 +- .../src/AuthProvider/ServerAuthProvider.tsx | 4 +-- .../auth/src/AuthProvider/useCurrentUser.ts | 4 +-- .../src/AuthProvider/useForgotPassword.ts | 2 +- packages/auth/src/AuthProvider/useHasRole.ts | 2 +- packages/auth/src/AuthProvider/useLogIn.ts | 10 +++---- packages/auth/src/AuthProvider/useLogOut.ts | 4 +-- .../src/AuthProvider/useReauthenticate.ts | 8 ++--- .../auth/src/AuthProvider/useResetPassword.ts | 2 +- packages/auth/src/AuthProvider/useSignUp.ts | 8 ++--- packages/auth/src/AuthProvider/useToken.ts | 2 +- .../src/AuthProvider/useValidateResetToken.ts | 2 +- .../auth/src/__tests__/AuthProvider.test.tsx | 4 +-- packages/auth/src/authFactory.ts | 10 +++---- packages/auth/src/index.ts | 12 ++++---- packages/auth/src/useAuth.ts | 2 +- packages/auth/tsconfig.json | 2 ++ yarn.lock | 1 + 21 files changed, 91 insertions(+), 58 deletions(-) create mode 100644 packages/auth/build.ts diff --git a/packages/auth/build.ts b/packages/auth/build.ts new file mode 100644 index 000000000000..869b35842e36 --- /dev/null +++ b/packages/auth/build.ts @@ -0,0 +1,24 @@ +import { build, defaultBuildOptions } from '@redwoodjs/framework-tools' + +// ESM build +await build({ + buildOptions: { + ...defaultBuildOptions, + bundle: true, + entryPoints: ['./src/index.ts'], + format: 'esm', + outExtension: { '.js': '.mjs' }, + packages: 'external', + }, +}) + +// CJS build +await build({ + buildOptions: { + ...defaultBuildOptions, + bundle: true, + entryPoints: ['./src/index.ts'], + outExtension: { '.js': '.cjs' }, + packages: 'external', + }, +}) diff --git a/packages/auth/package.json b/packages/auth/package.json index dd8ba5b1fd61..8523afa8348a 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -7,14 +7,19 @@ "directory": "packages/auth" }, "license": "MIT", - "main": "./dist/index.js", + "type": "module", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "default": "./dist/index.cjs" + }, "types": "./dist/index.d.ts", "files": [ "dist" ], "scripts": { - "build": "yarn build:js && yarn build:types", - "build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\"", + "build": "tsx ./build.ts && yarn build:types", + "__build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\"", "build:pack": "yarn pack -o redwoodjs-auth.tgz", "build:types": "tsc --build --verbose", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", @@ -25,7 +30,8 @@ "dependencies": { "@babel/runtime-corejs3": "7.24.1", "core-js": "3.36.1", - "react": "18.3.0-canary-a870b2d54-20240314" + "react": "18.3.0-canary-a870b2d54-20240314", + "tsx": "4.7.1" }, "devDependencies": { "@babel/cli": "7.24.1", diff --git a/packages/auth/src/AuthProvider/AuthProvider.tsx b/packages/auth/src/AuthProvider/AuthProvider.tsx index 1a0b17fe99d8..d992c05c4fb6 100644 --- a/packages/auth/src/AuthProvider/AuthProvider.tsx +++ b/packages/auth/src/AuthProvider/AuthProvider.tsx @@ -1,22 +1,22 @@ import type { ReactNode } from 'react' import React, { useContext, useEffect, useState } from 'react' -import type { AuthContextInterface, CurrentUser } from '../AuthContext' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthContextInterface, CurrentUser } from '../AuthContext.js' +import type { AuthImplementation } from '../AuthImplementation.js' -import type { AuthProviderState } from './AuthProviderState' -import { defaultAuthProviderState } from './AuthProviderState' -import { ServerAuthContext } from './ServerAuthProvider' -import { useCurrentUser } from './useCurrentUser' -import { useForgotPassword } from './useForgotPassword' -import { useHasRole } from './useHasRole' -import { useLogIn } from './useLogIn' -import { useLogOut } from './useLogOut' -import { useReauthenticate } from './useReauthenticate' -import { useResetPassword } from './useResetPassword' -import { useSignUp } from './useSignUp' -import { useToken } from './useToken' -import { useValidateResetToken } from './useValidateResetToken' +import type { AuthProviderState } from './AuthProviderState.js' +import { defaultAuthProviderState } from './AuthProviderState.js' +import { ServerAuthContext } from './ServerAuthProvider.js' +import { useCurrentUser } from './useCurrentUser.js' +import { useForgotPassword } from './useForgotPassword.js' +import { useHasRole } from './useHasRole.js' +import { useLogIn } from './useLogIn.js' +import { useLogOut } from './useLogOut.js' +import { useReauthenticate } from './useReauthenticate.js' +import { useResetPassword } from './useResetPassword.js' +import { useSignUp } from './useSignUp.js' +import { useToken } from './useToken.js' +import { useValidateResetToken } from './useValidateResetToken.js' export interface AuthProviderProps { skipFetchCurrentUser?: boolean diff --git a/packages/auth/src/AuthProvider/AuthProviderState.ts b/packages/auth/src/AuthProvider/AuthProviderState.ts index f9dbe07c02ff..3bcaa6ed6035 100644 --- a/packages/auth/src/AuthProvider/AuthProviderState.ts +++ b/packages/auth/src/AuthProvider/AuthProviderState.ts @@ -1,4 +1,4 @@ -import type { CurrentUser } from '../AuthContext' +import type { CurrentUser } from '../AuthContext.js' export type AuthProviderState = { loading: boolean diff --git a/packages/auth/src/AuthProvider/ServerAuthProvider.tsx b/packages/auth/src/AuthProvider/ServerAuthProvider.tsx index b9ca2e8364a2..c90f568fab15 100644 --- a/packages/auth/src/AuthProvider/ServerAuthProvider.tsx +++ b/packages/auth/src/AuthProvider/ServerAuthProvider.tsx @@ -1,8 +1,8 @@ import type { ReactNode } from 'react' import React from 'react' -import type { AuthProviderState } from './AuthProviderState' -import { defaultAuthProviderState } from './AuthProviderState' +import type { AuthProviderState } from './AuthProviderState.js' +import { defaultAuthProviderState } from './AuthProviderState.js' export type ServerAuthState = AuthProviderState & { cookieHeader?: string diff --git a/packages/auth/src/AuthProvider/useCurrentUser.ts b/packages/auth/src/AuthProvider/useCurrentUser.ts index bd385c9bc1cb..480528a9f33d 100644 --- a/packages/auth/src/AuthProvider/useCurrentUser.ts +++ b/packages/auth/src/AuthProvider/useCurrentUser.ts @@ -1,8 +1,8 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' -import { useToken } from './useToken' +import { useToken } from './useToken.js' export const useCurrentUser = (authImplementation: AuthImplementation) => { const getToken = useToken(authImplementation) diff --git a/packages/auth/src/AuthProvider/useForgotPassword.ts b/packages/auth/src/AuthProvider/useForgotPassword.ts index 7589648c735f..945e7a9c303c 100644 --- a/packages/auth/src/AuthProvider/useForgotPassword.ts +++ b/packages/auth/src/AuthProvider/useForgotPassword.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' export const useForgotPassword = < TUser, diff --git a/packages/auth/src/AuthProvider/useHasRole.ts b/packages/auth/src/AuthProvider/useHasRole.ts index fd324c40bf1c..0201baddb055 100644 --- a/packages/auth/src/AuthProvider/useHasRole.ts +++ b/packages/auth/src/AuthProvider/useHasRole.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react' -import type { CurrentUser } from '../AuthContext' +import type { CurrentUser } from '../AuthContext.js' export const useHasRole = (currentUser: CurrentUser | null) => { /** diff --git a/packages/auth/src/AuthProvider/useLogIn.ts b/packages/auth/src/AuthProvider/useLogIn.ts index 9e9515b6b0a0..80c556106533 100644 --- a/packages/auth/src/AuthProvider/useLogIn.ts +++ b/packages/auth/src/AuthProvider/useLogIn.ts @@ -1,11 +1,11 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' -import type { AuthProviderState } from './AuthProviderState' -import { defaultAuthProviderState } from './AuthProviderState' -import type { useCurrentUser } from './useCurrentUser' -import { useReauthenticate } from './useReauthenticate' +import type { AuthProviderState } from './AuthProviderState.js' +import { defaultAuthProviderState } from './AuthProviderState.js' +import type { useCurrentUser } from './useCurrentUser.js' +import { useReauthenticate } from './useReauthenticate.js' export const useLogIn = < TUser, diff --git a/packages/auth/src/AuthProvider/useLogOut.ts b/packages/auth/src/AuthProvider/useLogOut.ts index a5d0b942db23..e7306eb06676 100644 --- a/packages/auth/src/AuthProvider/useLogOut.ts +++ b/packages/auth/src/AuthProvider/useLogOut.ts @@ -1,8 +1,8 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' -import type { AuthProviderState } from './AuthProviderState' +import type { AuthProviderState } from './AuthProviderState.js' export const useLogOut = < TUser, diff --git a/packages/auth/src/AuthProvider/useReauthenticate.ts b/packages/auth/src/AuthProvider/useReauthenticate.ts index 11de939fa017..6837628e5e3b 100644 --- a/packages/auth/src/AuthProvider/useReauthenticate.ts +++ b/packages/auth/src/AuthProvider/useReauthenticate.ts @@ -1,10 +1,10 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' -import type { AuthProviderState } from './AuthProviderState' -import type { useCurrentUser } from './useCurrentUser' -import { useToken } from './useToken' +import type { AuthProviderState } from './AuthProviderState.js' +import type { useCurrentUser } from './useCurrentUser.js' +import { useToken } from './useToken.js' const notAuthenticatedState = { isAuthenticated: false, diff --git a/packages/auth/src/AuthProvider/useResetPassword.ts b/packages/auth/src/AuthProvider/useResetPassword.ts index 9ce8c4587f3c..162994e3294c 100644 --- a/packages/auth/src/AuthProvider/useResetPassword.ts +++ b/packages/auth/src/AuthProvider/useResetPassword.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' export const useResetPassword = < TUser, diff --git a/packages/auth/src/AuthProvider/useSignUp.ts b/packages/auth/src/AuthProvider/useSignUp.ts index 596cd8155f05..3fc97a8020a0 100644 --- a/packages/auth/src/AuthProvider/useSignUp.ts +++ b/packages/auth/src/AuthProvider/useSignUp.ts @@ -1,10 +1,10 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' -import type { AuthProviderState } from './AuthProviderState' -import type { useCurrentUser } from './useCurrentUser' -import { useReauthenticate } from './useReauthenticate' +import type { AuthProviderState } from './AuthProviderState.js' +import type { useCurrentUser } from './useCurrentUser.js' +import { useReauthenticate } from './useReauthenticate.js' export const useSignUp = < TUser, diff --git a/packages/auth/src/AuthProvider/useToken.ts b/packages/auth/src/AuthProvider/useToken.ts index 10ba69b51635..9e17e0cac997 100644 --- a/packages/auth/src/AuthProvider/useToken.ts +++ b/packages/auth/src/AuthProvider/useToken.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' export const useToken = (authImplementation: AuthImplementation) => { return useCallback(async () => { diff --git a/packages/auth/src/AuthProvider/useValidateResetToken.ts b/packages/auth/src/AuthProvider/useValidateResetToken.ts index f7ea795f3d86..eeafd5a3c9f6 100644 --- a/packages/auth/src/AuthProvider/useValidateResetToken.ts +++ b/packages/auth/src/AuthProvider/useValidateResetToken.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react' -import type { AuthImplementation } from '../AuthImplementation' +import type { AuthImplementation } from '../AuthImplementation.js' export const useValidateResetToken = < TUser, diff --git a/packages/auth/src/__tests__/AuthProvider.test.tsx b/packages/auth/src/__tests__/AuthProvider.test.tsx index bad662ad8235..76838343794a 100644 --- a/packages/auth/src/__tests__/AuthProvider.test.tsx +++ b/packages/auth/src/__tests__/AuthProvider.test.tsx @@ -14,8 +14,8 @@ import '@testing-library/jest-dom/jest-globals' import { graphql } from 'msw' import { setupServer } from 'msw/node' -import type { CustomTestAuthClient } from './fixtures/customTestAuth' -import { createCustomTestAuth } from './fixtures/customTestAuth' +import type { CustomTestAuthClient } from './fixtures/customTestAuth.js' +import { createCustomTestAuth } from './fixtures/customTestAuth.js' configure({ asyncUtilTimeout: 5_000, diff --git a/packages/auth/src/authFactory.ts b/packages/auth/src/authFactory.ts index 33c00aa5732d..ec909c729108 100644 --- a/packages/auth/src/authFactory.ts +++ b/packages/auth/src/authFactory.ts @@ -1,8 +1,8 @@ -import type { CurrentUser } from './AuthContext' -import { createAuthContext } from './AuthContext' -import type { AuthImplementation } from './AuthImplementation' -import { createAuthProvider } from './AuthProvider/AuthProvider' -import { createUseAuth } from './useAuth' +import type { CurrentUser } from './AuthContext.js' +import { createAuthContext } from './AuthContext.js' +import type { AuthImplementation } from './AuthImplementation.js' +import { createAuthProvider } from './AuthProvider/AuthProvider.js' +import { createUseAuth } from './useAuth.js' export function createAuthentication< TUser, diff --git a/packages/auth/src/index.ts b/packages/auth/src/index.ts index 14a8cc83fbba..26085895dc6b 100644 --- a/packages/auth/src/index.ts +++ b/packages/auth/src/index.ts @@ -1,7 +1,7 @@ -export { AuthContextInterface, CurrentUser } from './AuthContext' -export { useNoAuth, UseAuth } from './useAuth' -export { createAuthentication } from './authFactory' -export type { AuthImplementation } from './AuthImplementation' +export { AuthContextInterface, CurrentUser } from './AuthContext.js' +export { useNoAuth, UseAuth } from './useAuth.js' +export { createAuthentication } from './authFactory.js' +export type { AuthImplementation } from './AuthImplementation.js' -export * from './AuthProvider/AuthProviderState' -export * from './AuthProvider/ServerAuthProvider' +export * from './AuthProvider/AuthProviderState.js' +export * from './AuthProvider/ServerAuthProvider.js' diff --git a/packages/auth/src/useAuth.ts b/packages/auth/src/useAuth.ts index 301aa66877b8..80b74f92bdc7 100644 --- a/packages/auth/src/useAuth.ts +++ b/packages/auth/src/useAuth.ts @@ -1,6 +1,6 @@ import React from 'react' -import type { AuthContextInterface } from './AuthContext' +import type { AuthContextInterface } from './AuthContext.js' export function createUseAuth< TUser, diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 35c7dc051767..44411494225a 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -1,6 +1,8 @@ { "extends": "../../tsconfig.compilerOption.json", "compilerOptions": { + "moduleResolution": "NodeNext", + "module": "NodeNext", "rootDir": "src", "outDir": "dist", }, diff --git a/yarn.lock b/yarn.lock index 7e8758897c43..fc1ab2281e1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7956,6 +7956,7 @@ __metadata: jest-environment-jsdom: "npm:29.7.0" msw: "npm:1.3.3" react: "npm:18.3.0-canary-a870b2d54-20240314" + tsx: "npm:4.7.1" typescript: "npm:5.4.3" languageName: unknown linkType: soft From 448789c114cbda02502f7bbd37d7d58db1803f24 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 4 Apr 2024 17:05:11 +0200 Subject: [PATCH 02/15] Try .js re-export --- packages/testing/src/web/mockAuth.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testing/src/web/mockAuth.tsx b/packages/testing/src/web/mockAuth.tsx index 1624f98bc473..4e2e179c0123 100644 --- a/packages/testing/src/web/mockAuth.tsx +++ b/packages/testing/src/web/mockAuth.tsx @@ -2,7 +2,7 @@ import React from 'react' // Exporting everything here, but exports further down in this file will // override exports with the same name -export * from '@redwoodjs/auth/dist/index' +export * from '@redwoodjs/auth/dist/index.js' import { mockedUserMeta } from './mockRequests' From ebc87688beee5091990c06450d3cd06ae9e6a6c0 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 4 Apr 2024 17:33:08 +0200 Subject: [PATCH 03/15] No auth dist-re-export --- packages/testing/src/web/mockAuth.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testing/src/web/mockAuth.tsx b/packages/testing/src/web/mockAuth.tsx index 4e2e179c0123..0d27ed7c6e42 100644 --- a/packages/testing/src/web/mockAuth.tsx +++ b/packages/testing/src/web/mockAuth.tsx @@ -2,7 +2,7 @@ import React from 'react' // Exporting everything here, but exports further down in this file will // override exports with the same name -export * from '@redwoodjs/auth/dist/index.js' +export * from '@redwoodjs/auth' import { mockedUserMeta } from './mockRequests' From b939b59260020794bd4856ed36be709871703d0d Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 4 Apr 2024 18:18:28 +0200 Subject: [PATCH 04/15] vitest --- packages/auth/.babelrc.js | 1 - packages/auth/jest.config.js | 5 --- packages/auth/package.json | 11 ++--- .../auth/src/__tests__/AuthProvider.test.tsx | 42 +++++++++++-------- packages/auth/vitest.config.mts | 8 ++++ packages/auth/vitest.setup.mts | 11 +++++ yarn.lock | 4 +- 7 files changed, 49 insertions(+), 33 deletions(-) delete mode 100644 packages/auth/.babelrc.js delete mode 100644 packages/auth/jest.config.js create mode 100644 packages/auth/vitest.config.mts create mode 100644 packages/auth/vitest.setup.mts diff --git a/packages/auth/.babelrc.js b/packages/auth/.babelrc.js deleted file mode 100644 index 3b2c815712d9..000000000000 --- a/packages/auth/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' } diff --git a/packages/auth/jest.config.js b/packages/auth/jest.config.js deleted file mode 100644 index e691bb8f6dbd..000000000000 --- a/packages/auth/jest.config.js +++ /dev/null @@ -1,5 +0,0 @@ -/** @type {import('@jest/types').Config.InitialOptions} */ -module.exports = { - testEnvironment: 'jest-environment-jsdom', - testPathIgnorePatterns: ['fixtures', 'dist'], -} diff --git a/packages/auth/package.json b/packages/auth/package.json index 8523afa8348a..0a5d89aa357f 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -19,13 +19,12 @@ ], "scripts": { "build": "tsx ./build.ts && yarn build:types", - "__build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\"", "build:pack": "yarn pack -o redwoodjs-auth.tgz", "build:types": "tsc --build --verbose", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "jest src", - "test:watch": "yarn test --watch" + "test": "vitest run", + "test:watch": "vitest watch" }, "dependencies": { "@babel/runtime-corejs3": "7.24.1", @@ -34,14 +33,12 @@ "tsx": "4.7.1" }, "devDependencies": { - "@babel/cli": "7.24.1", "@babel/core": "^7.22.20", "@testing-library/jest-dom": "6.4.2", "@testing-library/react": "14.2.2", - "jest": "29.7.0", - "jest-environment-jsdom": "29.7.0", "msw": "1.3.3", - "typescript": "5.4.3" + "typescript": "5.4.3", + "vitest": "1.4.0" }, "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1" } diff --git a/packages/auth/src/__tests__/AuthProvider.test.tsx b/packages/auth/src/__tests__/AuthProvider.test.tsx index 76838343794a..aa8848330654 100644 --- a/packages/auth/src/__tests__/AuthProvider.test.tsx +++ b/packages/auth/src/__tests__/AuthProvider.test.tsx @@ -10,9 +10,17 @@ import { configure, } from '@testing-library/react' import { renderHook, act } from '@testing-library/react' -import '@testing-library/jest-dom/jest-globals' import { graphql } from 'msw' import { setupServer } from 'msw/node' +import { + afterAll, + beforeAll, + beforeEach, + describe, + expect, + test, + vi, +} from 'vitest' import type { CustomTestAuthClient } from './fixtures/customTestAuth.js' import { createCustomTestAuth } from './fixtures/customTestAuth.js' @@ -61,7 +69,7 @@ const customTestAuth: CustomTestAuthClient = { signup: () => {}, logout: () => {}, getToken: () => 'hunter2', - getUserMetadata: jest.fn(() => null), + getUserMetadata: vi.fn(() => null), forgotPassword: () => {}, resetPassword: () => true, validateResetToken: () => ({}), @@ -82,7 +90,7 @@ beforeEach(() => { name: 'Peter Pistorius', email: 'nospam@example.net', } - customTestAuth.getUserMetadata = jest.fn(() => null) + customTestAuth.getUserMetadata = vi.fn(() => null) }) describe('Custom auth provider', () => { @@ -176,7 +184,7 @@ describe('Custom auth provider', () => { expect(mockAuthClient.getUserMetadata).toBeCalledTimes(1) // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -221,7 +229,7 @@ describe('Custom auth provider', () => { expect(mockAuthClient.getUserMetadata).toBeCalledTimes(1) // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -256,7 +264,7 @@ describe('Custom auth provider', () => { expect(mockAuthClient.getUserMetadata).toBeCalledTimes(1) // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -293,7 +301,7 @@ describe('Custom auth provider', () => { ) const mockAuthClient = customTestAuth - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -342,7 +350,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -389,7 +397,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -436,7 +444,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -483,7 +491,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -529,7 +537,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -572,7 +580,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -619,7 +627,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -665,7 +673,7 @@ describe('Custom auth provider', () => { expect(screen.queryByText('Has Super User:')).not.toBeInTheDocument() // Replace "getUserMetadata" with actual data, and login! - mockAuthClient.getUserMetadata = jest.fn(() => { + mockAuthClient.getUserMetadata = vi.fn(() => { return { sub: 'abcdefg|123456', username: 'peterp', @@ -686,7 +694,7 @@ describe('Custom auth provider', () => { }) test('proxies forgotPassword() calls to client', async () => { - const mockedForgotPassword = jest.spyOn(customTestAuth, 'forgotPassword') + const mockedForgotPassword = vi.spyOn(customTestAuth, 'forgotPassword') mockedForgotPassword.mockImplementation((username: string) => { expect(username).toEqual('username') }) @@ -749,7 +757,7 @@ describe('Custom auth provider', () => { }) test("getToken doesn't fail if client throws an error", async () => { - customTestAuth.getToken = jest.fn(() => { + customTestAuth.getToken = vi.fn(() => { throw 'Login Required' }) diff --git a/packages/auth/vitest.config.mts b/packages/auth/vitest.config.mts new file mode 100644 index 000000000000..52ec6b09db8f --- /dev/null +++ b/packages/auth/vitest.config.mts @@ -0,0 +1,8 @@ +import { defineConfig, configDefaults } from 'vitest/config' + +export default defineConfig({ + test: { + exclude: [...configDefaults.exclude, '**/fixtures'], + environment: 'jsdom', + }, +}) diff --git a/packages/auth/vitest.setup.mts b/packages/auth/vitest.setup.mts new file mode 100644 index 000000000000..8ad7daa202a6 --- /dev/null +++ b/packages/auth/vitest.setup.mts @@ -0,0 +1,11 @@ +import { afterEach } from 'vitest' +import { cleanup } from '@testing-library/react' +import '@testing-library/jest-dom/vitest' + +afterEach(() => { + // If vitest globals are enabled testing-library will clean up after each + // test automatically, but we don't enable globals, so we have to manually + // clean up here + // https://testing-library.com/docs/react-testing-library/api/#cleanup + cleanup() +}) diff --git a/yarn.lock b/yarn.lock index fc1ab2281e1e..b99fe3f2f6b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7946,18 +7946,16 @@ __metadata: version: 0.0.0-use.local resolution: "@redwoodjs/auth@workspace:packages/auth" dependencies: - "@babel/cli": "npm:7.24.1" "@babel/core": "npm:^7.22.20" "@babel/runtime-corejs3": "npm:7.24.1" "@testing-library/jest-dom": "npm:6.4.2" "@testing-library/react": "npm:14.2.2" core-js: "npm:3.36.1" - jest: "npm:29.7.0" - jest-environment-jsdom: "npm:29.7.0" msw: "npm:1.3.3" react: "npm:18.3.0-canary-a870b2d54-20240314" tsx: "npm:4.7.1" typescript: "npm:5.4.3" + vitest: "npm:1.4.0" languageName: unknown linkType: soft From 622ec266a34e200a0bd92c6d13bd636237972d91 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 4 Apr 2024 22:31:37 +0200 Subject: [PATCH 05/15] vitest setup and url --- .vscode/settings.json | 1 + packages/auth/package.json | 2 +- packages/auth/src/__tests__/AuthProvider.test.tsx | 8 ++++---- .../auth/src/__tests__/fixtures/customTestAuth.ts | 2 +- packages/auth/tsconfig.build.json | 11 +++++++++++ packages/auth/tsconfig.json | 8 +++++++- packages/auth/{vitest.config.mts => vitest.config.ts} | 1 + packages/auth/{vitest.setup.mts => vitest.setup.ts} | 2 +- 8 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 packages/auth/tsconfig.build.json rename packages/auth/{vitest.config.mts => vitest.config.ts} (83%) rename packages/auth/{vitest.setup.mts => vitest.setup.ts} (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 53cfbc6d3cc9..2ee344962552 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -32,6 +32,7 @@ "memfs", "opentelemetry", "pino", + "Pistorius", "redwoodjs", "RWJS", "tailwindcss", diff --git a/packages/auth/package.json b/packages/auth/package.json index 0a5d89aa357f..98bd3f4095ee 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -20,7 +20,7 @@ "scripts": { "build": "tsx ./build.ts && yarn build:types", "build:pack": "yarn pack -o redwoodjs-auth.tgz", - "build:types": "tsc --build --verbose", + "build:types": "tsc --build --verbose tsconfig.build.json", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", "test": "vitest run", diff --git a/packages/auth/src/__tests__/AuthProvider.test.tsx b/packages/auth/src/__tests__/AuthProvider.test.tsx index aa8848330654..3e99e79e478f 100644 --- a/packages/auth/src/__tests__/AuthProvider.test.tsx +++ b/packages/auth/src/__tests__/AuthProvider.test.tsx @@ -1,15 +1,14 @@ -require('whatwg-fetch') - import React, { useEffect, useState } from 'react' import { + act, render, + renderHook, screen, fireEvent, waitFor, configure, } from '@testing-library/react' -import { renderHook, act } from '@testing-library/react' import { graphql } from 'msw' import { setupServer } from 'msw/node' import { @@ -38,7 +37,8 @@ let CURRENT_USER_DATA: { email: 'nospam@example.net', } -globalThis.RWJS_API_GRAPHQL_URL = '/.netlify/functions/graphql' +globalThis.RWJS_API_GRAPHQL_URL = + 'https://example.com/api/.netlify/functions/graphql' const server = setupServer( graphql.query('__REDWOOD__AUTH_GET_CURRENT_USER', (_req, res, ctx) => { diff --git a/packages/auth/src/__tests__/fixtures/customTestAuth.ts b/packages/auth/src/__tests__/fixtures/customTestAuth.ts index 6536c4eee079..9592f6d5465e 100644 --- a/packages/auth/src/__tests__/fixtures/customTestAuth.ts +++ b/packages/auth/src/__tests__/fixtures/customTestAuth.ts @@ -1,4 +1,4 @@ -import { CurrentUser, createAuthentication } from '../../index' +import { CurrentUser, createAuthentication } from '../../index.js' interface User { sub: string diff --git a/packages/auth/tsconfig.build.json b/packages/auth/tsconfig.build.json new file mode 100644 index 000000000000..4169a621c61e --- /dev/null +++ b/packages/auth/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.compilerOption.json", + "compilerOptions": { + "moduleResolution": "NodeNext", + "module": "NodeNext", + "baseUrl": ".", + "rootDir": "src", + "outDir": "dist", + }, + "include": ["src", "ambient.d.ts"], +} diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 44411494225a..2c1461941620 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -6,5 +6,11 @@ "rootDir": "src", "outDir": "dist", }, - "include": ["src", "ambient.d.ts"] + "include": ["src", "ambient.d.ts", "./vitest.setup.ts", "__tests__"], + "exclude": [ + "dist", + "node_modules", + "**/__mocks__", + "**/__fixtures__", + ] } diff --git a/packages/auth/vitest.config.mts b/packages/auth/vitest.config.ts similarity index 83% rename from packages/auth/vitest.config.mts rename to packages/auth/vitest.config.ts index 52ec6b09db8f..a832fed4d8b8 100644 --- a/packages/auth/vitest.config.mts +++ b/packages/auth/vitest.config.ts @@ -4,5 +4,6 @@ export default defineConfig({ test: { exclude: [...configDefaults.exclude, '**/fixtures'], environment: 'jsdom', + setupFiles: ['vitest.setup.ts'], }, }) diff --git a/packages/auth/vitest.setup.mts b/packages/auth/vitest.setup.ts similarity index 100% rename from packages/auth/vitest.setup.mts rename to packages/auth/vitest.setup.ts index 8ad7daa202a6..5b6e47c1e415 100644 --- a/packages/auth/vitest.setup.mts +++ b/packages/auth/vitest.setup.ts @@ -1,5 +1,5 @@ -import { afterEach } from 'vitest' import { cleanup } from '@testing-library/react' +import { afterEach } from 'vitest' import '@testing-library/jest-dom/vitest' afterEach(() => { From 4fbfa4763b6c143f260f4c109ed55991f136f4f8 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 5 Apr 2024 18:39:51 +0200 Subject: [PATCH 06/15] update package.json according to review comments --- packages/auth/package.json | 6 ++---- yarn.lock | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/auth/package.json b/packages/auth/package.json index 98bd3f4095ee..3bf9f5871901 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -27,16 +27,14 @@ "test:watch": "vitest watch" }, "dependencies": { - "@babel/runtime-corejs3": "7.24.1", "core-js": "3.36.1", - "react": "18.3.0-canary-a870b2d54-20240314", - "tsx": "4.7.1" + "react": "18.3.0-canary-a870b2d54-20240314" }, "devDependencies": { - "@babel/core": "^7.22.20", "@testing-library/jest-dom": "6.4.2", "@testing-library/react": "14.2.2", "msw": "1.3.3", + "tsx": "4.7.1", "typescript": "5.4.3", "vitest": "1.4.0" }, diff --git a/yarn.lock b/yarn.lock index b99fe3f2f6b3..911530db7626 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7946,8 +7946,6 @@ __metadata: version: 0.0.0-use.local resolution: "@redwoodjs/auth@workspace:packages/auth" dependencies: - "@babel/core": "npm:^7.22.20" - "@babel/runtime-corejs3": "npm:7.24.1" "@testing-library/jest-dom": "npm:6.4.2" "@testing-library/react": "npm:14.2.2" core-js: "npm:3.36.1" From 977223e36cda4d8f7c62e32e01c5858b8d8c4409 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:02:37 +0100 Subject: [PATCH 07/15] add omitted dependencies --- packages/auth-providers/supabase/web/package.json | 1 + packages/auth/package.json | 1 + yarn.lock | 2 ++ 3 files changed, 4 insertions(+) diff --git a/packages/auth-providers/supabase/web/package.json b/packages/auth-providers/supabase/web/package.json index be6238f9776c..d9244119c6ce 100644 --- a/packages/auth-providers/supabase/web/package.json +++ b/packages/auth-providers/supabase/web/package.json @@ -24,6 +24,7 @@ }, "dependencies": { "@babel/runtime-corejs3": "7.24.1", + "@redwoodjs/auth": "workspace:*", "core-js": "3.36.1" }, "devDependencies": { diff --git a/packages/auth/package.json b/packages/auth/package.json index 3bf9f5871901..e6d85f0ff6e2 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -31,6 +31,7 @@ "react": "18.3.0-canary-a870b2d54-20240314" }, "devDependencies": { + "@redwoodjs/framework-tools": "workspace:*", "@testing-library/jest-dom": "6.4.2", "@testing-library/react": "14.2.2", "msw": "1.3.3", diff --git a/yarn.lock b/yarn.lock index 911530db7626..2e87107a8bd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7877,6 +7877,7 @@ __metadata: "@babel/cli": "npm:7.24.1" "@babel/core": "npm:^7.22.20" "@babel/runtime-corejs3": "npm:7.24.1" + "@redwoodjs/auth": "workspace:*" "@supabase/supabase-js": "npm:2.40.0" "@types/react": "npm:^18.2.55" core-js: "npm:3.36.1" @@ -7946,6 +7947,7 @@ __metadata: version: 0.0.0-use.local resolution: "@redwoodjs/auth@workspace:packages/auth" dependencies: + "@redwoodjs/framework-tools": "workspace:*" "@testing-library/jest-dom": "npm:6.4.2" "@testing-library/react": "npm:14.2.2" core-js: "npm:3.36.1" From b95ef2dc09fb1465ea6bbdc071e631f1ce322ac1 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 6 Apr 2024 15:12:17 +0200 Subject: [PATCH 08/15] auth tsconfig add missing reference --- packages/auth/tsconfig.build.json | 3 +++ packages/auth/tsconfig.json | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/auth/tsconfig.build.json b/packages/auth/tsconfig.build.json index 4ebc4dd448cd..973bd940e755 100644 --- a/packages/auth/tsconfig.build.json +++ b/packages/auth/tsconfig.build.json @@ -7,4 +7,7 @@ "outDir": "dist", }, "include": ["src", "ambient.d.ts"], + "references": [ + { "path": "../framework-tools" } + ] } diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 71c59791f0bb..bb87b357b479 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -12,5 +12,8 @@ "./vitest.setup.ts", "__tests__" ], - "exclude": ["dist", "node_modules", "**/__mocks__", "**/__fixtures__"] + "exclude": ["dist", "node_modules", "**/__mocks__", "**/__fixtures__"], + "references": [ + { "path": "../framework-tools" } + ] } From 39a5f1e9eb09b7826bcdbfbd7c0bce011222f396 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 6 Apr 2024 16:33:42 +0200 Subject: [PATCH 09/15] update build script --- packages/auth/build.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/auth/build.ts b/packages/auth/build.ts index 869b35842e36..a6a2266cfc2b 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -4,8 +4,7 @@ import { build, defaultBuildOptions } from '@redwoodjs/framework-tools' await build({ buildOptions: { ...defaultBuildOptions, - bundle: true, - entryPoints: ['./src/index.ts'], + tsconfig: 'tsconfig.build.json', format: 'esm', outExtension: { '.js': '.mjs' }, packages: 'external', @@ -16,8 +15,7 @@ await build({ await build({ buildOptions: { ...defaultBuildOptions, - bundle: true, - entryPoints: ['./src/index.ts'], + tsconfig: 'tsconfig.build.json', outExtension: { '.js': '.cjs' }, packages: 'external', }, From 45a428452a1d3e4eda593f9ddb3c2434619044c7 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 6 Apr 2024 16:47:16 +0200 Subject: [PATCH 10/15] add main field to package.json --- packages/auth/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/auth/package.json b/packages/auth/package.json index e6d85f0ff6e2..3d93db38562d 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -14,6 +14,7 @@ "default": "./dist/index.cjs" }, "types": "./dist/index.d.ts", + "main": "./dist/index.cjs", "files": [ "dist" ], From c1411c391ac84204158856990979f5f10ffa683e Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 6 Apr 2024 17:28:36 +0200 Subject: [PATCH 11/15] dist/esm --- packages/auth/build.ts | 9 +++++++-- packages/auth/package.json | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/auth/build.ts b/packages/auth/build.ts index a6a2266cfc2b..86a06acf685c 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -1,3 +1,5 @@ +import { renameSync, writeFileSync } from 'node:fs' + import { build, defaultBuildOptions } from '@redwoodjs/framework-tools' // ESM build @@ -6,7 +8,7 @@ await build({ ...defaultBuildOptions, tsconfig: 'tsconfig.build.json', format: 'esm', - outExtension: { '.js': '.mjs' }, + outdir: 'dist/esm', packages: 'external', }, }) @@ -16,7 +18,10 @@ await build({ buildOptions: { ...defaultBuildOptions, tsconfig: 'tsconfig.build.json', - outExtension: { '.js': '.cjs' }, packages: 'external', }, }) + +renameSync('dist/index.js', 'dist/index.cjs') +writeFileSync('dist/package.json', JSON.stringify({ type: 'commonjs' })) +writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' })) diff --git a/packages/auth/package.json b/packages/auth/package.json index 3d93db38562d..171e9eda8703 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -10,11 +10,10 @@ "type": "module", "exports": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", + "import": "./dist/esm/index.js", "default": "./dist/index.cjs" }, "types": "./dist/index.d.ts", - "main": "./dist/index.cjs", "files": [ "dist" ], From 9bf13551fde6aedf8949c70e0bc5273fb645dc52 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 7 Apr 2024 11:39:02 +0200 Subject: [PATCH 12/15] Explain post-build steps --- packages/auth/build.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/auth/build.ts b/packages/auth/build.ts index 86a06acf685c..95875f3a3620 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -22,6 +22,15 @@ await build({ }, }) +// Because the package.json files has `type: module` the CJS entry file can't +// be named `index.js` because in that case it would be treated as an ESM file. +// By changing it to .cjs it will be treated as a CommonJS file. renameSync('dist/index.js', 'dist/index.cjs') + +// Place a package.json file with `type: commonjs` in the dist folder so that +// all .js files are treated as CommonJS files. writeFileSync('dist/package.json', JSON.stringify({ type: 'commonjs' })) + +// Place a package.json file with `type: module` in the dist/esm folder so that +// all .js files are treated as ES Module files. writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' })) From cf98382a4af3e8bf614f5f470cd585403b23dd72 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 7 Apr 2024 14:56:28 +0200 Subject: [PATCH 13/15] isolateModules && esm tsc --- packages/auth/package.json | 2 +- packages/auth/src/index.ts | 5 +++-- packages/auth/tsconfig.build-esm.json | 14 ++++++++++++++ packages/auth/tsconfig.build.json | 1 + packages/auth/tsconfig.json | 1 + 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 packages/auth/tsconfig.build-esm.json diff --git a/packages/auth/package.json b/packages/auth/package.json index 171e9eda8703..3dd06d6cbcc7 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -20,7 +20,7 @@ "scripts": { "build": "tsx ./build.ts && yarn build:types", "build:pack": "yarn pack -o redwoodjs-auth.tgz", - "build:types": "tsc --build --verbose tsconfig.build.json", + "build:types": "tsc --build --verbose tsconfig.build.json && tsc --build --verbose tsconfig.build-esm.json", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", "test": "vitest run", diff --git a/packages/auth/src/index.ts b/packages/auth/src/index.ts index 26085895dc6b..3f0f49c51925 100644 --- a/packages/auth/src/index.ts +++ b/packages/auth/src/index.ts @@ -1,5 +1,6 @@ -export { AuthContextInterface, CurrentUser } from './AuthContext.js' -export { useNoAuth, UseAuth } from './useAuth.js' +export type { AuthContextInterface, CurrentUser } from './AuthContext.js' +export { useNoAuth } from './useAuth.js' +export type { UseAuth } from './useAuth.js' export { createAuthentication } from './authFactory.js' export type { AuthImplementation } from './AuthImplementation.js' diff --git a/packages/auth/tsconfig.build-esm.json b/packages/auth/tsconfig.build-esm.json new file mode 100644 index 000000000000..de5a45368b9e --- /dev/null +++ b/packages/auth/tsconfig.build-esm.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.compilerOption.json", + "compilerOptions": { + "isolatedModules": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", + "rootDir": "src", + "outDir": "dist/esm", + }, + "include": ["src", "ambient.d.ts"], + "references": [ + { "path": "../framework-tools" } + ] +} diff --git a/packages/auth/tsconfig.build.json b/packages/auth/tsconfig.build.json index 973bd940e755..6cb547bce6f0 100644 --- a/packages/auth/tsconfig.build.json +++ b/packages/auth/tsconfig.build.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.compilerOption.json", "compilerOptions": { + "isolatedModules": true, "moduleResolution": "NodeNext", "module": "NodeNext", "rootDir": "src", diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index bb87b357b479..d435973639c6 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.compilerOption.json", "compilerOptions": { + "isolatedModules": true, "moduleResolution": "NodeNext", "module": "NodeNext", "outDir": "dist" From 28191e0899dafffcefba63258e34fb300be405d9 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 7 Apr 2024 15:00:35 +0200 Subject: [PATCH 14/15] use esm tsconfig for esm build (does't really matter, but looks more consistent) --- packages/auth/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/build.ts b/packages/auth/build.ts index 95875f3a3620..c859e8581af0 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -6,7 +6,7 @@ import { build, defaultBuildOptions } from '@redwoodjs/framework-tools' await build({ buildOptions: { ...defaultBuildOptions, - tsconfig: 'tsconfig.build.json', + tsconfig: 'tsconfig.build-esm.json', format: 'esm', outdir: 'dist/esm', packages: 'external', From d35643f1923e4473888167cdba5b2e951511ee6e Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 7 Apr 2024 15:03:13 +0200 Subject: [PATCH 15/15] update path to index.d.ts --- packages/auth/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/package.json b/packages/auth/package.json index 3dd06d6cbcc7..b60ee36b3145 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -9,7 +9,7 @@ "license": "MIT", "type": "module", "exports": { - "types": "./dist/index.d.ts", + "types": "./dist/esm/index.d.ts", "import": "./dist/esm/index.js", "default": "./dist/index.cjs" },