Skip to content

Commit 90ac7e5

Browse files
fix path gets not resolved in pl create script (#1266)
1 parent f3596a4 commit 90ac7e5

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/cli/bin/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const path = require('path');
66
const chalk = require('chalk');
77
const EventEmitter = require('events').EventEmitter;
88
const hasYarn = require('has-yarn');
9-
const { resolveFileInPackage } = require('@pattern-lab/core/src/lib/resolver');
9+
const {
10+
resolvePackageFolder,
11+
resolveFileInPackage,
12+
} = require('@pattern-lab/core/src/lib/resolver');
1013

1114
/**
1215
* @name log
@@ -159,7 +162,7 @@ const fetchPackage = packageName =>
159162
const checkAndInstallPackage = packageName =>
160163
wrapAsync(function*() {
161164
try {
162-
require.resolve(packageName);
165+
resolvePackageFolder(packageName);
163166
return true;
164167
} catch (err) {
165168
debug(

packages/core/src/lib/resolver.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@
22

33
const path = require('path');
44

5+
/**
6+
* @func resolvePackageLocations
7+
* Resolves all possible package locations
8+
*/
9+
const resolvePackageLocations = () => {
10+
let lookupPath = path.resolve(process.env.projectDir);
11+
const paths = [lookupPath];
12+
while (path.dirname(lookupPath) !== lookupPath) {
13+
lookupPath = path.join(lookupPath, '../');
14+
paths.push(lookupPath);
15+
}
16+
return paths;
17+
};
18+
519
/**
620
* @func resolveFileInPackage
721
* Resolves a file inside a package
822
*/
923
const resolveFileInPackage = (packageName, ...pathElements) => {
10-
return require.resolve(path.join(packageName, ...pathElements));
24+
if (process.env.projectDir) {
25+
return require.resolve(path.join(packageName, ...pathElements), {
26+
paths: resolvePackageLocations(),
27+
});
28+
} else {
29+
return require.resolve(path.join(packageName, ...pathElements));
30+
}
1131
};
1232

1333
/**

0 commit comments

Comments
 (0)