@@ -28,6 +28,10 @@ import {
2828} from "../../common/declarations" ;
2929import { ICleanupService } from "../../definitions/cleanup-service" ;
3030import { injector } from "../../common/yok" ;
31+ import {
32+ resolvePackagePath ,
33+ resolvePackageJSONPath ,
34+ } from "../../helpers/package-path-helper" ;
3135
3236// todo: move out of here
3337interface IWebpackMessage < T = any > {
@@ -71,7 +75,7 @@ export class WebpackCompilerService
7175 ) : Promise < any > {
7276 return new Promise ( async ( resolve , reject ) => {
7377 if ( this . webpackProcesses [ platformData . platformNameLowerCase ] ) {
74- resolve ( ) ;
78+ resolve ( void 0 ) ;
7579 return ;
7680 }
7781
@@ -584,45 +588,38 @@ export class WebpackCompilerService
584588
585589 private getWebpackExecutablePath ( projectData : IProjectData ) : string {
586590 if ( this . isWebpack5 ( projectData ) ) {
587- const packagePath = require . resolve (
588- "@nativescript/webpack/package.json" ,
589- {
590- paths : [ projectData . projectDir ] ,
591- }
592- ) ;
591+ const packagePath = resolvePackagePath ( "@nativescript/webpack" , {
592+ paths : [ projectData . projectDir ] ,
593+ } ) ;
593594
594- return path . resolve (
595- packagePath . replace ( "package.json" , "" ) ,
596- "dist" ,
597- "bin" ,
598- "index.js"
599- ) ;
595+ if ( packagePath ) {
596+ return path . resolve ( packagePath , "dist" , "bin" , "index.js" ) ;
597+ }
600598 }
601599
602- return path . join (
603- projectData . projectDir ,
604- "node_modules" ,
605- "webpack" ,
606- "bin" ,
607- "webpack.js"
608- ) ;
600+ const packagePath = resolvePackagePath ( "webpack" , {
601+ paths : [ projectData . projectDir ] ,
602+ } ) ;
603+
604+ if ( ! packagePath ) {
605+ return "" ;
606+ }
607+
608+ return path . resolve ( packagePath , "bin" , "webpack.js" ) ;
609609 }
610610
611611 private isWebpack5 ( projectData : IProjectData ) : boolean {
612- try {
613- const packagePath = require . resolve (
614- "@nativescript/webpack/package.json" ,
615- {
616- paths : [ projectData . projectDir ] ,
617- }
618- ) ;
619- const ver = semver . coerce ( require ( packagePath ) . version ) ;
612+ const packageJSONPath = resolvePackageJSONPath ( "@nativescript/webpack" , {
613+ paths : [ projectData . projectDir ] ,
614+ } ) ;
615+
616+ if ( packageJSONPath ) {
617+ const packageData = this . $fs . readJson ( packageJSONPath ) ;
618+ const ver = semver . coerce ( packageData . version ) ;
620619
621620 if ( semver . satisfies ( ver , ">= 5.0.0" ) ) {
622621 return true ;
623622 }
624- } catch ( ignore ) {
625- //
626623 }
627624
628625 return false ;
0 commit comments