Skip to content

Commit 0bc3d98

Browse files
committed
feat: allow for @cypress/webpack-batteries-included-preprocessor to fully resolve the user tsconfig compiler options
1 parent 1d2a26a commit 0bc3d98

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

npm/vite-dev-server/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"resolveJsonModule": true,
55
"target": "ES2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */,
66
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7+
"moduleResolution": "node",
78
"lib": [
89
"es2015",
910
"dom"

npm/webpack-batteries-included-preprocessor/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const addTypeScriptConfig = (file, options) => {
5050
loader: require.resolve('ts-loader'),
5151
options: {
5252
compiler: options.typescript,
53+
// pass in the resolved compiler options from the tsconfig file into ts-loader to most accurately transpile the code
54+
...(configFile ? {
55+
compilerOptions: configFile.config.compilerOptions,
56+
} : {}),
5357
logLevel: 'error',
5458
silent: true,
5559
transpileOnly: true,

npm/webpack-batteries-included-preprocessor/test/unit/index.spec.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ describe('webpack-batteries-included-preprocessor', () => {
6767
mock.stop('@cypress/webpack-preprocessor')
6868
})
6969

70+
it('correctly passes the options in the user\'s tsconfig.json options into ts-loader', () => {
71+
getTsConfigMock.returns({
72+
config: {
73+
compilerOptions: {
74+
module: 'ESNext',
75+
moduleResolution: 'Bundler',
76+
},
77+
path: '/foo/tsconfig.json',
78+
},
79+
})
80+
81+
const preprocessorCB = preprocessor({
82+
typescript: true,
83+
webpackOptions,
84+
})
85+
86+
preprocessorCB({
87+
filePath: 'foo.ts',
88+
outputPath: '.js',
89+
})
90+
91+
const tsLoader = webpackOptions.module.rules[0].use[0]
92+
93+
expect(tsLoader.loader).to.contain('ts-loader')
94+
95+
expect(tsLoader.options.compiler).to.be.true
96+
expect(tsLoader.options.logLevel).to.equal('error')
97+
expect(tsLoader.options.silent).to.be.true
98+
expect(tsLoader.options.transpileOnly).to.be.true
99+
100+
// compilerOptions are overridden (sourceMap=true) by `@cypress/webpack-preprocessor` if ts-loader is present
101+
expect(tsLoader.options.compilerOptions).to.deep.equal({
102+
module: 'ESNext',
103+
moduleResolution: 'Bundler',
104+
})
105+
})
106+
70107
it('always returns loader options even if there is an error discovering the user\'s tsconfig.json', () => {
71108
getTsConfigMock.returns(null)
72109

@@ -89,7 +126,7 @@ describe('webpack-batteries-included-preprocessor', () => {
89126
expect(tsLoader.options.silent).to.be.true
90127
expect(tsLoader.options.transpileOnly).to.be.true
91128

92-
// compilerOptions are set by `@cypress/webpack-preprocessor` if ts-loader is present
129+
// compilerOptions are overridden (sourceMap=true) by `@cypress/webpack-preprocessor` if ts-loader is present
93130
expect(tsLoader.options.compilerOptions).to.be.undefined
94131
})
95132
})

npm/webpack-dev-server/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"resolveJsonModule": true,
55
"target": "ES2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */,
66
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7+
"moduleResolution": "node",
78
"lib": [
89
"es2015",
910
"dom"

0 commit comments

Comments
 (0)