()
| 44 | } |
| 45 | |
| 46 | async function locateWrapper(): Promise<WrapperLocation | null> { |
| 47 | const candidates: WrapperLocation[] = [] |
| 48 | |
| 49 | if (app.isPackaged) { |
| 50 | candidates.push({ |
| 51 | wrapperPath: path.join(process.resourcesPath, WRAPPER_NAME), |
| 52 | cliJsPath: path.join(process.resourcesPath, 'cli.js') |
| 53 | }) |
| 54 | } |
| 55 | |
| 56 | const here = path.dirname(fileURLToPath(import.meta.url)) |
| 57 | const devCliJs = path.join(here, 'cli.js') |
| 58 | candidates.push({ |
| 59 | wrapperPath: await ensureDevWrapper(devCliJs), |
| 60 | cliJsPath: devCliJs |
| 61 | }) |
| 62 | |
| 63 | for (const c of candidates) { |
| 64 | try { |
| 65 | const [wrapperStat, cliStat] = await Promise.all([ |
| 66 | fsp.stat(c.wrapperPath), |
| 67 | fsp.stat(c.cliJsPath) |
| 68 | ]) |
| 69 | if (wrapperStat.isFile() && cliStat.isFile()) return c |
| 70 | } catch { |
| 71 | /* keep trying */ |
| 72 | } |
| 73 | } |
| 74 | return null |
| 75 | } |
| 76 | |
| 77 | async function ensureDevWrapper(cliJsPath: string): Promise<string> { |
| 78 | const dir = path.join(app.getPath('userData'), 'cli') |
no test coverage detected