{"name":"insert-module-globals","version":"2.3.0","description":"insert implicit module globals into a module-deps stream","main":"index.js","bin":{"insert-module-globals":"bin/cmd.js"},"dependencies":{"commondir":"~0.0.1","lexical-scope":"~0.0.14","process":"~0.5.1","through":"~2.3.4","duplexer":"~0.1.1","JSONStream":"~0.7.1","defined":"0.0.0"},"devDependencies":{"tap":"~0.4.0","browser-pack":"~0.10.2","native-buffer-browserify":"~2.0.0","module-deps":"~1.0.2","browserify":"~2.32.0"},"scripts":{"test":"tap test/*.js","prepublish":"./bundle.sh"},"repository":{"type":"git","url":"git://github.com/substack/insert-module-globals.git"},"homepage":"https://github.com/substack/insert-module-globals","keywords":["__filename","__dirname","global","process","module-deps","browser-pack","browserify"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","bugs":{"url":"https://github.com/substack/insert-module-globals/issues"},"_id":"insert-module-globals@2.3.0","dist":{"shasum":"cae8f749d5da88471c8427820ee0026e6b9a8b7c","tarball":"http://registry-npm.ywwl.com/insert-module-globals/download/insert-module-globals-2.3.0.tgz","integrity":"sha512-39oIrJCBLSkeATBAFLbOFW6Uewa7tWArpK4mS4SmVot2DV4p6x+Nlhcsmt/stv9fqUXjNwIg8yWVnLYCdXo7sg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH5Ltkm2WugIsoAFXP54ZNpO7FpRISkOjILM0HrL+Cr0AiA4MRtHQw0z+tOpUS2PLkkwfihcsizJ6ILzC0luB9bYAw=="}],"size":13547,"noattachment":false,"key":"/insert-module-globals/-/insert-module-globals-2.3.0.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"substack","email":"mail@substack.net"},"maintainers":[{"name":"substack","email":"mail@substack.net"}],"directories":{},"readme":"# insert-module-globals\n\ninsert implicit module globals\n(`__filename`, `__dirname`, `process`, `global`, `setImmediate`, `clearImmediate` and `Buffer`)\nas a browserify-style transform\n\n[![build status](https://secure.travis-ci.org/browserify/insert-module-globals.png)](http://travis-ci.org/browserify/insert-module-globals)\n\n# example\n\n``` js\nvar mdeps = require('module-deps');\nvar bpack = require('browser-pack');\nvar insert = require('insert-module-globals');\nfunction inserter (file) {\n    return insert(file, { basedir: __dirname + '/files' });\n}\n\nvar files = [ __dirname + '/files/main.js' ];\nmdeps(files, { transform: inserter })\n    .pipe(bpack({ raw: true }))\n    .pipe(process.stdout)\n;\n```\n\n```\n$ node example/insert.js | node\nin main.js: {\"__filename\":\"/main.js\",\"__dirname\":\"/\"}\nin foo/index.js: {\"__filename\":\"/foo/index.js\",\"__dirname\":\"/foo\"}\n```\n\nor use the command-line scripts:\n\n```\n$ module-deps main.js | insert-module-globals | browser-pack | node\nin main.js: {\"__filename\":\"/main.js\",\"__dirname\":\"/\"}\nin foo/index.js: {\"__filename\":\"/foo/index.js\",\"__dirname\":\"/foo\"}\n```\n\nor use insert-module-globals as a transform:\n\n```\n$ module-deps main.js --transform insert-module-globals | browser-pack | node\nin main.js: {\"__filename\":\"/main.js\",\"__dirname\":\"/\"}\nin foo/index.js: {\"__filename\":\"/foo/index.js\",\"__dirname\":\"/foo\"}\n```\n\n# methods\n\n``` js\nvar insertGlobals = require('insert-module-globals')\n```\n\n## var inserter = insertGlobals(file, opts)\n\nReturn a transform stream `inserter` for the filename `file` that will accept a\njavascript file as input and will output the file with a closure around the\ncontents as necessary to define extra builtins.\n\nWhen `opts.always` is true, wrap every file with all the global variables\nwithout parsing. This is handy because parsing the scope can take a long time,\nso you can prioritize fast builds over saving bytes in the final output. When\n`opts.always` is truthy but not true, avoid parsing but perform a quick test to\ndetermine if wrapping should be skipped.\n\nUse `opts.vars` to override the default inserted variables, or set\n`opts.vars[name]` to `undefined` to not insert a variable which would otherwise\nbe inserted.\n\n`opts.vars` properties with a `.` in their name will be executed instead of the\nparent object if ONLY that property is used. For example, `\"Buffer.isBuffer\"`\nwill mask `\"Buffer\"` only when there is a `Buffer.isBuffer()` call in a file and\nno other references to `Buffer`.\n\nIf `opts.debug` is true, an inline source map will be generated to compensate\nfor the extra lines.\n\n# events\n\n## inserter.on('global', function (name) {})\n\nWhen a global is detected, the inserter stream emits a `'global'` event.\n\n# usage\n\n```\nusage: insert-module-globals {basedir}\n```\n\n# install\n\nWith [npm](https://npmjs.org), to get the library do:\n\n```\nnpm install insert-module-globals\n```\n\nand to get the bin script do:\n\n```\nnpm install -g insert-module-globals\n```\n\n# insert custom globals.\n\n`insert-module-globals` can also insert arbitary globals into files.\nPass in an object of functions as the `vars` option.\n\n``` js\nvar vars = {\n    process: function (file, basedir) {\n        return {\n            id: \"path/to/custom_process.js\",\n            source: customProcessContent\n        }\n    },\n    Buffer: function (file, basedir) {\n        return {\n            id: 'path/to/custom_buffer.js',\n            source: customProcessContent,\n            //suffix is optional\n            //it's used to extract the value from the module.\n            //it becomes: require(...).Buffer in this case.\n            suffix: '.Buffer'\n        }\n    },\n    Math: function () {\n        //if you return a string,\n        //it's simply set as the value.\n        return '{}'\n        //^ any attempt to use Math[x] will throw!\n    }\n}\n\nfunction inserter (file) {\n    return insert(file, { vars: vars });\n}\nmdeps(files, { transform: inserter })\n    .pipe(bpack({ raw: true }))\n    .pipe(process.stdout)\n```\n\n\n# license\n\nMIT\n","publish_time":1388257291084,"_cnpm_publish_time":1388257291084,"dist-tags":{"latest":"7.2.1"}}