16
16
*/
17
17
18
18
const execa = require ( 'execa' ) ;
19
- const pify = require ( 'pify' ) ;
20
19
const which = require ( 'which' ) ;
21
- const path = require ( 'path' ) ;
22
- const fs = require ( 'fs-extra ' ) ;
20
+ const path = require ( 'node: path' ) ;
21
+ const fs = require ( 'node:fs/promises ' ) ;
23
22
const { CordovaError, events } = require ( 'cordova-common' ) ;
24
23
const npa = require ( 'npm-package-arg' ) ;
25
24
const pacote = require ( 'pacote' ) ;
26
25
const semver = require ( 'semver' ) ;
27
26
28
- // pify's multiArgs unfortunately causes resolve to wrap errors in an Array.
29
- // Thus we wrap the function again to unpack these wrapped errors.
30
- const rslv = pify ( require ( 'resolve' ) , { multiArgs : true } ) ;
31
- const resolve = ( ...args ) => rslv ( ...args ) . catch ( ( [ err ] ) => { throw err ; } ) ;
27
+ function resolvePackage ( ...args ) {
28
+ return new Promise ( ( resolve , reject ) => {
29
+ require ( 'resolve' ) ( ...args , ( err , ...result ) => {
30
+ if ( err ) {
31
+ reject ( err ) ;
32
+ } else {
33
+ resolve ( result ) ;
34
+ }
35
+ } ) ;
36
+ } ) ;
37
+ }
32
38
33
39
/**
34
40
* Installs a module from npm, a git url or the local file system.
@@ -47,7 +53,7 @@ module.exports = async function (target, dest, opts = {}) {
47
53
}
48
54
49
55
// Create dest if it doesn't exist yet
50
- fs . ensureDirSync ( dest ) ;
56
+ await fs . mkdir ( dest , { recursive : true } ) ;
51
57
52
58
// First try to determine the name from the spec using npa. This is very cheap.
53
59
let { name, rawSpec } = npa ( target , dest ) ;
@@ -83,7 +89,7 @@ async function installPackage (target, dest, opts) {
83
89
await isNpmInstalled ( ) ;
84
90
85
91
// Ensure that `npm` installs to `dest` and not any of its ancestors
86
- await fs . ensureDir ( path . join ( dest , 'node_modules' ) ) ;
92
+ await fs . mkdir ( path . join ( dest , 'node_modules' ) , { recursive : true } ) ;
87
93
88
94
// Run `npm` to install requested package
89
95
const args = npmArgs ( target , opts ) ;
@@ -114,7 +120,7 @@ async function resolvePathToPackage (name, basedir) {
114
120
115
121
// We resolve the path to the module's package.json to avoid getting the
116
122
// path to `main` which could be located anywhere in the package
117
- const [ pkgJsonPath , pkgJson ] = await resolve ( `${ name } /package.json` , { paths, basedir } ) ;
123
+ const [ pkgJsonPath , pkgJson ] = await resolvePackage ( `${ name } /package.json` , { paths, basedir } ) ;
118
124
119
125
return [ path . dirname ( pkgJsonPath ) , pkgJson ] ;
120
126
}
0 commit comments