Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

insert implicit module globals into a module-deps stream

License

NotificationsYou must be signed in to change notification settings

browserify/insert-module-globals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

insert implicit module globals(__filename,__dirname,process,global,setImmediate,clearImmediate andBuffer)as a browserify-style transform

build status

example

varmdeps=require('module-deps');varbpack=require('browser-pack');varinsert=require('insert-module-globals');functioninserter(file){returninsert(file,{basedir:__dirname+'/files'});}varfiles=[__dirname+'/files/main.js'];mdeps(files,{transform:inserter}).pipe(bpack({raw:true})).pipe(process.stdout);
$ node example/insert.js | nodein 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 | nodein 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 | nodein main.js: {"__filename":"/main.js","__dirname":"/"}in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}

methods

varinsertGlobals=require('insert-module-globals')

var inserter = insertGlobals(file, opts)

Return a transform streaminserter for the filenamefile that will accept ajavascript file as input and will output the file with a closure around thecontents as necessary to define extra builtins.

Whenopts.always is true, wrap every file with all the global variableswithout 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. Whenopts.always is truthy but not true, avoid parsing but perform a quick test todetermine if wrapping should be skipped.

Useopts.vars to override the default inserted variables, or setopts.vars[name] toundefined to not insert a variable which would otherwisebe inserted.

opts.vars properties with a. in their name will be executed instead of theparent object if ONLY that property is used. For example,"Buffer.isBuffer"will mask"Buffer" only when there is aBuffer.isBuffer() call in a file andno other references toBuffer.

Ifopts.debug is true, an inline source map will be generated to compensatefor the extra lines.

events

inserter.on('global', function (name) {})

When a global is detected, the inserter stream emits a'global' event.

usage

usage: insert-module-globals {basedir}

install

Withnpm, to get the library do:

npm install insert-module-globals

and to get the bin script do:

npm install -g insert-module-globals

insert custom globals.

insert-module-globals can also insert arbitary globals into files.Pass in an object of functions as thevars option.

varvars={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'{}'//^ any attempt to use Math[x] will throw!}}functioninserter(file){returninsert(file,{vars:vars});}mdeps(files,{transform:inserter}).pipe(bpack({raw:true})).pipe(process.stdout)

license

MIT

About

insert implicit module globals into a module-deps stream

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp