Skip to content

Commit

Permalink
Make use of deep paths more clear in app router package (#1581)
Browse files Browse the repository at this point in the history
* Only use esm

* Use mjs imports instead of cjs

* Use mjs version of config

* Use `ApolloClient`/`InMemoryCache`

* Add changesets

* Use `isolatedModules`. Thanks @theodesp !

* Make the temp use of deep imports more clear
  • Loading branch information
blakewilson authored Sep 19, 2023
1 parent 77c5d4f commit 507cc4e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
11 changes: 1 addition & 10 deletions packages/experimental-app-router/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ import {
import { setContext } from '@apollo/client/link/context';
// eslint-disable-next-line import/extensions
import { registerApolloClient } from '@apollo/experimental-nextjs-app-support/rsc';
// eslint-disable-next-line import/extensions
/**
* We are currently importing these utils from their respective dist paths because importing
* from the root will also include the FaustProvider component, which throws an error because
* it does not have the "use client" directive set.
*
* @todo Find a workaround for importing these utils without invoking FaustProvider.
*/
import { getConfig } from '@faustwp/core/dist/mjs/config/index.js';
import { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js';
import { fetchAccessToken } from './server/auth/fetchAccessToken.js';
import { getConfig, getGraphqlEndpoint } from './faust-core-utils.js';

async function createFaustApolloClient(authenticated = false) {
const { possibleTypes } = getConfig();
Expand Down
13 changes: 13 additions & 0 deletions packages/experimental-app-router/src/faust-core-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* We are currently importing these utils from their deep paths because importing
* from the main export will also include the FaustProvider component, which throws an error because
* it does not have the "use client" directive set.
*
* @todo Find a workaround for importing these utils without invoking FaustProvider.
* @see https://github.com/vercel/next.js/issues/12557#issuecomment-1427088366
*/
export { getConfig } from '@faustwp/core/dist/mjs/config/index.js';
export { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js';
export { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js';
export { getWpSecret } from '@faustwp/core/dist/mjs/lib/getWpSecret.js';
export { isValidEmail } from '@faustwp/core/dist/mjs/utils/assert.js';
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { gql } from '@apollo/client';
// eslint-disable-next-line import/extensions
import { print } from '@apollo/client/utilities';
import { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js';
import { isValidEmail } from '@faustwp/core/dist/mjs/utils/assert.js';
import { fetchTokens } from '../server/auth/fetchTokens.js';
import { setRefreshToken } from './utils/setRefreshToken.js';
import { isValidEmail, getGraphqlEndpoint } from '../faust-core-utils.js';

export const GENERATE_AUTHORIZATION_CODE = gql`
mutation GenerateAuthorizationCode(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cookies } from 'next/headers.js';
import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js';
import { getWpUrl } from '../faust-core-utils.js';

export async function onLogout() {
'use server';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js';
import { cookies } from 'next/headers.js';
import { getWpUrl } from '../../faust-core-utils.js';

/**
* Sets the refresh token to the proper cookie. This can only be used within
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js';
// eslint-disable-next-line import/extensions
import { cookies } from 'next/headers';
import { AuthorizeResponse } from '../routeHandler/tokenHandler.js';
import { getUrl } from '../../lib/getUrl.js';
import { getWpUrl } from '../../faust-core-utils.js';

/**
* Fetches tokens using either the refresh token cookie or the provided
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js';
import { getWpSecret } from '@faustwp/core/dist/mjs/lib/getWpSecret.js';
import { cookies } from 'next/headers.js';
import { NextResponse } from 'next/server.js';
import { getWpUrl, getWpSecret } from '../../faust-core-utils.js';

export type AuthorizeResponse = {
accessToken: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
onLogin,
validationError,
} from '../../src/server-actions/loginAction.js';
import { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js';
import * as fetchTokens from '../../src/server/auth/fetchTokens.js';
import * as setRefreshToken from '../../src/server-actions/utils/setRefreshToken.js';
import { getGraphqlEndpoint } from '../../src/faust-core-utils.js';

// // https://github.com/aelbore/esbuild-jest/issues/26#issuecomment-893763840
const nextHeaders = { cookies };
Expand Down

1 comment on commit 507cc4e

@headless-platform-by-wp-engine

Choose a reason for hiding this comment

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

Check out the recent updates to your Atlas environment:

App Environment URL Build
faustjs canary https://hg…wered.com ✅ (logs)

Learn more about building on Atlas in our documentation.

Please sign in to comment.