New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rollup-plugin-node-globals

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-node-globals

insert the same globals browserify does

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
decreased by-13.17%
Maintainers
1
Weekly downloads
 
Created
Source

rollup-plugin-node-globals

Plugin to insert node globals including so code that works with browserify should work even if it uses process or buffers. This is based on rollup-plugin-inject .

  • process
  • global
  • Buffer
  • __dirname
  • __filename

Plus process.nextTick and process.browser are optimized to only pull in themselves and __dirname and __filename point to the file on disk

There are a few options to control output

  • process - pass false to disable process polyfilling
  • global - pass false to disable global polyfilling
  • buffer - pass false to disable Buffer polyfilling
  • dirname - pass false to disable __dirname polyfilling
  • filename - pass false to disable __filename polyfilling
  • baseDir which is used for resolving __dirname and __filename.

examples

var foo;
if (process.browser) {
  foo = 'bar';
} else {
  foo = 'baz';
}

turns into

import {browser} from 'path/to/process';
var foo;
if (browser) {
  foo = 'bar';
} else {
  foo = 'baz';
}

but with rollup that ends up being

var browser = true;
var foo;
if (browser) {
  foo = 'bar';
} else {
  foo = 'baz';
}

or

var timeout;
if (global.setImmediate) {
  timeout = global.setImmediate;
} else {
  timeout = global.setTimeout;
}
export default timeout;

turns into

import {_global} from 'path/to/global.js';
var timeout;
if (_global.setImmediate) {
  timeout = _global.setImmediate;
} else {
  timeout = _global.setTimeout;
}
export default timeout;

which rollup turns into

var _global = typeof global !== "undefined" ? global :
            typeof self !== "undefined" ? self :
            typeof window !== "undefined" ? window : {}

var timeout;
if (_global.setImmediate) {
  timeout = _global.setImmediate;
} else {
  timeout = _global.setTimeout;
}
var timeout$1 = timeout;

export default timeout$1;

With that top piece only showing up once no matter how many times global was used.

Keywords

FAQs

Package last updated on 11 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc