@@ -56,14 +56,16 @@ describe("projectData", () => {
56
56
configData ?: {
57
57
shared ?: boolean ;
58
58
webpackConfigPath ?: string ;
59
+ bundlerConfigPath ?: string ;
59
60
projectName ?: string ;
61
+ bundler ?: string ;
60
62
} ;
61
63
} ) : IProjectData => {
62
64
const testInjector = createTestInjector ( ) ;
63
65
const fs = testInjector . resolve ( "fs" ) ;
64
66
testInjector . register (
65
67
"projectConfigService" ,
66
- stubs . ProjectConfigServiceStub . initWithConfig ( opts ?. configData )
68
+ stubs . ProjectConfigServiceStub . initWithConfig ( opts ?. configData ) ,
67
69
) ;
68
70
69
71
fs . exists = ( filePath : string ) => {
@@ -98,7 +100,7 @@ describe("projectData", () => {
98
100
const assertProjectType = (
99
101
dependencies : any ,
100
102
devDependencies : any ,
101
- expectedProjecType : string
103
+ expectedProjecType : string ,
102
104
) => {
103
105
const projectData = prepareTest ( {
104
106
packageJsonData : {
@@ -125,7 +127,7 @@ describe("projectData", () => {
125
127
assertProjectType (
126
128
{ "nativescript-vue" : "*" } ,
127
129
{ typescript : "*" } ,
128
- "Vue.js"
130
+ "Vue.js" ,
129
131
) ;
130
132
} ) ;
131
133
@@ -141,7 +143,7 @@ describe("projectData", () => {
141
143
assertProjectType (
142
144
null ,
143
145
{ "nativescript-dev-typescript" : "*" } ,
144
- "Pure TypeScript"
146
+ "Pure TypeScript" ,
145
147
) ;
146
148
} ) ;
147
149
@@ -195,13 +197,13 @@ describe("projectData", () => {
195
197
const projectData = prepareTest ( ) ;
196
198
assert . equal (
197
199
projectData . webpackConfigPath ,
198
- path . join ( projectDir , "webpack.config.js" )
200
+ path . join ( projectDir , "webpack.config.js" ) ,
199
201
) ;
200
202
} ) ;
201
203
202
204
it ( "returns correct path when full path is set in nsconfig.json" , ( ) => {
203
205
const pathToConfig = path . resolve (
204
- path . join ( "/testDir" , "innerDir" , "mywebpack.config.js" )
206
+ path . join ( "/testDir" , "innerDir" , "mywebpack.config.js" ) ,
205
207
) ;
206
208
const projectData = prepareTest ( {
207
209
configData : { webpackConfigPath : pathToConfig } ,
@@ -211,7 +213,7 @@ describe("projectData", () => {
211
213
212
214
it ( "returns correct path when relative path is set in nsconfig.json" , ( ) => {
213
215
const pathToConfig = path . resolve (
214
- path . join ( "projectDir" , "innerDir" , "mywebpack.config.js" )
216
+ path . join ( "projectDir" , "innerDir" , "mywebpack.config.js" ) ,
215
217
) ;
216
218
const projectData = prepareTest ( {
217
219
configData : {
@@ -221,4 +223,81 @@ describe("projectData", () => {
221
223
assert . equal ( projectData . webpackConfigPath , pathToConfig ) ;
222
224
} ) ;
223
225
} ) ;
226
+
227
+ describe ( "bundlerConfigPath" , ( ) => {
228
+ it ( "default path to webpack.config.js is set when nsconfig.json does not set value" , ( ) => {
229
+ const projectData = prepareTest ( ) ;
230
+ assert . equal (
231
+ projectData . bundlerConfigPath ,
232
+ path . join ( projectDir , "webpack.config.js" ) ,
233
+ ) ;
234
+ } ) ;
235
+
236
+ it ( "should use webpackConfigPath property when bundlerConfigPath is not defined" , ( ) => {
237
+ const pathToConfig = path . resolve (
238
+ path . join ( "/testDir" , "innerDir" , "mywebpack.config.js" ) ,
239
+ ) ;
240
+ const projectData = prepareTest ( {
241
+ configData : { webpackConfigPath : pathToConfig } ,
242
+ } ) ;
243
+ assert . equal ( projectData . bundlerConfigPath , pathToConfig ) ;
244
+ } ) ;
245
+
246
+ it ( "returns correct path when full path is set in nsconfig.json" , ( ) => {
247
+ const pathToConfig = path . resolve (
248
+ path . join ( "/testDir" , "innerDir" , "mywebpack.config.js" ) ,
249
+ ) ;
250
+ const projectData = prepareTest ( {
251
+ configData : { bundlerConfigPath : pathToConfig } ,
252
+ } ) ;
253
+ assert . equal ( projectData . bundlerConfigPath , pathToConfig ) ;
254
+ } ) ;
255
+
256
+ it ( "returns correct path when relative path is set in nsconfig.json" , ( ) => {
257
+ const pathToConfig = path . resolve (
258
+ path . join ( "projectDir" , "innerDir" , "mywebpack.config.js" ) ,
259
+ ) ;
260
+ const projectData = prepareTest ( {
261
+ configData : {
262
+ bundlerConfigPath : path . join ( "./innerDir" , "mywebpack.config.js" ) ,
263
+ } ,
264
+ } ) ;
265
+ assert . equal ( projectData . bundlerConfigPath , pathToConfig ) ;
266
+ } ) ;
267
+
268
+ it ( "should use bundlerConfigPath instead of webpackConfigPath if both are defined." , ( ) => {
269
+ const pathToConfig = path . resolve (
270
+ path . join ( "projectDir" , "innerDir" , "myrspack.config.js" ) ,
271
+ ) ;
272
+ const projectData = prepareTest ( {
273
+ configData : {
274
+ webpackConfigPath : path . join ( "./innerDir" , "mywebpack.config.js" ) ,
275
+ bundlerConfigPath : path . join ( "./innerDir" , "myrspack.config.js" ) ,
276
+ } ,
277
+ } ) ;
278
+ assert . equal ( projectData . bundlerConfigPath , pathToConfig ) ;
279
+ } ) ;
280
+ } ) ;
281
+
282
+ describe ( "bundler" , ( ) => {
283
+ it ( "sets bundler to 'webpack' by default when nsconfig.json does not specify a bundler" , ( ) => {
284
+ const projectData = prepareTest ( ) ;
285
+ assert . equal ( projectData . bundler , "webpack" ) ;
286
+ } ) ;
287
+
288
+ it ( "sets bundler to 'webpack' when explicitly defined in nsconfig.json" , ( ) => {
289
+ const projectData = prepareTest ( { configData : { bundler : "webpack" } } ) ;
290
+ assert . equal ( projectData . bundler , "webpack" ) ;
291
+ } ) ;
292
+
293
+ it ( "sets bundler to 'rspack' when explicitly defined in nsconfig.json" , ( ) => {
294
+ const projectData = prepareTest ( { configData : { bundler : "rspack" } } ) ;
295
+ assert . equal ( projectData . bundler , "rspack" ) ;
296
+ } ) ;
297
+
298
+ it ( "sets bundler to 'vite' when explicitly defined in nsconfig.json" , ( ) => {
299
+ const projectData = prepareTest ( { configData : { bundler : "vite" } } ) ;
300
+ assert . equal ( projectData . bundler , "vite" ) ;
301
+ } ) ;
302
+ } ) ;
224
303
} ) ;
0 commit comments