Skip to content

Commit 81fce0e

Browse files
authored
fix: force moduleResolution: 'node' when ts-node is registered in the… (#28709)
* fix: force moduleResolution: 'node' when ts-node is registered in the cypress process to make sure value is compatible with commonjs (which is already forced). [run ci] * Update cli/CHANGELOG.md
1 parent 7df6df4 commit 81fce0e

File tree

4 files changed

+9
-35
lines changed

4 files changed

+9
-35
lines changed

.circleci/workflows.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mainBuildFilters: &mainBuildFilters
2929
- develop
3030
- /^release\/\d+\.\d+\.\d+$/
3131
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
32-
- 'chore/update_aws_sdk'
32+
- 'fix/set_module_resolution_with_commonjs'
3333
- 'publish-binary'
3434
- 'em/circle2'
3535

@@ -42,7 +42,7 @@ macWorkflowFilters: &darwin-workflow-filters
4242
- equal: [ develop, << pipeline.git.branch >> ]
4343
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4444
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
45-
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
45+
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
4646
- equal: [ 'ryanm/fix/service-worker-capture', << pipeline.git.branch >> ]
4747
- matches:
4848
pattern: /^release\/\d+\.\d+\.\d+$/
@@ -54,8 +54,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
5454
- equal: [ develop, << pipeline.git.branch >> ]
5555
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5656
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
57-
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
58-
- equal: [ 'chore/update_webpack_deps_to_latest_webpack4_compat', << pipeline.git.branch >> ]
57+
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
5958
- equal: [ 'em/circle2', << pipeline.git.branch >> ]
6059
- matches:
6160
pattern: /^release\/\d+\.\d+\.\d+$/
@@ -79,8 +78,7 @@ windowsWorkflowFilters: &windows-workflow-filters
7978
- equal: [ develop, << pipeline.git.branch >> ]
8079
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
8180
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
82-
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
83-
- equal: [ 'chore/update_windows_signing', << pipeline.git.branch >> ]
81+
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
8482
- equal: [ 'lerna-optimize-tasks', << pipeline.git.branch >> ]
8583
- equal: [ 'mschile/mochaEvents_win_sep', << pipeline.git.branch >> ]
8684
- matches:
@@ -152,7 +150,7 @@ commands:
152150
name: Set environment variable to determine whether or not to persist artifacts
153151
command: |
154152
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
155-
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "chore/update_aws_sdk" ]]; then
153+
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "fix/set_module_resolution_with_commonjs" ]]; then
156154
export SHOULD_PERSIST_ARTIFACTS=true
157155
fi' >> "$BASH_ENV"
158156
# You must run `setup_should_persist_artifacts` command and be using bash before running this command

cli/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
_Released 1/16/2024 (PENDING)_
55

66
**Bugfixes:**
7-
7+
- 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. This fix does not impact the ESM Typescript configuration loader. Fixes [#27731](https://github.com/cypress-io/cypress/issues/27731).
88
- 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).
99
- 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).
1010
- 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).

packages/server/lib/plugins/child/ts_node.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const getTsNodeOptions = (tsPath, registeredFile) => {
2323
*/
2424
const compilerOptions = {
2525
module: 'commonjs',
26+
moduleResolution: 'node',
2627
...(semver.satisfies(version, '>=4.5.0')
2728
// Only adding this option for TS >= 4.5.0
2829
? { preserveValueImports: false }
@@ -34,9 +35,6 @@ const getTsNodeOptions = (tsPath, registeredFile) => {
3435

3536
if (process.env.TS_NODE_COMPILER) {
3637
try {
37-
// @ts-expect-error - compilerOptions is an object we can assign properties on.
38-
// It's the 'tsconfig.compilerOptions'.
39-
compilerOptions.moduleResolution = 'node'
4038
compiler = require.resolve(process.env.TS_NODE_COMPILER, { paths: [path.dirname(registeredFile)] })
4139
} catch {
4240
// ts-node compiler not installed in project directory

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('lib/plugins/child/ts_node', () => {
2424
dir: '/path/to/plugins',
2525
compilerOptions: {
2626
module: 'commonjs',
27+
moduleResolution: 'node',
2728
},
2829
ignore: [
2930
'(?:^|/)node_modules/',
@@ -38,35 +39,14 @@ describe('lib/plugins/child/ts_node', () => {
3839
sinon.stub(typescriptObject, 'version').value('4.5.0')
3940
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')
4041

41-
expect(tsnode.register).to.be.calledWith({
42-
transpileOnly: true,
43-
compiler: 'typescript/lib/typescript.js',
44-
dir: '/path/to/plugins',
45-
compilerOptions: {
46-
module: 'commonjs',
47-
preserveValueImports: false,
48-
},
49-
ignore: [
50-
'(?:^|/)node_modules/',
51-
'/packages/telemetry/dist/span-exporters/ipc-span-exporter',
52-
'/packages/telemetry/dist/span-exporters/console-trace-link-exporter',
53-
'/packages/telemetry/dist/processors/on-start-span-processor',
54-
],
55-
})
56-
})
57-
58-
it('registers ts-node with commonjs and node moduleResolution when process.env.TS_NODE_COMPILER is set', () => {
59-
process.env.TS_NODE_COMPILER = true
60-
sinon.stub(typescriptObject, 'version').value('1.1.1')
61-
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')
62-
6342
expect(tsnode.register).to.be.calledWith({
6443
transpileOnly: true,
6544
compiler: 'typescript/lib/typescript.js',
6645
dir: '/path/to/plugins',
6746
compilerOptions: {
6847
module: 'commonjs',
6948
moduleResolution: 'node',
49+
preserveValueImports: false,
7050
},
7151
ignore: [
7252
'(?:^|/)node_modules/',
@@ -75,8 +55,6 @@ describe('lib/plugins/child/ts_node', () => {
7555
'/packages/telemetry/dist/processors/on-start-span-processor',
7656
],
7757
})
78-
79-
delete process.env.TS_NODE_COMPILER
8058
})
8159

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

0 commit comments

Comments
 (0)