-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use posix path for ts-node loader #22550
Changes from all commits
ef14d08
6c15a7b
f914082
c246e37
ffe3fd0
19280b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,11 @@ import { | |
} from '../sources/migration' | ||
import { makeCoreData } from '../data' | ||
import { LegacyPluginsIpc } from '../data/LegacyPluginsIpc' | ||
import { hasTypeScriptInstalled } from '../util' | ||
import { hasTypeScriptInstalled, toPosix } from '../util' | ||
|
||
const debug = debugLib('cypress:data-context:MigrationActions') | ||
|
||
const tsNode = require.resolve('@packages/server/lib/plugins/child/register_ts_node') | ||
const tsNode = toPosix(require.resolve('@packages/server/lib/plugins/child/register_ts_node')) | ||
|
||
export function getConfigWithDefaults (legacyConfig: any) { | ||
const newConfig = _.cloneDeep(legacyConfig) | ||
|
@@ -103,7 +103,7 @@ export async function processConfigViaLegacyPlugins (projectRoot: string, legacy | |
// this matches the 9.x behavior, which is what we want for | ||
// processing legacy pluginsFile (we never supported `"type": "module") in 9.x. | ||
if (hasTypeScriptInstalled(projectRoot)) { | ||
const tsNodeLoader = `--require ${tsNode}` | ||
const tsNodeLoader = `--require "${tsNode}"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before: Needs posix and quotes. Would be great if someone can actually test on their machine (I did, and I added two tests with projects containing spaces, but good to clarify). |
||
|
||
if (!childOptions.env) { | ||
childOptions.env = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import fs from 'fs-extra' | |
import path from 'path' | ||
import inspector from 'inspector' | ||
import debugLib from 'debug' | ||
import { autoBindDebug, hasTypeScriptInstalled } from '../util' | ||
import { autoBindDebug, hasTypeScriptInstalled, toPosix } from '../util' | ||
import _ from 'lodash' | ||
import { pathToFileURL } from 'url' | ||
|
||
|
@@ -17,7 +17,7 @@ const debug = debugLib(`cypress:lifecycle:ProjectConfigIpc`) | |
const CHILD_PROCESS_FILE_PATH = require.resolve('@packages/server/lib/plugins/child/require_async_child') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets fix CHILD_PROCESS_FILE_PATH one as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this is actually a problem? Eg - I added regression tests, none of them fail. Kind of hesitant to add this helper unless it's actually necessary. We use it like this: const proc = fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions) I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: I see https://docs.cypress.io/guides/references/advanced-installation#Binary-cache
Since Cypress is always in a directory w/o a space, this has never been a problem. If it's never been a problem, I am kind of hesitant to add this change right now before shipping (without another round of manual testing and a way to reproduce the error it's meant to be fixing. |
||
|
||
const tsNodeEsm = pathToFileURL(require.resolve('ts-node/esm/transpile-only')).href | ||
const tsNode = require.resolve('@packages/server/lib/plugins/child/register_ts_node') | ||
const tsNode = toPosix(require.resolve('@packages/server/lib/plugins/child/register_ts_node')) | ||
|
||
export type IpcHandler = (ipc: ProjectConfigIpc) => void | ||
|
||
|
@@ -128,6 +128,7 @@ export class ProjectConfigIpc extends EventEmitter { | |
let resolved = false | ||
|
||
this._childProcess.on('error', (err) => { | ||
debug('unhandled error in child process %s', err) | ||
this.handleChildProcessError(err, this, resolved, reject) | ||
reject(err) | ||
}) | ||
|
@@ -139,6 +140,7 @@ export class ProjectConfigIpc extends EventEmitter { | |
* but it's not. | ||
*/ | ||
this.on('childProcess:unhandledError', (err) => { | ||
debug('unhandled error in child process %s', err) | ||
this.handleChildProcessError(err, this, resolved, reject) | ||
reject(err) | ||
}) | ||
|
@@ -150,6 +152,7 @@ export class ProjectConfigIpc extends EventEmitter { | |
}) | ||
|
||
this.once('loadConfig:error', (err) => { | ||
debug('error loading config %s', err) | ||
this.killChildProcess() | ||
reject(err) | ||
}) | ||
|
@@ -289,7 +292,7 @@ export class ProjectConfigIpc extends EventEmitter { | |
// We do NOT use the `--loader` flag because we have some additional | ||
// custom logic for ts-node when used with CommonJS that needs to be evaluated | ||
// so we need to load and evaluate the hook first using the `--require` module API. | ||
const tsNodeLoader = `--require ${tsNode}` | ||
const tsNodeLoader = `--require "${tsNode}"` | ||
|
||
if (childOptions.env.NODE_OPTIONS) { | ||
childOptions.env.NODE_OPTIONS += ` ${tsNodeLoader}` | ||
|
@@ -302,9 +305,7 @@ export class ProjectConfigIpc extends EventEmitter { | |
// TODO: Consider using userland `esbuild` with Node's --loader API to handle ESM. | ||
} | ||
|
||
const proc = fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions) | ||
|
||
return proc | ||
return fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions) | ||
} | ||
|
||
private handleChildProcessError (err: any, ipc: ProjectConfigIpc, resolved: boolean, reject: (reason?: any) => void) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
e2e: { | ||
supportFile: false, | ||
setupNodeEvents (on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"projectFixtureDirectory": "simple_passing" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this helper necessary? Can we use path.joint out of the box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilyrohrbough I believe the intent here is to properly escape the actual resolved path that's returned from
require.resolve
, whichpath.join
wouldn't help withThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the helper is the fix. We need to posix-ify the path, even on windows.