Skip to content

Commit 4977d30

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

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.circleci/workflows.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mainBuildFilters: &mainBuildFilters
3838
- /^release\/\d+\.\d+\.\d+$/
3939
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4040
- 'update-v8-snapshot-cache-on-develop'
41-
- 'feat/replace_tsnode_for_tsx_config_process'
41+
- 'feat/wbip_full_resolve_ts_config'
4242

4343
# usually we don't build Mac app - it takes a long time
4444
# but sometimes we want to really confirm we are doing the right thing
@@ -49,7 +49,7 @@ macWorkflowFilters: &darwin-workflow-filters
4949
- equal: [ develop, << pipeline.git.branch >> ]
5050
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5151
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
52-
- equal: [ 'feat/replace_tsnode_for_tsx_config_process', << pipeline.git.branch >> ]
52+
- equal: [ 'feat/wbip_full_resolve_ts_config', << pipeline.git.branch >> ]
5353
- matches:
5454
pattern: /^release\/\d+\.\d+\.\d+$/
5555
value: << pipeline.git.branch >>
@@ -60,7 +60,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
6060
- equal: [ develop, << pipeline.git.branch >> ]
6161
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
6262
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
63-
- equal: [ 'feat/replace_tsnode_for_tsx_config_process', << pipeline.git.branch >> ]
63+
- equal: [ 'feat/wbip_full_resolve_ts_config', << pipeline.git.branch >> ]
6464
- matches:
6565
pattern: /^release\/\d+\.\d+\.\d+$/
6666
value: << pipeline.git.branch >>
@@ -83,7 +83,7 @@ windowsWorkflowFilters: &windows-workflow-filters
8383
- equal: [ develop, << pipeline.git.branch >> ]
8484
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
8585
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
86-
- equal: [ 'feat/replace_tsnode_for_tsx_config_process', << pipeline.git.branch >> ]
86+
- equal: [ 'feat/wbip_full_resolve_ts_config', << pipeline.git.branch >> ]
8787
- matches:
8888
pattern: /^release\/\d+\.\d+\.\d+$/
8989
value: << pipeline.git.branch >>
@@ -157,7 +157,7 @@ commands:
157157
name: Set environment variable to determine whether or not to persist artifacts
158158
command: |
159159
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
160-
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "feat/replace_tsnode_for_tsx_config_process" ]]; then
160+
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "feat/wbip_full_resolve_ts_config" ]]; then
161161
export SHOULD_PERSIST_ARTIFACTS=true
162162
fi' >> "$BASH_ENV"
163163
# You must run `setup_should_persist_artifacts` command and be using bash before running this command

npm/vite-dev-server/tsconfig.json

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 38 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)