Require Buffer rather than expecting a global #132

Open
kemitchell wants to merge 1 commit from kemitchell/require-buffer into master
kemitchell commented 2021-12-21 23:41:55 +00:00 (Migrated from github.com)

This tiny PR adds const Buffer = require('buffer').Buffer; to the top of lib/util.js, so that util.js can call Buffer.from without relying on Buffer being a global. This allows code bundlers and other static analyzers to detect the use of Buffer and shim it (e.g. with npm:buffer) if it is not part of the target environment, such as when bundling for web browsers.

I suspect this approach might satisfy some of the people describing hold-ups in #68. I have been able to use this fork to bundle gray-matter with esbuild without error.

I would be comfortable publishing this with a patch-level version bump.

This tiny PR adds `const Buffer = require('buffer').Buffer;` to the top of `lib/util.js`, so that `util.js` can call `Buffer.from` without relying on `Buffer` being a global. This allows code bundlers and other static analyzers to detect the use of Buffer and shim it (e.g. with [npm:buffer](https://www.npmjs.com/package/buffer)) if it is not part of the target environment, such as when bundling for web browsers. I suspect this approach might satisfy some of the people describing hold-ups in #68. I have been able to use this fork to bundle gray-matter with esbuild without error. I would be comfortable publishing this with a patch-level version bump.
firmart commented 2021-12-23 02:20:50 +00:00 (Migrated from github.com)

I just upgraded react-scripts to v5 and hit #68. For now, I added temporarily global.Buffer = global.Buffer || require('buffer').Buffer; in my codebase, but would appreciate this PR be merged to solve the issue.

I just upgraded `react-scripts` to v5 and hit #68. For now, I added temporarily `global.Buffer = global.Buffer || require('buffer').Buffer;` in my codebase, but would appreciate this PR be merged to solve the issue.
segevfiner commented 2023-04-20 19:23:47 +00:00 (Migrated from github.com)

@jonschlinkert Are you still maintaining this library? It would be quite helpful to get this merged so it can work with modern WebPack 5+, Vite, and so on, which no longer include node shims by default. There are also several other PRs that help keep this library in shape that you might want look at.

@jonschlinkert Are you still maintaining this library? It would be quite helpful to get this merged so it can work with modern WebPack 5+, Vite, and so on, which no longer include node shims by default. There are also several other PRs that help keep this library in shape that you might want look at.
This pull request has changes conflicting with the target branch.
  • lib/utils.js
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin kemitchell/require-buffer:kemitchell/require-buffer
git switch kemitchell/require-buffer
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rtlabs-llm-agents/gms-gray-matter!132
No description provided.