Symlinking a gulpfile but getting path symlink ran from
<p>My apologies if this seems obvious, but I'm rather new to Node and I couldn't find the solution to this. </p>

<p>Currently I'm working on a project where we have multiple sites in repository and they all need to be built with gulp. The process to build each site is essentially the same, so we want to move <code>gulpfile.js</code> out of each site's subdirectory and into the repo's root and symlink it into each sub directory. This saves us from needing to maintain multiple gulpfiles and needing duplicate node_modules. </p>

<p>Running a setup script to symlink the gulpfile and run <code>npm install</code> after cloning works great except for one minor problem; we need to reference the <code>package.json</code> file in each site's directory to get its name, version, etc as part of some of the gulp tasks. When I symlink the gulpfile, <code>var pkg = require('./package.json')</code> always resolves to the <code>package.json</code> at the root of the repo and not where the symlink was called from (and that makes sense, but is not what I need). </p>

<p>How can I maintain this symlink structure for the gulpfile, but have <code>require('./package.json')</code> resolve to say <code>./Site_1/package.json</code> instead of <code>./package.json</code></p>

<pre><code>.
├── Site_1
│   ├── README.md
│   ├── config.yml
│   ├── dist
│   ├── gulpfile.js -&gt; ../gulpfile.js
│   ├── package.json
│   └── src
├── Site_2
│   ├── README.md
│   ├── config.yml
│   ├── dist
│   ├── gulpfile.js -&gt; ../gulpfile.js
│   ├── package.json
│   └── src
├── package.json
├── gulpfile.js
├── node_modules/
</code></pre>