From c6e0050c0222726892f314bc4d1625e10be08703 Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Thu, 11 Jan 2024 14:03:12 -0500 Subject: [PATCH 1/2] 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] --- .circleci/workflows.yml | 12 ++++----- cli/CHANGELOG.md | 2 +- packages/server/lib/plugins/child/ts_node.js | 4 +-- .../test/unit/plugins/child/ts_node_spec.js | 26 ++----------------- 4 files changed, 9 insertions(+), 35 deletions(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 4966a5afb7b8..5fb8141292bb 100644 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -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' @@ -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+$/ @@ -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+$/ @@ -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: @@ -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 diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index be74c24e20c6..0d9b4013fde9 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -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). - 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). diff --git a/packages/server/lib/plugins/child/ts_node.js b/packages/server/lib/plugins/child/ts_node.js index f5e75701379d..4520fd036fac 100644 --- a/packages/server/lib/plugins/child/ts_node.js +++ b/packages/server/lib/plugins/child/ts_node.js @@ -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 } @@ -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 diff --git a/packages/server/test/unit/plugins/child/ts_node_spec.js b/packages/server/test/unit/plugins/child/ts_node_spec.js index ecaed2b3a6f6..8bdb03abb9ab 100644 --- a/packages/server/test/unit/plugins/child/ts_node_spec.js +++ b/packages/server/test/unit/plugins/child/ts_node_spec.js @@ -24,6 +24,7 @@ describe('lib/plugins/child/ts_node', () => { dir: '/path/to/plugins', compilerOptions: { module: 'commonjs', + moduleResolution: 'node', }, ignore: [ '(?:^|/)node_modules/', @@ -38,28 +39,6 @@ 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', @@ -67,6 +46,7 @@ describe('lib/plugins/child/ts_node', () => { compilerOptions: { module: 'commonjs', moduleResolution: 'node', + preserveValueImports: false, }, ignore: [ '(?:^|/)node_modules/', @@ -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', () => { From fb894df07411601f048fa445475ca3d044f92f8a Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Tue, 16 Jan 2024 10:09:22 -0500 Subject: [PATCH 2/2] Update cli/CHANGELOG.md --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 0d9b4013fde9..c0a5ec8cb4c6 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -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). +- 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). - 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).