21
21
// MODULES //
22
22
23
23
var path = require ( 'path' ) ;
24
+ var cwd = require ( 'process' ) . cwd ;
24
25
var logger = require ( 'debug' ) ;
25
26
var resolve = require ( 'resolve' ) . sync ;
26
- var objectKeys = require ( '@stdlib/utils/keys' ) ;
27
- var cwd = require ( '@stdlib/process/cwd' ) ;
28
- var copy = require ( '@stdlib/utils/copy' ) ;
29
- var isString = require ( '@stdlib/assert/is-string' ) . isPrimitive ;
30
- var isObject = require ( '@stdlib/assert/is-plain-object' ) ;
31
27
var hasOwnProp = require ( '@stdlib/assert/has-own-property' ) ;
32
28
var parentPath = require ( '@stdlib/fs/resolve-parent-path' ) . sync ;
33
- var dirname = require ( '@stdlib/utils/dirname' ) ;
34
29
var convertPath = require ( '@stdlib/utils/convert-path' ) ;
30
+ var isObject = require ( './is_object.js' ) ;
35
31
var unique = require ( './unique.js' ) ;
36
32
var validate = require ( './validate.js' ) ;
37
33
var DEFAULTS = require ( './defaults.json' ) ;
@@ -79,10 +75,10 @@ function manifest( fpath, conditions, options ) {
79
75
var j ;
80
76
var k ;
81
77
82
- if ( ! isString ( fpath ) ) {
78
+ if ( typeof fpath !== 'string' ) {
83
79
throw new TypeError ( 'invalid argument. First argument must be a string. Value: `' + fpath + '`.' ) ;
84
80
}
85
- opts = copy ( DEFAULTS ) ;
81
+ opts = JSON . parse ( JSON . stringify ( DEFAULTS ) ) ;
86
82
if ( arguments . length > 2 ) {
87
83
err = validate ( opts , options ) ;
88
84
if ( err ) {
@@ -95,11 +91,11 @@ function manifest( fpath, conditions, options ) {
95
91
debug ( 'Options: %s' , JSON . stringify ( opts ) ) ;
96
92
97
93
fpath = path . resolve ( opts . basedir , fpath ) ;
98
- dir = dirname ( fpath ) ;
94
+ dir = path . dirname ( fpath ) ;
99
95
debug ( 'Manifest file path: %s' , fpath ) ;
100
96
101
97
conf = require ( fpath ) ; // eslint-disable-line stdlib/no-dynamic-require
102
- conf = copy ( conf ) ;
98
+ conf = JSON . parse ( JSON . stringify ( conf ) ) ;
103
99
debug ( 'Manifest: %s' , JSON . stringify ( conf ) ) ;
104
100
105
101
// TODO: validate a loaded manifest (conf) according to a JSON schema
@@ -109,7 +105,7 @@ function manifest( fpath, conditions, options ) {
109
105
throw new TypeError ( 'invalid argument. Second argument must be an object. Value: `' + conditions + '`.' ) ;
110
106
}
111
107
debug ( 'Provided conditions: %s' , JSON . stringify ( conditions ) ) ;
112
- coptnames = objectKeys ( conf . options ) ;
108
+ coptnames = Object . keys ( conf . options ) ;
113
109
for ( i = 0 ; i < coptnames . length ; i ++ ) {
114
110
key = coptnames [ i ] ;
115
111
if ( hasOwnProp ( conditions , key ) ) {
@@ -135,7 +131,7 @@ function manifest( fpath, conditions, options ) {
135
131
}
136
132
// If we exhausted all the options, then we found a match...
137
133
if ( j === coptnames . length ) {
138
- obj = copy ( o ) ;
134
+ obj = JSON . parse ( JSON . stringify ( o ) ) ;
139
135
debug ( 'Matching configuration: %s' , JSON . stringify ( obj ) ) ;
140
136
break ;
141
137
}
@@ -172,9 +168,9 @@ function manifest( fpath, conditions, options ) {
172
168
173
169
// Resolve a dependency's path by finding the dependency's `package.json`:
174
170
mpath = parentPath ( 'package.json' , {
175
- 'dir' : dirname ( mpath )
171
+ 'dir' : path . dirname ( mpath )
176
172
} ) ;
177
- mpath = dirname ( mpath ) ;
173
+ mpath = path . dirname ( mpath ) ;
178
174
debug ( 'Dependency path: %s' , mpath ) ;
179
175
180
176
// Load the dependency configuration (recursive):
0 commit comments