Skip to content

Commit

Permalink
re: @mjhenkes review
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Jun 2, 2022
1 parent 3bb9203 commit fd8df6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/data-context/src/data/ProjectLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,13 @@ export class ProjectLifecycleManager {
}

try {
const packageJson = this.ctx.fs.readJsonSync(this._pathToFile('package.json'))
const pkgJson = this.ctx.fs.readJsonSync(this._pathToFile('package.json'))

if (packageJson.type === 'module') {
if (pkgJson.type === 'module') {
metaState.isProjectUsingESModules = true
}

metaState.isUsingTypeScript = detectLanguage(this.projectRoot, packageJson, metaState.hasLegacyCypressJson) === 'ts'
metaState.isUsingTypeScript = detectLanguage({ projectRoot: this.projectRoot, pkgJson, isMigrating: metaState.hasLegacyCypressJson }) === 'ts'
} catch {
// No need to handle
}
Expand Down
2 changes: 1 addition & 1 deletion packages/scaffold-config/src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function detectFramework (projectPath: string): DetectFramework {
* END
*/

export function detectLanguage (projectRoot: string, pkgJson: PkgJson, isMigrating = false): 'js' | 'ts' {
export function detectLanguage ({ projectRoot, pkgJson, isMigrating = false }: { projectRoot: string, pkgJson: PkgJson, isMigrating?: boolean }): 'js' | 'ts' {
try {
if (fs.existsSync(path.join(projectRoot, 'cypress.config.ts'))) {
debug('Detected cypress.config.ts - using TS')
Expand Down
28 changes: 14 additions & 14 deletions packages/scaffold-config/test/unit/detect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ describe('detectFramework', () => {
describe('detectLanguage', () => {
it('existing project with `cypress.config.ts`', async () => {
const projectRoot = await scaffoldMigrationProject('config-with-ts')
const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})

it('existing project with `cypress.config.js`', async () => {
const projectRoot = await scaffoldMigrationProject('config-with-js')
const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('js')
})
Expand All @@ -239,7 +239,7 @@ describe('detectLanguage', () => {

fakeDepsInNodeModules(projectRoot, [{ devDependency: 'typescript', version: '4.3.6' }])
const pkgJson = fs.readJsonSync(path.join(projectRoot, 'package.json'))
const actual = detectLanguage(projectRoot, pkgJson)
const actual = detectLanguage({ projectRoot, pkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -248,23 +248,23 @@ describe('detectLanguage', () => {
const projectRoot = await scaffoldMigrationProject('pristine-npm')

fakeDepsInNodeModules(projectRoot, [{ devDependency: 'typescript', version: '4.3.6' }])
const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})

it('detects js if typescript is not resolvable when there is a tsconfig.json', async () => {
let projectRoot = await scaffoldMigrationProject('pristine-npm')

const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('js')

projectRoot = await scaffoldMigrationProject('pristine-npm')

fakeDepsInNodeModules(projectRoot, [{ devDependency: 'typescript', version: '4.3.6' }])

const actualTypescript = detectLanguage(projectRoot, {} as PkgJson)
const actualTypescript = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actualTypescript).to.eq('ts')
})
Expand All @@ -273,7 +273,7 @@ describe('detectLanguage', () => {
const projectRoot = await scaffoldMigrationProject('migration')

fakeDepsInNodeModules(projectRoot, [{ devDependency: 'typescript', version: '4.3.6' }])
const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -297,7 +297,7 @@ describe('detectLanguage', () => {

fakeDepsInNodeModules(projectRoot, [{ devDependency: 'typescript', version: '4.3.6' }])

const actual = detectLanguage(projectRoot, {} as PkgJson, true)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson, isMigrating: true })

expect(actual).to.eq('js')
})
Expand All @@ -309,7 +309,7 @@ describe('detectLanguage', () => {

removeAllTsFilesExcept(projectRoot, 'support')

const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -321,7 +321,7 @@ describe('detectLanguage', () => {

removeAllTsFilesExcept(projectRoot, 'plugins')

const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -334,7 +334,7 @@ describe('detectLanguage', () => {
// detected based on `integration/**/*.tsx
removeAllTsFilesExcept(projectRoot, 'integration')

const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -347,7 +347,7 @@ describe('detectLanguage', () => {
// detected based on `integration/**/*.tsx
removeAllTsFilesExcept(projectRoot, 'integration')

const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -360,7 +360,7 @@ describe('detectLanguage', () => {
// detected based on `integration/**/*.tsx
removeAllTsFilesExcept(projectRoot, 'component')

const actual = detectLanguage(projectRoot, {} as PkgJson)
const actual = detectLanguage({ projectRoot, pkgJson: {} as PkgJson })

expect(actual).to.eq('ts')
})
Expand All @@ -374,7 +374,7 @@ describe('detectLanguage', () => {
await fs.writeFile(path.join(projectRoot, 'node_modules', 'some-node-module', 'tsconfig.json'), '')
const pkgJson = fs.readJsonSync(path.join(projectRoot, 'package.json'))

const actual = detectLanguage(projectRoot, pkgJson)
const actual = detectLanguage({ projectRoot, pkgJson })

expect(actual).to.eq('js')
})
Expand Down

0 comments on commit fd8df6e

Please sign in to comment.