@@ -114,6 +114,79 @@ test('api: extendPackage function', async () => {
114
114
} )
115
115
} )
116
116
117
+ test ( 'api: extendPackage allow git, github, http, file version ranges' , async ( ) => {
118
+ const generator = new Generator ( '/' , { plugins : [
119
+ {
120
+ id : 'test' ,
121
+ apply : api => {
122
+ api . extendPackage ( {
123
+ dependencies : {
124
+ foo :
'git+ssh://[email protected] :npm/npm.git#v1.0.27' ,
125
+ baz : 'git://github.com/npm/npm.git#v1.0.27' ,
126
+ bar : 'expressjs/express' ,
127
+ bad : 'mochajs/mocha#4727d357ea' ,
128
+ bac : 'http://asdf.com/asdf.tar.gz' ,
129
+ bae : 'file:../dyl' ,
130
+ 'my-lib' : 'https://bitbucket.org/user/my-lib.git#semver:^1.0.0'
131
+ }
132
+ } )
133
+ }
134
+ }
135
+ ] } )
136
+
137
+ await generator . generate ( )
138
+
139
+ const pkg = JSON . parse ( fs . readFileSync ( '/package.json' , 'utf-8' ) )
140
+ expect ( pkg ) . toEqual ( {
141
+ dependencies : {
142
+ foo :
'git+ssh://[email protected] :npm/npm.git#v1.0.27' ,
143
+ baz : 'git://github.com/npm/npm.git#v1.0.27' ,
144
+ bar : 'expressjs/express' ,
145
+ bad : 'mochajs/mocha#4727d357ea' ,
146
+ bac : 'http://asdf.com/asdf.tar.gz' ,
147
+ bae : 'file:../dyl' ,
148
+ 'my-lib' : 'https://bitbucket.org/user/my-lib.git#semver:^1.0.0'
149
+ }
150
+ } )
151
+ } )
152
+
153
+ test ( 'api: extendPackage merge nonstrictly semver deps' , async ( ) => {
154
+ const generator = new Generator ( '/' , { plugins : [
155
+ {
156
+ id : 'test' ,
157
+ apply : api => {
158
+ api . extendPackage ( {
159
+ dependencies : {
160
+ 'my-lib' : 'https://bitbucket.org/user/my-lib.git#semver:1.0.0' ,
161
+ bar : 'expressjs/express'
162
+ }
163
+ } )
164
+ }
165
+ } ,
166
+ {
167
+ id : 'test2' ,
168
+ apply : api => {
169
+ api . extendPackage ( {
170
+ dependencies : {
171
+ 'my-lib' : 'https://bitbucket.org/user/my-lib.git#semver:1.2.0' ,
172
+ bar : 'expressjs/express'
173
+ }
174
+ } )
175
+ }
176
+ }
177
+ ] } )
178
+
179
+ await generator . generate ( )
180
+
181
+ const pkg = JSON . parse ( fs . readFileSync ( '/package.json' , 'utf-8' ) )
182
+ expect ( pkg ) . toEqual ( {
183
+ dependencies : {
184
+ 'my-lib' : 'https://bitbucket.org/user/my-lib.git#semver:1.2.0' ,
185
+ bar : 'expressjs/express'
186
+ }
187
+ } )
188
+ } )
189
+
117
190
test ( 'api: extendPackage merge dependencies' , async ( ) => {
118
191
const generator = new Generator ( '/' , { plugins : [
119
192
{
@@ -208,6 +281,40 @@ test('api: extendPackage dependencies conflict', async () => {
208
281
} ) ) . toBe ( true )
209
282
} )
210
283
284
+ test ( 'api: extendPackage merge warn nonstrictly semver deps' , async ( ) => {
285
+ new Generator ( '/' , { plugins : [
286
+ {
287
+ id : 'test3' ,
288
+ apply : api => {
289
+ api . extendPackage ( {
290
+ dependencies : {
291
+ bar : 'expressjs/express'
292
+ }
293
+ } )
294
+ }
295
+ } ,
296
+ {
297
+ id : 'test4' ,
298
+ apply : api => {
299
+ api . extendPackage ( {
300
+ dependencies : {
301
+ bar : 'expressjs/express#1234'
302
+ }
303
+ } )
304
+ }
305
+ }
306
+ ] } )
307
+
308
+ expect ( logs . warn . some ( ( [ msg ] ) => {
309
+ return (
310
+ msg . match ( / c o n f l i c t i n g v e r s i o n s f o r p r o j e c t d e p e n d e n c y " b a r " / ) &&
311
+ msg . match ( / e x p r e s s j s \/ e x p r e s s i n j e c t e d b y g e n e r a t o r " t e s t 3 " / ) &&
312
+ msg . match ( / e x p r e s s j s \/ e x p r e s s # 1 2 3 4 i n j e c t e d b y g e n e r a t o r " t e s t 4 " / ) &&
313
+ msg . match ( / U s i n g v e r s i o n \( e x p r e s s j s \/ e x p r e s s \) / )
314
+ )
315
+ } ) ) . toBe ( true )
316
+ } )
317
+
211
318
test ( 'api: render fs directory' , async ( ) => {
212
319
const generator = new Generator ( '/' , { plugins : [
213
320
{
0 commit comments