Skip to content

Commit f82d283

Browse files
committed
chore: make launcher an independent package
1 parent 893e7e8 commit f82d283

File tree

15 files changed

+98
-47
lines changed

15 files changed

+98
-47
lines changed

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
5050
- [x] packages/electron ✅ **COMPLETED**
5151
- [ ] packages/https-proxy **PARTIAL** - entry point is JS
5252
- [x] packages/icons ✅ **COMPLETED**
53-
- [x] packages/launcher ✅ **COMPLETED** (needs independent bundle but lower priority)
53+
- [x] packages/launcher ✅ **COMPLETED**
5454
- [x] packages/launchpad ✅ **COMPLETED**
5555
- [x] packages/net-stubbing ✅ **COMPLETED**
5656
- [ ] packages/network **PARTIAL** - entry point is JS

packages/launcher/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
**/dist
1+
**/cjs
2+
**/esm
23
**/*.d.ts
34
**/package-lock.json
45
**/tsconfig.json

packages/launcher/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cjs/
2+
esm/

packages/launcher/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/launcher/lib/darwin/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import execa from 'execa'
44
import fs from 'fs-extra'
55
import path from 'path'
66
import plist from 'plist'
7+
import type { PlistValue } from 'plist'
78

89
const debugVerbose = Debug('cypress-verbose:launcher:darwin:util')
910

@@ -25,9 +26,9 @@ export async function parsePlist (p: string, property: string): Promise<string>
2526
const file = await fs.readFile(pl, 'utf8')
2627
const val = plist.parse(file)
2728

28-
return String(val[property]) // explicitly convert value to String type
29+
return String(val[property as keyof PlistValue]) // explicitly convert value to String type
2930
} catch (err) {
30-
return failed(err) // to make TS compiler happy
31+
return failed(err as Error) // to make TS compiler happy
3132
}
3233
}
3334

packages/launcher/lib/detect.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import _, { compact, extend, find } from 'lodash'
1+
import _, { compact, extend, find, uniqBy } from 'lodash'
22
import os from 'os'
3-
import { removeDuplicateBrowsers } from '@packages/data-context/src/sources/BrowserDataSource'
43
import { knownBrowsers } from './known-browsers'
54
import * as darwinHelper from './darwin'
65
import { notDetectedAtPathErr } from './errors'
@@ -26,8 +25,16 @@ type HasVersion = Omit<Partial<FoundBrowser>, 'version' | 'name'> & {
2625
name: string
2726
}
2827

28+
function getBrowserKey<T extends {name: string, version: string | number}> (browser: T) {
29+
return `${browser.name}-${browser.version}`
30+
}
31+
32+
function removeDuplicateBrowsers (browsers: FoundBrowser[]) {
33+
return uniqBy(browsers, getBrowserKey)
34+
}
35+
2936
export const getMajorVersion = (version: string): string => {
30-
return version.split('.')[0]
37+
return version.split('.')[0] as string
3138
}
3239

3340
// Determines if found browser is supported by Cypress. If found to be
@@ -199,7 +206,7 @@ export const detectByPath = async (
199206
})
200207
}
201208

202-
const detectBrowserFromKey = (browserKey): Browser | undefined => {
209+
const detectBrowserFromKey = (browserKey: string): Browser | undefined => {
203210
return find(goalBrowsers, (goalBrowser) => {
204211
return (
205212
goalBrowser.name === browserKey ||

packages/launcher/lib/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { detect, detectByPath } from './detect'
2+
3+
import { launch } from './browsers'
4+
5+
export {
6+
detect,
7+
detectByPath,
8+
launch,
9+
}

packages/launcher/lib/linux/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async function getLinuxBrowser (
115115

116116
return foundBrowser as FoundBrowser
117117
} catch (err) {
118-
return logAndThrowError(err)
118+
return logAndThrowError(err as Error)
119119
}
120120
}
121121

packages/launcher/lib/windows/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function formChromeForTestingAppPath () {
5656
].map(normalize)
5757
}
5858

59-
function getFirefoxPaths (editionFolder) {
59+
function getFirefoxPaths (editionFolder: string) {
6060
return () => {
6161
return (['Program Files', 'Program Files (x86)'])
6262
.map((programFiles) => {
@@ -134,7 +134,7 @@ function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
134134
debugVerbose('looking at possible paths... %o', { browser, exePaths })
135135

136136
// shift and try paths 1-by-1 until we find one that works
137-
const tryNextExePath = async () => {
137+
const tryNextExePath = async (): Promise<FoundBrowser> => {
138138
const exePath = exePaths.shift()
139139

140140
if (!exePath) {
@@ -180,12 +180,18 @@ export function doubleEscape (s: string) {
180180
return win32.join(...s.split(win32.sep)).replace(/\\/g, '\\\\')
181181
}
182182

183-
export function getVersionString (path: string) {
183+
export function getVersionString (path: string): Promise<string> {
184184
// on Windows using "--version" seems to always start the full
185185
// browser, no matter what one does.
186186

187187
try {
188-
return Promise.resolve(winVersionInfo(path).FileVersion)
188+
const fileVersion = winVersionInfo(path).FileVersion
189+
190+
if (!fileVersion) {
191+
throw new Error(`Failed to get version string for ${path}`)
192+
}
193+
194+
return Promise.resolve(fileVersion)
189195
} catch (err) {
190196
return Promise.reject(err)
191197
}

packages/launcher/package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"name": "@packages/launcher",
33
"version": "0.0.0-development",
44
"private": true,
5+
"main": "./cjs/index.js",
56
"scripts": {
6-
"build-prod": "tsc --project .",
7-
"check-ts": "tsc --noEmit && yarn -s tslint",
8-
"clean": "rimraf --glob 'lib/*.js' && rimraf --glob 'lib/**/*.js' || true",
7+
"build": "yarn build:cjs && yarn build:esm",
8+
"build-prod": "yarn build",
9+
"build:cjs": "tsc -p tsconfig.cjs.json",
10+
"build:esm": "tsc -p tsconfig.esm.json",
11+
"check-ts": "tsc --noEmit -p tsconfig.cjs.json && tsc --noEmit -p tsconfig.esm.json && yarn -s tslint -p tsconfig.cjs.json",
912
"clean-deps": "rimraf node_modules",
10-
"clean-js": "yarn clean",
1113
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
1214
"size": "t=\"cypress-v0.0.0.tgz\"; yarn pack --filename \"${t}\"; wc -c \"cli/${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
1315
"test": "yarn test-unit",
@@ -29,15 +31,18 @@
2931
"@packages/data-context": "0.0.0-development",
3032
"@packages/ts": "0.0.0-development",
3133
"@packages/types": "0.0.0-development",
34+
"@types/plist": "^3.0.5",
35+
"@types/win-version-info": "^3.1.3",
3236
"mock-fs": "5.4.0",
3337
"typescript": "~5.4.5",
3438
"vitest": "^3.2.4"
3539
},
3640
"files": [
37-
"index.js",
38-
"lib"
41+
"cjs/*",
42+
"esm/*"
3943
],
40-
"types": "index.ts",
44+
"types": "./cjs/index.d.ts",
45+
"module": "./esm/index.js",
4146
"nx": {
4247
"implicitDependencies": [
4348
"@packages/data-context"

0 commit comments

Comments
 (0)