{"id":18458771,"url":"https://github.com/browserify/insert-module-globals","last_synced_at":"2025-05-15T12:05:02.336Z","repository":{"id":7043901,"uuid":"8321974","full_name":"browserify/insert-module-globals","owner":"browserify","description":"insert implicit module globals into a module-deps stream","archived":false,"fork":false,"pushed_at":"2024-12-21T10:15:24.000Z","size":222,"stargazers_count":26,"open_issues_count":10,"forks_count":47,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T22:18:03.839Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/browserify.png","metadata":{"files":{"readme":"readme.markdown","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-02-20T20:55:17.000Z","updated_at":"2023-11-22T00:59:05.000Z","dependencies_parsed_at":"2025-01-05T01:15:37.596Z","dependency_job_id":null,"html_url":"https://github.com/browserify/insert-module-globals","commit_stats":{"total_commits":187,"total_committers":16,"mean_commits":11.6875,"dds":"0.39037433155080214","last_synced_commit":"0549e4372523ec2c967058b0bfce51fad9038b0f"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Finsert-module-globals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Finsert-module-globals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Finsert-module-globals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserify%2Finsert-module-globals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/browserify","download_url":"https://codeload.github.com/browserify/insert-module-globals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T08:19:58.693Z","updated_at":"2025-05-15T12:04:57.321Z","avatar_url":"https://github.com/browserify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrowserify%2Finsert-module-globals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrowserify%2Finsert-module-globals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrowserify%2Finsert-module-globals/lists"}