Closed btimby closed 3 years ago
Looks cool, I will review this. Feel free to poke me in a few days if I haven't done it. Thanks!
@btimby this LGTM but I'm running into a build issue I can't resolve. For some reason the minify
stage is throwing an error on my local. Hope to get this merged soon.
Is the error:
$ npm run-script minify
> bugout@0.0.10 minify /home/btimby/Code/bugout
> cat bugout.js | minify > bugout.min.js
cat: bugout.js: No such file or directory
If so:
$ git diff package.json
diff --git a/package.json b/package.json
index 43b5205..db26d35 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,7 @@
},
"scripts": {
"build": "npm run compile && npm run minify",
- "minify": "cat bugout.js | minify > bugout.min.js",
+ "minify": "cat index.js | minify > bugout.min.js",
"compile": "browserify -s Bugout index.js > bugout.js",
"disc": "browserify -s Bugout --full-paths index.js | discify > disc.html",
"size": "npm run build && cat bugout.min.js | gzip | wc -c",
No, bugout.js
is easily generated with npm run compile
. The error is the following:
$ npm run minify
> bugout@0.0.10 minify /home/chrism/dev/bugout
> cat bugout.js | minify > bugout.min.js
TypeError: unknown: Cannot read property 'add' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bugout@0.0.10 minify: `cat bugout.js | minify > bugout.min.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bugout@0.0.10 minify script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I suspect something is b0rked with the minify
binary on my path but I can't figure out what it is.
Disregard, I see now that minify depends on compile. Sorry. Guessing you are getting this:
$ npm run-script minify
> bugout@0.0.10 minify /home/btimby/Code/bugout
> cat bugout.js | minify > bugout.min.js
TypeError: unknown: Cannot read property 'add' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bugout@0.0.10 minify: `cat bugout.js | minify > bugout.min.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bugout@0.0.10 minify script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/btimby/.npm/_logs/2021-02-20T03_38_47_733Z-debug.log
The weird thing is I get this error even if I check out old versions so it must be something on my system.
Ah ok, you're getting it too. Maybe it's an issue with browserify. Hmm.
This issue may help: https://github.com/babel/minify/issues/974, specifically the last comment referencing: https://babeljs.io/docs/en/babel-plugin-transform-parameters
@draeder thanks very much, that led me to the same workaround the webtorrent project used.
This change allows a caller to utilize an existing
Torrent
instance. For my project, this is desirable because I am using the torrent to distribute the content of a web application, and using bugout to allow the application to communicate between client / server.Basically, I allow the caller to seed or add a torrent, then instantiate
Bugout
on top of the torrent. I also modified thedestroy
method to leave the torrent intact if it was provided by the caller. I added a test to ensure the provided torrent is used. I updated the documentation to mention the new option.Here is an example of how I am using this functionality:
First, on the server-side, I seed the torrent: https://github.com/btimby/ug/blob/master/src/engine/server.js#L312
Then instantiate Bugout, this is done in the
seed()
callback, which is fairly late, but it works: https://github.com/btimby/ug/blob/master/src/engine/server.js#L99On the client-side, I
add()
the torrent, then instantiateBugout
, allowing it to wire up the protocol extension before fetching the torrent contents. https://github.com/btimby/ug/blob/master/src/engine/server.js#L331Please let me know if I missed anything or made any mistakes.