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: force moduleResolution: 'node' when ts-node is registered in the… #28709

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mainBuildFilters: &mainBuildFilters
- develop
- /^release\/\d+\.\d+\.\d+$/
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'chore/update_aws_sdk'
- 'fix/set_module_resolution_with_commonjs'
- 'publish-binary'
- 'em/circle2'

Expand All @@ -42,7 +42,7 @@ macWorkflowFilters: &darwin-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/service-worker-capture', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
Expand All @@ -54,8 +54,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
- equal: [ 'chore/update_webpack_deps_to_latest_webpack4_compat', << pipeline.git.branch >> ]
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
- equal: [ 'em/circle2', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
Expand All @@ -79,8 +78,7 @@ windowsWorkflowFilters: &windows-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
- equal: [ 'chore/update_windows_signing', << pipeline.git.branch >> ]
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
- equal: [ 'lerna-optimize-tasks', << pipeline.git.branch >> ]
- equal: [ 'mschile/mochaEvents_win_sep', << pipeline.git.branch >> ]
- matches:
Expand Down Expand Up @@ -152,7 +150,7 @@ commands:
name: Set environment variable to determine whether or not to persist artifacts
command: |
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "chore/update_aws_sdk" ]]; then
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "fix/set_module_resolution_with_commonjs" ]]; then
export SHOULD_PERSIST_ARTIFACTS=true
fi' >> "$BASH_ENV"
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
Expand Down
2 changes: 1 addition & 1 deletion cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
_Released 1/16/2024 (PENDING)_

**Bugfixes:**

- Force `moduleResolution` to `node` when `typescript` projects are detected to correctly run Cypress. This change should not have a large impact as `commonjs` is already forced when `ts-node` is registered. Fixes [#27731](https://github.com/cypress-io/cypress/issues/27731).
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe worth noting it doesn't work with the esm loader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or maybe that it doesn't impact it?

AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
- No longer wait for additional frames when recording a video for a spec that was skipped by the Cloud due to Auto Cancellation. Fixes [#27898](https://github.com/cypress-io/cypress/issues/27898).
- Now `node_modules` will not be ignored if a project path or a provided path to spec files contains it. Fixes [#23616](https://github.com/cypress-io/cypress/issues/23616).
- Updated display of assertions and commands with a URL argument to escape markdown formatting so that values are displayed as is and assertion values display as bold. Fixes [#24960](https://github.com/cypress-io/cypress/issues/24960) and [#28100](https://github.com/cypress-io/cypress/issues/28100).
Expand Down
4 changes: 1 addition & 3 deletions packages/server/lib/plugins/child/ts_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const getTsNodeOptions = (tsPath, registeredFile) => {
*/
const compilerOptions = {
module: 'commonjs',
moduleResolution: 'node',
...(semver.satisfies(version, '>=4.5.0')
// Only adding this option for TS >= 4.5.0
? { preserveValueImports: false }
Expand All @@ -34,9 +35,6 @@ const getTsNodeOptions = (tsPath, registeredFile) => {

if (process.env.TS_NODE_COMPILER) {
try {
// @ts-expect-error - compilerOptions is an object we can assign properties on.
// It's the 'tsconfig.compilerOptions'.
compilerOptions.moduleResolution = 'node'
compiler = require.resolve(process.env.TS_NODE_COMPILER, { paths: [path.dirname(registeredFile)] })
} catch {
// ts-node compiler not installed in project directory
Expand Down
26 changes: 2 additions & 24 deletions packages/server/test/unit/plugins/child/ts_node_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('lib/plugins/child/ts_node', () => {
dir: '/path/to/plugins',
compilerOptions: {
module: 'commonjs',
moduleResolution: 'node',
},
ignore: [
'(?:^|/)node_modules/',
Expand All @@ -38,35 +39,14 @@ describe('lib/plugins/child/ts_node', () => {
sinon.stub(typescriptObject, 'version').value('4.5.0')
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')

expect(tsnode.register).to.be.calledWith({
transpileOnly: true,
compiler: 'typescript/lib/typescript.js',
dir: '/path/to/plugins',
compilerOptions: {
module: 'commonjs',
preserveValueImports: false,
},
ignore: [
'(?:^|/)node_modules/',
'/packages/telemetry/dist/span-exporters/ipc-span-exporter',
'/packages/telemetry/dist/span-exporters/console-trace-link-exporter',
'/packages/telemetry/dist/processors/on-start-span-processor',
],
})
})

it('registers ts-node with commonjs and node moduleResolution when process.env.TS_NODE_COMPILER is set', () => {
process.env.TS_NODE_COMPILER = true
sinon.stub(typescriptObject, 'version').value('1.1.1')
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')

expect(tsnode.register).to.be.calledWith({
transpileOnly: true,
compiler: 'typescript/lib/typescript.js',
dir: '/path/to/plugins',
compilerOptions: {
module: 'commonjs',
moduleResolution: 'node',
preserveValueImports: false,
},
ignore: [
'(?:^|/)node_modules/',
Expand All @@ -75,8 +55,6 @@ describe('lib/plugins/child/ts_node', () => {
'/packages/telemetry/dist/processors/on-start-span-processor',
],
})

delete process.env.TS_NODE_COMPILER
})

it('does not register ts-node if typescript is not installed', () => {
Expand Down