Skip to content

Commit 376795f

Browse files
fix(webpack-dev-server): add typeRoots to generated tsconfig for angular (#27117)
* feat(webpack-dev-server): generate a local tsconfig file * chore: remove comments * chore: use relative paths * test(webpack-dev-server): update tsconfig tests * test(webpack-dev-server): update tsconfig tests * test(webpack-dev-server): update tsconfig tests * test(webpack-dev-server): upt outDir path * chore: build binary * Update npm/webpack-dev-server/src/helpers/angularHandler.ts Co-authored-by: Stokes Player <[email protected]> * fix(webpack-dev-server): use tmp but add typeRoots * chore: update workflow to build binary * remove redundant node_modules/types * remove node_modules/types from assertions --------- Co-authored-by: Stokes Player <[email protected]>
1 parent ddec92d commit 376795f

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

.circleci/workflows.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ mainBuildFilters: &mainBuildFilters
3030
- /^release\/\d+\.\d+\.\d+$/
3131
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
3232
- 'update-v8-snapshot-cache-on-develop'
33-
- 'chore/use_cloud_m1_runners'
33+
- 'jordanpowell88/angular-tsconfig'
34+
- 'fix/chrome_crash_recovery'
3435

3536
# usually we don't build Mac app - it takes a long time
3637
# but sometimes we want to really confirm we are doing the right thing
@@ -41,7 +42,8 @@ macWorkflowFilters: &darwin-workflow-filters
4142
- equal: [ develop, << pipeline.git.branch >> ]
4243
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4344
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
44-
- equal: [ 'chore/use_cloud_m1_runners', << pipeline.git.branch >> ]
45+
- equal: ['jordanpowell88/angular-tsconfig', << pipeline.git.branch >> ]
46+
- equal: [ 'mschile/issue-26900_browserCriClient', << pipeline.git.branch >> ]
4547
- matches:
4648
pattern: /^release\/\d+\.\d+\.\d+$/
4749
value: << pipeline.git.branch >>
@@ -52,7 +54,8 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
5254
- equal: [ develop, << pipeline.git.branch >> ]
5355
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5456
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
55-
- equal: [ 'chore/use_cloud_m1_runners', << pipeline.git.branch >> ]
57+
- equal: [ 'jordanpowell88/angular-tsconfig', << pipeline.git.branch >> ]
58+
- equal: [ 'mschile/issue-26900_browserCriClient', << pipeline.git.branch >> ]
5659
- matches:
5760
pattern: /^release\/\d+\.\d+\.\d+$/
5861
value: << pipeline.git.branch >>
@@ -142,7 +145,7 @@ commands:
142145
- run:
143146
name: Check current branch to persist artifacts
144147
command: |
145-
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "mschile/issue-26900_browserCriClient" ]]; then
148+
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "jordanpowell88/angular-tsconfig" ]]; then
146149
echo "Not uploading artifacts or posting install comment for this branch."
147150
circleci-agent step halt
148151
fi

npm/webpack-dev-server/src/helpers/angularHandler.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,23 @@ export async function generateTsConfig (devServerConfig: AngularWebpackDevServer
136136
includePaths.push(...polyfills.map((p: string) => getProjectFilePath(workspaceRoot, p)))
137137
}
138138

139-
const cypressTypes = getProjectFilePath(workspaceRoot, 'node_modules', 'cypress', 'types', 'index.d.ts')
139+
const typeRoots = [
140+
getProjectFilePath(workspaceRoot, 'node_modules'),
141+
]
140142

141-
includePaths.push(cypressTypes)
143+
const types = ['cypress']
142144

143145
const tsConfigContent = JSON.stringify({
144146
extends: getProjectFilePath(projectRoot, buildOptions.tsConfig ?? 'tsconfig.json'),
145147
compilerOptions: {
146148
outDir: getProjectFilePath(projectRoot, 'out-tsc/cy'),
147149
allowSyntheticDefaultImports: true,
148150
skipLibCheck: true,
151+
types,
152+
typeRoots,
149153
},
150154
include: includePaths,
151-
})
155+
}, null, 2)
152156

153157
const tsConfigPath = path.join(await getTempDir(), 'tsconfig.json')
154158

npm/webpack-dev-server/test/handlers/angularHandler.spec.ts

+12-23
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,24 @@ import '../support'
1919
import { scaffoldMigrationProject } from '../test-helpers/scaffoldProject'
2020

2121
chai.use(chaiPromise)
22-
2322
describe('angularHandler', function () {
2423
this.timeout(1000 * 60)
25-
2624
it('sources the config from angular-13', async () => {
2725
const projectRoot = await scaffoldMigrationProject('angular-13')
2826

2927
process.chdir(projectRoot)
30-
3128
const devServerConfig = {
3229
cypressConfig: {
3330
projectRoot,
3431
specPattern: 'src/**/*.cy.ts',
3532
} as Cypress.PluginConfigOptions,
3633
framework: 'angular',
3734
} as AngularWebpackDevServerConfig
38-
3935
const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)
4036

4137
expect(webpackConfig).to.exist
4238
expect((webpackConfig?.entry as any).main).to.be.undefined
4339
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))
44-
4540
const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)
4641

4742
await expectLoadsAngularJson(projectRoot)
@@ -54,21 +49,18 @@ describe('angularHandler', function () {
5449
const projectRoot = await scaffoldMigrationProject('angular-14')
5550

5651
process.chdir(projectRoot)
57-
5852
const devServerConfig = {
5953
cypressConfig: {
6054
projectRoot,
6155
specPattern: 'src/**/*.cy.ts',
6256
} as Cypress.PluginConfigOptions,
6357
framework: 'angular',
6458
} as AngularWebpackDevServerConfig
65-
6659
const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)
6760

6861
expect(webpackConfig).to.exist
6962
expect((webpackConfig?.entry as any).main).to.be.undefined
7063
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))
71-
7264
const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)
7365

7466
await expectLoadsAngularJson(projectRoot)
@@ -81,21 +73,18 @@ describe('angularHandler', function () {
8173
const projectRoot = await scaffoldMigrationProject('angular-15')
8274

8375
process.chdir(projectRoot)
84-
8576
const devServerConfig = {
8677
cypressConfig: {
8778
projectRoot,
8879
specPattern: 'src/**/*.cy.ts',
8980
} as Cypress.PluginConfigOptions,
9081
framework: 'angular',
9182
} as AngularWebpackDevServerConfig
92-
9383
const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)
9484

9585
expect(webpackConfig).to.exist
9686
expect((webpackConfig?.entry as any).main).to.be.undefined
9787
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))
98-
9988
const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)
10089

10190
await expectLoadsAngularJson(projectRoot)
@@ -129,7 +118,6 @@ describe('angularHandler', function () {
129118
const projectRoot = await scaffoldMigrationProject('angular-custom-config')
130119

131120
process.chdir(projectRoot)
132-
133121
const devServerConfig = {
134122
framework: 'angular',
135123
cypressConfig: {
@@ -140,13 +128,11 @@ describe('angularHandler', function () {
140128
projectConfig: customProjectConfig,
141129
},
142130
} as unknown as AngularWebpackDevServerConfig
143-
144131
const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)
145132

146133
expect(webpackConfig).to.exist
147134
expect((webpackConfig?.entry as any).main).to.be.undefined
148135
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))
149-
150136
await expectLoadsAngularJson(projectRoot)
151137
await expectLoadsAngularCLiModules(projectRoot)
152138
await expectGeneratesTsConfig(devServerConfig, customProjectConfig.buildOptions)
@@ -181,28 +167,22 @@ const expectNormalizeProjectConfig = async (projectRoot: string) => {
181167

182168
return projectConfig
183169
}
184-
185170
const expectLoadsAngularJson = async (projectRoot: string) => {
186171
const angularJson = await getAngularJson(projectRoot)
187172

188173
expect(angularJson).to.not.be.null
189-
190174
await expect(getAngularJson(path.join('..', projectRoot))).to.be.rejected
191175
}
192-
193176
const expectLoadsAngularCLiModules = async (projectRoot: string) => {
194177
const angularCliModules = await getAngularCliModules(projectRoot)
195178

196179
expect(angularCliModules.generateBrowserWebpackConfigFromContext).to.not.be.null
197180
expect(angularCliModules.getStylesConfig).to.not.be.null
198181
expect(angularCliModules.getCommonConfig).to.not.be.null
199-
200182
await expect(getAngularCliModules(path.join('..', projectRoot))).to.be.rejected
201183
}
202-
203184
const expectLoadsAngularBuildOptions = (buildOptions: BuildOptions) => {
204185
const tsConfig = 'tsconfig.cypress.json'
205-
206186
let finalBuildOptions = getAngularBuildOptions(buildOptions, tsConfig)
207187

208188
expect(finalBuildOptions.aot).to.be.false
@@ -211,7 +191,6 @@ const expectLoadsAngularBuildOptions = (buildOptions: BuildOptions) => {
211191
expect(finalBuildOptions.outputHashing).to.equal('none')
212192
expect(finalBuildOptions.budgets).to.be.undefined
213193
}
214-
215194
const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerConfig, buildOptions: any) => {
216195
const { projectRoot } = devServerConfig.cypressConfig
217196
let tsConfigPath = await generateTsConfig(devServerConfig, buildOptions)
@@ -228,11 +207,16 @@ const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerC
228207
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')),
229208
allowSyntheticDefaultImports: true,
230209
skipLibCheck: true,
210+
typeRoots: [
211+
toPosix(path.join(projectRoot, 'node_modules')),
212+
],
213+
types: [
214+
'cypress',
215+
],
231216
},
232217
include: [
233218
toPosix(path.join(projectRoot, 'src/**/*.cy.ts')),
234219
toPosix(path.join(projectRoot, 'src/polyfills.ts')),
235-
toPosix(path.join(projectRoot, 'node_modules/cypress/types/index.d.ts')),
236220
],
237221
})
238222

@@ -256,11 +240,16 @@ const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerC
256240
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')),
257241
allowSyntheticDefaultImports: true,
258242
skipLibCheck: true,
243+
typeRoots: [
244+
toPosix(path.join(projectRoot, 'node_modules')),
245+
],
246+
types: [
247+
'cypress',
248+
],
259249
},
260250
include: [
261251
toPosix(path.join(projectRoot, 'src/**/*.cy.ts')),
262252
toPosix(supportFile),
263-
toPosix(path.join(projectRoot, 'node_modules/cypress/types/index.d.ts')),
264253
],
265254
})
266255
}

0 commit comments

Comments
 (0)