Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cli/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const path = require('path');
const chalk = require('chalk');
const EventEmitter = require('events').EventEmitter;
const hasYarn = require('has-yarn');
const { resolveFileInPackage } = require('@pattern-lab/core/src/lib/resolver');
const {
resolvePackageFolder,
resolveFileInPackage,
} = require('@pattern-lab/core/src/lib/resolver');

/**
* @name log
Expand Down Expand Up @@ -159,7 +162,7 @@ const fetchPackage = packageName =>
const checkAndInstallPackage = packageName =>
wrapAsync(function*() {
try {
require.resolve(packageName);
resolvePackageFolder(packageName);
return true;
} catch (err) {
debug(
Expand Down
22 changes: 21 additions & 1 deletion packages/core/src/lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@

const path = require('path');

/**
* @func resolvePackageLocations
* Resolves all possible package locations
*/
const resolvePackageLocations = () => {
let lookupPath = path.resolve(process.env.projectDir);
const paths = [lookupPath];
while (path.dirname(lookupPath) !== lookupPath) {
lookupPath = path.join(lookupPath, '../');
paths.push(lookupPath);
}
return paths;
};

/**
* @func resolveFileInPackage
* Resolves a file inside a package
*/
const resolveFileInPackage = (packageName, ...pathElements) => {
return require.resolve(path.join(packageName, ...pathElements));
if (process.env.projectDir) {
return require.resolve(path.join(packageName, ...pathElements), {
paths: resolvePackageLocations(),
});
} else {
return require.resolve(path.join(packageName, ...pathElements));
}
};

/**
Expand Down