Created
November 2, 2014 17:11
-
-
Save jackboberg/3b9ccd6cd8d4fa76860b to your computer and use it in GitHub Desktop.
npm preinstall symlink `node_modules/_` to `{root}/lib`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| /** | |
| * preinstall | |
| * | |
| * creates a symlink in `node_modules` to allow non-relative local `require` | |
| * require('_/foo'); // loads {root}/lib/foo/index.js | |
| * | |
| * set as npm preinstall command | |
| * { "scripts": "preinstall": "./bin/preinstall"} | |
| */ | |
| var fs = require('fs'); | |
| var path = require('path'); | |
| var symlink = "_"; | |
| var libDir = path.join(__dirname, '..', 'lib'); | |
| var reqDir = path.join(__dirname, '..', 'node_modules'); | |
| var symLinkPath = path.join(reqDir, symlink); | |
| if ( ! fs.existsSync(symLinkPath)) { | |
| fs.symlinkSync(libDir, symLinkPath, 'dir'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment