Skip to content

Commit

Permalink
Fix CLERK_RETHEME build issue on clerk-js (#2127)
Browse files Browse the repository at this point in the history
* fix(clerk-js): Use the proper tsconfig for declarations based on $CLERK_RETHEME

* fix(clerk-js): Introduce and use `~ui` alias

In order to be able to switch between /ui and /ui.retheme simply by changing the active tsconfig file

* fix(clerk-js): Import from relative dir instead of ui

* Create chilly-donuts-work.md
  • Loading branch information
nikosdouvlis authored Nov 14, 2023
1 parent b986c4c commit 4fda068
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .changeset/chilly-donuts-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/clerk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build": "npm run build:bundle && npm run build:declarations",
"build:analyze": "webpack-bundle-analyzer stats.json dist/",
"build:bundle": "npm run clean && webpack --config webpack.config.js --env production",
"build:declarations": "tsc -p tsconfig.declarations.json",
"build:declarations": "if [ \"$CLERK_RETHEME\" = \"true\" ] || [ \"$CLERK_RETHEME\" = \"1\" ]; then tsc -p tsconfig.declarations.retheme.json; else tsc -p tsconfig.declarations.json; fi",
"build:stats": "webpack --config webpack.config.js --env production --json=stats.json --env variant=\"clerk.browser\"",
"bundlewatch": "npx bundlewatch --config bundlewatch.config.json",
"clean": "rimraf ./dist",
Expand Down
3 changes: 2 additions & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import type {
UserResource,
} from '@clerk/types';

import type { MountComponentRenderer } from '../ui/Components';
import type { MountComponentRenderer } from '~ui/Components';

import {
appendAsQueryParams,
buildURL,
Expand Down
4 changes: 3 additions & 1 deletion packages/clerk-js/src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import './utils/setWebpackChunkPublicPath';
import 'regenerator-runtime/runtime';

import Clerk from './core/clerk';
import { mountComponentRenderer } from './ui/Components';

// eslint-disable-next-line import/no-unresolved -- this is a webpack alias
import { mountComponentRenderer } from '~ui/Components';

Clerk.mountComponentRenderer = mountComponentRenderer;

Expand Down
4 changes: 3 additions & 1 deletion packages/clerk-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'regenerator-runtime/runtime';

// eslint-disable-next-line import/no-unresolved -- this is a webpack alias
import { mountComponentRenderer } from '~ui/Components';

import Clerk from './core/clerk';
import { mountComponentRenderer } from './ui/Components';

export * from './core/resources/Error';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { ComponentType } from 'react';
import React from 'react';

import { warnings } from '../../core/warnings';
import type { AvailableComponentProps } from '../../ui/types';
import type { ComponentGuard } from '../../utils';
import { noOrganizationExists, noUserExists, sessionExistsAndSingleSessionModeEnabled } from '../../utils';
import { useCoreClerk, useEnvironment, useOptions } from '../contexts';
import { useRouter } from '../router';
import type { AvailableComponentProps } from '../types';

function withRedirectToHome<P extends AvailableComponentProps>(
Component: ComponentType<P>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRouter } from '../../../ui/router';
import { runIfFunctionOrReturn } from '../../../utils';
import { AlertIcon, Flex, Link, Text } from '../../customizables';
import { useRouter } from '../../router';

export const BillingWidget = ({
__unstable_manageBillingUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from '../../../ui/router';
import { runIfFunctionOrReturn } from '../../../utils';
import { useCoreOrganization, useOrganizationProfileContext } from '../../contexts';
import { Col, Flex, Link, Text } from '../../customizables';
import { useRouter } from '../../router';

export const MembershipWidget = () => {
const { organization } = useCoreOrganization();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import { Plus } from '../../../ui/icons';
import { useCoreUser } from '../../contexts';
import { descriptors, localizationKeys } from '../../customizables';
import { Action, SecondaryActions } from '../../elements';
import { Plus } from '../../icons';
import { UserInvitationSuggestionList } from './UserInvitationSuggestionList';
import type { UserMembershipListProps } from './UserMembershipList';
import { UserMembershipList } from './UserMembershipList';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const APPEARANCE_KEYS = containsAllElementsConfigKeys([
'socialButtonsProviderIcon',

'enterpriseButtonsProviderIcon',

'alternativeMethods',
'alternativeMethodsBlockButton',
'alternativeMethodsBlockButtonText',
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui.retheme/elements/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { SelectId } from '@clerk/types';
import type { PropsWithChildren, ReactElement } from 'react';
import React, { useState } from 'react';

import { usePopover, useSearchInput } from '../../ui/hooks';
import { Button, descriptors, Flex, Icon, Text } from '../customizables';
import { usePopover, useSearchInput } from '../hooks';
import { Caret, MagnifyingGlass } from '../icons';
import type { PropsOfComponent, ThemableCssProp } from '../styledSystem';
import { animations, common } from '../styledSystem';
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui.retheme/router/Route.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { LoadedClerk } from '@clerk/types';
import React from 'react';

import { useCoreClerk } from '../../ui/contexts';
import { pathFromFullPath, trimTrailingSlash } from '../../utils';
import { useCoreClerk } from '../contexts';
import { useNavigateToFlowStart } from '../hooks';
import { newPaths } from './newPaths';
import { match } from './pathToRegexp';
Expand Down
8 changes: 8 additions & 0 deletions packages/clerk-js/tsconfig.declarations.retheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.declarations.json",
"compilerOptions": {
"paths": {
"~ui/*": ["./ui.retheme/*"]
}
}
}
6 changes: 4 additions & 2 deletions packages/clerk-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
"useUnknownInCatchVariables": false,
"declaration": false,
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react"
// "noUncheckedIndexedAccess": true // TODO: Enable and progressively fix related errors
"jsxImportSource": "@emotion/react",
"paths": {
"~ui/*": ["./ui/*"]
}
},
"include": [
"src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const common = ({ mode }) => {
// @see https://webpack.js.org/configuration/resolve/#resolveextensions
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx'],
alias: {
...(uiRetheme && { './ui': './ui.retheme' }),
'~ui': uiRetheme ? './ui.retheme' : './ui',
},
},
plugins: [
Expand Down

0 comments on commit 4fda068

Please sign in to comment.