Gathering detailed insights and metrics for insert-module-globals
Gathering detailed insights and metrics for insert-module-globals
Gathering detailed insights and metrics for insert-module-globals
Gathering detailed insights and metrics for insert-module-globals
insert implicit module globals into a module-deps stream
npm install insert-module-globals
84.5
Supply Chain
97.8
Quality
81.6
Maintenance
100
Vulnerability
98.9
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
26 Stars
201 Commits
47 Forks
5 Watching
2 Branches
37 Contributors
Updated on 22 Nov 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-12.5%
204,210
Compared to previous day
Last week
4.8%
1,351,843
Compared to previous week
Last month
23.3%
5,084,243
Compared to previous month
Last year
-20.8%
50,487,130
Compared to previous year
insert implicit module globals
(__filename
, __dirname
, process
, global
, setImmediate
, clearImmediate
and Buffer
)
as a browserify-style transform
1var mdeps = require('module-deps'); 2var bpack = require('browser-pack'); 3var insert = require('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('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.
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 insert-module-globals
and to get the bin script do:
npm install -g 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
security policy file detected
Details
Reason
license file detected
Details
Reason
Found 5/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
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