Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bankai rewrite #241

Merged
merged 51 commits into from
Sep 28, 2017
Merged

Bankai rewrite #241

merged 51 commits into from
Sep 28, 2017

Conversation

yoshuawuyts
Copy link
Member

@yoshuawuyts yoshuawuyts commented Sep 20, 2017

Everything is new! Would be cool if people could take this for a test ride so we can fix bugs. Thanks!

Bankai start

bankai2

Bankai build

bankai3

Known issues

  • SIGTERM can leave the cursor as hidden
  • extracting critical CSS does only detects classes, not tag name selectors
  • reloading scripts for SSR in document can crash, causing stale builds
  • SIPHASH24 sometimes generates a new hash for the same files (could be our browserify pipeline too, need to investigate)

var os = require('os')

var selfsigned = require('selfsigned')
var getPort = require('getPort')
Copy link
Member

@goto-bus-stop goto-bus-stop Sep 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ node ../../choojs/bankai/bin.js app.js
module.js:529
    throw err;
    ^

Error: Cannot find module 'getPort'

This require should be all lowercase getport for case sensitive file systems

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch; thanks!

@YerkoPalma
Copy link
Member

Seems like tests are not passing for node 4


function handleScripts () {
log.info('scripts', 'reloading')
window.location.reload()
Copy link
Contributor

@bendik bendik Sep 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reloading causes a SSE connection broken error in console, at least in Firefox.
How about adding this?

window.addEventListener('beforeunload', function (event) {
  source.close()
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, fixed! :D

@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Sep 20, 2017

Looks like this is caused by npm rather than Node versions. It seems that for whatever reason the documents:list event never fires; not sure why.

@ajoslin
Copy link

ajoslin commented Sep 20, 2017

With this and @goto-bus-stop's work, Browserify is becoming the best choice again, like it used to be :)

Big thanks Yosh, I can't wait to try this out.

@thlorenz
Copy link

I may have the solution for your cursor problem. Wrote this a while back when I ran into similar problems. Not sure if it'll handle SIGTERM though (it has been a while).

@yoshuawuyts
Copy link
Member Author

@thlorenz thanks for the pointer, fixed the cursor issue :D

@jbergstroem
Copy link
Contributor

FWIW this doesn't work great with pnpm (npm replacement). Likely due to a missing dep and npm's flattening assumptions. I can't look into this right now -- expect tomorrow.

~/oss/bankai $ ./bin.js build -d example
14:30:17 ✨  created: ./dist
14:30:17 🚨  bankai.asset: could not find a file for 
14:30:17 ✨  created: ./dist/manifest.json
 
~/oss/bankai ±pr/241 $ echo $?
0

@yoshuawuyts
Copy link
Member Author

@jbergstroem !!! that's great news; I thought it might be a missing file, but dependency-check didn't return any positives. Given this is true, it would fix it for node@4 too! :D

@YerkoPalma
Copy link
Member

There are some options that now are not supported by bankai. Are they completly erased now? for instance the port and address options? Also there are differences from the api and the cli, for instance, how could you manipulate assets path from the cli? it seems that you can't but it can be done with the node api

@jbergstroem
Copy link
Contributor

This is also a bit concerning imo (slow):

$ time node bin.js   
  Please specify a bankai command:
    $ bankai <command>

  For example:
    $ bankai start index.js

  Run bankai --help to see all options.
node bin.js  0.84s user 0.11s system 101% cpu 0.940 total

$ time npm help   
<snip>
npm help  0.19s user 0.07s system 76% cpu 0.337 total

@yoshuawuyts
Copy link
Member Author

@YerkoPalma Ports are now automatically generated (8080-9000). The assets path has become more of a convention thing - picking up assets/ and content/. We haven't set extra paths yet for the JS API, but I think that'd be a good addition - although if you have some common paths in mind we could add those to the CLI too

@jbergstroem made the imports in bin.js dynamic; should be sped up by a whole bunch!

@jbergstroem
Copy link
Contributor

I seem to be getting different hashing (clean repo). MacOS 10.13 17A362a, node 8.5.0:

not ok 34 ·· ·· <script src="/scripts/c4bc18653915ae8c/bundle.js" defer>
  ---
    operator: equal
    expected: '<script src="/scripts/c4bc18653915ae8c/bundle.js" defer>'
    actual:   '<script src="/scripts/75023dc608219a4e/bundle.js" defer>'
    at: assertHtml (/Users/jbergstroem/wrk/oss/bankai/node_modules/assert-html/index.js:82:15)

@YerkoPalma
Copy link
Member

I'm cool with conventions, I just didn't see it in the readme so I had to dig into the code to find out that the cli use by default assets/ and content/ (to be added) as assets path. Maybe a changelog could be useful (another question, what about the electron mode?).

@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Sep 20, 2017

@jbergstroem bizarre; that could only be if for some reason WASM is acting up, the input files have changed, or like the algo isn't working. Dep for that is in https://github.com/yoshuawuyts/buffer-graph/ and https://github.com/mafintosh/siphash24 - we might need to switch to blake2b tbh; will probably be more stable

edit: it definitely sounds as if the files have somehow changed; looked at the WASM function and it should be deterministic. Urgh, I'm not sure why the input files would change tho :/

@jbergstroem
Copy link
Contributor

jbergstroem commented Sep 20, 2017

@yoshuawuyts you probs want this:

--- a/test/service-worker.js      2017-09-20 18:39:16.000000000 -0300
+++ b/test/service-worker.js  2017-09-20 18:39:11.000000000 -0300
@@ -47,7 +47,7 @@
     assert.ok(res.hash, 'output hash exists')
   })
 
-  compiler.script('bundle.js', function (err, res) {
+  compiler.scripts('bundle.js', function (err, res) {
     assert.error(err, 'no error writing script')
     rimraf.sync(tmpDirname)
   })
@@ -72,7 +72,7 @@
     assert.ok(res, 'output exists')
   })
 
-  compiler.script('bundle.js', function (err, res) {
+  compiler.scripts('bundle.js', function (err, res) {
     assert.error(err, 'no error writing script')
     rimraf.sync(tmpDirname)
   })

..and add it to index.js?

@jbergstroem
Copy link
Contributor

@yoshuawuyts said:
it definitely sounds as if the files have somehow changed

At least the repo is intact:

$ rm -rf node_modules && npm i -q && git reset --hard && node test/document.js 

> [email protected] install /Users/jbergstroem/wrk/oss/bankai/node_modules/fsevents
> node install

[fsevents] Success: "/Users/jbergstroem/wrk/oss/bankai/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
added 885 packages in 46.893s
HEAD is now at e6f1152 make it fast
<snip>
not ok 31 ·· ·· <script src="/scripts/c4bc18653915ae8c/bundle.js" defer>
  ---
    operator: equal
    expected: '<script src="/scripts/c4bc18653915ae8c/bundle.js" defer>'
    actual:   '<script src="/scripts/75023dc608219a4e/bundle.js" defer>'
    at: assertHtml (/Users/jbergstroem/wrk/oss/bankai/node_modules/assert-html/index.js:82:15)
    stack: |-
      Error: ·· ·· <script src="/scripts/c4bc18653915ae8c/bundle.js" defer>
          at Test.assert [as _assert] (/Users/jbergstroem/wrk/oss/bankai/node_modules/tape/lib/test.js:212:54)
          at Test.bound [as _assert] (/Users/jbergstroem/wrk/oss/bankai/node_modules/tape/lib/test.js:64:32)
          at Test.equal.Test.equals.Test.isEqual.Test.is.Test.strictEqual.Test.strictEquals (/Users/jbergstroem/wrk/oss/bankai/node_modules/tape/lib/test.js:347:10)
          at Test.bound [as equal] (/Users/jbergstroem/wrk/oss/bankai/node_modules/tape/lib/test.js:64:32)
          at assertHtml (/Users/jbergstroem/wrk/oss/bankai/node_modules/assert-html/index.js:82:15)
          at /Users/jbergstroem/wrk/oss/bankai/test/document.js:99:5
          at /Users/jbergstroem/wrk/oss/bankai/index.js:127:5
          at /Users/jbergstroem/wrk/oss/bankai/lib/queue.js:24:5
          at Array.forEach (<anonymous>)
          at Queue.ready (/Users/jbergstroem/wrk/oss/bankai/lib/queue.js:23:13)
  ...

@s3ththompson
Copy link
Member

This looks amazing! So excited to swap it out in my current projects.

Would be nice if there was a quick JS API migration guide... should I just copy over the contents of cmd-start? Do you plan to leave handling gzip and content-type headers at the userland level?

@yoshuawuyts
Copy link
Member Author

@s3ththompson oh boy; yeah so the whole API was rewritten from scratch. I'm not sure how much of a migration guide could exist, I'd mostly just suggest to read the docs.

That said, we should probably document the different directories we look for; same for files. Probably also document some of the flags that aren't documented yet (watch, reload), and errr - yeah that's about it? On it! 😁

@sholtomaud
Copy link
Contributor

Can I suggest some little attention to #242 & #243 before pulling. Sorry. But many ★★★★★ for the direction.

@yoshuawuyts
Copy link
Member Author

@jondashkyle thanks for pointing these out!


  • entry file: I can't think of a way around this at the moment. Even if we'd allow you to pass a --basedir flag to set a basedir, we'd run into trouble. At the moment the only way to approach this I can recommend would be to move index.js to the root of your project. Sorry :(
  • large files: yeah, was worried this might happen. Node only has, like 1.5GB of memory - anything beyond that would make it crash. You might want to try again, because we just moved off the WASM build (which might be what caused your crash to happen) and onto a regular JS one. The longer term solution for this will probably be to never copy the asset files into memory tho (especially with stuff like video, haha).
  • live reload: yeah, noticed that too. I think after this patch lands, and we get some of the other bugs fixed we should do a pass on performance. I'm pretty sure we can speed this up!

Hope this makes sense; thanks again for chiming in! ✨

@yoshuawuyts
Copy link
Member Author

Hmmmmm, we definitely seem to be having some sort of race condition in our test somewhere. Something is throwing off the hash of bundle.js- but only sometimes

var url = req.url
compiler.documents(url, function (err, node) {
if (err) {
return compiler.documents('/404', function (err, node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was just looking this over trying to implement a default: you've got two err, the other one should probably be error or something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o/ Thanks for reporting - this is fine tho! The closures work alright in this case; there's no bugs here (:

@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Sep 27, 2017

Soooo, all boxes are ticked for an initial beta release? Can people please verify this works on their code?

Biggest follow ups for next patches in the beta will be:

  • improve our error story. Right now if a crash happens, it can fail without warning which is super frustrating for people
  • figure out a better story for assets, so we don't overflow memory
  • perhaps sneak in stuff like pack-flat for browserify, if source maps get the fix
  • figure out pre-gyp on Windows for .br files; this one's tricky.

Holler if I've missed anything! Thanks all 😁

@yoshuawuyts
Copy link
Member Author

TESTS ARE PASSING. SSR RELOADING WORKS. The time for final reviews is now. Unless something is totally broken for someone here, we should be good to merge and put out an initial beta release! 🎉

@ajoslin
Copy link

ajoslin commented Sep 27, 2017

@yoshuawuyts errors are still not being outputted, both for bankai start and bankai build.

@s3ththompson
Copy link
Member

s3ththompson commented Sep 27, 2017

@yoshuawuyts same wasm RangeError with blake2b (will open issue). can we start with a pure JS solution and upgrade to wasm when the kinks are worked out? i think there are still some subtle issues with wasm heap size that require some investigation...

FWIW, @jbergstroem's original PR worked for me with blakejs

@jbergstroem
Copy link
Contributor

jbergstroem commented Sep 27, 2017

@yoshuawuyts sorry to say that hashing still seems to be a problem. I don't have too much time to dedicate to this but I'll make an attempt at debugging it soon.

Edit: I guess this doesn't have too big a significance seeing how its primary job is bundling assets, not consistently naming folders. I'd expect an issue to be opened though.

@yoshuawuyts
Copy link
Member Author

@ajoslin you're totally right; hope this is better!

screen shot 2017-09-28 at 15 33 32

@yoshuawuyts
Copy link
Member Author

Okay, so I'm not thrilled about the lastest pass on errors - but getting it 100% right means implementing proper progress bar logic, more control over re-rendering, and a partial rewrite of the way we create UI (might need to ditch ansi-diff-stream). It's a little over the top haha.

So kinda feel that for now error handling is good enough for a beta; going to fix the blake2b error and then we should be good!

@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Sep 28, 2017

@s3ththompson reverted the change, range error should be fixed again!


time to release

Welp, that concludes this lil episode. Gonna merge this patch and publish as a beta release. Any feedback can be sent to #246. Thanks!

@yoshuawuyts yoshuawuyts merged commit 38df6f9 into master Sep 28, 2017
@yoshuawuyts yoshuawuyts deleted the new-new-new branch September 28, 2017 16:53
@yoshuawuyts
Copy link
Member Author

📦 v9.0.0-rc1

@s3ththompson
Copy link
Member

@yoshuawuyts RangeError fixed! thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.