Skip to content

Commit 6bb9799

Browse files
committed
refactor(deps): remove direct dependency on arrify
1 parent 446707a commit 6bb9799

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

Diff for: package.json

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"@types/which": "^2.0.1",
6565
"@typescript-eslint/eslint-plugin": "^5.45.1",
6666
"@typescript-eslint/parser": "^5.45.1",
67-
"arrify": "^2.0.1",
6867
"commitizen": "^4.2.4",
6968
"concurrently": "^7.0.0",
7069
"cosmiconfig": "^7.0.1",

Diff for: src/utils.js

+43-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const fs = require('fs')
22
const path = require('path')
33
const rimraf = require('rimraf')
44
const mkdirp = require('mkdirp')
5-
const arrify = require('arrify')
65
const has = require('lodash.has')
76
const readPkgUp = require('read-pkg-up')
87
const which = require('which')
@@ -66,19 +65,42 @@ function resolveBin(
6665
const fromRoot = (/** @type {string[]} */ ...p) => path.join(appDirectory, ...p)
6766
const hasFile = (/** @type {string[]} */ ...p) => fs.existsSync(fromRoot(...p))
6867

69-
const ifFile = (
70-
/** @type {*} */ files,
71-
/** @type {*} */ t,
72-
/** @type {*} */ f,
73-
) => (arrify(files).some((/** @type {*} */ file) => hasFile(file)) ? t : f)
68+
/**
69+
* @param {string | string[]} stringOrArray
70+
*/
71+
const liftStringArray = stringOrArray =>
72+
typeof stringOrArray === 'string' ? [stringOrArray] : stringOrArray
73+
74+
/**
75+
*
76+
* @template T
77+
* @template F
78+
*
79+
* @param {string | string[]} files
80+
* @param {T} t
81+
* @param {F} f
82+
*/
83+
const ifFile = (files, t, f) =>
84+
liftStringArray(files).some(file => hasFile(file)) ? t : f
7485

7586
const getPkgName = () => pkg.name
7687

77-
const hasPkgProp = (/** @type {*} */ props) =>
78-
arrify(props).some((/** @type {*} */ prop) => has(pkg, prop))
88+
/**
89+
* @param {string | string[]} props
90+
*/
91+
const hasPkgProp = props => liftStringArray(props).some(prop => has(pkg, prop))
7992

80-
const hasPkgSubProp = (/** @type {*} */ pkgProp) => (/** @type {*} */ props) =>
81-
hasPkgProp(arrify(props).map((/** @type {*} */ p) => `${pkgProp}.${p}`))
93+
/**
94+
* @param {string} pkgProp
95+
*/
96+
const hasPkgSubProp =
97+
pkgProp =>
98+
/**
99+
* @param {string | string[]} props
100+
* @returns
101+
*/
102+
props =>
103+
hasPkgProp(liftStringArray(props).map(p => `${pkgProp}.${p}`))
82104

83105
const ifPkgSubProp =
84106
(/** @type {*} */ pkgProp) =>
@@ -95,11 +117,17 @@ const hasAnyDep = (/** @type {*} */ args) =>
95117
const ifPeerDep = ifPkgSubProp('peerDependencies')
96118
const ifDep = ifPkgSubProp('dependencies')
97119
const ifDevDep = ifPkgSubProp('devDependencies')
98-
const ifAnyDep = (
99-
/** @type {*} */ deps,
100-
/** @type {*} */ t,
101-
/** @type {*} */ f,
102-
) => (hasAnyDep(arrify(deps)) ? t : f)
120+
121+
/**
122+
* @template T
123+
* @template F
124+
*
125+
* @param {string | string[]} deps
126+
* @param {T} t
127+
* @param {F} f
128+
*/
129+
const ifAnyDep = (deps, t, f) => (hasAnyDep(liftStringArray(deps)) ? t : f)
130+
103131
const ifScript = ifPkgSubProp('scripts')
104132

105133
function parseEnv(/** @type {string} */ name, /** @type {*} */ def) {

0 commit comments

Comments
 (0)