{"id":15642930,"url":"https://github.com/benjamn/install","last_synced_at":"2025-04-05T04:10:48.761Z","repository":{"id":6855484,"uuid":"8104268","full_name":"benjamn/install","owner":"benjamn","description":"Minimal JavaScript module loader","archived":false,"fork":false,"pushed_at":"2022-11-22T06:32:30.000Z","size":673,"stargazers_count":63,"open_issues_count":11,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T11:04:54.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://benjamn.github.io/install/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benjamn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-09T00:49:58.000Z","updated_at":"2025-02-06T17:11:29.000Z","dependencies_parsed_at":"2023-01-13T14:08:00.306Z","dependency_job_id":null,"html_url":"https://github.com/benjamn/install","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Finstall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Finstall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Finstall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Finstall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benjamn","download_url":"https://codeload.github.com/benjamn/install/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284949,"owners_count":20913704,"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-10-03T11:58:10.989Z","updated_at":"2025-04-05T04:10:48.741Z","avatar_url":"https://github.com/benjamn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# install [![Build Status](https://travis-ci.org/benjamn/install.svg?branch=master)](https://travis-ci.org/benjamn/install) [![Greenkeeper badge](https://badges.greenkeeper.io/benjamn/install.svg)](https://greenkeeper.io/)\n\nThe [CommonJS module syntax](http://wiki.commonjs.org/wiki/Modules/1.1) is one of the most widely accepted conventions in the JavaScript ecosystem. Everyone seems to agree that `require` and `exports` are a reasonable way of expressing module dependencies and interfaces, and the tools for managing modular code are getting better all the time.\n\nMuch less of a consensus has developed around the best way to deliver CommonJS modules to a web browser, where the synchronous semantics of `require` pose a non-trivial implementation challenge. This module loader contributes to that confusion, yet also demonstrates that an amply-featured module loader need not stretch into the hundreds or thousands of lines.\n\nInstallation\n---\nFrom NPM:\n\n    npm install install\n\nFrom GitHub:\n\n    cd path/to/node_modules\n    git clone git://github.com/benjamn/install.git\n    cd install\n    npm install .\n\nUsage\n---\n\nThe first step is to create an `install` function by calling the\n`makeInstaller` method. Note that all of the options described below are\noptional:\n\n```js\nvar install = require(\"install\").makeInstaller({\n  // Optional list of file extensions to be appended to required module\n  // identifiers if they do not exactly match an installed module.\n  extensions: [\".js\", \".json\"],\n\n  // If defined, the options.fallback function will be called when no\n  // installed module is found for a required module identifier. Often\n  // options.fallback will be implemented in terms of the native Node\n  // require function, which has the ability to load binary modules.\n  fallback,\n\n  // Boolean flag indicating whether the installed code will be running in\n  // a web browser.\n  browser,\n\n  // List of fields to look for in package.json files to determine the\n  // main entry module of the package. The first field listed here whose\n  // value is a string will be used to resolve the entry module. Defaults\n  // to just [\"main\"], or [\"browser\", \"main\"] if options.browser is true.\n  mainFields: [\"browser\", \"main\"],\n});\n```\n\nThe second step is to install some modules by passing a nested tree of\nobjects and functions to the `install` function:\n\n```js\nvar require = install({\n  \"main.js\"(require, exports, module) {\n    // On the client, the \"assert\" module should be install-ed just like\n    // any other module. On the server, since \"assert\" is a built-in Node\n    // module, it may make sense to let the options.fallback function\n    // handle such requirements. Both ways work equally well.\n    var assert = require(\"assert\");\n\n    assert.strictEqual(\n      // This require function uses the same lookup rules as Node, so it\n      // will find \"package\" in the \"node_modules\" directory below.\n      require(\"package\").name,\n      \"/node_modules/package/entry.js\"\n    );\n\n    exports.name = module.id;\n  },\n\n  node_modules: {\n    package: {\n      // If package.json is not defined, a module called \"index.js\" will\n      // be used as the main entry point for the package. Otherwise the\n      // exports.main property will identify the entry point.\n      \"package.json\"(require, exports, module) {\n        exports.name = \"package\";\n        exports.version = \"0.1.0\";\n        exports.main = \"entry.js\";\n      },\n\n      \"entry.js\"(require, exports, module) {\n        exports.name = module.id;\n      }\n    }\n  }\n});\n```\n\nNote that the `install` function merely installs modules without\nevaluating them, so the third and final step is to `require` any entry\npoint modules that you wish to evaluate:\n\n```js\nconsole.log(require(\"./main\").name);\n// =\u003e \"/main.js\"\n```\n\nThis is the \"root\" `require` function returned by the `install`\nfunction. If you're using the `install` package in a CommonJS environment\nlike Node, be careful that you don't overwrite the `require` function\nprovided by that system.\n\nIf you need to change the behavior of the `module` object that each module\nfunction receives as its third parameter, the shared `Module` constructor\nis exposed as a property of the `install` function returned by the\n`makeInstaller` factory:\n\n```js\nvar install = makeInstaller(options);\nvar proto = install.Module.prototype;\n\n// Wrap all Module.prototype.require calls with some sort of logging.\nproto.require = wrapWithLogging(proto.require);\n\n// Add a new method available to all modules via module.newMethod(...).\nproto.newMethod = function () {...};\n```\n\nMany more examples of how to use the `install` package can be found in the\n[tests](https://github.com/benjamn/install/blob/master/test/run.js).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjamn%2Finstall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjamn%2Finstall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjamn%2Finstall/lists"}