Skip to content

Commit

Permalink
Use .js imports in src (#1224)
Browse files Browse the repository at this point in the history
* Use .js imports in src

* Bump dev

* Add WP extension aliases
  • Loading branch information
jacogr authored Mar 9, 2023
1 parent fa55477 commit 6bfddb0
Show file tree
Hide file tree
Showing 157 changed files with 624 additions and 621 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"devDependencies": {
"@babel/core": "^7.21.0",
"@polkadot/dev": "^0.70.4",
"@polkadot/dev": "^0.71.1",
"@types/node": "^18.14.5",
"i18next-scanner": "^4.1.1",
"sinon-chrome": "^3.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/background/RequestBytesSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { KeyringPair } from '@polkadot/keyring/types';
import type { SignerPayloadRaw } from '@polkadot/types/types';
import type { HexString } from '@polkadot/util/types';
import type { RequestSign } from './types';
import type { RequestSign } from './types.js';

import { wrapBytes } from '@polkadot/extension-dapp/wrapBytes';
import { TypeRegistry } from '@polkadot/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { KeyringPair } from '@polkadot/keyring/types';
import type { SignerPayloadJSON } from '@polkadot/types/types';
import type { HexString } from '@polkadot/util/types';
import type { RequestSign } from './types';
import type { RequestSign } from './types.js';

import { TypeRegistry } from '@polkadot/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { TypeRegistry } from '@polkadot/types';
import keyring from '@polkadot/ui-keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';

import { AccountsStore } from '../../stores';
import Extension from './Extension';
import State, { AuthUrls } from './State';
import Tabs from './Tabs';
import { AccountsStore } from '../../stores/index.js';
import Extension from './Extension.js';
import State, { AuthUrls } from './State.js';
import Tabs from './Tabs.js';

describe('Extension', () => {
let extension: Extension;
Expand Down
8 changes: 4 additions & 4 deletions packages/extension-base/src/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@polkadot/
import type { Registry, SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import type { KeypairType } from '@polkadot/util-crypto/types';
import type { AccountJson, AllowedPath, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountBatchExport, RequestAccountChangePassword, RequestAccountCreateExternal, RequestAccountCreateHardware, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountForget, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestActiveTabsUrlUpdate, RequestAuthorizeApprove, RequestBatchRestore, RequestDeriveCreate, RequestDeriveValidate, RequestJsonRestore, RequestMetadataApprove, RequestMetadataReject, RequestSeedCreate, RequestSeedValidate, RequestSigningApprovePassword, RequestSigningApproveSignature, RequestSigningCancel, RequestSigningIsLocked, RequestTypes, RequestUpdateAuthorizedAccounts, ResponseAccountExport, ResponseAccountsExport, ResponseAuthorizeList, ResponseDeriveValidate, ResponseJsonGetAccountInfo, ResponseSeedCreate, ResponseSeedValidate, ResponseSigningIsLocked, ResponseType, SigningRequest } from '../types';
import type { AccountJson, AllowedPath, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountBatchExport, RequestAccountChangePassword, RequestAccountCreateExternal, RequestAccountCreateHardware, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountForget, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestActiveTabsUrlUpdate, RequestAuthorizeApprove, RequestBatchRestore, RequestDeriveCreate, RequestDeriveValidate, RequestJsonRestore, RequestMetadataApprove, RequestMetadataReject, RequestSeedCreate, RequestSeedValidate, RequestSigningApprovePassword, RequestSigningApproveSignature, RequestSigningCancel, RequestSigningIsLocked, RequestTypes, RequestUpdateAuthorizedAccounts, ResponseAccountExport, ResponseAccountsExport, ResponseAuthorizeList, ResponseDeriveValidate, ResponseJsonGetAccountInfo, ResponseSeedCreate, ResponseSeedValidate, ResponseSigningIsLocked, ResponseType, SigningRequest } from '../types.js';

import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults';
import { metadataExpand } from '@polkadot/extension-chains';
Expand All @@ -16,9 +16,9 @@ import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/
import { assert, isHex } from '@polkadot/util';
import { keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';

import { withErrorLog } from './helpers';
import State, { AuthorizedAccountsDiff } from './State';
import { createSubscription, unsubscribe } from './subscriptions';
import { withErrorLog } from './helpers.js';
import State, { AuthorizedAccountsDiff } from './State.js';
import { createSubscription, unsubscribe } from './subscriptions.js';

type CachedUnlocks = Record<string, number>;

Expand Down
6 changes: 3 additions & 3 deletions packages/extension-base/src/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { MetadataDef, ProviderMeta } from '@polkadot/extension-inject/types';
import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
import type { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types';
import type { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types.js';

import { BehaviorSubject } from 'rxjs';

Expand All @@ -13,8 +13,8 @@ import { knownGenesis } from '@polkadot/networks/defaults';
import settings from '@polkadot/ui-settings';
import { assert } from '@polkadot/util';

import { MetadataStore } from '../../stores';
import { withErrorLog } from './helpers';
import { MetadataStore } from '../../stores/index.js';
import { withErrorLog } from './helpers.js';

interface Resolver<T> {
reject: (error: Error) => void;
Expand Down
12 changes: 6 additions & 6 deletions packages/extension-base/src/background/handlers/Tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { KeyringPair } from '@polkadot/keyring/types';
import type { JsonRpcResponse } from '@polkadot/rpc-provider/types';
import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import type { MessageTypes, RequestAccountList, RequestAccountUnsubscribe, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestTypes, ResponseRpcListProviders, ResponseSigning, ResponseTypes, SubscriptionMessageTypes } from '../types';
import type { MessageTypes, RequestAccountList, RequestAccountUnsubscribe, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestTypes, ResponseRpcListProviders, ResponseSigning, ResponseTypes, SubscriptionMessageTypes } from '../types.js';

import { PHISHING_PAGE_REDIRECT } from '@polkadot/extension-base/defaults';
import { canDerive } from '@polkadot/extension-base/utils';
Expand All @@ -16,11 +16,11 @@ import keyring from '@polkadot/ui-keyring';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
import { assert, isNumber } from '@polkadot/util';

import RequestBytesSign from '../RequestBytesSign';
import RequestExtrinsicSign from '../RequestExtrinsicSign';
import { withErrorLog } from './helpers';
import State, { AuthResponse } from './State';
import { createSubscription, unsubscribe } from './subscriptions';
import RequestBytesSign from '../RequestBytesSign.js';
import RequestExtrinsicSign from '../RequestExtrinsicSign.js';
import { withErrorLog } from './helpers.js';
import State, { AuthResponse } from './State.js';
import { createSubscription, unsubscribe } from './subscriptions.js';

interface AccountSub {
subscription: Subscription;
Expand Down
10 changes: 5 additions & 5 deletions packages/extension-base/src/background/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { MessageTypes, TransportRequestMessage } from '../types';
import type { MessageTypes, TransportRequestMessage } from '../types.js';

import { assert } from '@polkadot/util';

import { PORT_EXTENSION } from '../../defaults';
import Extension from './Extension';
import State from './State';
import Tabs from './Tabs';
import { PORT_EXTENSION } from '../../defaults.js';
import Extension from './Extension.js';
import State from './State.js';
import Tabs from './Tabs.js';

const state = new State();
const extension = new Extension(state);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { MessageTypesWithSubscriptions, SubscriptionMessageTypes } from '../types';
import type { MessageTypesWithSubscriptions, SubscriptionMessageTypes } from '../types.js';

type Subscriptions = Record<string, chrome.runtime.Port>;

Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { KeyringPairs$Json } from '@polkadot/ui-keyring/types';
import type { HexString } from '@polkadot/util/types';
import type { KeypairType } from '@polkadot/util-crypto/types';

import { ALLOWED_PATH } from '../defaults';
import { AuthResponse, AuthUrls } from './handlers/State';
import { ALLOWED_PATH } from '../defaults.js';
import { AuthResponse, AuthUrls } from './handlers/State.js';

type KeysWithDefinedValues<T> = {
[K in keyof T]: T[K] extends undefined ? never : K
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

export { packageInfo } from './packageInfo';
export { packageInfo } from './packageInfo.js';
4 changes: 2 additions & 2 deletions packages/extension-base/src/detectPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { detectPackage } from '@polkadot/util';

import others from './detectOther';
import { packageInfo } from './packageInfo';
import others from './detectOther.js';
import { packageInfo } from './packageInfo.js';

detectPackage(packageInfo, null, others);
2 changes: 1 addition & 1 deletion packages/extension-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// Since we inject into pages, we skip this
// import './detectPackage';

export * from './bundle';
export * from './bundle.js';
2 changes: 1 addition & 1 deletion packages/extension-base/src/page/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { InjectedAccount, InjectedAccounts, Unsubcall } from '@polkadot/extension-inject/types';
import type { SendRequest } from './types';
import type { SendRequest } from './types.js';

// External to class, this.# is not private enough (yet)
let sendRequest: SendRequest;
Expand Down
10 changes: 5 additions & 5 deletions packages/extension-base/src/page/Injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

import type { Injected } from '@polkadot/extension-inject/types';
import type { SendRequest } from './types';
import type { SendRequest } from './types.js';

import Accounts from './Accounts';
import Metadata from './Metadata';
import PostMessageProvider from './PostMessageProvider';
import Signer from './Signer';
import Accounts from './Accounts.js';
import Metadata from './Metadata.js';
import PostMessageProvider from './PostMessageProvider.js';
import Signer from './Signer.js';

export default class implements Injected {
public readonly accounts: Accounts;
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/page/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { InjectedMetadata, InjectedMetadataKnown, MetadataDef } from '@polkadot/extension-inject/types';
import type { SendRequest } from './types';
import type { SendRequest } from './types.js';

// External to class, this.# is not private enough (yet)
let sendRequest: SendRequest;
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/page/PostMessageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { InjectedProvider, ProviderList, ProviderMeta } from '@polkadot/extension-inject/types';
import type { ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
import type { AnyFunction } from '@polkadot/types/types';
import type { SendRequest } from './types';
import type { SendRequest } from './types.js';

import EventEmitter from 'eventemitter3';

Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/page/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { Signer as SignerInterface, SignerResult } from '@polkadot/api/types';
import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { SendRequest } from './types';
import type { SendRequest } from './types.js';

// External to class, this.# is not private enough (yet)
let sendRequest: SendRequest;
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-base/src/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import type { MessageTypes, MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes, TransportRequestMessage, TransportResponseMessage } from '../background/types';

import { MESSAGE_ORIGIN_PAGE } from '../defaults';
import { getId } from '../utils/getId';
import Injected from './Injected';
import { MESSAGE_ORIGIN_PAGE } from '../defaults.js';
import { getId } from '../utils/getId.js';
import Injected from './Injected.js';

// when sending a message from the injector to the extension, we
// - create an event - this we send to the loader
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/stores/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import type { KeyringJson, KeyringStore } from '@polkadot/ui-keyring/types';

import { EXTENSION_PREFIX } from '../defaults';
import BaseStore from './Base';
import { EXTENSION_PREFIX } from '../defaults.js';
import BaseStore from './Base.js';

export default class AccountsStore extends BaseStore<KeyringJson> implements KeyringStore {
constructor () {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/stores/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import type { MetadataDef } from '@polkadot/extension-inject/types';

import { EXTENSION_PREFIX } from '../defaults';
import BaseStore from './Base';
import { EXTENSION_PREFIX } from '../defaults.js';
import BaseStore from './Base.js';

export default class MetadataStore extends BaseStore<MetadataDef> {
constructor () {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

export { default as AccountsStore } from './Accounts';
export { default as MetadataStore } from './Metadata';
export { default as AccountsStore } from './Accounts.js';
export { default as MetadataStore } from './Metadata.js';
2 changes: 1 addition & 1 deletion packages/extension-base/src/utils/getId.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { EXTENSION_PREFIX } from '../defaults';
import { EXTENSION_PREFIX } from '../defaults.js';

let counter = 0;

Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

export { canDerive } from './canDerive';
export { canDerive } from './canDerive.js';
4 changes: 2 additions & 2 deletions packages/extension-chains/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import type { MetadataDef } from '@polkadot/extension-inject/types';
import type { ChainProperties } from '@polkadot/types/interfaces';
import type { Chain } from './types';
import type { Chain } from './types.js';

import { Metadata, TypeRegistry } from '@polkadot/types';
import { base64Decode } from '@polkadot/util-crypto';

export { packageInfo } from './packageInfo';
export { packageInfo } from './packageInfo.js';

// imports chain details, generally metadata. For the generation of these,
// inside the api, run `yarn chain:info --ws <url>`
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-chains/src/detectPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { detectPackage } from '@polkadot/util';

import others from './detectOther';
import { packageInfo } from './packageInfo';
import others from './detectOther.js';
import { packageInfo } from './packageInfo.js';

detectPackage(packageInfo, null, others);
2 changes: 1 addition & 1 deletion packages/extension-chains/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// Since we inject into pages, we skip this
// import './detectPackage';

export * from './bundle';
export * from './bundle.js';
2 changes: 1 addition & 1 deletion packages/extension-compat-metamask/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Web3 from 'web3';

import { assert } from '@polkadot/util';

export { packageInfo } from './packageInfo';
export { packageInfo } from './packageInfo.js';

interface RequestArguments {
method: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-compat-metamask/src/detectPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { detectPackage } from '@polkadot/util';

import others from './detectOther';
import { packageInfo } from './packageInfo';
import others from './detectOther.js';
import { packageInfo } from './packageInfo.js';

detectPackage(packageInfo, null, others);
2 changes: 1 addition & 1 deletion packages/extension-compat-metamask/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// Since we inject into pages, we skip this
// import './detectPackage';

export * from './bundle';
export * from './bundle.js';
6 changes: 3 additions & 3 deletions packages/extension-dapp/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type { InjectedAccount, InjectedAccountWithMeta, InjectedExtension, Injec
import { isPromise, objectSpread, u8aEq } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';

import { documentReadyPromise } from './util';
import { documentReadyPromise } from './util.js';

// expose utility functions
export { packageInfo } from './packageInfo';
export { unwrapBytes, wrapBytes } from './wrapBytes';
export { packageInfo } from './packageInfo.js';
export { unwrapBytes, wrapBytes } from './wrapBytes.js';

// just a helper (otherwise we cast all-over, so shorter and more readable)
const win = window as Window & InjectedWindow;
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-dapp/src/detectPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { detectPackage } from '@polkadot/util';

import others from './detectOther';
import { packageInfo } from './packageInfo';
import others from './detectOther.js';
import { packageInfo } from './packageInfo.js';

detectPackage(packageInfo, null, others);
2 changes: 1 addition & 1 deletion packages/extension-dapp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// Since we inject into pages, we skip this
// import './detectPackage';

export * from './bundle';
export * from './bundle.js';
2 changes: 1 addition & 1 deletion packages/extension-dapp/src/wrapBytes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

import { ETHEREUM, POSTFIX, PREFIX, unwrapBytes, wrapBytes } from './wrapBytes';
import { ETHEREUM, POSTFIX, PREFIX, unwrapBytes, wrapBytes } from './wrapBytes.js';

const TEST_DATA = 'this is just some random message that we expect to be wrapped along the way';
const TEST_ETH = u8aConcat(ETHEREUM, TEST_DATA);
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-inject/src/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2019-2023 @polkadot/extension-inject authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Injected, InjectedExtension, InjectedWindow, InjectOptions } from './types';
import type { Injected, InjectedExtension, InjectedWindow, InjectOptions } from './types.js';

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

export { packageInfo } from './packageInfo';
export { packageInfo } from './packageInfo.js';

// setting for new-style connect (more-secure with no details exposed without
// user acknowledgement, however slightly less-compatible with all dapps, some
Expand Down
Loading

0 comments on commit 6bfddb0

Please sign in to comment.