Skip to content

Commit 1fd4bad

Browse files
committed
convert resolve to ts (tsx works inside child process)
1 parent 2cb528a commit 1fd4bad

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

packages/server/lib/modes/run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ async function ready (options: ReadyOptions) {
11311131
socketId,
11321132
parallel,
11331133
onError,
1134+
// @ts-expect-error - browser is not typed correctly
11341135
browser,
11351136
project,
11361137
runUrl,

packages/server/lib/util/resolve.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import debugModule from 'debug'
2+
const debug = debugModule('cypress:server:plugins')
3+
4+
/**
5+
* Resolves the path to 'typescript' module.
6+
*
7+
* @param {projectRoot} path to the project root
8+
* @returns {string|null} path if typescript exists, otherwise null
9+
*/
10+
export const typescript = (projectRoot) => {
11+
if (process.env['CYPRESS_INTERNAL_NO_TYPESCRIPT'] === '1' || !projectRoot) {
12+
return null
13+
}
14+
15+
try {
16+
debug('resolving typescript with projectRoot %o', projectRoot)
17+
18+
const resolved = require.resolve('typescript', { paths: [projectRoot] })
19+
20+
debug('resolved typescript %s', resolved)
21+
22+
return resolved
23+
} catch (e) {
24+
debug('could not resolve typescript, error: %s', e.message)
25+
26+
return null
27+
}
28+
}

packages/server/test/unit/plugins/child/run_child_fixture.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
const childProcess = require('child_process')
22
const path = require('path')
33

4+
// load with tsx?
45
const REQUIRE_ASYNC_CHILD_PATH = require.resolve('@packages/server/lib/plugins/child/require_async_child')
56

67
let proc
78

89
process.on('message', (msg) => {
910
if (msg.msg === 'spawn') {
10-
proc = childProcess.fork(REQUIRE_ASYNC_CHILD_PATH, ['--projectRoot', msg.data.projectRoot, '--file', path.join(msg.data.projectRoot, 'cypress.config.js')])
11+
proc = childProcess.fork(REQUIRE_ASYNC_CHILD_PATH, ['--projectRoot', msg.data.projectRoot, '--file', path.join(msg.data.projectRoot, 'cypress.config.js')], {
12+
env: {
13+
NODE_OPTIONS: '--import tsx',
14+
},
15+
})
16+
1117
proc.on('message', (msg) => {
1218
process.send({ childMessage: msg })
1319
})

0 commit comments

Comments
 (0)