Skip to content
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

Merged
merged 6 commits into from Jun 28, 2022

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Jun 28, 2022

User facing changelog

Correctly escape ts-node require when running on windows.

Additional details

Fixes a bug where TypeScript users with spaces in their path could not launch Cypress. Introduced in abd986a#diff-b0bd90502ad464c0d541a0e47822d15fec9ba5434dc4225d2993305e1ec7d30aR19. require.resolve returns a path which we pass to NODE_OPTIONS in the form of --require <path> which errors if there is white space in the path. The fix is to change the path to use posix separators.

Steps to test

  • go on windows
  • put cypress in a directory with white space
  • yarn dev wasn't working - now it is
  • you should also be able to load a project that's got white space in the path
  • you also should be able to migrate a project w/ white space - this might have explained some migration issues, too, for anyone migrating after this regression.

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?

sainthkh and others added 4 commits June 28, 2022 15:37
* fix: distribute files to machines for external contributors.

* fix path

* fix

* fix glob

* fix

* fix glob pattern spec->cy.

* fix

* echo things.

* test

* use cd.

* fix component tests.

* test

* test

* fix

* refactor

* test distribut-step

fix error
fix
fix
test
TEST

* Revert "test distribut-step"

This reverts commit 15c3606.

* Revert "refactor"

This reverts commit 21a8ad9.

* reduce flake by increasing viewport height

Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 28, 2022

Thanks for taking the time to open a PR!

@lmiller1990 lmiller1990 force-pushed the lmiller/windows-fix-white-spaces branch from 8cfd2ee to c246e37 Compare June 28, 2022 06:42
@lmiller1990 lmiller1990 marked this pull request as ready for review June 28, 2022 08:08
@lmiller1990 lmiller1990 requested review from a team and tgriesser as code owners June 28, 2022 08:08
@lmiller1990 lmiller1990 requested review from mschile, astone123, mjhenkes, tbiethman, ZachJW34 and a team and removed request for a team, tgriesser and mschile June 28, 2022 08:08
@@ -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}"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before: --require C:\project with spaces\node_modules\ts-node\dist\ts-node.js. Broken
Now: `--require "C:/project with spaces/node_modules/ts-node/dist/ts-node.js"

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).

@cypress
Copy link

cypress bot commented Jun 28, 2022



Test summary

37681 0 456 0Flakiness 10


Run details

Project cypress
Status Passed
Commit 19280b2
Started Jun 28, 2022 8:47 AM
Ended Jun 28, 2022 9:05 AM
Duration 17:58 💡
OS Linux Debian - 10.11
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

actions/click.cy.js Flakiness
1 ... > scroll-behavior > can scroll to and click elements in html with scroll-behavior: smooth
xhr.cy.js Flakiness
1 ... > logs request + response headers
2 ... > logs request + response headers
3 ... > logs Method, Status, URL, and XHR
4 ... > logs response
This comment includes only the first 5 flaky tests. See all 10 flaky tests in the Cypress Dashboard.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard


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'))
Copy link
Member

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?

Suggested change
const tsNode = toPosix(require.resolve('@packages/server/lib/plugins/child/register_ts_node'))
const tsNode = require.resolve(path.join('@packages', 'server', 'lib','plugins','child', 'register_ts_node'))

Copy link
Member

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, which path.join wouldn't help with

Copy link
Contributor Author

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.

@@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets fix CHILD_PROCESS_FILE_PATH one as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 fork must be smart enough to escape the path on its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

  • Windows: /AppData/Local/Cypress/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.

@tgriesser tgriesser self-requested a review June 28, 2022 13:55
@mjhenkes mjhenkes merged commit c0ea9bd into develop Jun 28, 2022
@mjhenkes mjhenkes deleted the lmiller/windows-fix-white-spaces branch June 28, 2022 14:00
@lmiller1990 lmiller1990 mentioned this pull request Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress migration tool doesn't appear + stack trace in the console Cypress doesn't load or open its window
6 participants