Gathering detailed insights and metrics for @zdychacek/insert-module-globals
Gathering detailed insights and metrics for @zdychacek/insert-module-globals
Gathering detailed insights and metrics for @zdychacek/insert-module-globals
Gathering detailed insights and metrics for @zdychacek/insert-module-globals
insert implicit module globals into a module-deps stream
npm install @zdychacek/insert-module-globals
Typescript
Module System
Node Version
NPM Version
JavaScript (99.62%)
Shell (0.38%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
187 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jul 14, 2017
Latest Version
8.0.3
Package Id
@zdychacek/insert-module-globals@8.0.3
Size
7.85 kB
NPM Version
4.1.2
Node Version
7.7.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This is a fork of insert-module-globals
which uses Babylon parser instead of acorn
.
Inserts implicit module globals
(__filename
, __dirname
, process
, global
, and Buffer
)
as a browserify-style transform
1var mdeps = require('module-deps'); 2var bpack = require('browser-pack'); 3var insert = require('@zdychacek/insert-module-globals'); 4function inserter (file) { 5 return insert(file, { basedir: __dirname + '/files' }); 6} 7 8var files = [ __dirname + '/files/main.js' ]; 9mdeps(files, { transform: inserter }) 10 .pipe(bpack({ raw: true })) 11 .pipe(process.stdout) 12;
$ node example/insert.js | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}
or use the command-line scripts:
$ module-deps main.js | insert-module-globals | browser-pack | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}
or use insert-module-globals as a transform:
$ module-deps main.js --transform insert-module-globals | browser-pack | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}
1var insertGlobals = require('@zdychacek/insert-module-globals')
Return a transform stream inserter
for the filename file
that will accept a
javascript file as input and will output the file with a closure around the
contents as necessary to define extra builtins.
When opts.always
is true, wrap every file with all the global variables
without parsing. This is handy because parsing the scope can take a long time,
so you can prioritize fast builds over saving bytes in the final output. When
opts.always
is truthy but not true, avoid parsing but perform a quick test to
determine if wrapping should be skipped.
Use opts.vars
to override the default inserted variables, or set
opts.vars[name]
to undefined
to not insert a variable which would otherwise
be inserted.
opts.vars
properties with a .
in their name will be executed instead of the
parent object if ONLY that property is used. For example, "Buffer.isBuffer"
will mask "Buffer"
only when there is a Buffer.isBuffer()
call in a file and
no other references to Buffer
.
If opts.debug
is true, an inline source map will be generated to compensate
for the extra lines.
You cas pass list of plugins for Bybylon parser via opts.parserPlugins
option.
When a global is detected, the inserter stream emits a 'global'
event.
usage: insert-module-globals {basedir}
With npm, to get the library do:
npm install @zdychacek/insert-module-globals
and to get the bin script do:
npm install -g @zdychacek/insert-module-globals
insert-module-globals
can also insert arbitary globals into files.
Pass in an object of functions as the vars
option.
1var vars = { 2 process: function (file, basedir) { 3 return { 4 id: "path/to/custom_process.js", 5 source: customProcessContent 6 } 7 }, 8 Buffer: function (file, basedir) { 9 return { 10 id: 'path/to/custom_buffer.js', 11 source: customProcessContent, 12 //suffix is optional 13 //it's used to extract the value from the module. 14 //it becomes: require(...).Buffer in this case. 15 suffix: '.Buffer' 16 } 17 }, 18 Math: function () { 19 //if you return a string, 20 //it's simply set as the value. 21 return '{}' 22 //^ any attempt to use Math[x] will throw! 23 } 24} 25 26function inserter (file) { 27 return insert(file, { vars: vars }); 28} 29mdeps(files, { transform: inserter }) 30 .pipe(bpack({ raw: true })) 31 .pipe(process.stdout)
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More