Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ardeois
Copy link
Contributor

@ardeois ardeois commented Jan 16, 2017

Fixes #167

Since version 0.4.9, we require fs but it should fail if we are in
a browser. However, browser-source-map-support.js is bundled with
browserify which converts unsupported builtins to empty object. See
https://github.com/substack/node-browserify/blob/8f5ebbf505/lib/builtins.js#L12
This PR checks if required fs contains readFileSync which is part
of fs API.

Tests:

npm run build && npm run serve-tests

Then open http://127.0.0.1:1336/browser-test/

Copy link
Collaborator

@LinusU LinusU left a comment

Choose a reason for hiding this comment

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

Thank you for this, just a few nits

fs = require('fs');
fs = require('fs');
if (!fs.readFileSync) {
// If fs is empty, we are in the browser
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, it's not empty, it's: https://www.npmjs.com/package/browserify-fs

How about:

try {
  fs = require('fs');
  if (!fs.existsSync || !fs.readFileSync) {
    // fs doesn't have all methods we need
    fs = null;
  }
} catch (err) {
  /* noop */
}

also, please keep the indentation at 2 spaces :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well we don't use browserify-fs plugin so without this it we don't have a functionnal fs.
node-browserify default builtins are defined here https://github.com/substack/node-browserify/blob/8f5ebbf50544bdbdf34d4e0f336ac531152a5da4/lib/builtins.js

For the code comment I'll fix that right away

@ardeois
Copy link
Contributor Author

ardeois commented Jan 16, 2017

@LinusU comments applied and commit amended

Fixes #167

Since version 0.4.9, we require `fs` but it should fail if we are in
a browser. However, `browser-source-map-support.js` is bundled with
browserify which converts unsupported builtins to empty object. See
https://github.com/substack/node-browserify/blob/8f5ebbf505/lib/builtins.js#L12
This PR checks if required `fs` contains `readFileSync` which is part
of `fs` API.
@ardeois
Copy link
Contributor Author

ardeois commented Jan 16, 2017

Amended again for 2 spaces indentation
@LinusU can you please review?

@@ -4,6 +4,10 @@ var path = require('path');
var fs;
try {
fs = require('fs');
if (!fs.readFileSync || !fs.readFileSync) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a typo here, one of them should be existsSync

@oskarols
Copy link

Chiming in with that this is breaking https://github.com/tschaub/karma-source-map-support for us. Would be most grateful for a fix :)

@ludovicthomas
Copy link

Same issue for me. Would be nice to have a fix merged quickly.

@ardeois
Copy link
Contributor Author

ardeois commented Jan 17, 2017

@LinusU oops sorry for that. Just fixed it.

@LinusU
Copy link
Collaborator

LinusU commented Jan 17, 2017

Thanks!

@LinusU LinusU merged commit ce4cb35 into evanw:master Jan 17, 2017
@LinusU
Copy link
Collaborator

LinusU commented Jan 17, 2017

Released as 0.4.10

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.

4 participants