Skip to content

Commit 78a9cb1

Browse files
committed
Moving the resolver functions to the core package
1 parent 31bc3f4 commit 78a9cb1

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

packages/cli/bin/install-edition.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ const {
1010
wrapAsync,
1111
writeJsonAsync,
1212
getJSONKey,
13+
} = require('./utils');
14+
const {
1315
resolveFileInPackage,
1416
resolveDirInPackage,
15-
} = require('./utils');
17+
} = require('@pattern-lab/core/src/lib/resolver');
1618

1719
// https://github.com/TehShrike/deepmerge#overwrite-array
1820
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;

packages/cli/bin/install-plugin.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
const _ = require('lodash');
44

5-
const {
6-
checkAndInstallPackage,
7-
wrapAsync,
8-
resolveFileInPackage,
9-
} = require('./utils');
5+
const { checkAndInstallPackage, wrapAsync } = require('./utils');
6+
const { resolveFileInPackage } = require('@pattern-lab/core/src/lib/resolver');
107

118
const installPlugin = (plugin, config) =>
129
wrapAsync(function*() {

packages/cli/bin/install-starterkit.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const {
66
wrapAsync,
77
checkAndInstallPackage,
88
readJsonAsync,
9+
} = require('./utils');
10+
const {
911
resolveFileInPackage,
1012
resolveDirInPackage,
11-
} = require('./utils');
13+
} = require('@pattern-lab/core/src/lib/resolver');
1214

1315
const installStarterkit = (starterkit, config) =>
1416
wrapAsync(function*() {

packages/cli/bin/utils.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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');
910

1011
/**
1112
* @name log
@@ -182,30 +183,6 @@ const writeJsonAsync = (filePath, data) =>
182183
yield fs.outputJSON(filePath, data, { spaces: 2 });
183184
});
184185

185-
/**
186-
* @func resolveFileInPackage
187-
* Resolves a file inside a package
188-
*/
189-
const resolveFileInPackage = (packageName, ...pathElements) => {
190-
return require.resolve(path.join(packageName, ...pathElements));
191-
};
192-
193-
/**
194-
* @func resolveDirInPackage
195-
* Resolves a file inside a package
196-
*/
197-
const resolveDirInPackage = (packageName, ...pathElements) => {
198-
return path.dirname(resolveFileInPackage(packageName, pathElements));
199-
};
200-
201-
/**
202-
* @func resolvePackageFolder
203-
* Resolves the location of a package on disc
204-
*/
205-
const resolvePackageFolder = packageName => {
206-
return path.dirname(resolveDirInPackage(packageName, 'package.json'));
207-
};
208-
209186
/**
210187
* @func getJSONKey
211188
* Installs package, then returns the value for the given JSON file's key within
@@ -237,7 +214,4 @@ module.exports = {
237214
checkAndInstallPackage,
238215
noop,
239216
getJSONKey,
240-
resolveFileInPackage,
241-
resolveDirInPackage,
242-
resolvePackageFolder,
243217
};

packages/core/src/lib/resolver.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
/**
6+
* @func resolveFileInPackage
7+
* Resolves a file inside a package
8+
*/
9+
const resolveFileInPackage = (packageName, ...pathElements) => {
10+
return require.resolve(path.join(packageName, ...pathElements));
11+
};
12+
13+
/**
14+
* @func resolveDirInPackage
15+
* Resolves a file inside a package
16+
*/
17+
const resolveDirInPackage = (packageName, ...pathElements) => {
18+
return path.dirname(resolveFileInPackage(packageName, ...pathElements));
19+
};
20+
21+
/**
22+
* @func resolvePackageFolder
23+
* Resolves the location of a package on disc
24+
*/
25+
const resolvePackageFolder = packageName => {
26+
return path.dirname(resolveFileInPackage(packageName, 'package.json'));
27+
};
28+
29+
module.exports = {
30+
resolveFileInPackage,
31+
resolveDirInPackage,
32+
resolvePackageFolder,
33+
};

packages/core/src/lib/starterkit_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const starterkit_manager = function(config) {
2929
kitDirStats = fs.statSync(kitPath);
3030
} catch (ex) {
3131
logger.warning(
32-
`${starterkitName} not found, use npm to install it first.`
32+
`${starterkitName} not found, use npm or another package manager to install it first.`
3333
);
3434
logger.warning(`${starterkitName} not loaded.`);
3535
return;

0 commit comments

Comments
 (0)