Skip to content

Commit

Permalink
FIX: import assert deprecation in NodeJS 22 (#2807)
Browse files Browse the repository at this point in the history
* fix: implement a workaround for nodejs22 which has dropped assert, while retaining backwards compatibility with NodeJS >= 16
  • Loading branch information
SilentBot1 committed Jun 13, 2024
1 parent 45b3b1a commit 9654581
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import ConnPool from './lib/conn-pool.js' // browser exclude
import Torrent from './lib/torrent.js'
import { NodeServer, BrowserServer } from './lib/server.js'

import info from './package.json' assert { type: 'json' }
const VERSION = info.version
import VERSION from './version.cjs'

const debug = debugFactory('webtorrent')

Expand Down
3 changes: 1 addition & 2 deletions lib/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import utp from './utp.cjs' // browser exclude
import WebConn from './webconn.js'
import { Selections } from './selections.js'

import info from '../package.json' assert { type: 'json' }
import VERSION from '../version.cjs'

const debug = debugFactory('webtorrent:torrent')
const MAX_BLOCK_LENGTH = 128 * 1024
Expand All @@ -56,7 +56,6 @@ const FILESYSTEM_CONCURRENCY = process.browser ? cpus().length : 2

const RECONNECT_WAIT = [1_000, 5_000, 15_000]

const VERSION = info.version
const USER_AGENT = `WebTorrent/${VERSION} (https://webtorrent.io)`

let TMP
Expand Down
3 changes: 1 addition & 2 deletions lib/webconn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { hash, concat } from 'uint8-util'
import Wire from 'bittorrent-protocol'
import once from 'once'

import info from '../package.json' assert { type: 'json' }
import VERSION from '../version.cjs'

const debug = debugFactory('webtorrent:webconn')
const VERSION = info.version

const SOCKET_TIMEOUT = 60000
const RETRY_DELAY = 10000
Expand Down
2 changes: 2 additions & 0 deletions version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Exports package.json to work around "with" and "assert" for backwards compatability.
module.exports = require('./package.json').version

0 comments on commit 9654581

Please sign in to comment.