File tree Expand file tree Collapse file tree 4 files changed +40
-2
lines changed
spec/fixtures/api/app-path Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ function loadApplicationPackage (packagePath: string) {
8585 // Override app name and version.
8686 packagePath = path . resolve ( packagePath )
8787 const packageJsonPath = path . join ( packagePath , 'package.json' )
88+ let appPath
8889 if ( fs . existsSync ( packageJsonPath ) ) {
8990 let packageJson
9091 try {
@@ -102,11 +103,12 @@ function loadApplicationPackage (packagePath: string) {
102103 } else if ( packageJson . name ) {
103104 app . setName ( packageJson . name )
104105 }
105- app . _setDefaultAppPaths ( packagePath )
106+ appPath = packagePath
106107 }
107108
108109 try {
109- Module . _resolveFilename ( packagePath , module , true )
110+ const filePath = Module . _resolveFilename ( packagePath , module , true )
111+ app . _setDefaultAppPaths ( appPath || path . dirname ( filePath ) )
110112 } catch ( e ) {
111113 showErrorMessage ( `Unable to find Electron app at ${ packagePath } \n\n${ e . message } ` )
112114 return
Original file line number Diff line number Diff line change @@ -649,6 +649,28 @@ describe('app module', () => {
649649 } )
650650 } )
651651
652+ describe ( 'getAppPath' , ( ) => {
653+ it ( 'works for directories with package.json' , async ( ) => {
654+ const { appPath } = await runTestApp ( 'app-path' )
655+ expect ( appPath ) . to . equal ( path . resolve ( fixturesPath , 'api/app-path' ) )
656+ } )
657+
658+ it ( 'works for directories with index.js' , async ( ) => {
659+ const { appPath } = await runTestApp ( 'app-path/lib' )
660+ expect ( appPath ) . to . equal ( path . resolve ( fixturesPath , 'api/app-path/lib' ) )
661+ } )
662+
663+ it ( 'works for files without extension' , async ( ) => {
664+ const { appPath } = await runTestApp ( 'app-path/lib/index' )
665+ expect ( appPath ) . to . equal ( path . resolve ( fixturesPath , 'api/app-path/lib' ) )
666+ } )
667+
668+ it ( 'works for files' , async ( ) => {
669+ const { appPath } = await runTestApp ( 'app-path/lib/index.js' )
670+ expect ( appPath ) . to . equal ( path . resolve ( fixturesPath , 'api/app-path/lib' ) )
671+ } )
672+ } )
673+
652674 describe ( 'getPath(name)' , ( ) => {
653675 it ( 'returns paths that exist' , ( ) => {
654676 const paths = [
Original file line number Diff line number Diff line change 1+ const { app } = require ( 'electron' )
2+
3+ const payload = {
4+ appPath : app . getAppPath ( )
5+ }
6+
7+ process . stdout . write ( JSON . stringify ( payload ) )
8+ process . stdout . end ( )
9+
10+ process . exit ( )
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " app-path" ,
3+ "main" : " lib/index.js"
4+ }
You can’t perform that action at this time.
0 commit comments