FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update 'buffer' to v5.x by feross · Pull Request #1678 · browserify/browserify · GitHub

Update 'buffer' to v5.x - #1678

Merged
feross merged 2 commits into
masterfrom
buffer-5
Jan 25, 2017
Merged

feross merged 2 commits into
masterfrom
buffer-5

Conversation

feross commented Jan 24, 2017 •
edited
Loading

Copy link
Copy Markdown
Member

Browser support

buffer v5.x drops support for IE8-10.

This allows us to remove the Object implementation and rely on a single
fast implementation based on Typed Arrays, greatly simplifying the maintanence of the
buffer package.

Typed arrays are supported by 97.08% of the U.S. browser market and 92.02% of the
global browser market. Source: http://caniuse.com/#search=typed This number
continues to increase at a steady rate each month.

If IE8-10 support is critical to your web app, you can continue to rely on
browserify v13.

Bundle size

This change shrinks the size of buffer modestly.

55.1kb -> 52.1kb (full size, with comments)
7.0kb -> 6.7kb (minified, gzipped)

Bug fixes

buffer v5.x contains several important fixes including:

Semver

This should be released as semver major.

ghost commented Jan 25, 2017 •
edited by ghost
Loading

Copy link
Copy Markdown

This looks good to me. Another option for users would be to depend on the buffer package explicitly or to do:

npm install buffer@^4
browserify -r buffer/:buffer main.js > bundle.js

Users can also include a typed array polyfill: https://github.com/inexorabletash/polyfill/blob/master/typedarray.js

buffer v5 requires Uint8Array to be defined. apparently it is
not defined by default in node v0.10.
feross merged commit d7ea3dd into master Jan 25, 2017
feross deleted the buffer-5 branch January 25, 2017 04:23

lorenzos commented Jan 25, 2017 •
edited
Loading

Copy link
Copy Markdown

Sorry to bother you, but I'm not sure if this means IE8-10 compatibility is compromised for every bundle I build using browserify, of it's only when I use require('buffer') in my app (which I don't). Can you clarify, please?

ghost commented Jan 25, 2017

Copy link
Copy Markdown

This patch only affects when your code uses Buffer as a global or when you (or some module you use) does require('buffer').

feross commented Jan 25, 2017 •
edited
Loading

Copy link
Copy Markdown
Member Author

@lorenzos One way to quickly find out of you're using Buffer in your app (even indirectly) is to grep your bundle file for a string that appears in buffer/index.js, like "TYPED_ARRAY_SUPPORT".

If running grep "TYPED_ARRAY_SUPPORT" bundle.js returns nothing then buffer is not included in your bundle.js.

JDvorak commented Jan 26, 2017 •
edited
Loading

Copy link
Copy Markdown

Is there a recommended solution for those of us who are targeting audiences restricted to those versions of IE (e.g. certain federal agencies of the USA)? Sticking to v13 is only a viable option if hotfixes can be expected if security problems arise.

feross commented Jan 26, 2017

Copy link
Copy Markdown
Member Author

@JDvorak Browserify usually runs in development (as a build step), not on production servers, so security issues are unlikely.

To continue using an older version of buffer, you can do the following:

$ npm install buffer@4 --save
$ browserify -r buffer/:buffer main.js > bundle.js

feross commented Jan 26, 2017 •
edited
Loading

Copy link
Copy Markdown
Member Author

@JDvorak Out of curiosity, what is the oldest version of IE that government agencies (or your agency) is required to support?

Copy link
Copy Markdown

@substack @feross Thank you very much for your explanation, I checked with grep, I do not use it.

JDvorak commented Jan 26, 2017 via email •
edited
Loading

Copy link
Copy Markdown

Copy link
Copy Markdown

IE10 supports Uint8Array so it should work on IE10, only IE8 and IE9 is left behind.

Copy link
Copy Markdown

Anyway, IE8 support was dropped when introduced Array.isArray method in 13.0.1.

JDvorak commented Jan 30, 2017 via email

Copy link
Copy Markdown

feross commented Jan 31, 2017 •
edited
Loading

Copy link
Copy Markdown
Member Author

@tgabi333 Unfortunately, IE10's Uint8Array support is buggy, where sometimes slice() returns the wrong length buffer. This gave us trouble to make buffer pass all the tests from Node.js core, so IE10 was actually also using the Object implementation before buffer v5.

I thought about letting IE10 use the typed array implementation now -- since a buggy implementation would be better than none. But IE10 also lacks support for __proto__, which makes it difficult to subclass typed arrays with the methods we need for buffer.

boneskull added a commit to mochajs/mocha that referenced this pull request Sep 27, 2017
boneskull added a commit to mochajs/mocha that referenced this pull request Sep 27, 2017
boneskull added a commit to mochajs/mocha that referenced this pull request Sep 27, 2017
boneskull added a commit to mochajs/mocha that referenced this pull request Sep 28, 2017
boneskull added a commit to mochajs/mocha that referenced this pull request Sep 29, 2017
boneskull added a commit to mochajs/mocha that referenced this pull request Sep 29, 2017
boneskull added a commit to mochajs/mocha that referenced this pull request Sep 29, 2017

dwighthouse commented Jan 30, 2019 •
edited
Loading

Copy link
Copy Markdown

This looks good to me. Another option for users would be to depend on the buffer package explicitly or to do:

npm install buffer@^4
browserify -r buffer/:buffer main.js > bundle.js

@substack How do you accomplish this buffer replacement with buffer 4 when using the Browserify API, not command line? This doesn't appear to work:

var b = browserify({
    entries: testEntry,
    debug: false,
});
b.require('buffer/:buffer');
b.transform('babelify', {
    plugins: [
        ['module-resolver', { root: [rootPath] }],
        'babel-plugin-transform-esm-to-cjs',
    ],
});

It errors out: Error: Cannot find module 'buffer/:buffer'

I'm trying to use Tape with older browsers, which recommends Browserify as the build tool, which thanks to this PR, no longer supports older IEs, as described here.

ljharb commented Jan 30, 2019

Copy link
Copy Markdown
Member

One way or another, we need to restore IE support of packages using Buffer by default here. What paths are available?

Copy link
Copy Markdown

Also, I hesitate to use the method of adding a global polyfill for Uint8Array or some other type not supported in older browsers, since my library is focused on types themselves. Having these polyfills globally visible could affect the purity of my testing environment, which already falls back when certain types are not detected.

Alternatively, I could increase the complexity of my type testing to check un-polyfillable parts of the types.

goto-bus-stop commented Jan 30, 2019 •
edited
Loading

Copy link
Copy Markdown
Member

FWIW, the API equivalent to -r buffer/:buffer is

b.require(require.resolve('buffer/'), { expose: 'buffer' })

Copy link
Copy Markdown

@goto-bus-stop Thank you. This code does indeed cause the older version of Buffer to be used. However, it also causes the start of the built file to contain:

"use strict";

require = function () {
...

Since it's in strict mode, and require isn't already defined in the file, this causes an error: Uncaught ReferenceError: require is not defined.

Changing it manually to use the window reference does work, however:

"use strict";

window.require = function () {
...

However, having to manually go in and do string replacements on built files is a bad precedent.

I don't need to expose buffer externally, only do the reference swap as described above. I'm curious why Browserify would create invalid code here.

goto-bus-stop commented Jan 30, 2019 •
edited
Loading

Copy link
Copy Markdown
Member

is your build process adding "use strict" somehow? bare browserify should not do that. browserify's code is not invalid, but it doesn't work in strict mode. it does not add "use strict" to bundles because not every node module expects to be run in strict mode. Modules that do expect it already contain "use strict" at the top, and browserify correctly keeps that in each individual module.

I don't need to expose buffer externally, only do the reference swap as described above.

this is indeed a side effect of the current 'solution' for aliasing, and it's not ideal.

Copy link
Copy Markdown

@goto-bus-stop You are right. One instance of Babel was adding it.

Ouch, ok.

sgilroy pushed a commit to TwineHealth/mocha that referenced this pull request Feb 27, 2019

ghost commented May 4, 2020

Copy link
Copy Markdown

i have the same problem any solution please.i use truffle drizzle-react-native

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL