Skip to content

Commit 7bec6c5

Browse files
committed
refactor(utils): pull out relative path helper function
1 parent e4f6e38 commit 7bec6c5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/scripts/pre-commit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const {
77
hasPkgProp,
88
hasFile,
99
ifScript,
10+
relative,
1011
resolveBin,
1112
getPkgName,
1213
} = require('../utils')
1314
const {buildConfig} = require('../config/helpers/build-lint-staged')
1415

15-
const here = p => path.join(__dirname, p)
16-
const hereRelative = p => here(p).replace(process.cwd(), '.')
16+
const hereRelative = relative(__dirname)
1717

1818
const args = process.argv.slice(2)
1919
const {argv: parsedArgs, aliases} = yargsParser.detailed(args)

src/utils.js

+15
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ function hasLocalConfig(moduleName, searchOptions = {}) {
162162
return result !== null
163163
}
164164

165+
/**
166+
* Get function that converts relative paths to absolute
167+
*
168+
* @param {string} dirname `__dirname`
169+
*/
170+
const relative =
171+
dirname =>
172+
/**
173+
*
174+
* @param {string} p relative path
175+
*/
176+
p =>
177+
path.join(dirname, p).replace(process.cwd(), '.')
178+
165179
module.exports = {
166180
appDirectory,
167181
fromRoot,
@@ -180,6 +194,7 @@ module.exports = {
180194
ifScript,
181195
parseEnv,
182196
pkg,
197+
relative,
183198
resolveBin,
184199
resolveHoverScripts,
185200
uniq,

0 commit comments

Comments
 (0)