You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
10 KiB

{
"author": {
"name": "Arnout Kazemier",
"email": "info@3rd-Eden.com",
"url": "3rd-Eden.com"
},
"name": "canihaz",
"description": "canihaz allows you to lazy install npm modules because not every dependency is needed.",
"keywords": [
"npm",
"install",
"module",
"lazy",
"require",
"dependencies",
"optionalDepdencies"
],
"version": "1.0.0",
"scripts": {
"test": "make test"
},
"homepage": "https://github.com/3rd-Eden/canihaz",
"repository": {
"type": "git",
"url": "git://github.com/3rd-Eden/canihaz.git"
},
"main": "index.js",
"dependencies": {
"which": "1.0.x",
"semver": "1.1.x",
"mkdirp": "0.3.x"
},
"devDependencies": {
"mocha": "1.7.x",
"chai": "1.4.x",
"rimraf": "2.1.x"
},
"canihaz": {
"request": "2.12.x",
"routable": "git://github.com/3rd-Eden/routable.git#master",
"useragent": "*"
},
"fooBar": {
"request": "*"
},
"existingDependencies": {
"semver": "1.1.x"
},
"readme": "# canihaz - supercharged dependency loading and installation\n[![build status](https://secure.travis-ci.org/3rd-Eden/canihaz.png)](http://travis-ci.org/3rd-Eden/canihaz)\n\nCanihaz is a module that allows you to lazily install and require NPM modules\nthat might not be required for the core functionality of your library. This\nincludes, but is not limited to:\n\n- Optional dependencies\n- Dependencies that are only used for your optional CLI interface\n- Dependencies that are sparsely used in the application\n\nMy use case for this library is a front-end build system that I have been\ndeveloping. It's called [square][square] and uses a plugin based system to\nprocess your front-end code such as CSS, JavaScript and all possible\npre-processors. If I wanted to support every CSS pre-processor I would have had\nto specify: sass, less and stylus in the dependencies, but nobody is ever going\nto use all of them, so 90% of these modules would have been pointless bloat. And\nI, personally hate code bloat. It's a disease that spreads exponentially with\nevery module that is released and dependent upon. So to combat this bloat\nI wanted to have a way to lazy load and (silently) install the modules when they\nare needed.\n\n[square]: /observing/square\n\n---\n\n## Table of Contents\n\n- [Installation][0]\n- [How does it work][1]\n- [API][2]\n - [package.json example][2.1]\n - [Configuration][2.2]\n - [Configured dependencies][2.3]\n - [Un-configured dependencies][2.4]\n - [Multiple dependencies][2.5]\n- [Changelog][3]\n- [License][4]\n\n[0]: #installation \"Install all the things\"\n[1]: #how-does-it-work \"it's like magic, unicorns and narwals combined in to awesomness\"\n[2]: #api \"The bits that you can use and configure\"\n[2.1]: #packagejson-example\n[2.2]: #configuration\n[2.3]: #installingrequiring-a-configured-dependency\n[2.4]: #installingrequiring-a-un-configured-dependency\n[2.5]: #installingrequiring-multiple-dependencies\n[4]: #license-mit \"Stuff\"\n\n---\n\n## Installation\n\nThis module should be installed using NPM:\n\n```bash\nnpm install canihaz --save\n```\n\nThe `--save` parameter tells NPM that it should add it to your package.json, so\nless editing for you.\n\nIf you do not install it using NPM, make sure that install it in\na `node_modules` folder and do not symlink it.. Unless you don't want to use the\nautomatic dependency resolution.\n\n---\n\n## How does it work\n\nI always tell people that you should understand how a module works before you\nuse it, checkout out the source or at least read the damned documentation.\n\nWhen you initialize the module after you required it it will go up 2 directories\nto go out of the `node_modules` folder and attempt to read out the\n`package.json` file of the module that depends on canihaz. It requires the\npackage.json and search for the dependencies, it searches for `canihaz` key by\ndefault but it can be configured. When it found the dependencies, it attaches\nthe names to the returned object and creates a really simple usable interface\nfor it:\n\n```js\nvar canihaz = require('canihaz')(.. config ..);\n\ncanihaz.dep(function requireallthethings(err, dep) {\n .. dep is installed if it's not installed before or just required\n});\n```\n\nIt automatically knows which version it should install for you as you specified\nthat in the object. Installing a dependency that isn't pre-defined in your\n`package.json` you could do something similar:\n\n```js\nvar canihaz = require('canihaz')();\n\ncanihaz(dep, version, function lazyloading(err, dep) {\n .. dep is installed with the specified version\n});\n```\n\nBut before it tries to install the module it checks it it's perhaps globally\ninstalled (with the correct version) or if it's already installed before in the\nspecified location. When all these checks fail, we continue with the\ninstallation. In older version of canihaz we called the NPM api programatically\nbut there were a couple of issues with this, like install race conditions and it\ndidn't use the users set configurations. That's why we are currently spawning an\nNPM child process. So you need to have NPM installed globally and set in your\npath. The added benefit of this is that the installation becomes completely\nsilent as NPM is usually really chatty and last but not least, it already works\nas this module is installed through NPM.\n\nOnce it's finally installed it attempts to require it again, if it succeeds it\nwill call your callback without any error arguments and provide the library in\nthe callback. If the installation failed or it failed to require you're\nbasically fucked.\n\n## API\n\n#### package.json example\n\nIn the example below, we install canihaz as dependency, and have all our\noptional dependencies in the property `canihaz` which will be read out by\nmodule.\n\n```js\n{\n \"name\": \"example\"\n , \"description\": \"example description\"\n , \"version\": \"0.0.0\"\n , \"dependencies\": {\n \"canihaz\": \"0.0.x\"\n }\n , \"canihaz\": {\n \"coffee-script\": \"1.3.3\"\n , \"csslint\": \"0.9.8\"\n , \"jshint\": \"0.7.1\"\n , \"socket.io\": \"0.9.6\"\n , \"stylus\": \"0.27.2\"\n , \"watch\": \"0.5.1\"\n }\n}\n```\n\n#### configuration\n\n- dot: Should we create a special dot folder for storage? This is saved in\n the home directory of the user. Should be a string.\n- home: The location of the home folders, as this is operating system\n specific or you might want to override this if you want to store the dot\n folder in a different location. Should be string.\n- location: The location of the package.json that we need to parse and read out\n the possible dependencies for lazy installation.\n- key: Which property should we scan for the optional dependencies? This\n allows you to also lazy install optionalDependencies for example.\n- installation: The installation location, this is where the dependencies will\n be installed. It defaults to the `package.json` folder.\n\nExample:\n\n```js\nvar canihaz = require('canihaz')({\n key: 'cliDependencies' // read out `cliDependencies` instead of `canihaz`\n});\n```\n\n#### installing/requiring a configured dependency\n\nThe dependencies that you specify in the `package.json` are automatically\nintroduced to the returned export. It assumes that it's loaded by the package\nthat we specified above.\n\n```js\nvar canihaz = require('canihaz')();\n\ncanihaz.jshint(function loading(err, jshint) {\n // jshint is now loaded, unless we got an error\n});\n```\n\n#### installing/requiring a un-configured dependency\n\nInstalling or requiring a dependency that isn't in the `package.json` require\ndirect usage of the API:\n\n```js\nvar canihaz = require('canihaz')();\n\ncanihaz('jshint', '0.7.x', function lazyloading(err, jsint) {\n // jsint is installed with the specified version\n});\n```\n\n#### installing/requiring multiple dependencies\n\nSometimes you just need a load of modules. There are 2 different ways this is\ndone, if the modules are defined in the `package.json` it will automatically use\ntheir specified function and doesn't require you to specify the version numbers:\n\n```js\nvar canihaz = require('canihaz')();\n\ncanihaz(\n 'jshint', 'stylus', 'express'\n , function lazyloading(err, jsint, stylus, express) {\n // the modules are loaded or installed in the same order as the arguments\n }\n);\n```\n\nIf you need to a bunch of modules that are not specified in the package. \n\n```js\ncanihaz(\n { name: 'jshint', version: '0.7.x' }\n , { name: 'stylus', version: '' }\n , { name: 'express', version: '3.0.x' }\n , function lazyloading(err, jsint, stylus, express) {\n // the modules are loaded or installed in the same order as the arguments\n }\n);\n```\n\n---\n\n## Changelog\n\n__1.0.0__ Rewritten to use the `npm` binary for all installations because the\nprogramatically API causes to much issues and edge cases. 1.0.0 also features a\nfull test suite and a reworked more powerful API.\n\n_all other version were crap anyways_\n\n---\n\n## License (MIT)\n\nCopyright (c) 2013 Arnout Kazemier, 3rd-Eden.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"readmeFilename": "README.md",
"_id": "canihaz@1.0.0",
"_from": "canihaz@~1.0.0"
}