Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
712 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | const path = require('path');
|
---|
3 | const resolveCwd = require('resolve-cwd');
|
---|
4 | const pkgDir = require('pkg-dir');
|
---|
5 |
|
---|
6 | module.exports = filename => {
|
---|
7 | const globalDir = pkgDir.sync(path.dirname(filename));
|
---|
8 | const relativePath = path.relative(globalDir, filename);
|
---|
9 | const pkg = require(path.join(globalDir, 'package.json'));
|
---|
10 | const localFile = resolveCwd.silent(path.join(pkg.name, relativePath));
|
---|
11 |
|
---|
12 | // Use `path.relative()` to detect local package installation,
|
---|
13 | // because __filename's case is inconsistent on Windows
|
---|
14 | // Can use `===` when targeting Node.js 8
|
---|
15 | // See https://github.com/nodejs/node/issues/6624
|
---|
16 | return localFile && path.relative(localFile, filename) !== '' ? require(localFile) : null;
|
---|
17 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.