Skip to content

Instantly share code, notes, and snippets.

@jackboberg
Created November 2, 2014 17:11
Show Gist options
  • Select an option

  • Save jackboberg/3b9ccd6cd8d4fa76860b to your computer and use it in GitHub Desktop.

Select an option

Save jackboberg/3b9ccd6cd8d4fa76860b to your computer and use it in GitHub Desktop.
npm preinstall symlink `node_modules/_` to `{root}/lib`
#!/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