From 24ca84f1dbbb4d4583062f228dd20f80a767e775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Tue, 31 Jan 2023 12:02:56 -0800 Subject: [PATCH] build: fix typings and webpack errors (#825) --- .github/workflows/check.yaml | 3 + package-lock.json | 171 ++++++++++++++++------------ package.json | 6 +- src/bee-debug.ts | 3 + src/bee.ts | 1 + src/chunk/soc.ts | 2 + src/feed/index.ts | 2 + src/modules/bytes.ts | 2 + src/modules/bzz.ts | 2 + src/modules/chunk.ts | 2 + src/modules/debug/balance.ts | 2 + src/modules/debug/chequebook.ts | 2 + src/modules/debug/chunk.ts | 2 + src/modules/debug/connectivity.ts | 2 + src/modules/debug/settlements.ts | 2 + src/modules/debug/stake.ts | 2 + src/modules/debug/stamps.ts | 2 + src/modules/debug/states.ts | 2 + src/modules/debug/status.ts | 2 + src/modules/debug/tag.ts | 2 + src/modules/debug/transactions.ts | 2 + src/modules/feed.ts | 2 + src/modules/pinning.ts | 2 + src/modules/pss.ts | 2 + src/modules/soc.ts | 2 + src/modules/status.ts | 2 + src/modules/stewardship.ts | 2 + src/modules/tag.ts | 2 + src/types/index.ts | 4 + src/utils/http.ts | 10 +- test/integration/feed/index.spec.ts | 2 + test/tests-setup.ts | 2 + test/utils.ts | 2 + webpack.config.ts | 2 +- 34 files changed, 167 insertions(+), 85 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 4ef61deb..29c7e02a 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -53,6 +53,9 @@ jobs: - name: Check typings run: npm run check:types + - name: Check build + run: npm run build + - name: Trigger API Docs update PR uses: peter-evans/repository-dispatch@v1 if: github.ref == 'refs/heads/master' diff --git a/package-lock.json b/package-lock.json index 5f917fed..fedba437 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,10 +73,10 @@ "sinon-chai": "^3.7.0", "terser-webpack-plugin": "^5.3.1", "ts-node": "^10.9.1", - "typescript": "^4.9.3", - "webpack": "^5.72.1", + "typescript": "^4.9.5", + "webpack": "^5.75.0", "webpack-bundle-analyzer": "^4.5.0", - "webpack-cli": "^4.9.2" + "webpack-cli": "^5.0.1" }, "engines": { "bee": "1.11.1-1992b846", @@ -3471,31 +3471,42 @@ } }, "node_modules/@webpack-cli/configtest": { - "version": "1.1.1", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@webpack-cli/configtest/-/configtest-2.0.1.tgz", + "integrity": "sha512-njsdJXJSiS2iNbQVS0eT8A/KPnmyH4pv1APj2K0d1wrZcBLw+yppxOy4CGqa0OxDJkzfL/XELDhD8rocnIwB5A==", "dev": true, - "license": "MIT", + "engines": { + "node": ">=14.15.0" + }, "peerDependencies": { - "webpack": "4.x.x || 5.x.x", - "webpack-cli": "4.x.x" + "webpack": "5.x.x", + "webpack-cli": "5.x.x" } }, "node_modules/@webpack-cli/info": { - "version": "1.4.1", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@webpack-cli/info/-/info-2.0.1.tgz", + "integrity": "sha512-fE1UEWTwsAxRhrJNikE7v4EotYflkEhBL7EbajfkPlf6E37/2QshOy/D48Mw8G5XMFlQtS6YV42vtbG9zBpIQA==", "dev": true, - "license": "MIT", - "dependencies": { - "envinfo": "^7.7.3" + "engines": { + "node": ">=14.15.0" }, "peerDependencies": { - "webpack-cli": "4.x.x" + "webpack": "5.x.x", + "webpack-cli": "5.x.x" } }, "node_modules/@webpack-cli/serve": { - "version": "1.6.1", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@webpack-cli/serve/-/serve-2.0.1.tgz", + "integrity": "sha512-0G7tNyS+yW8TdgHwZKlDWYXFA6OJQnoLCQvYKkQP0Q2X205PSQ6RNUj0M+1OB/9gRQaUZ/ccYfaxd0nhaWKfjw==", "dev": true, - "license": "MIT", + "engines": { + "node": ">=14.15.0" + }, "peerDependencies": { - "webpack-cli": "4.x.x" + "webpack": "5.x.x", + "webpack-cli": "5.x.x" }, "peerDependenciesMeta": { "webpack-dev-server": { @@ -3524,9 +3535,10 @@ } }, "node_modules/acorn": { - "version": "8.7.0", + "version": "8.8.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", + "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", "dev": true, - "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -4243,6 +4255,15 @@ "dev": true, "license": "MIT" }, + "node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true, + "engines": { + "node": "^12.20.0 || >=14" + } + }, "node_modules/commondir": { "version": "1.0.1", "dev": true, @@ -4884,9 +4905,10 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.9.3", + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz", + "integrity": "sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ==", "dev": true, - "license": "MIT", "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.2.0" @@ -4897,8 +4919,9 @@ }, "node_modules/envinfo": { "version": "7.8.1", + "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.8.1.tgz", + "integrity": "sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw==", "dev": true, - "license": "MIT", "bin": { "envinfo": "dist/cli.js" }, @@ -5877,8 +5900,9 @@ }, "node_modules/glob-to-regexp": { "version": "0.4.1", - "dev": true, - "license": "BSD-2-Clause" + "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", + "dev": true }, "node_modules/global-dirs": { "version": "0.1.1", @@ -6243,6 +6267,15 @@ "node": ">= 0.4" } }, + "node_modules/interpret": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-3.1.1.tgz", + "integrity": "sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==", + "dev": true, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/invariant": { "version": "2.2.2", "dev": true, @@ -9197,6 +9230,18 @@ "node": ">=8.10.0" } }, + "node_modules/rechoir": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz", + "integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==", + "dev": true, + "dependencies": { + "resolve": "^1.20.0" + }, + "engines": { + "node": ">= 10.13.0" + } + }, "node_modules/redent": { "version": "3.0.0", "dev": true, @@ -10002,8 +10047,9 @@ }, "node_modules/tapable": { "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", "dev": true, - "license": "MIT", "engines": { "node": ">=6" } @@ -10427,9 +10473,10 @@ } }, "node_modules/typescript": { - "version": "4.9.3", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, - "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -10606,9 +10653,10 @@ } }, "node_modules/watchpack": { - "version": "2.3.1", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", + "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", "dev": true, - "license": "MIT", "dependencies": { "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.1.2" @@ -10634,20 +10682,21 @@ } }, "node_modules/webpack": { - "version": "5.72.1", + "version": "5.75.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.75.0.tgz", + "integrity": "sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==", "dev": true, - "license": "MIT", "dependencies": { "@types/eslint-scope": "^3.7.3", "@types/estree": "^0.0.51", "@webassemblyjs/ast": "1.11.1", "@webassemblyjs/wasm-edit": "1.11.1", "@webassemblyjs/wasm-parser": "1.11.1", - "acorn": "^8.4.1", + "acorn": "^8.7.1", "acorn-import-assertions": "^1.7.6", "browserslist": "^4.14.5", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.9.3", + "enhanced-resolve": "^5.10.0", "es-module-lexer": "^0.9.0", "eslint-scope": "5.1.1", "events": "^3.2.0", @@ -10660,7 +10709,7 @@ "schema-utils": "^3.1.0", "tapable": "^2.1.1", "terser-webpack-plugin": "^5.1.3", - "watchpack": "^2.3.1", + "watchpack": "^2.4.0", "webpack-sources": "^3.2.3" }, "bin": { @@ -10802,39 +10851,42 @@ } }, "node_modules/webpack-cli": { - "version": "4.9.2", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-5.0.1.tgz", + "integrity": "sha512-S3KVAyfwUqr0Mo/ur3NzIp6jnerNpo7GUO6so51mxLi1spqsA17YcMXy0WOIJtBSnj748lthxC6XLbNKh/ZC+A==", "dev": true, - "license": "MIT", "dependencies": { "@discoveryjs/json-ext": "^0.5.0", - "@webpack-cli/configtest": "^1.1.1", - "@webpack-cli/info": "^1.4.1", - "@webpack-cli/serve": "^1.6.1", + "@webpack-cli/configtest": "^2.0.1", + "@webpack-cli/info": "^2.0.1", + "@webpack-cli/serve": "^2.0.1", "colorette": "^2.0.14", - "commander": "^7.0.0", - "execa": "^5.0.0", + "commander": "^9.4.1", + "cross-spawn": "^7.0.3", + "envinfo": "^7.7.3", "fastest-levenshtein": "^1.0.12", "import-local": "^3.0.2", - "interpret": "^2.2.0", - "rechoir": "^0.7.0", + "interpret": "^3.1.1", + "rechoir": "^0.8.0", "webpack-merge": "^5.7.3" }, "bin": { "webpack-cli": "bin/cli.js" }, "engines": { - "node": ">=10.13.0" + "node": ">=14.15.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" }, "peerDependencies": { - "webpack": "4.x.x || 5.x.x" + "webpack": "5.x.x" }, "peerDependenciesMeta": { "@webpack-cli/generators": { "optional": true }, - "@webpack-cli/migrate": { - "optional": true - }, "webpack-bundle-analyzer": { "optional": true }, @@ -10848,33 +10900,6 @@ "dev": true, "license": "MIT" }, - "node_modules/webpack-cli/node_modules/commander": { - "version": "7.2.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 10" - } - }, - "node_modules/webpack-cli/node_modules/interpret": { - "version": "2.2.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/webpack-cli/node_modules/rechoir": { - "version": "0.7.0", - "dev": true, - "license": "MIT", - "dependencies": { - "resolve": "^1.9.0" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/webpack-merge": { "version": "5.7.3", "dev": true, diff --git a/package.json b/package.json index ab21057e..4631ff3d 100644 --- a/package.json +++ b/package.json @@ -122,10 +122,10 @@ "sinon-chai": "^3.7.0", "terser-webpack-plugin": "^5.3.1", "ts-node": "^10.9.1", - "typescript": "^4.9.3", - "webpack": "^5.72.1", + "typescript": "^4.9.5", + "webpack": "^5.75.0", "webpack-bundle-analyzer": "^4.5.0", - "webpack-cli": "^4.9.2" + "webpack-cli": "^5.0.1" }, "engines": { "node": ">=14.0.0", diff --git a/src/bee-debug.ts b/src/bee-debug.ts index f2c52fed..9ae7979b 100644 --- a/src/bee-debug.ts +++ b/src/bee-debug.ts @@ -63,7 +63,10 @@ import { } from './types' import * as tag from './modules/debug/tag' import * as stamps from './modules/debug/stamps' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky-universal' + import { DEFAULT_KY_CONFIG, wrapRequestClosure, wrapResponseClosure } from './utils/http' import { sleep } from './utils/sleep' import { deepMerge } from './utils/merge' diff --git a/src/bee.ts b/src/bee.ts index 56cd5d03..ec07c1bb 100644 --- a/src/bee.ts +++ b/src/bee.ts @@ -78,6 +78,7 @@ import { UploadResult, } from './types' +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' import { DEFAULT_KY_CONFIG, wrapRequestClosure, wrapResponseClosure } from './utils/http' import { isReadable } from './utils/stream' diff --git a/src/chunk/soc.ts b/src/chunk/soc.ts index 4a87c05e..09afa98c 100644 --- a/src/chunk/soc.ts +++ b/src/chunk/soc.ts @@ -12,6 +12,8 @@ import * as socAPI from '../modules/soc' import * as chunkAPI from '../modules/chunk' import { EthAddress } from '../utils/eth' import { assertAddress } from '../utils/type' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const IDENTIFIER_SIZE = 32 diff --git a/src/feed/index.ts b/src/feed/index.ts index bc947e49..7687453b 100644 --- a/src/feed/index.ts +++ b/src/feed/index.ts @@ -21,6 +21,8 @@ import { bytesToHex, hexToBytes, HexString, makeHexString } from '../utils/hex' import { readUint64BigEndian, writeUint64BigEndian } from '../utils/uint64' import * as chunkAPI from '../modules/chunk' import { EthAddress, HexEthAddress, makeHexEthAddress } from '../utils/eth' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' import type { FeedType } from './type' diff --git a/src/modules/bytes.ts b/src/modules/bytes.ts index 15a5620c..45026e98 100644 --- a/src/modules/bytes.ts +++ b/src/modules/bytes.ts @@ -5,6 +5,8 @@ import { http } from '../utils/http' import { wrapBytesWithHelpers } from '../utils/bytes' import { UploadResult } from '../types' import { makeTagUid } from '../utils/type' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const endpoint = 'bytes' diff --git a/src/modules/bzz.ts b/src/modules/bzz.ts index 15f86ecf..4e6e7eb6 100644 --- a/src/modules/bzz.ts +++ b/src/modules/bzz.ts @@ -19,6 +19,8 @@ import { assertCollection } from '../utils/collection' import { wrapBytesWithHelpers } from '../utils/bytes' import { isReadable } from '../utils/stream' import { makeTagUid } from '../utils/type' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const bzzEndpoint = 'bzz' diff --git a/src/modules/chunk.ts b/src/modules/chunk.ts index e6ac4f79..2dee28f2 100644 --- a/src/modules/chunk.ts +++ b/src/modules/chunk.ts @@ -2,6 +2,8 @@ import type { BatchId, Data, Reference, ReferenceOrEns, ReferenceResponse, Uploa import { extractUploadHeaders } from '../utils/headers' import { http } from '../utils/http' import { wrapBytesWithHelpers } from '../utils/bytes' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const endpoint = 'chunks' diff --git a/src/modules/debug/balance.ts b/src/modules/debug/balance.ts index 83eced3b..9749e790 100644 --- a/src/modules/debug/balance.ts +++ b/src/modules/debug/balance.ts @@ -1,5 +1,7 @@ import { http } from '../../utils/http' import type { PeerBalance, BalanceResponse } from '../../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const balancesEndpoint = 'balances' diff --git a/src/modules/debug/chequebook.ts b/src/modules/debug/chequebook.ts index 587e2f5e..8ecae71b 100644 --- a/src/modules/debug/chequebook.ts +++ b/src/modules/debug/chequebook.ts @@ -10,6 +10,8 @@ import type { CashoutOptions, TransactionHash, } from '../../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const chequebookEndpoint = 'chequebook' diff --git a/src/modules/debug/chunk.ts b/src/modules/debug/chunk.ts index 54c078ef..72eeb2e6 100644 --- a/src/modules/debug/chunk.ts +++ b/src/modules/debug/chunk.ts @@ -1,5 +1,7 @@ import type { BeeGenericResponse } from '../../types' import { http } from '../../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const endpoint = 'chunks' diff --git a/src/modules/debug/connectivity.ts b/src/modules/debug/connectivity.ts index abdf7f2f..b18f0c5a 100644 --- a/src/modules/debug/connectivity.ts +++ b/src/modules/debug/connectivity.ts @@ -1,5 +1,7 @@ import { http } from '../../utils/http' import type { NodeAddresses, Peer, PingResponse, RemovePeerResponse, Topology } from '../../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' export async function getNodeAddresses(kyOptions: KyOptions): Promise { diff --git a/src/modules/debug/settlements.ts b/src/modules/debug/settlements.ts index 796dba26..86e510ed 100644 --- a/src/modules/debug/settlements.ts +++ b/src/modules/debug/settlements.ts @@ -1,5 +1,7 @@ import { http } from '../../utils/http' import type { Settlements, AllSettlements } from '../../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const settlementsEndpoint = 'settlements' diff --git a/src/modules/debug/stake.ts b/src/modules/debug/stake.ts index 77219864..1d82577a 100644 --- a/src/modules/debug/stake.ts +++ b/src/modules/debug/stake.ts @@ -1,5 +1,7 @@ import { http } from '../../utils/http' import { BeeGenericResponse, NumberString, TransactionOptions } from '../../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const STAKE_ENDPOINT = 'stake' diff --git a/src/modules/debug/stamps.ts b/src/modules/debug/stamps.ts index 8987c46d..d485eea4 100644 --- a/src/modules/debug/stamps.ts +++ b/src/modules/debug/stamps.ts @@ -1,5 +1,7 @@ import type { BatchId, PostageBatch, NumberString, PostageBatchBuckets, PostageBatchOptions } from '../../types' import { http } from '../../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const STAMPS_ENDPOINT = 'stamps' diff --git a/src/modules/debug/states.ts b/src/modules/debug/states.ts index 5cc5f7f8..ea7174b6 100644 --- a/src/modules/debug/states.ts +++ b/src/modules/debug/states.ts @@ -1,5 +1,7 @@ import { http } from '../../utils/http' import { ChainState, ReserveState, WalletBalance } from '../../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const RESERVE_STATE_ENDPOINT = 'reservestate' diff --git a/src/modules/debug/status.ts b/src/modules/debug/status.ts index 5302efb4..1a4cf80d 100644 --- a/src/modules/debug/status.ts +++ b/src/modules/debug/status.ts @@ -2,6 +2,8 @@ import { http } from '../../utils/http' import type { Health, NodeInfo } from '../../types/debug' import { BeeVersions } from '../../types/debug' import getMajorSemver from 'semver/functions/major.js' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' // Following lines bellow are automatically updated with GitHub Action when Bee version is updated diff --git a/src/modules/debug/tag.ts b/src/modules/debug/tag.ts index 135cbf49..c5085f39 100644 --- a/src/modules/debug/tag.ts +++ b/src/modules/debug/tag.ts @@ -1,5 +1,7 @@ import { ExtendedTag } from '../../types' import { http } from '../../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const endpoint = 'tags' diff --git a/src/modules/debug/transactions.ts b/src/modules/debug/transactions.ts index 6432b811..6aa29e19 100644 --- a/src/modules/debug/transactions.ts +++ b/src/modules/debug/transactions.ts @@ -1,5 +1,7 @@ import { NumberString, TransactionHash, TransactionInfo } from '../../types' import { http } from '../../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const transactionsEndpoint = 'transactions' diff --git a/src/modules/feed.ts b/src/modules/feed.ts index 87d41bea..bd267adb 100644 --- a/src/modules/feed.ts +++ b/src/modules/feed.ts @@ -4,6 +4,8 @@ import { FeedType } from '../feed/type' import { HexEthAddress } from '../utils/eth' import { extractUploadHeaders } from '../utils/headers' import { BeeError } from '../utils/error' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const feedEndpoint = 'feeds' diff --git a/src/modules/pinning.ts b/src/modules/pinning.ts index 6d758128..7aa545fd 100644 --- a/src/modules/pinning.ts +++ b/src/modules/pinning.ts @@ -1,5 +1,7 @@ import type { BeeGenericResponse, Pin, Reference } from '../types' import { http } from '../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const PINNING_ENDPOINT = 'pins' diff --git a/src/modules/pss.ts b/src/modules/pss.ts index 9dbb7dea..d204b752 100644 --- a/src/modules/pss.ts +++ b/src/modules/pss.ts @@ -4,6 +4,8 @@ import { prepareData } from '../utils/data' import { http } from '../utils/http' import { extractUploadHeaders } from '../utils/headers' import type { BatchId, BeeGenericResponse, PublicKey } from '../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const endpoint = 'pss' diff --git a/src/modules/soc.ts b/src/modules/soc.ts index 16ed9e0c..56e39d00 100644 --- a/src/modules/soc.ts +++ b/src/modules/soc.ts @@ -1,6 +1,8 @@ import { BatchId, Reference, ReferenceResponse, UploadOptions } from '../types' import { extractUploadHeaders } from '../utils/headers' import { http } from '../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const socEndpoint = 'soc' diff --git a/src/modules/status.ts b/src/modules/status.ts index 38b44e86..3813eb1c 100644 --- a/src/modules/status.ts +++ b/src/modules/status.ts @@ -1,4 +1,6 @@ import { http } from '../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' /** diff --git a/src/modules/stewardship.ts b/src/modules/stewardship.ts index 1b953ad6..026e4d5c 100644 --- a/src/modules/stewardship.ts +++ b/src/modules/stewardship.ts @@ -1,5 +1,7 @@ import type { ReferenceOrEns } from '../types' import { http } from '../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const stewardshipEndpoint = 'stewardship' diff --git a/src/modules/tag.ts b/src/modules/tag.ts index 929b4cc1..806f1266 100644 --- a/src/modules/tag.ts +++ b/src/modules/tag.ts @@ -1,5 +1,7 @@ import { Reference, Tag } from '../types' import { http } from '../utils/http' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' const endpoint = 'tags' diff --git a/src/types/index.ts b/src/types/index.ts index 760dc1d5..4c392aaa 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,11 +6,15 @@ import type { Bytes } from '../utils/bytes' import type { BeeError } from '../utils/error' import type { EthAddress, HexEthAddress } from '../utils/eth' import type { HexString } from '../utils/hex' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type ky from 'ky-universal' import type { Readable as NativeReadable } from 'stream' import type { Readable as CompatibilityReadable } from 'readable-stream' import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' export * from './debug' diff --git a/src/utils/http.ts b/src/utils/http.ts index f1bba825..58eb247c 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -1,5 +1,7 @@ import { BeeError, BeeNotAJsonError, BeeRequestError, BeeResponseError } from './error' import type { BeeRequest, BeeResponse, HookCallback, HttpMethod, Ky } from '../types' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { HTTPError, Options as KyOptions } from 'ky-universal' import { normalizeToReadableStream } from './stream' import { isObject, isStrictlyObject } from './type' @@ -176,15 +178,7 @@ async function getKy(): Promise { return ky } - // We use TSImportLib as TypeScript otherwise transpiles the `await import` into `require` call for CommonJS modules. - // The TSImportLib is used only in Node context as there is defined the `module` object. - // In browser&webpack is then used directly `await import()` as babel-loader only - // removes TS syntax and hence preserves `await import` in the browser build. - // if (importLib && importLib.import_) { - // ky = (await importLib.import_('ky-universal')).default - // } else { ky = (await import('ky-universal')).default - // } if (!ky) { throw new Error('Ky was not found while it should have been!') diff --git a/test/integration/feed/index.spec.ts b/test/integration/feed/index.spec.ts index 9ad2c18f..b41cce33 100644 --- a/test/integration/feed/index.spec.ts +++ b/test/integration/feed/index.spec.ts @@ -8,6 +8,8 @@ import { makeContentAddressedChunk } from '../../../src/chunk/cac' import * as chunkAPI from '../../../src/modules/chunk' import type { BytesReference, PrivateKeyBytes, Signer, Topic } from '../../../src/types' import { BeeResponseError } from '../../../src' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' import { expect } from 'chai' diff --git a/test/tests-setup.ts b/test/tests-setup.ts index c9d61523..c37873a6 100644 --- a/test/tests-setup.ts +++ b/test/tests-setup.ts @@ -1,6 +1,8 @@ /* eslint-disable no-console */ import { createPostageBatch, getPostageBatch } from '../src/modules/debug/stamps' import { BatchId } from '../src' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' import chai, { Assertion } from 'chai' import chaiAsPromised from 'chai-as-promised' diff --git a/test/utils.ts b/test/utils.ts index 2a730e12..8e3fbdaa 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,5 +1,7 @@ import { Readable } from 'stream' import { ReadableStream as ReadableStreamPolyfill } from 'web-streams-polyfill' + +// @ts-ignore: Needed TS otherwise complains about importing ESM package in CJS even though they are just typings import type { Options as KyOptions } from 'ky' import type { Address, BatchId, BeeGenericResponse, PlainBytesReference, PostageBatch, Reference } from '../src/types' diff --git a/webpack.config.ts b/webpack.config.ts index 18e60a19..f49b0bdc 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -29,7 +29,7 @@ const base = async (env?: Partial): Promise => output: { path, filename, - sourceMapFilename: filename + '.map', + sourceMapFilename: '[file].map[query]', library: 'BeeJs', libraryTarget: 'umd', globalObject: 'this',