-
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 require.resolve when yarn v2 is detected #15623
Closed
blake-transcend
wants to merge
18
commits into
cypress-io:develop
from
blake-transcend:issue-8008-typescript-plugins-pnp
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ac2f274
fix: Use require.resolve when yarn v2 is detected
blake-transcend e0dea49
Update resolve.js
blake-transcend e31ce74
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend f457d77
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend 8120618
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend 051aec4
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend 89c245b
Update resolve.js
blake-transcend 89997d4
Update resolve.js
blake-transcend 4e47428
Update resolve.js
blake-transcend 67cf414
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend a056378
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend d889411
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend 89d0252
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend 2529c82
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend 7ce42cb
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend c135cda
Merge branch 'develop' into issue-8008-typescript-plugins-pnp
blake-transcend b8c5c6d
add 4_yarn_v2_spec
flotwig 2a58263
update spec to use `yarn node` to launch cli
flotwig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from 'fs-extra' | ||
import os from 'os' | ||
import path from 'path' | ||
import cp from 'child_process' | ||
import util from 'util' | ||
import e2e from '../support/helpers/e2e' | ||
import Fixtures from '../support/helpers/fixtures' | ||
|
||
const exec = async (cmd, ...args) => { | ||
console.log(`Running "${cmd}"...`) | ||
const ret = await util.promisify(cp.exec)(cmd, ...args) | ||
.catch((err) => { | ||
console.error('Error:', err) | ||
|
||
return err | ||
}) | ||
|
||
console.log('stdout:', ret.stdout) | ||
ret.stderr && console.log('stderr:', ret.stderr) | ||
|
||
return ret | ||
} | ||
|
||
const fixtureDir = Fixtures.path('projects/yarn-v2') | ||
const cypressCli = path.join(__dirname, '../../../../cli/bin/cypress') | ||
|
||
describe('e2e yarn v2', () => { | ||
let projectDir | ||
|
||
beforeEach(async function () { | ||
this.timeout(240000) | ||
|
||
// copy yarn-v2 to tmpdir so node_modules resolution won't fall back to project root | ||
projectDir = path.join(os.tmpdir(), `cy-yarn-v2-${Date.now()}`) | ||
|
||
await fs.mkdir(projectDir) | ||
await fs.copy(fixtureDir, projectDir) | ||
|
||
const projectExec = (cmd) => exec(cmd, { cwd: projectDir }) | ||
|
||
// set up and verify the yarn v2 project | ||
// https://yarnpkg.com/getting-started/migration#step-by-step | ||
await projectExec('yarn set version berry') | ||
expect((await projectExec('yarn --version')).stdout).to.match(/^2\./) | ||
await projectExec('yarn') | ||
}) | ||
|
||
// @see https://github.com/cypress-io/cypress/pull/15623 | ||
e2e.it('can load typescript plugins files', { | ||
snapshot: false, | ||
command: 'yarn', | ||
browser: 'electron', | ||
onRun: async (run) => { | ||
await run({ | ||
args: `node ${cypressCli} run --dev --spec=* --project=${projectDir}`.split(' '), | ||
spawnOpts: { | ||
cwd: projectDir, | ||
shell: true, | ||
}, | ||
}) | ||
}, | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
packages/server/test/support/fixtures/projects/yarn-v2/.yarnrc.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: pnp |
1 change: 1 addition & 0 deletions
1
packages/server/test/support/fixtures/projects/yarn-v2/cypress.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
packages/server/test/support/fixtures/projects/yarn-v2/cypress/integration/spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
it('passes', () => {}) |
4 changes: 4 additions & 0 deletions
4
packages/server/test/support/fixtures/projects/yarn-v2/cypress/plugins/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// typescript dummy code | ||
exports = (on: any, config: any) => { | ||
return config | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/server/test/support/fixtures/projects/yarn-v2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "yarn-v2", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"typescript": "^4.2.4" | ||
}, | ||
"license": "MIT" | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/server/test/support/fixtures/projects/yarn-v2/yarn.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This file is generated by running "yarn install" inside your project. | ||
# Manual changes might be lost - proceed with caution! | ||
|
||
__metadata: | ||
version: 4 | ||
cacheKey: 7 | ||
|
||
typescript@^4.2.4: | ||
version: 4.2.4 | ||
resolution: "typescript@npm:4.2.4" | ||
bin: | ||
tsc: bin/tsc | ||
tsserver: bin/tsserver | ||
checksum: edaede2fa77f56b7fba80ee624a2368ab1216e75b0434d968ccb47ab0a5e2f6d94f848b3b111c1237dd71e988cd376af26370dcdad3b94355c76e759f0dd0a1e | ||
languageName: node | ||
linkType: hard | ||
|
||
"typescript@patch:typescript@^4.2.4#builtin<compat/typescript>": | ||
version: 4.2.4 | ||
resolution: "typescript@patch:typescript@npm%3A4.2.4#builtin<compat/typescript>::version=4.2.4&hash=a45b0e" | ||
bin: | ||
tsc: bin/tsc | ||
tsserver: bin/tsserver | ||
checksum: 3be44317593182e8ce494c114e7ad9b0bb2553a22f3085cc6da4f0a36912c20850daa9be4c898af2ab6fc8b12f430c1c9e46ac715721867cd38643f2350d3ef9 | ||
languageName: node | ||
linkType: hard | ||
|
||
"yarn-v2@workspace:.": | ||
version: 0.0.0-use.local | ||
resolution: "yarn-v2@workspace:." | ||
dependencies: | ||
typescript: ^4.2.4 | ||
languageName: unknown | ||
linkType: soft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the problem is that
require.resolve
here is still not the patchedrequire.resolve
that Yarn v2 expects, since we are running Cypress inside of Cypress's own Electron-Node instance.Maybe the solution is to fall back to trying to use
@yarnpkg/pnp
to discover the path ifrequire.resolve('typescript')
fails? https://yarnpkg.com/advanced/pnpapi#resolvetounqualifiedThere 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.
This code actually works fine for me, my coworkers, and our CI. Could the cause be that your e2e test isn't executing cypress from yarn like you're supposed to (
yarn cypress ...
)? I believe that's where it injects its custom resolver. It would also probably be pretty difficult to detect which package manager you are using if you're executing outside of your package manager's environmentThere 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.
Oh, I didn't realize yarn v2 required launching stuff like that, it will probably pass once the test is updated then
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.
@blake-transcend I updated the spec to use
yarn node
to launchcypress run
via the CLI, but it still seems to fail with that same error. Since I'm not super familiar with how to test this (even manually), do you want to take a try at writing a test for this?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.
Sure I can try with your test