Skip to content

Commit 08c7ea0

Browse files
authored
Merge branch '10.0-release' into tgriesser/feat/UNIFY-1267
2 parents 1c99864 + 8381efe commit 08c7ea0

File tree

12 files changed

+106
-6
lines changed

12 files changed

+106
-6
lines changed

cli/scripts/start-build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ includeTypes.forEach((folder) => {
2424

2525
shell.exec('babel lib -d build/lib')
2626
shell.exec('babel index.js -o build/index.js')
27+
shell.cp('index.mjs', 'build/index.mjs')

packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export const e2eProjectDirs = [
144144
'todos',
145145
'ts-installed',
146146
'ts-proj',
147+
'ts-proj-4-5',
147148
'ts-proj-custom-names',
148149
'ts-proj-esmoduleinterop-true',
149150
'ts-proj-tsconfig-in-plugins',

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,39 @@ const debugLib = require('debug')
33
const path = require('path')
44
const tsnode = require('ts-node')
55
const resolve = require('../../util/resolve')
6+
const semver = require('semver')
67

78
const debug = debugLib('cypress:server:ts-node')
89

910
const getTsNodeOptions = (tsPath, registeredFile) => {
11+
const version = require(tsPath).version || '0.0.0'
12+
13+
/**
14+
* NOTE: This circumvents a limitation of ts-node
15+
*
16+
* The "preserveValueImports" option was introduced in TypeScript 4.5.0
17+
* https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#disabling-import-elision
18+
*
19+
* If we pass an unknown compiler option to ts-node,
20+
* it ignores all options passed.
21+
* If we want `module: "commonjs"` to always be used,
22+
* we need to only set options that are supported in this version of TypeScript.
23+
*/
24+
const compilerOptions = {
25+
module: 'commonjs',
26+
...(semver.satisfies(version, '>=4.5.0')
27+
// Only adding this option for TS >= 4.5.0
28+
? { preserveValueImports: false }
29+
: {}
30+
),
31+
}
32+
1033
/**
1134
* @type {import('ts-node').RegisterOptions}
1235
*/
1336
const opts = {
1437
compiler: process.env.TS_NODE_COMPILER || tsPath, // use the user's installed typescript
15-
compilerOptions: {
16-
module: 'CommonJS',
17-
},
38+
compilerOptions,
1839
// resolves tsconfig.json starting from the plugins directory
1940
// instead of the cwd (the project root)
2041
dir: path.dirname(registeredFile),

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require('../../../spec_helper')
22

33
const tsnode = require('ts-node')
4+
const typescriptObject = require('typescript/lib/typescript.js')
45

56
const resolve = require(`../../../../lib/util/resolve`)
67

@@ -9,19 +10,35 @@ const tsNodeUtil = require('../../../../lib/plugins/child/ts_node')
910
describe('lib/plugins/child/ts_node', () => {
1011
beforeEach(() => {
1112
sinon.stub(tsnode, 'register')
12-
sinon.stub(resolve, 'typescript').returns('/path/to/typescript.js')
13+
sinon.stub(resolve, 'typescript').returns('typescript/lib/typescript.js')
1314
})
1415

1516
describe('typescript registration', () => {
1617
it('registers ts-node if typescript is installed', () => {
18+
sinon.stub(typescriptObject, 'version').value('1.1.1')
1719
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')
1820

1921
expect(tsnode.register).to.be.calledWith({
2022
transpileOnly: true,
21-
compiler: '/path/to/typescript.js',
23+
compiler: 'typescript/lib/typescript.js',
2224
dir: '/path/to/plugins',
2325
compilerOptions: {
24-
module: 'CommonJS',
26+
module: 'commonjs',
27+
},
28+
})
29+
})
30+
31+
it('registers ts-node with preserveValueImports if typescript 4.5.0 is installed', () => {
32+
sinon.stub(typescriptObject, 'version').value('4.5.0')
33+
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')
34+
35+
expect(tsnode.register).to.be.calledWith({
36+
transpileOnly: true,
37+
compiler: 'typescript/lib/typescript.js',
38+
dir: '/path/to/plugins',
39+
compilerOptions: {
40+
module: 'commonjs',
41+
preserveValueImports: false,
2542
},
2643
})
2744
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { add } from './math'
2+
3+
it('is true', () => {
4+
// @ts-ignore
5+
expect(add(1, 2)).to.eq(3)
6+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const add = (a: number, b: number) => {
2+
return a + b
3+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
// import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@test-project/ts-proj-4-5",
3+
"version": "0.0.0-test",
4+
"private": true,
5+
"dependencies": {
6+
"typescript": "4.5.2"
7+
}
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"preserveValueImports": true
5+
}
6+
}

0 commit comments

Comments
 (0)