package
insert implicit module globals into a module-deps stream
npm install insert-module-globalsGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
insert implicit module globals
(__filename, __dirname, process, global, setImmediate, clearImmediate and Buffer)
as a browserify-style transform
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('insert-module-globals');
function inserter (file) {
return insert(file, { basedir: __dirname + '/files' });
}
var files = [ __dirname + '/files/main.js' ];
mdeps(files, { transform: inserter })
.pipe(bpack({ raw: true }))
.pipe(process.stdout)
;$ 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"}var 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-globalsand to get the bin script do:
npm install -g insert-module-globalsinsert-module-globals can also insert arbitary globals into files.
Pass in an object of functions as the vars option.
var vars = {
process: function (file, basedir) {
return {
id: "path/to/custom_process.js",
source: customProcessContent
}
},
Buffer: function (file, basedir) {
return {
id: 'path/to/custom_buffer.js',
source: customProcessContent,
//suffix is optional
//it's used to extract the value from the module.
//it becomes: require(...).Buffer in this case.
suffix: '.Buffer'
}
},
Math: function () {
//if you return a string,
//it's simply set as the value.
return '{}'
MIT
Estimated unpacked size across 30 packages.
1.9 MB
Includes dependencies.
gkatsev
me@gkatsev.com
maxogden
max@maxogden.com
thlorenz
thlorenz10@gmail.com
terinjokes
terinjokes@gmail.com
jmm
npm-public@jessemccarthy.net
mellowmelon
palmermebane@gmail.com
ashaffer88
darawk@gmail.com
balupton
b@lupton.cc
cwmma
calvin.metcalf@gmail.com
jprichardson
jprichardson@gmail.com
indutny
blackhole@livebox.sh
jryans
jryans@gmail.com
sethvincent
sethvincent@gmail.com
yoshuawuyts
javascript@yosh.is
ungoldman
ungoldman@gmail.com
ahdinosaur
michael.williams@enspiral.com
elnounch
contact@elnounch.net
parshap
parshap+npm@gmail.com
yerkopalma
yerko.palma@usach.cl
forbeslindesay
forbes@lindesay.co.uk
leichtgewicht
martin.heidegger@gmail.com
garann
garann@gmail.com
bret
bcomnes@gmail.com
anandthakker
vestibule@anandthakker.net
mattdesl
dave.des@gmail.com
hughsk
hughskennedy@gmail.com
fpereira1
pereira.filype@gmail.com
goto-bus-stop
renee@kooi.me
bpostlethwaite
post.ben.here@gmail.com
emilbayes
github@tixz.dk
stevemao
maochenyan@gmail.com
pkrumins
peteris.krumins@gmail.com
tehshrike
me@JoshDuff.com
defunctzombie
shtylman@gmail.com
lukechilds
lukechilds123@gmail.com
raynos
raynos2@gmail.com
~0.11.0
0.11.10
^2.0.0
5.0.12
^1.1.0
2.0.5
^1.0.3
1.3.5
^1.5.2
2.0.1
^1.6.1
2.0.0
^1.0.1
2.0.0
^0.8.0
0.8.0
^1.1.2
1.1.3