Skip to content

Commit

Permalink
fix: utp support bundlers and preprocessors (#2564)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Jun 5, 2023
1 parent 86612b3 commit 8b13937
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/conn-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import debugFactory from 'debug'
import queueMicrotask from 'queue-microtask'

import Peer from './peer.js'
import utp from './utp.js' // browser exclude
import utp from './utp.cjs' // browser exclude

const debug = debugFactory('webtorrent:conn-pool')

Expand Down
2 changes: 1 addition & 1 deletion lib/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import utPex from 'ut_pex' // browser exclude
import File from './file.js'
import Peer from './peer.js'
import RarityMap from './rarity-map.js'
import utp from './utp.js' // browser exclude
import utp from './utp.cjs' // browser exclude
import WebConn from './webconn.js'

import info from '../package.json' assert { type: 'json' }
Expand Down
12 changes: 12 additions & 0 deletions lib/utp.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// this file needs to conditionally import a module, ESM doesn't support this synchronously
// we could avoid .cjs by using node:module but that doesn't sit well with preprocessors like typescript
// and bundlers which can bundle for node like webpack

module.exports = (() => {
try {
return require('utp-native')
} catch (err) {
console.warn('WebTorrent: uTP not supported', err)
return {}
}
})()
12 changes: 0 additions & 12 deletions lib/utp.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "module",
"browser": {
"./lib/conn-pool.js": false,
"./lib/utp.js": false,
"./lib/utp.cjs": false,
"bittorrent-dht": false,
"http": false,
"fs": false,
Expand All @@ -24,7 +24,7 @@
"url": "https://github.com/webtorrent/webtorrent/issues"
},
"chromeapp": {
"./lib/utp.js": false,
"./lib/utp.cjs": false,
"fs-chunk-store": "memory-chunk-store",
"http": "@webtorrent/http-node",
"https": "@webtorrent/http-node",
Expand Down

0 comments on commit 8b13937

Please sign in to comment.