From e6d3189edf1a170197a799b97d84c632692b394f Mon Sep 17 00:00:00 2001 From: Cas <6506529+ThaUnknown@users.noreply.github.com> Date: Mon, 5 Dec 2022 23:06:54 +0100 Subject: [PATCH] feat: esm (#431) BREAKING CHANGE: ESM only * feat: esm * fix: linter oops --- bin/cmd.js | 4 ++-- client.js | 26 ++++++++++++----------- examples/express-embed/server.js | 4 ++-- index.js | 9 ++++---- lib/client/http-tracker.js | 25 +++++++++++----------- lib/client/tracker.js | 4 ++-- lib/client/udp-tracker.js | 26 ++++++++++++----------- lib/client/websocket-tracker.js | 20 ++++++++++-------- lib/common-node.js | 29 +++++++++++++------------ lib/common.js | 21 ++++++++++++------- lib/server/parse-http.js | 4 ++-- lib/server/parse-udp.js | 6 +++--- lib/server/parse-websocket.js | 4 ++-- lib/server/swarm.js | 12 ++++++----- package.json | 6 +++++- server.js | 36 +++++++++++++++++--------------- test/client-large-torrent.js | 8 +++---- test/client-magnet.js | 10 ++++----- test/client-ws-socket-pool.js | 8 +++---- test/client.js | 12 +++++------ test/common.js | 8 ++++--- test/destroy.js | 8 +++---- test/evict.js | 8 +++---- test/filter.js | 8 +++---- test/querystring.js | 4 ++-- test/request-handler.js | 10 ++++----- test/scrape.js | 25 +++++++++++----------- test/server.js | 8 +++---- test/stats.js | 10 ++++----- 29 files changed, 192 insertions(+), 171 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 965e00f7..fb7e0653 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -const minimist = require('minimist') -const Server = require('../').Server +import minimist from 'minimist' +import { Server } from '../index.js' const argv = minimist(process.argv.slice(2), { alias: { diff --git a/client.js b/client.js index c091c319..c90d7f90 100644 --- a/client.js +++ b/client.js @@ -1,14 +1,16 @@ -const debug = require('debug')('bittorrent-tracker:client') -const EventEmitter = require('events') -const once = require('once') -const parallel = require('run-parallel') -const Peer = require('simple-peer') -const queueMicrotask = require('queue-microtask') - -const common = require('./lib/common') -const HTTPTracker = require('./lib/client/http-tracker') // empty object in browser -const UDPTracker = require('./lib/client/udp-tracker') // empty object in browser -const WebSocketTracker = require('./lib/client/websocket-tracker') +import Debug from 'debug' +import EventEmitter from 'events' +import once from 'once' +import parallel from 'run-parallel' +import Peer from 'simple-peer' +import queueMicrotask from 'queue-microtask' + +import common from './lib/common.js' +import HTTPTracker from './lib/client/http-tracker.js' // empty object in browser +import UDPTracker from './lib/client/udp-tracker.js' // empty object in browser +import WebSocketTracker from './lib/client/websocket-tracker.js' + +const debug = Debug('bittorrent-tracker:client') /** * BitTorrent tracker client. @@ -289,4 +291,4 @@ Client.scrape = (opts, cb) => { return client } -module.exports = Client +export default Client diff --git a/examples/express-embed/server.js b/examples/express-embed/server.js index cfdbbec8..947dcbfb 100755 --- a/examples/express-embed/server.js +++ b/examples/express-embed/server.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -const Server = require('../..').Server -const express = require('express') +import { Server } from '../../index.js' +import express from 'express' const app = express() // https://wiki.theory.org/BitTorrentSpecification#peer_id diff --git a/index.js b/index.js index de5d73c7..e812c41c 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ /*! bittorrent-tracker. MIT License. WebTorrent LLC */ -const Client = require('./client') -const Server = require('./server') +import Client from './client.js' +import Server from './server.js' -module.exports = Client -module.exports.Client = Client -module.exports.Server = Server +export default Client +export { Client, Server } diff --git a/lib/client/http-tracker.js b/lib/client/http-tracker.js index 6fcea8d7..8dfe718a 100644 --- a/lib/client/http-tracker.js +++ b/lib/client/http-tracker.js @@ -1,14 +1,15 @@ -const arrayRemove = require('unordered-array-remove') -const bencode = require('bencode') -const clone = require('clone') -const compact2string = require('compact2string') -const debug = require('debug')('bittorrent-tracker:http-tracker') -const get = require('simple-get') -const Socks = require('socks') - -const common = require('../common') -const Tracker = require('./tracker') - +import arrayRemove from 'unordered-array-remove' +import bencode from 'bencode' +import clone from 'clone' +import Debug from 'debug' +import get from 'simple-get' +import Socks from 'socks' + +import common from '../common.js' +import Tracker from './tracker.js' +import compact2string from 'compact2string' + +const debug = Debug('bittorrent-tracker:http-tracker') const HTTP_SCRAPE_SUPPORT = /\/(announce)[^/]*$/ /** @@ -256,4 +257,4 @@ class HTTPTracker extends Tracker { HTTPTracker.prototype.DEFAULT_ANNOUNCE_INTERVAL = 30 * 60 * 1000 // 30 minutes -module.exports = HTTPTracker +export default HTTPTracker diff --git a/lib/client/tracker.js b/lib/client/tracker.js index cbbd23de..1129ecd8 100644 --- a/lib/client/tracker.js +++ b/lib/client/tracker.js @@ -1,4 +1,4 @@ -const EventEmitter = require('events') +import EventEmitter from 'events' class Tracker extends EventEmitter { constructor (client, announceUrl) { @@ -25,4 +25,4 @@ class Tracker extends EventEmitter { } } -module.exports = Tracker +export default Tracker diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index 65d97e40..9162d76f 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -1,14 +1,16 @@ -const arrayRemove = require('unordered-array-remove') -const BN = require('bn.js') -const clone = require('clone') -const compact2string = require('compact2string') -const debug = require('debug')('bittorrent-tracker:udp-tracker') -const dgram = require('dgram') -const randombytes = require('randombytes') -const Socks = require('socks') - -const common = require('../common') -const Tracker = require('./tracker') +import arrayRemove from 'unordered-array-remove' +import BN from 'bn.js' +import clone from 'clone' +import Debug from 'debug' +import dgram from 'dgram' +import randombytes from 'randombytes' +import Socks from 'socks' + +import common from '../common.js' +import Tracker from './tracker.js' +import compact2string from 'compact2string' + +const debug = Debug('bittorrent-tracker:udp-tracker') /** * UDP torrent tracker client (for an individual tracker) @@ -329,4 +331,4 @@ function toUInt64 (n) { function noop () {} -module.exports = UDPTracker +export default UDPTracker diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index 1573cfd2..3799510a 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -1,12 +1,14 @@ -const clone = require('clone') -const debug = require('debug')('bittorrent-tracker:websocket-tracker') -const Peer = require('simple-peer') -const randombytes = require('randombytes') -const Socket = require('simple-websocket') -const Socks = require('socks') +import clone from 'clone' +import Debug from 'debug' +import Peer from 'simple-peer' +import randombytes from 'randombytes' +import Socket from 'simple-websocket' +import Socks from 'socks' -const common = require('../common') -const Tracker = require('./tracker') +import common from '../common.js' +import Tracker from './tracker.js' + +const debug = Debug('bittorrent-tracker:websocket-tracker') // Use a socket pool, so tracker clients share WebSocket objects for the same server. // In practice, WebSockets are pretty slow to establish, so this gives a nice performance @@ -439,4 +441,4 @@ WebSocketTracker._socketPool = socketPool function noop () {} -module.exports = WebSocketTracker +export default WebSocketTracker diff --git a/lib/common-node.js b/lib/common-node.js index dab4b675..18af19c9 100644 --- a/lib/common-node.js +++ b/lib/common-node.js @@ -3,23 +3,23 @@ * These are separate from common.js so they can be skipped when bundling for the browser. */ -const querystring = require('querystring') +import querystring from 'querystring' -exports.IPV4_RE = /^[\d.]+$/ -exports.IPV6_RE = /^[\da-fA-F:]+$/ -exports.REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/ +export const IPV4_RE = /^[\d.]+$/ +export const IPV6_RE = /^[\da-fA-F:]+$/ +export const REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/ -exports.CONNECTION_ID = Buffer.concat([toUInt32(0x417), toUInt32(0x27101980)]) -exports.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 } -exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3, paused: 4 } -exports.EVENT_IDS = { +export const CONNECTION_ID = Buffer.concat([toUInt32(0x417), toUInt32(0x27101980)]) +export const ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 } +export const EVENTS = { update: 0, completed: 1, started: 2, stopped: 3, paused: 4 } +export const EVENT_IDS = { 0: 'update', 1: 'completed', 2: 'started', 3: 'stopped', 4: 'paused' } -exports.EVENT_NAMES = { +export const EVENT_NAMES = { update: 'update', completed: 'complete', started: 'start', @@ -31,20 +31,19 @@ exports.EVENT_NAMES = { * Client request timeout. How long to wait before considering a request to a * tracker server to have timed out. */ -exports.REQUEST_TIMEOUT = 15000 +export const REQUEST_TIMEOUT = 15000 /** * Client destroy timeout. How long to wait before forcibly cleaning up all * pending requests, open sockets, etc. */ -exports.DESTROY_TIMEOUT = 1000 +export const DESTROY_TIMEOUT = 1000 -function toUInt32 (n) { +export function toUInt32 (n) { const buf = Buffer.allocUnsafe(4) buf.writeUInt32BE(n, 0) return buf } -exports.toUInt32 = toUInt32 /** * `querystring.parse` using `unescape` instead of decodeURIComponent, since bittorrent @@ -52,7 +51,7 @@ exports.toUInt32 = toUInt32 * @param {string} q * @return {Object} */ -exports.querystringParse = q => querystring.parse(q, null, null, { decodeURIComponent: unescape }) +export const querystringParse = q => querystring.parse(q, null, null, { decodeURIComponent: unescape }) /** * `querystring.stringify` using `escape` instead of encodeURIComponent, since bittorrent @@ -60,7 +59,7 @@ exports.querystringParse = q => querystring.parse(q, null, null, { decodeURIComp * @param {Object} obj * @return {string} */ -exports.querystringStringify = obj => { +export const querystringStringify = obj => { let ret = querystring.stringify(obj, null, null, { encodeURIComponent: escape }) ret = ret.replace(/[@*/+]/g, char => // `escape` doesn't encode the characters @*/+ so we do it manually `%${char.charCodeAt(0).toString(16).toUpperCase()}`) diff --git a/lib/common.js b/lib/common.js index 0a2026bc..d418a323 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,18 +1,19 @@ /** * Functions/constants needed by both the client and server. */ +import * as common from './common-node.js' -exports.DEFAULT_ANNOUNCE_PEERS = 50 -exports.MAX_ANNOUNCE_PEERS = 82 +export const DEFAULT_ANNOUNCE_PEERS = 50 +export const MAX_ANNOUNCE_PEERS = 82 -exports.binaryToHex = str => { +export const binaryToHex = str => { if (typeof str !== 'string') { str = String(str) } return Buffer.from(str, 'binary').toString('hex') } -exports.hexToBinary = str => { +export const hexToBinary = str => { if (typeof str !== 'string') { str = String(str) } @@ -31,7 +32,7 @@ exports.hexToBinary = str => { // Bug reports: // - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880 // - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505 -exports.parseUrl = str => { +export const parseUrl = str => { const url = new URL(str.replace(/^udp:/, 'http:')) if (str.match(/^udp:/)) { @@ -45,5 +46,11 @@ exports.parseUrl = str => { return url } -const config = require('./common-node') -Object.assign(exports, config) +export default { + DEFAULT_ANNOUNCE_PEERS, + MAX_ANNOUNCE_PEERS, + binaryToHex, + hexToBinary, + parseUrl, + ...common +} diff --git a/lib/server/parse-http.js b/lib/server/parse-http.js index 7b2d5e2c..5847251f 100644 --- a/lib/server/parse-http.js +++ b/lib/server/parse-http.js @@ -1,6 +1,6 @@ -module.exports = parseHttpRequest +import common from '../common.js' -const common = require('../common') +export default parseHttpRequest function parseHttpRequest (req, opts) { if (!opts) opts = {} diff --git a/lib/server/parse-udp.js b/lib/server/parse-udp.js index 939bcb5d..935420cd 100644 --- a/lib/server/parse-udp.js +++ b/lib/server/parse-udp.js @@ -1,7 +1,7 @@ -module.exports = parseUdpRequest +import ipLib from 'ip' +import common from '../common.js' -const ipLib = require('ip') -const common = require('../common') +export default parseUdpRequest function parseUdpRequest (msg, rinfo) { if (msg.length < 16) throw new Error('received packet is too short') diff --git a/lib/server/parse-websocket.js b/lib/server/parse-websocket.js index 21b48fcb..5aeba9e1 100644 --- a/lib/server/parse-websocket.js +++ b/lib/server/parse-websocket.js @@ -1,6 +1,6 @@ -module.exports = parseWebSocketRequest +import common from '../common.js' -const common = require('../common') +export default parseWebSocketRequest function parseWebSocketRequest (socket, opts, params) { if (!opts) opts = {} diff --git a/lib/server/swarm.js b/lib/server/swarm.js index c3602133..9e3a0a20 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -1,7 +1,9 @@ -const arrayRemove = require('unordered-array-remove') -const debug = require('debug')('bittorrent-tracker:swarm') -const LRU = require('lru') -const randomIterate = require('random-iterate') +import arrayRemove from 'unordered-array-remove' +import Debug from 'debug' +import LRU from 'lru' +import randomIterate from 'random-iterate' + +const debug = Debug('bittorrent-tracker:swarm') // Regard this as the default implementation of an interface that you // need to support when overriding Server.createSwarm() and Server.getSwarm() @@ -159,4 +161,4 @@ class Swarm { } } -module.exports = Swarm +export default Swarm diff --git a/package.json b/package.json index 74f64391..afe4b7fd 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "bugs": { "url": "https://github.com/webtorrent/bittorrent-tracker/issues" }, + "type": "module", "dependencies": { "bencode": "^2.0.1", "bittorrent-peerid": "^1.3.3", @@ -60,7 +61,10 @@ "wrtc": "0.4.7" }, "engines": { - "node": ">=12" + "node": ">=12.20.0" + }, + "exports": { + "import": "./index.js" }, "keywords": [ "bittorrent", diff --git a/server.js b/server.js index 3bdbea71..3ef4349c 100644 --- a/server.js +++ b/server.js @@ -1,19 +1,21 @@ -const bencode = require('bencode') -const debug = require('debug')('bittorrent-tracker:server') -const dgram = require('dgram') -const EventEmitter = require('events') -const http = require('http') -const peerid = require('bittorrent-peerid') -const series = require('run-series') -const string2compact = require('string2compact') -const WebSocketServer = require('ws').Server - -const common = require('./lib/common') -const Swarm = require('./lib/server/swarm') -const parseHttpRequest = require('./lib/server/parse-http') -const parseUdpRequest = require('./lib/server/parse-udp') -const parseWebSocketRequest = require('./lib/server/parse-websocket') - +import bencode from 'bencode' +import Debug from 'debug' +import dgram from 'dgram' +import EventEmitter from 'events' +import http from 'http' +import peerid from 'bittorrent-peerid' +import series from 'run-series' +import string2compact from 'string2compact' +import ws from 'ws' + +import common from './lib/common.js' +import Swarm from './lib/server/swarm.js' +import parseHttpRequest from './lib/server/parse-http.js' +import parseUdpRequest from './lib/server/parse-udp.js' +import parseWebSocketRequest from './lib/server/parse-websocket.js' + +const { Server: WebSocketServer } = ws +const debug = Debug('bittorrent-tracker:server') const hasOwnProperty = Object.prototype.hasOwnProperty /** @@ -805,4 +807,4 @@ function toNumber (x) { function noop () {} -module.exports = Server +export default Server diff --git a/test/client-large-torrent.js b/test/client-large-torrent.js index a72f9cb0..db0d0fbf 100644 --- a/test/client-large-torrent.js +++ b/test/client-large-torrent.js @@ -1,7 +1,7 @@ -const Client = require('../') -const common = require('./common') -const fixtures = require('webtorrent-fixtures') -const test = require('tape') +import Client from '../index.js' +import common from './common.js' +import fixtures from 'webtorrent-fixtures' +import test from 'tape' const peerId = Buffer.from('01234567890123456789') diff --git a/test/client-magnet.js b/test/client-magnet.js index 7138cbd9..a6268b3f 100644 --- a/test/client-magnet.js +++ b/test/client-magnet.js @@ -1,8 +1,8 @@ -const Client = require('../') -const common = require('./common') -const fixtures = require('webtorrent-fixtures') -const magnet = require('magnet-uri') -const test = require('tape') +import Client from '../index.js' +import common from './common.js' +import fixtures from 'webtorrent-fixtures' +import magnet from 'magnet-uri' +import test from 'tape' const peerId = Buffer.from('01234567890123456789') diff --git a/test/client-ws-socket-pool.js b/test/client-ws-socket-pool.js index 4c041c2a..6d3fe1a3 100644 --- a/test/client-ws-socket-pool.js +++ b/test/client-ws-socket-pool.js @@ -1,7 +1,7 @@ -const Client = require('../') -const common = require('./common') -const fixtures = require('webtorrent-fixtures') -const test = require('tape') +import Client from '../index.js' +import common from './common.js' +import fixtures from 'webtorrent-fixtures' +import test from 'tape' const peerId = Buffer.from('01234567890123456789') const port = 6681 diff --git a/test/client.js b/test/client.js index 4ad16f85..c579058c 100644 --- a/test/client.js +++ b/test/client.js @@ -1,9 +1,9 @@ -const Client = require('../') -const common = require('./common') -const http = require('http') -const fixtures = require('webtorrent-fixtures') -const net = require('net') -const test = require('tape') +import Client from '../index.js' +import common from './common.js' +import http from 'http' +import fixtures from 'webtorrent-fixtures' +import net from 'net' +import test from 'tape' const peerId1 = Buffer.from('01234567890123456789') const peerId2 = Buffer.from('12345678901234567890') diff --git a/test/common.js b/test/common.js index 9bd098ed..5ff6ce39 100644 --- a/test/common.js +++ b/test/common.js @@ -1,6 +1,6 @@ -const Server = require('../').Server +import { Server } from '../index.js' -exports.createServer = (t, opts, cb) => { +export const createServer = (t, opts, cb) => { if (typeof opts === 'string') opts = { serverType: opts } opts.http = (opts.serverType === 'http') @@ -27,7 +27,7 @@ exports.createServer = (t, opts, cb) => { }) } -exports.mockWebsocketTracker = client => { +export const mockWebsocketTracker = client => { client._trackers[0]._generateOffers = (numwant, cb) => { const offers = [] for (let i = 0; i < numwant; i++) { @@ -38,3 +38,5 @@ exports.mockWebsocketTracker = client => { }) } } + +export default { mockWebsocketTracker, createServer } diff --git a/test/destroy.js b/test/destroy.js index 27d47605..e9d7af3a 100644 --- a/test/destroy.js +++ b/test/destroy.js @@ -1,7 +1,7 @@ -const Client = require('../') -const common = require('./common') -const fixtures = require('webtorrent-fixtures') -const test = require('tape') +import Client from '../index.js' +import common from './common.js' +import fixtures from 'webtorrent-fixtures' +import test from 'tape' const peerId = Buffer.from('01234567890123456789') const port = 6881 diff --git a/test/evict.js b/test/evict.js index a256a916..76967fd3 100644 --- a/test/evict.js +++ b/test/evict.js @@ -1,7 +1,7 @@ -const Client = require('../') -const common = require('./common') -const test = require('tape') -const wrtc = require('wrtc') +import Client from '../index.js' +import common from './common.js' +import test from 'tape' +import wrtc from 'wrtc' const infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705' const peerId = Buffer.from('01234567890123456789') diff --git a/test/filter.js b/test/filter.js index fee7dd77..4dc3da02 100644 --- a/test/filter.js +++ b/test/filter.js @@ -1,7 +1,7 @@ -const Client = require('../') -const common = require('./common') -const fixtures = require('webtorrent-fixtures') -const test = require('tape') +import Client from '../index.js' +import common from './common.js' +import fixtures from 'webtorrent-fixtures' +import test from 'tape' const peerId = Buffer.from('01234567890123456789') diff --git a/test/querystring.js b/test/querystring.js index 2ce20fe2..85e14e54 100644 --- a/test/querystring.js +++ b/test/querystring.js @@ -1,5 +1,5 @@ -const common = require('../lib/common') -const test = require('tape') +import common from '../lib/common.js' +import test from 'tape' // https://github.com/webtorrent/webtorrent/issues/196 test('encode special chars +* in http tracker urls', t => { diff --git a/test/request-handler.js b/test/request-handler.js index b60f9674..b24110fa 100644 --- a/test/request-handler.js +++ b/test/request-handler.js @@ -1,8 +1,8 @@ -const Client = require('../') -const common = require('./common') -const fixtures = require('webtorrent-fixtures') -const test = require('tape') -const Server = require('../server') +import Client from '../index.js' +import common from './common.js' +import fixtures from 'webtorrent-fixtures' +import test from 'tape' +import Server from '../server.js' const peerId = Buffer.from('01234567890123456789') diff --git a/test/scrape.js b/test/scrape.js index 047d2495..b702fc68 100644 --- a/test/scrape.js +++ b/test/scrape.js @@ -1,16 +1,15 @@ -const bencode = require('bencode') -const Client = require('../') -const common = require('./common') -const commonLib = require('../lib/common') -const commonTest = require('./common') -const fixtures = require('webtorrent-fixtures') -const get = require('simple-get') -const test = require('tape') +import bencode from 'bencode' +import Client from '../index.js' +import common from './common.js' +import commonLib from '../lib/common.js' +import fixtures from 'webtorrent-fixtures' +import get from 'simple-get' +import test from 'tape' const peerId = Buffer.from('01234567890123456789') function testSingle (t, serverType) { - commonTest.createServer(t, serverType, (server, announceUrl) => { + common.createServer(t, serverType, (server, announceUrl) => { const client = new Client({ infoHash: fixtures.leaves.parsedTorrent.infoHash, announce: announceUrl, @@ -52,7 +51,7 @@ test('ws: single info_hash scrape', t => { }) function clientScrapeStatic (t, serverType) { - commonTest.createServer(t, serverType, (server, announceUrl) => { + common.createServer(t, serverType, (server, announceUrl) => { const client = Client.scrape({ announce: announceUrl, infoHash: fixtures.leaves.parsedTorrent.infoHash, @@ -116,7 +115,7 @@ function clientScrapeMulti (t, serverType) { const infoHash1 = fixtures.leaves.parsedTorrent.infoHash const infoHash2 = fixtures.alice.parsedTorrent.infoHash - commonTest.createServer(t, serverType, (server, announceUrl) => { + common.createServer(t, serverType, (server, announceUrl) => { Client.scrape({ infoHash: [infoHash1, infoHash2], announce: announceUrl @@ -156,7 +155,7 @@ test('server: multiple info_hash scrape (manual http request)', t => { const binaryInfoHash1 = commonLib.hexToBinary(fixtures.leaves.parsedTorrent.infoHash) const binaryInfoHash2 = commonLib.hexToBinary(fixtures.alice.parsedTorrent.infoHash) - commonTest.createServer(t, 'http', (server, announceUrl) => { + common.createServer(t, 'http', (server, announceUrl) => { const scrapeUrl = announceUrl.replace('/announce', '/scrape') const url = `${scrapeUrl}?${commonLib.querystringStringify({ @@ -192,7 +191,7 @@ test('server: all info_hash scrape (manual http request)', t => { const binaryInfoHash = commonLib.hexToBinary(fixtures.leaves.parsedTorrent.infoHash) - commonTest.createServer(t, 'http', (server, announceUrl) => { + common.createServer(t, 'http', (server, announceUrl) => { const scrapeUrl = announceUrl.replace('/announce', '/scrape') // announce a torrent to the tracker diff --git a/test/server.js b/test/server.js index 0acfabd9..cb1095e1 100644 --- a/test/server.js +++ b/test/server.js @@ -1,7 +1,7 @@ -const Client = require('../') -const common = require('./common') -const test = require('tape') -const wrtc = require('wrtc') +import Client from '../index.js' +import common from './common.js' +import test from 'tape' +import wrtc from 'wrtc' const infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705' const peerId = Buffer.from('01234567890123456789') diff --git a/test/stats.js b/test/stats.js index 74128c2f..3ffa3fe3 100644 --- a/test/stats.js +++ b/test/stats.js @@ -1,8 +1,8 @@ -const Client = require('../') -const commonTest = require('./common') -const fixtures = require('webtorrent-fixtures') -const get = require('simple-get') -const test = require('tape') +import Client from '../index.js' +import commonTest from './common.js' +import fixtures from 'webtorrent-fixtures' +import get from 'simple-get' +import test from 'tape' const peerId = Buffer.from('-WW0091-4ea5886ce160') const unknownPeerId = Buffer.from('01234567890123456789')