diff --git a/package.json b/package.json index b973ce391..2ff527c03 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "devDependencies": { "@babel/core": "^7.16.7", - "@polkadot/dev": "^0.65.12", + "@polkadot/dev": "^0.65.13", "@types/jest": "^27.4.0" }, "resolutions": { diff --git a/packages/util/src/versionDetect.spec.ts b/packages/util/src/versionDetect.spec.ts index 9100363e8..675959389 100644 --- a/packages/util/src/versionDetect.spec.ts +++ b/packages/util/src/versionDetect.spec.ts @@ -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: -\tcjs ${VER1}\t${PATH}/01 -\tcjs ${VER2} \t${PATH}/02`; +\t ${VER1}\t${PATH}/01 +\tesm ${VER2} \t${PATH}/02`; it('should not log the first time', (): void => { const spy = jest.spyOn(console, 'warn'); @@ -27,7 +27,7 @@ The following conflicting packages were found: it('should log the second time', (): void => { const spy = jest.spyOn(console, 'warn'); - detectPackage({ name: PKG, version: VER2 }, `${PATH}/02`); + detectPackage({ name: PKG, type: 'esm', version: VER2 }, `${PATH}/02`); expect(spy).toHaveBeenCalledWith(MISMATCH); spy.mockRestore(); }); @@ -35,7 +35,7 @@ The following conflicting packages were found: it('should allow for function use', (): void => { const spy = jest.spyOn(console, 'warn'); - detectPackage({ name: PKG, version: VER3 }, () => `${PATH}/03`); + detectPackage({ name: PKG, type: 'cjs', version: VER3 }, () => `${PATH}/03`); expect(spy).toHaveBeenCalledWith(`${MISMATCH} \tcjs ${VER3} \t${PATH}/03`); spy.mockRestore(); diff --git a/packages/util/src/versionDetect.ts b/packages/util/src/versionDetect.ts index 7bb8c016a..195f3d21f 100644 --- a/packages/util/src/versionDetect.ts +++ b/packages/util/src/versionDetect.ts @@ -6,18 +6,19 @@ 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; interface PackageJson { name: string; + path?: string; + type?: string; version: string; } interface VersionPath { - isEsm?: boolean; path?: string; + type?: string; version: string; } @@ -72,15 +73,17 @@ function flattenVersions (entry: VersionPath[]): string { : version; const all = entry.map(toPath); const verLength = getVersionLength(all); - const stringify = ({ isEsm, path, version }: VersionPath) => - `\t${isEsm ? 'esm' : 'cjs'} ${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '' : path}`; + const stringify = ({ path, type, version }: VersionPath) => + `\t${`${type || ''}`.padStart(3)} ${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '' : path}`; return all.map(stringify).join('\n'); } /** @internal */ -function getPath (pathOrFn?: FnString | string | false): string { - if (isFunction(pathOrFn)) { +function getPath (infoPath?: string, pathOrFn?: FnString | string | false): string { + if (infoPath) { + return infoPath; + } else if (isFunction(pathOrFn)) { try { return pathOrFn() || ''; } catch (error) { @@ -96,12 +99,12 @@ function getPath (pathOrFn?: FnString | string | false): string { * @summary Checks that a specific package is only imported once * @description A `@polkadot/*` version detection utility, checking for one occurence of a package in addition to checking for ddependency versions. */ -export function detectPackage ({ name, version }: PackageJson, pathOrFn?: FnString | string | false, deps: PackageJson[] = []): void { +export function detectPackage ({ name, path, type, version }: PackageJson, pathOrFn?: FnString | string | false, deps: PackageJson[] = []): void { assert(name.startsWith('@polkadot'), () => `Invalid package descriptor ${name}`); const entry = getEntry(name); - entry.push({ isEsm, path: getPath(pathOrFn), version }); + entry.push({ path: getPath(path, pathOrFn), type, version }); if (entry.length !== 1) { console.warn(`${name} has multiple versions, ensure that there is only one installed.\n${DEDUPE}\n${flattenVersions(entry)}`); diff --git a/yarn.lock b/yarn.lock index 75d02faad..8eac3c523 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1958,9 +1958,9 @@ __metadata: languageName: node linkType: hard -"@polkadot/dev@npm:^0.65.12": - version: 0.65.12 - resolution: "@polkadot/dev@npm:0.65.12" +"@polkadot/dev@npm:^0.65.13": + version: 0.65.13 + resolution: "@polkadot/dev@npm:0.65.13" dependencies: "@babel/cli": ^7.16.7 "@babel/core": ^7.16.7 @@ -2046,7 +2046,7 @@ __metadata: polkadot-exec-rollup: scripts/polkadot-exec-rollup.mjs polkadot-exec-tsc: scripts/polkadot-exec-tsc.mjs polkadot-exec-webpack: scripts/polkadot-exec-webpack.mjs - checksum: 8cb36b8057af0bb07d519fc6dcb69a41eb167e62ce01c15041631c3cfeeac76b5c9060ab607e258f00ba6b8a35ca0d204db33671cf54c858f05beda2c5668909 + checksum: 00508f66616867bf4bacaad6081924397386cb2cdc682ad6d24afe10061417bb07953e379b7027a6eba92e6f34c0b63feace821550675b918843549746b1093e languageName: node linkType: hard @@ -9175,7 +9175,7 @@ resolve@^2.0.0-next.3: resolution: "root-workspace-0b6124@workspace:." dependencies: "@babel/core": ^7.16.7 - "@polkadot/dev": ^0.65.12 + "@polkadot/dev": ^0.65.13 "@types/jest": ^27.4.0 languageName: unknown linkType: soft