@@ -132,6 +132,15 @@ export class PrepareController extends EventEmitter {
132132
133133 this . $logger . info ( "Preparing project..." ) ;
134134
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+
135144 if ( this . $mobileHelper . isAndroidPlatform ( prepareData . platform ) ) {
136145 await this . $projectConfigService . writeLegacyNSConfigIfNeeded (
137146 projectData . projectDir ,
@@ -411,10 +420,11 @@ export class PrepareController extends EventEmitter {
411420 projectData . projectDir
412421 ) ;
413422 const packageData : any = {
414- main : "bundle" ,
415423 ..._ . pick ( projectData . packageJsonData , [ "name" ] ) ,
416424 ...nsConfig ,
425+ main : "bundle" ,
417426 } ;
427+
418428 if (
419429 platformData . platformNameLowerCase === "ios" &&
420430 packageData . ios &&
@@ -451,6 +461,23 @@ export class PrepareController extends EventEmitter {
451461 ) ;
452462 }
453463
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+
454481 this . $fs . writeJson ( packagePath , packageData ) ;
455482 }
456483
0 commit comments