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

Script files don't work with Browserify (they aren't automatically embedded) #29

Closed
mitchhentges opened this issue May 5, 2016 · 4 comments
Labels
wontfix This will not be worked on

Comments

@mitchhentges
Copy link

mitchhentges commented May 5, 2016

win-detect-browsers invokes two scripts at runtime to find browser information: regListStream.wsf and stream.wsf. You can see one of these used here.

browserify works by taking a bunch of JS and putting it into a single bundle. However, external files aren't automatically bundled. It looks like they can be, though.

So, any browserify'd apps that are using win-detect-browsers won't work at runtime on other computers. However, unless __dirname is replaced, they will appear to work on development machines. This actually dinged us for our Electron app, James.

@vweevers
Copy link
Owner

Can you explain why you need to browserify for electron?

In any case, this is a tooling problem. Not for win-detect-browsers to solve. Note you can make a browserify bundle without overriding node.js builtins (fs etc). Would this work for you?

browserify --bare --no-detect-globals index.js > bundle.js

@mitchhentges
Copy link
Author

Two things: First, I'm using browserify with electron because it shrinks the overall file size by about 20x. Even when just packaging non-dev-dependencies, the app's index.js grows from 2.5MB to ~50MB. This isn't even counting speed benefits at compile-time and runtime.

Additionally, even if it wasn't browserified, the app is packaged into an asar archive as part of the packaging process. I did a small test where I put stream.wsf, util.vbs and friends in the root of the archive. Since a path argument is being supplied to the cscript binary, cscript still wasn't able to use the files, because they're hiding in the asar archive.

I'm learning about the challenges and alternatives as I investigate this issue, so I might be completely missing an obvious solution.

@vweevers
Copy link
Owner

As it is, you're gonna have to extract those files.

I haven't had the time to finish it, but the next version of win-detect-browsers is more modular, so maybe it'll be easier to meet your needs then. Someone could make "browser"-friendly versions of the windows scripting parts. E.g.:

  1. Read every script into memory, in a brfs compatible manner: var code = fs.readFileSync(__dirname + "/script.js", "utf8")
  2. Before spawning cscript, write the code to a temporary file, then do cscript tmp.js.

(I don't want to do this by default).

@vweevers
Copy link
Owner

As it is, you're gonna have to extract those files.

And additionally, when browserifying, use a custom value for __dirname, in a way that win-detect-browsers will be able to find the extracted files. See: insert-custom-globals and the default __dirname implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants