Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4de3a1339 | ||
|
|
69279f1b81 | ||
|
|
303c822d48 | ||
|
|
90ca8a0d78 | ||
|
|
94bbc6f2ee | ||
|
|
f4be1fe52e |
@@ -1,3 +1,7 @@
|
|||||||
|
# 2.1.1
|
||||||
|
|
||||||
|
- Update `detectPackage(<package.json>, __dirname?)` with calling folder
|
||||||
|
|
||||||
# 2.0.1
|
# 2.0.1
|
||||||
|
|
||||||
- Update w3f/schnorrkel to 0.8.5 (Full Substrate 2.x support, no 1.x support)
|
- Update w3f/schnorrkel to 0.8.5 (Full Substrate 2.x support, no 1.x support)
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@
|
|||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"version": "2.0.1"
|
"version": "2.1.1"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "2.0.1",
|
"version": "2.1.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"yarn": "^1.10.1"
|
"yarn": "^1.10.1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/keyring",
|
"name": "@polkadot/keyring",
|
||||||
"version": "2.0.1",
|
"version": "2.1.1",
|
||||||
"description": "Keyring management",
|
"description": "Keyring management",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.8.3",
|
"@babel/runtime": "^7.8.3",
|
||||||
"@polkadot/util": "^2.0.1",
|
"@polkadot/util": "^2.1.1",
|
||||||
"@polkadot/util-crypto": "^2.0.1"
|
"@polkadot/util-crypto": "^2.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,22 @@ import { decodeAddress, encodeAddress, setSS58Format } from '@polkadot/util-cryp
|
|||||||
|
|
||||||
import Keyring from './keyring';
|
import Keyring from './keyring';
|
||||||
|
|
||||||
|
let dirname;
|
||||||
let pkgJson;
|
let pkgJson;
|
||||||
|
|
||||||
|
try {
|
||||||
|
dirname = __dirname;
|
||||||
|
} catch (error) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pkgJson = require('./package.json');
|
pkgJson = require('./package.json');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
pkgJson = require('../package.json');
|
pkgJson = require('../package.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
detectPackage(pkgJson);
|
detectPackage(pkgJson, dirname);
|
||||||
|
|
||||||
export default Keyring;
|
export default Keyring;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util-crypto",
|
"name": "@polkadot/util-crypto",
|
||||||
"version": "2.0.1",
|
"version": "2.1.1",
|
||||||
"description": "A collection of useful crypto utilities for @polkadot",
|
"description": "A collection of useful crypto utilities for @polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.8.3",
|
"@babel/runtime": "^7.8.3",
|
||||||
"@polkadot/util": "^2.0.1",
|
"@polkadot/util": "^2.1.1",
|
||||||
"@polkadot/wasm-crypto": "^0.20.1",
|
"@polkadot/wasm-crypto": "^0.20.1",
|
||||||
"@types/bs58": "^4.0.0",
|
"@types/bs58": "^4.0.0",
|
||||||
"@types/elliptic": "^6.4.12",
|
"@types/elliptic": "^6.4.12",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util",
|
"name": "@polkadot/util",
|
||||||
"version": "2.0.1",
|
"version": "2.1.1",
|
||||||
"description": "A collection of useful utilities for @polkadot",
|
"description": "A collection of useful utilities for @polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -5,10 +5,15 @@
|
|||||||
import { detectPackage } from '.';
|
import { detectPackage } from '.';
|
||||||
|
|
||||||
describe('assertSingletonPackage', (): void => {
|
describe('assertSingletonPackage', (): void => {
|
||||||
|
const PKG = '@polkadot/util';
|
||||||
|
const VER1 = '9.8.0-beta.45';
|
||||||
|
const VER2 = '9.7.1';
|
||||||
|
const PATH = '/Users/jaco/Projects/polkadot-js/api/node_modules/@polkadot/util';
|
||||||
|
|
||||||
it('should not log the first time', (): void => {
|
it('should not log the first time', (): void => {
|
||||||
const spy = jest.spyOn(console, 'warn');
|
const spy = jest.spyOn(console, 'warn');
|
||||||
|
|
||||||
detectPackage({ name: '@polkadot/util', version: 'a.b.c-1st' });
|
detectPackage({ name: PKG, version: VER1 }, `${PATH}/01`);
|
||||||
expect(spy).not.toHaveBeenCalled();
|
expect(spy).not.toHaveBeenCalled();
|
||||||
spy.mockRestore();
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
@@ -16,8 +21,8 @@ describe('assertSingletonPackage', (): void => {
|
|||||||
it('should log the second time', (): void => {
|
it('should log the second time', (): void => {
|
||||||
const spy = jest.spyOn(console, 'warn');
|
const spy = jest.spyOn(console, 'warn');
|
||||||
|
|
||||||
detectPackage({ name: '@polkadot/util', version: 'a.b.c-2nd' });
|
detectPackage({ name: PKG, version: VER2 }, `${PATH}/02`);
|
||||||
expect(spy).toHaveBeenCalledWith('Multiple versions of @polkadot/util detected: a.b.c-1st, a.b.c-2nd. Ensure that there is only one version in your dependency tree');
|
expect(spy).toHaveBeenCalledWith(`Multiple instances of @polkadot/util detected, ensure that there is only one package in your dependency tree.\n\t${VER1}\t${PATH}/01\n\t${VER2} \t${PATH}/02`);
|
||||||
spy.mockRestore();
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,27 +3,51 @@
|
|||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import assert from './assert';
|
import assert from './assert';
|
||||||
|
import isString from './is/string';
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
type This = typeof globalThis;
|
type This = typeof globalThis;
|
||||||
|
|
||||||
interface PjsChecks extends This {
|
|
||||||
__polkadotjs: Record<string, string[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PackageJson {
|
interface PackageJson {
|
||||||
name: string;
|
name: string;
|
||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface VersionPath {
|
||||||
|
path?: string;
|
||||||
|
version: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PjsChecks extends This {
|
||||||
|
__polkadotjs: Record<string, VersionPath[]>;
|
||||||
|
}
|
||||||
|
|
||||||
type PjsGlobal = NodeJS.Global & PjsChecks;
|
type PjsGlobal = NodeJS.Global & PjsChecks;
|
||||||
type PjsWindow = Window & PjsChecks;
|
type PjsWindow = Window & PjsChecks;
|
||||||
|
|
||||||
|
function expandPath (path?: string): string {
|
||||||
|
return (!path || path.length < 5) ? '<unknown path>' : path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
function flattenVersions (_all: (VersionPath | string)[]): string {
|
||||||
|
const all: VersionPath[] = _all.map((version: VersionPath | string): VersionPath =>
|
||||||
|
isString(version)
|
||||||
|
? { version }
|
||||||
|
: version
|
||||||
|
);
|
||||||
|
const verLength = all.reduce((max, { version }): number => Math.max(max, version.length), 0);
|
||||||
|
|
||||||
|
return all
|
||||||
|
.map(({ path, version }): string => `\t${version.padEnd(verLength)}\t${expandPath(path)}`)
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name detectPackage
|
* @name detectPackage
|
||||||
* @summary Checks that a specific package is only imported once
|
* @summary Checks that a specific package is only imported once
|
||||||
*/
|
*/
|
||||||
export default function detectPackage ({ name, version }: PackageJson): void {
|
export default function detectPackage ({ name, version }: PackageJson, path?: string): void {
|
||||||
const _global = typeof window !== 'undefined'
|
const _global = typeof window !== 'undefined'
|
||||||
? window as PjsWindow
|
? window as PjsWindow
|
||||||
: global as PjsGlobal;
|
: global as PjsGlobal;
|
||||||
@@ -34,9 +58,11 @@ export default function detectPackage ({ name, version }: PackageJson): void {
|
|||||||
|
|
||||||
assert(name.startsWith('@polkadot'), `Invalid package descriptor ${name}`);
|
assert(name.startsWith('@polkadot'), `Invalid package descriptor ${name}`);
|
||||||
|
|
||||||
_global.__polkadotjs[name] = [...(_global.__polkadotjs[name] || []), version];
|
_global.__polkadotjs[name] = [...(_global.__polkadotjs[name] || []), { path, version }];
|
||||||
|
|
||||||
if (_global.__polkadotjs[name].length !== 1) {
|
if (_global.__polkadotjs[name].length !== 1) {
|
||||||
console.warn(`Multiple versions of ${name} detected: ${_global.__polkadotjs[name].join(', ')}. Ensure that there is only one version in your dependency tree`);
|
const versions = flattenVersions(_global.__polkadotjs[name]);
|
||||||
|
|
||||||
|
console.warn(`Multiple instances of ${name} detected, ensure that there is only one package in your dependency tree.\n${versions}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user