diff --git a/packages/wasm-crypto/src/detectPackage.d.ts b/packages/wasm-crypto/src/detectPackage.d.ts deleted file mode 100644 index acd63e87..00000000 --- a/packages/wasm-crypto/src/detectPackage.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import packageInfo from './package-info.json'; - -export { packageInfo }; diff --git a/packages/wasm-crypto/src/detectPackage.js b/packages/wasm-crypto/src/detectPackage.js deleted file mode 100644 index e3f00a8d..00000000 --- a/packages/wasm-crypto/src/detectPackage.js +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -const util = require('@polkadot/util'); - -const packageInfo = require('./package-info.json'); - -util.detectPackage(packageInfo, () => __dirname); - -exports.packageInfo = packageInfo; diff --git a/packages/wasm-crypto/src/detectPackage.mjs b/packages/wasm-crypto/src/detectPackage.mjs deleted file mode 100644 index e1331f08..00000000 --- a/packages/wasm-crypto/src/detectPackage.mjs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import { detectPackage } from '@polkadot/util'; - -import packageInfo from './package-info.json'; - -function getPath () { - return import.meta.url; -} - -detectPackage(packageInfo, getPath); - -export { packageInfo }; diff --git a/packages/wasm-crypto/src/detectPackage.ts b/packages/wasm-crypto/src/detectPackage.ts new file mode 100644 index 00000000..4d23fb44 --- /dev/null +++ b/packages/wasm-crypto/src/detectPackage.ts @@ -0,0 +1,25 @@ +// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use +// +// new URL(import.meta.url).pathname) +// +// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have +// nice things... In this case it is even worse since import.meta.url won't even make it compile, so +// there is a complete dead end with usage thereof +// +// When that is fixed, a solution is to have both .js & .mjs files, with the following content - +// +// cjs: util.detectPackage(packageInfo, () => __dirname); +// esm: detectPackage(packageInfo, () => import.meta.url); +// +// With the above we additionally need a .d.ts to just export the packageInfo + +import { detectPackage } from '@polkadot/util'; + +import packageInfo from './package-info.json'; + +detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname); + +export { packageInfo };