Skip to content

Commit

Permalink
chore: update module resolution to bundler (#1387)
Browse files Browse the repository at this point in the history
* chore: update module resolution to bundler

* fix: linter issues

* fix jest

* fix: build

* use import type

* lint
  • Loading branch information
ryanleecode authored Jul 8, 2024
1 parent 330e4a3 commit 727c616
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 92 deletions.
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
import baseConfig from '@polkadot/dev/config/eslint';

export default [
...baseConfig
...baseConfig,
{
rules: {
'import/extensions': 'off'
}
}
];
1 change: 1 addition & 0 deletions packages/extension-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/dev-test": "^0.79.3",
"@polkadot/extension-mocks": "0.48.3-1-x"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2019-2024 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

/* global chrome */

import '@polkadot/extension-mocks/chrome';

import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { ResponseSigning } from '@polkadot/extension-base/background/types';
import type { MetadataDef } from '@polkadot/extension-inject/types';
import type { KeyringPair } from '@polkadot/keyring/types';
Expand Down
3 changes: 3 additions & 0 deletions packages/extension-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"@polkadot/util-crypto": "^12.6.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/dev-test": "^0.79.3"
},
"peerDependencies": {
"@polkadot/api": "*",
"@polkadot/util": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-dapp/src/wrapBytes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2024 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import { u8aConcat, u8aEq, u8aToString } from '@polkadot/util';

Expand Down
1 change: 1 addition & 0 deletions packages/extension-inject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/dev-test": "^0.79.3",
"@types/chrome": "^0.0.254",
"@types/firefox-webext-browser": "^111.0.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-inject/src/cyrb53.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2024 @polkadot/extension-inject authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import { cyrb53 } from './cyrb53.js';

Expand Down
1 change: 1 addition & 0 deletions packages/extension-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/dev-test": "^0.79.3",
"@polkadot/extension-mocks": "0.48.3-1-x",
"@types/enzyme": "^3.10.18",
"@types/enzyme-adapter-react-16": "^1.0.9",
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Accounts/Account.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Authorize/Authorize.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { AccountJson, AuthorizeRequest } from '@polkadot/extension-base/background/types';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Derive/Derive.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { AccountJson, ResponseDeriveValidate } from '@polkadot/extension-base/background/types';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Export.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { KeyringPair$Json } from '@polkadot/keyring/types';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/ImportQr.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Signing/Signing.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { SigningRequest } from '@polkadot/extension-base/background/types';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/components/Address.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { AccountJson } from '@polkadot/extension-base/background/types';
import type { IconTheme } from '@polkadot/react-identicon/types';
import type { HexString } from '@polkadot/util/types';
Expand Down
102 changes: 44 additions & 58 deletions packages/extension-ui/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,62 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributor
// SPDX-License-Identifier: Apache-2.0

import type { WithTranslation } from 'react-i18next';
import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

import React from 'react';
import { withTranslation } from 'react-i18next';
import Header from '../partials/Header';
import Button from './Button';
import ButtonArea from './ButtonArea';
import VerticalSpace from './VerticalSpace';

import Header from '../partials/Header.js';
import Button from './Button.js';
import ButtonArea from './ButtonArea.js';
import VerticalSpace from './VerticalSpace.js';

interface Props extends WithTranslation {
interface ErrorBoundaryProps {
children: React.ReactNode;
className?: string;
error?: Error | null;
trigger?: string;
}

interface State {
error: Error | null;
}

const translate = withTranslation();

// NOTE: This is the only way to do an error boundary, via extend
class ErrorBoundary extends React.Component<Props> {
public override state: State = { error: null };

public static getDerivedStateFromError (error: Error): Partial<State> {
return { error };
}
const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ children, error: propError, trigger }) => {
const { t } = useTranslation();
const [error, setError] = useState<Error | null>(null);

public override componentDidUpdate (prevProps: Props) {
const { error } = this.state;
const { trigger } = this.props;
useEffect(() => {
if (error !== null && trigger) {
setError(null);
}
}, [error, trigger]);

if (error !== null && (prevProps.trigger !== trigger)) {
this.setState({ error: null });
useEffect(() => {
if (propError) {
setError(propError);
}
}
}, [propError]);

#goHome = () => {
this.setState({ error: null });
const goHome = useCallback(() => {
setError(null);
window.location.hash = '/';
};

public override render (): React.ReactNode {
const { children, t } = this.props;
const { error } = this.state;

return error
? (
<>
<Header text={t<string, Record<string, string>, string>('An error occurred')} />
<div>
{t('Something went wrong with the query and rendering of this component. {{message}}', {
replace: { message: error.message }
})}
</div>
<VerticalSpace />
<ButtonArea>
<Button
onClick={this.#goHome}
>
{t('Back to home')}
</Button>
</ButtonArea>
</>
)
: children;
}, [setError]);

if (error) {
return (
<>
<Header text={t('An error occurred')} />
<div>
{t('Something went wrong with the query and rendering of this component. {{message}}', {
replace: { message: error.message }
})}
</div>
<VerticalSpace />
<ButtonArea>
<Button onClick={goHome}>
{t('Back to home')}
</Button>
</ButtonArea>
</>
);
}
}

export default translate(ErrorBoundary);
return <>{children}</>;
};

export default ErrorBoundary;
4 changes: 2 additions & 2 deletions packages/extension-ui/src/messaging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

/* global chrome */

import '@polkadot/extension-mocks/chrome';

import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';

Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/partials/Header.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

import '@polkadot/extension-mocks/chrome';

import type { ReactWrapper } from 'enzyme';
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import enzyme from 'enzyme';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/util/buildHierarchy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />

/* eslint-disable jest/expect-expect */

import type * as _ from '@polkadot/dev-test/globals.d.ts';
import type { AccountJson, AccountWithChildren } from '@polkadot/extension-base/background/types';

import { buildHierarchy } from './buildHierarchy.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-ui/src/util/nextDerivationPath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals" />
import type * as _ from '@polkadot/dev-test/globals.d.ts';

import { nextDerivationPath } from './nextDerivationPath.js';

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"composite": true,
/* FIXME Dropzone is problematic with nodenext resolution */
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"paths": {
"@polkadot/extension": ["extension/src/index.ts"],
"@polkadot/extension/*": ["extension/src/*.ts"],
Expand Down
Loading

0 comments on commit 727c616

Please sign in to comment.