Use package-info (name/version only) for detectPackage (#2955)

* Use package-info (name/version only) for detectPackage

* Fixed @polkadot/dev?
This commit is contained in:
Jaco Greeff
2020-12-15 14:52:27 +01:00
committed by GitHub
parent a72d33ad24
commit 1d3dfc77a3
17 changed files with 74 additions and 76 deletions
+2 -11
View File
@@ -9,6 +9,7 @@ import type { ApiInterfaceRx, ApiTypes, DecoratedRpc, QueryableConsts, Queryable
import { assertReturn } from '@polkadot/util';
import { packageInfo } from '../detectPackage';
import { Init } from './Init';
interface PkgJson {
@@ -16,16 +17,6 @@ interface PkgJson {
version: string;
}
let pkgJson: PkgJson = { name: '@polkadot/api', version: '-' };
import('../package.json')
.then((_pkgJson: unknown): void => {
pkgJson = _pkgJson as PkgJson;
})
.catch((): void => {
// ignore
});
function assertResult<T> (value: T | undefined): T {
return assertReturn(value, 'Api needs to be initialized before using, listen on \'ready\'');
}
@@ -95,7 +86,7 @@ export abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> {
* @description The library information name & version (from package.json)
*/
public get libraryInfo (): string {
return `${pkgJson.name} v${pkgJson.version}`;
return `${(packageInfo as PkgJson).name} v${(packageInfo as PkgJson).version}`;
}
/**
+4 -2
View File
@@ -3,6 +3,8 @@
import { detectPackage } from '@polkadot/util';
import packageJson from './package.json';
import packageInfo from './package-info.json';
detectPackage(packageJson, typeof __dirname !== 'undefined' && __dirname);
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
export { packageInfo };
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
import packageInfo from './package-info.json';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
+2
View File
@@ -1,5 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import './detectPackage';
export { Metadata } from './Metadata';
export { constantsFromMeta, expandMetadata, extrinsicsFromMeta, storageFromMeta } from './decorate';
@@ -15,13 +15,11 @@ try {
['module-resolver', {
alias: {
'^@polkadot/api-derive(.*)': './packages/api-derive/src\\1',
'^@polkadot/api/package.json': './packages/api/package.json',
'^@polkadot/api(.*)': './packages/api/src/\\1',
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
'^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1',
'^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1',
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
'^@polkadot/types/package.json': './packages/types/package.json',
'^@polkadot/types(.*)': './packages/types/src\\1'
}
}]
@@ -16,7 +16,6 @@ try {
alias: {
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
'^@polkadot/types/package.json': './packages/types/package.json',
'^@polkadot/types(.*)': './packages/types/src\\1'
}
}]
@@ -17,7 +17,6 @@ try {
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
'^@polkadot/typegen(.*)': './packages/typegen/src\\1',
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
'^@polkadot/types/package.json': './packages/types/package.json',
'^@polkadot/types(.*)': './packages/types/src\\1'
}
}]
@@ -16,7 +16,6 @@ try {
alias: {
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
'^@polkadot/types/package.json': './packages/types/package.json',
'^@polkadot/types(.*)': './packages/types/src\\1'
}
}]
@@ -16,7 +16,6 @@ try {
alias: {
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
'^@polkadot/types/package.json': './packages/types/package.json',
'^@polkadot/types(.*)': './packages/types/src\\1'
}
}]
+1 -1
View File
@@ -7,7 +7,7 @@
import process from 'process';
import yargs from 'yargs';
import { ApiPromise, WsProvider } from '@polkadot/api/index';
import { ApiPromise, WsProvider } from '@polkadot/api';
/** @internal */
async function run (ws: string): Promise<void> {
+1 -1
View File
@@ -3,7 +3,7 @@
import Handlebars from 'handlebars';
import { Metadata } from '@polkadot/metadata';
import { Metadata } from '@polkadot/metadata/Metadata';
import staticData from '@polkadot/metadata/static';
import { TypeRegistry } from '@polkadot/types/create';
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
+1 -1
View File
@@ -6,7 +6,7 @@ import type { Registry } from '@polkadot/types/types';
import Handlebars from 'handlebars';
import { Metadata } from '@polkadot/metadata';
import { Metadata } from '@polkadot/metadata/Metadata';
import staticData from '@polkadot/metadata/static';
import { TypeRegistry } from '@polkadot/types/create';
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
+1 -1
View File
@@ -5,7 +5,7 @@ import type { Registry } from '@polkadot/types/types';
import Handlebars from 'handlebars';
import { Metadata } from '@polkadot/metadata';
import { Metadata } from '@polkadot/metadata/Metadata';
import staticData from '@polkadot/metadata/static';
import { TypeRegistry } from '@polkadot/types/create';
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
+2 -4
View File
@@ -3,8 +3,6 @@
import { detectPackage } from '@polkadot/util';
import packageJson from './package.json';
import packageInfo from './package-info.json';
// FIXME This really should be `import(...).then(...)`, but need to check rejections
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(packageJson, typeof __dirname !== 'undefined' && __dirname);
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);