Introduce detectOther (#1345)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default [];
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as transportInfo } from '@polkadot/hw-ledger-transports/packageInfo';
|
||||
import { packageInfo as utilInfo } from '@polkadot/util/packageInfo';
|
||||
|
||||
export default [transportInfo, utilInfo];
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as transportInfo } from '@polkadot/hw-ledger-transports/packageInfo';
|
||||
import { detectPackage, packageInfo as utilInfo } from '@polkadot/util';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import __dirname from './cjs/dirname';
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [transportInfo, utilInfo]);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, others);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/keyring authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as utilInfo } from '@polkadot/util/packageInfo';
|
||||
import { packageInfo as cryptoInfo } from '@polkadot/util-crypto/packageInfo';
|
||||
|
||||
export default [utilInfo, cryptoInfo];
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/keyring authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { detectPackage, packageInfo as utilInfo } from '@polkadot/util';
|
||||
import { packageInfo as cryptoInfo } from '@polkadot/util-crypto/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import __dirname from './cjs/dirname';
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [utilInfo, cryptoInfo]);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, others);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default [];
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as netInfo } from '@polkadot/networks/packageInfo';
|
||||
import { packageInfo as utilInfo } from '@polkadot/util/packageInfo';
|
||||
import { packageInfo as randomInfo } from '@polkadot/x-randomvalues';
|
||||
|
||||
export default [netInfo, utilInfo, randomInfo];
|
||||
@@ -1,11 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as netInfo } from '@polkadot/networks/packageInfo';
|
||||
import { detectPackage, packageInfo as utilInfo } from '@polkadot/util';
|
||||
import { packageInfo as randomInfo } from '@polkadot/x-randomvalues';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import __dirname from './cjs/dirname';
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [netInfo, utilInfo, randomInfo]);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, others);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as decoderInfo } from '@polkadot/x-textdecoder';
|
||||
import { packageInfo as encoderInfo } from '@polkadot/x-textencoder';
|
||||
|
||||
export default [decoderInfo, encoderInfo];
|
||||
@@ -16,11 +16,9 @@
|
||||
//
|
||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
||||
|
||||
import { packageInfo as decoderInfo } from '@polkadot/x-textdecoder';
|
||||
import { packageInfo as encoderInfo } from '@polkadot/x-textencoder';
|
||||
|
||||
import __dirname from './cjs/dirname';
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
import { detectPackage } from './versionDetect';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [decoderInfo, encoderInfo]);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, others);
|
||||
|
||||
@@ -5,6 +5,8 @@ import { BigInt } from '@polkadot/x-bigint';
|
||||
|
||||
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
|
||||
export const hasBuffer = typeof Buffer !== 'undefined';
|
||||
export const hasCjs = typeof require === 'function' && typeof module !== 'undefined';
|
||||
export const hasDirname = typeof __dirname !== 'undefined';
|
||||
export const hasEsm = !hasCjs;
|
||||
export const hasProcess = typeof process === 'object';
|
||||
export const hasWasm = typeof WebAssembly !== 'undefined';
|
||||
|
||||
@@ -13,8 +13,8 @@ describe('detectPackage', (): void => {
|
||||
const MISMATCH = `@polkadot/util has multiple versions, ensure that there is only one installed.
|
||||
Either remove and explicitly install matching versions or dedupe using your package manager.
|
||||
The following conflicting packages were found:
|
||||
\t${VER1}\t${PATH}/01
|
||||
\t${VER2} \t${PATH}/02`;
|
||||
\tcjs ${VER1}\t${PATH}/01
|
||||
\tcjs ${VER2} \t${PATH}/02`;
|
||||
|
||||
it('should not log the first time', (): void => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
@@ -37,7 +37,7 @@ The following conflicting packages were found:
|
||||
|
||||
detectPackage({ name: PKG, version: VER3 }, () => `${PATH}/03`);
|
||||
expect(spy).toHaveBeenCalledWith(`${MISMATCH}
|
||||
\t${VER3} \t${PATH}/03`);
|
||||
\tcjs ${VER3} \t${PATH}/03`);
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import { xglobal } from '@polkadot/x-global';
|
||||
import { isFunction } from './is/function';
|
||||
import { isString } from './is/string';
|
||||
import { assert } from './assert';
|
||||
import { hasEsm as isEsm } from './has';
|
||||
|
||||
type This = typeof globalThis;
|
||||
|
||||
@@ -15,6 +16,7 @@ interface PackageJson {
|
||||
}
|
||||
|
||||
interface VersionPath {
|
||||
isEsm?: boolean;
|
||||
path?: string;
|
||||
version: string;
|
||||
}
|
||||
@@ -70,8 +72,8 @@ function flattenVersions (entry: VersionPath[]): string {
|
||||
: version;
|
||||
const all = entry.map(toPath);
|
||||
const verLength = getVersionLength(all);
|
||||
const stringify = ({ path, version }: VersionPath) =>
|
||||
`\t${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`;
|
||||
const stringify = ({ isEsm, path, version }: VersionPath) =>
|
||||
`\t${isEsm ? 'esm' : 'cjs'} ${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`;
|
||||
|
||||
return all.map(stringify).join('\n');
|
||||
}
|
||||
@@ -99,7 +101,7 @@ export function detectPackage ({ name, version }: PackageJson, pathOrFn?: FnStri
|
||||
|
||||
const entry = getEntry(name);
|
||||
|
||||
entry.push({ path: getPath(pathOrFn), version });
|
||||
entry.push({ isEsm, path: getPath(pathOrFn), version });
|
||||
|
||||
if (entry.length !== 1) {
|
||||
console.warn(`${name} has multiple versions, ensure that there is only one installed.\n${DEDUPE}\n${flattenVersions(entry)}`);
|
||||
|
||||
Reference in New Issue
Block a user