From 83873a9e707691a0afb8af34b3b07824b6e84f01 Mon Sep 17 00:00:00 2001 From: Cas <6506529+ThaUnknown@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:32:11 +0100 Subject: [PATCH] feat: esm (#87) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: ESM only * feat: esm * Update index.js Co-authored-by: Diego Rodríguez Baquero Co-authored-by: Diego Rodríguez Baquero --- index.js | 16 +++++++++------- package.json | 10 ++++++++-- test/announce.js | 8 ++++---- test/basic.js | 8 ++++---- test/reuse-dht.js | 8 ++++---- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 2966b34b..df39bcd7 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,12 @@ /*! torrent-discovery. MIT License. WebTorrent LLC */ -const debug = require('debug')('torrent-discovery') -const DHT = require('bittorrent-dht/client') // empty object in browser -const EventEmitter = require('events').EventEmitter -const parallel = require('run-parallel') -const Tracker = require('bittorrent-tracker/client') -const LSD = require('bittorrent-lsd') +import Debug from 'debug' +import DHT from 'bittorrent-dht/client.js' // empty object in browser +import { EventEmitter } from 'events' +import parallel from 'run-parallel' +import Tracker from 'bittorrent-tracker/client.js' +import LSD from 'bittorrent-lsd' + +const debug = Debug('torrent-discovery') class Discovery extends EventEmitter { constructor (opts) { @@ -219,4 +221,4 @@ class Discovery extends EventEmitter { } } -module.exports = Discovery +export default Discovery diff --git a/package.json b/package.json index 0fd0e794..83fc9f10 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,14 @@ "url": "https://webtorrent.io" }, "browser": { - "bittorrent-dht/client": false, + "bittorrent-dht/client.js": false, "bittorrent-lsd": false }, "chromeapp": {}, "bugs": { "url": "https://github.com/webtorrent/torrent-discovery/issues" }, + "type": "module", "dependencies": { "bittorrent-dht": "^10.0.7", "bittorrent-tracker": "^9.19.0", @@ -44,7 +45,12 @@ "peer discovery" ], "license": "MIT", - "main": "index.js", + "engines": { + "node": ">=12.20.0" + }, + "exports": { + "import": "./index.js" + }, "repository": { "type": "git", "url": "git://github.com/webtorrent/torrent-discovery.git" diff --git a/test/announce.js b/test/announce.js index 9b2efd18..8b0c95ea 100644 --- a/test/announce.js +++ b/test/announce.js @@ -1,7 +1,7 @@ -const DHT = require('bittorrent-dht') -const Discovery = require('../') -const randombytes = require('randombytes') -const test = require('tape') +import DHT from 'bittorrent-dht' +import Discovery from '../index.js' +import randombytes from 'randombytes' +import test from 'tape' test('initialize with dht', t => { t.plan(5) diff --git a/test/basic.js b/test/basic.js index a2fd61a0..5cfce0bb 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,7 +1,7 @@ -const Discovery = require('../') -const DHT = require('bittorrent-dht') -const randombytes = require('randombytes') -const test = require('tape') +import Discovery from '../index.js' +import DHT from 'bittorrent-dht' +import randombytes from 'randombytes' +import test from 'tape' test('initialize with dht', t => { t.plan(1) diff --git a/test/reuse-dht.js b/test/reuse-dht.js index 283a2e66..26da6bb6 100644 --- a/test/reuse-dht.js +++ b/test/reuse-dht.js @@ -1,7 +1,7 @@ -const Discovery = require('../') -const DHT = require('bittorrent-dht') -const randombytes = require('randombytes') -const test = require('tape') +import Discovery from '../index.js' +import DHT from 'bittorrent-dht' +import randombytes from 'randombytes' +import test from 'tape' test('re-use dht, verify that peers are filtered', t => { t.plan(5)