8
8
} from '@theia/core/electron-shared/electron' ;
9
9
import { fork } from 'child_process' ;
10
10
import { AddressInfo } from 'net' ;
11
- import { join , dirname , isAbsolute , resolve } from 'path' ;
11
+ import { join , isAbsolute , resolve } from 'path' ;
12
12
import { promises as fs , Stats } from 'fs' ;
13
13
import { MaybePromise } from '@theia/core/lib/common/types' ;
14
14
import { ElectronSecurityToken } from '@theia/core/lib/electron-common/electron-token' ;
@@ -86,7 +86,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
86
86
return this . launch ( {
87
87
secondInstance : false ,
88
88
argv : this . processArgv . getProcessArgvWithoutBin ( process . argv ) ,
89
- cwd
89
+ cwd,
90
90
} ) ;
91
91
}
92
92
@@ -158,11 +158,11 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
158
158
/**
159
159
* The `path` argument is valid, if accessible and either pointing to a `.ino` file,
160
160
* or it's a directory, and one of the files in the directory is an `.ino` file.
161
- * The resolved filesystem path is pointing to the sketch folder to open in IDE2.
161
+ *
162
162
* If `undefined`, `path` was pointing to neither an accessible sketch file nor a sketch folder.
163
163
*
164
- * The sketch folder name and sketch file name can be different. This method is not that strict .
165
- * The `path` must be an absolute path.
164
+ * The sketch folder name and sketch file name can be different. This method is not sketch folder name compliant .
165
+ * The `path` must be an absolute, resolved path.
166
166
*/
167
167
private async isValidSketchPath ( path : string ) : Promise < string | undefined > {
168
168
let stats : Stats | undefined = undefined ;
@@ -178,14 +178,16 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
178
178
return undefined ;
179
179
}
180
180
if ( stats . isFile ( ) && path . endsWith ( '.ino' ) ) {
181
- return dirname ( path ) ;
181
+ return path ;
182
182
}
183
183
try {
184
184
const entries = await fs . readdir ( path , { withFileTypes : true } ) ;
185
- if (
186
- entries . some ( ( entry ) => entry . isFile ( ) && entry . name . endsWith ( '.ino' ) )
187
- ) {
188
- return path ;
185
+ const sketchFilename = entries
186
+ . filter ( ( entry ) => entry . isFile ( ) && entry . name . endsWith ( '.ino' ) )
187
+ . map ( ( { name } ) => name )
188
+ . sort ( ( left , right ) => left . localeCompare ( right ) ) [ 0 ] ;
189
+ if ( sketchFilename ) {
190
+ return join ( path , sketchFilename ) ;
189
191
}
190
192
} catch ( err ) {
191
193
throw err ;
0 commit comments