@@ -132,6 +132,15 @@ export class PrepareController extends EventEmitter {
132
132
133
133
this . $logger . info ( "Preparing project..." ) ;
134
134
135
+ // we need to mark the ~/package.json (used by core modules)
136
+ // as external for us to be able to write the config to it
137
+ // in writeRuntimePackageJson() below, because otherwise
138
+ // webpack will inline it into the bundle/vendor chunks
139
+ prepareData . env = prepareData . env || { } ;
140
+ prepareData . env . externals = prepareData . env . externals || [ ] ;
141
+ prepareData . env . externals . push ( "~/package.json" ) ;
142
+ prepareData . env . externals . push ( "package.json" ) ;
143
+
135
144
if ( this . $mobileHelper . isAndroidPlatform ( prepareData . platform ) ) {
136
145
await this . $projectConfigService . writeLegacyNSConfigIfNeeded (
137
146
projectData . projectDir ,
@@ -411,10 +420,11 @@ export class PrepareController extends EventEmitter {
411
420
projectData . projectDir
412
421
) ;
413
422
const packageData : any = {
414
- main : "bundle" ,
415
423
..._ . pick ( projectData . packageJsonData , [ "name" ] ) ,
416
424
...nsConfig ,
425
+ main : "bundle" ,
417
426
} ;
427
+
418
428
if (
419
429
platformData . platformNameLowerCase === "ios" &&
420
430
packageData . ios &&
@@ -451,6 +461,23 @@ export class PrepareController extends EventEmitter {
451
461
) ;
452
462
}
453
463
464
+ try {
465
+ // this will read the package.json that is already emitted by
466
+ // the GenerateNativeScriptEntryPointsPlugin webpack plugin
467
+ const emittedPackageData = this . $fs . readJson ( packagePath ) ;
468
+
469
+ // since ns7 we only care about the main key from the emitted
470
+ // package.json, the rest is coming from the new config.
471
+ if ( emittedPackageData ?. main ) {
472
+ packageData . main = emittedPackageData . main ;
473
+ }
474
+ } catch ( error ) {
475
+ this . $logger . trace (
476
+ "Failed to read emitted package.json. Error is: " ,
477
+ error
478
+ ) ;
479
+ }
480
+
454
481
this . $fs . writeJson ( packagePath , packageData ) ;
455
482
}
456
483
0 commit comments