Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack-dev-server): add typeRoots to generated tsconfig for angular #27117

Merged
merged 25 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b1e9722
feat(webpack-dev-server): generate a local tsconfig file
jordanpowell88 Jun 22, 2023
c8ab14f
chore: remove comments
jordanpowell88 Jun 23, 2023
5e8e19d
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jun 23, 2023
cf58585
chore: use relative paths
jordanpowell88 Jun 26, 2023
49923d3
Merge branch 'jordanpowell88/angular-tsconfig' of https://github.com/…
jordanpowell88 Jun 26, 2023
1f896b1
test(webpack-dev-server): update tsconfig tests
jordanpowell88 Jun 26, 2023
c8b808a
test(webpack-dev-server): update tsconfig tests
jordanpowell88 Jun 26, 2023
0d9a97a
test(webpack-dev-server): update tsconfig tests
jordanpowell88 Jun 26, 2023
52954af
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jun 26, 2023
a2d3987
Merge branch 'jordanpowell88/angular-tsconfig' of https://github.com/…
jordanpowell88 Jun 26, 2023
d3b8dd2
test(webpack-dev-server): upt outDir path
jordanpowell88 Jun 26, 2023
e8ab248
chore: build binary
jordanpowell88 Jun 26, 2023
fe130b7
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 6, 2023
3b2bb4b
Update npm/webpack-dev-server/src/helpers/angularHandler.ts
jordanpowell88 Jul 6, 2023
b7c85c6
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 6, 2023
491a0d2
fix(webpack-dev-server): use tmp but add typeRoots
jordanpowell88 Jul 7, 2023
20112de
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 7, 2023
9810e56
chore: update workflow to build binary
jordanpowell88 Jul 7, 2023
15aca64
Merge branch 'jordanpowell88/angular-tsconfig' of https://github.com/…
jordanpowell88 Jul 7, 2023
202ccc2
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 7, 2023
eb9a225
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 17, 2023
c991d53
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 17, 2023
aec1dab
Merge branch 'develop' into jordanpowell88/angular-tsconfig
jordanpowell88 Jul 17, 2023
67b86c8
remove redundant node_modules/types
jordanpowell88 Jul 17, 2023
1434534
remove node_modules/types from assertions
jordanpowell88 Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ mainBuildFilters: &mainBuildFilters
- /^release\/\d+\.\d+\.\d+$/
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'update-v8-snapshot-cache-on-develop'
- 'chore/use_cloud_m1_runners'
- 'jordanpowell88/angular-tsconfig'
- 'fix/chrome_crash_recovery'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -41,7 +42,8 @@ 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/use_cloud_m1_runners', << pipeline.git.branch >> ]
- equal: ['jordanpowell88/angular-tsconfig', << pipeline.git.branch >> ]
- equal: [ 'mschile/issue-26900_browserCriClient', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -52,7 +54,8 @@ 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/use_cloud_m1_runners', << pipeline.git.branch >> ]
- equal: [ 'jordanpowell88/angular-tsconfig', << pipeline.git.branch >> ]
- equal: [ 'mschile/issue-26900_browserCriClient', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -142,7 +145,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "mschile/issue-26900_browserCriClient" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "jordanpowell88/angular-tsconfig" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
10 changes: 7 additions & 3 deletions npm/webpack-dev-server/src/helpers/angularHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,23 @@ export async function generateTsConfig (devServerConfig: AngularWebpackDevServer
includePaths.push(...polyfills.map((p: string) => getProjectFilePath(workspaceRoot, p)))
}

const cypressTypes = getProjectFilePath(workspaceRoot, 'node_modules', 'cypress', 'types', 'index.d.ts')
const typeRoots = [
getProjectFilePath(workspaceRoot, 'node_modules'),
]

includePaths.push(cypressTypes)
const types = ['cypress']

const tsConfigContent = JSON.stringify({
extends: getProjectFilePath(projectRoot, buildOptions.tsConfig ?? 'tsconfig.json'),
compilerOptions: {
outDir: getProjectFilePath(projectRoot, 'out-tsc/cy'),
allowSyntheticDefaultImports: true,
skipLibCheck: true,
types,
typeRoots,
},
include: includePaths,
})
}, null, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this was just to get pretty formatting? Still needed since this is dumping to a temp dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, but makes it "pretty"er 🤣


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

Expand Down
35 changes: 12 additions & 23 deletions npm/webpack-dev-server/test/handlers/angularHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,24 @@ import '../support'
import { scaffoldMigrationProject } from '../test-helpers/scaffoldProject'

chai.use(chaiPromise)

describe('angularHandler', function () {
this.timeout(1000 * 60)

it('sources the config from angular-13', async () => {
const projectRoot = await scaffoldMigrationProject('angular-13')

process.chdir(projectRoot)

const devServerConfig = {
cypressConfig: {
projectRoot,
specPattern: 'src/**/*.cy.ts',
} as Cypress.PluginConfigOptions,
framework: 'angular',
} as AngularWebpackDevServerConfig

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)

expect(webpackConfig).to.exist
expect((webpackConfig?.entry as any).main).to.be.undefined
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))

const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)

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

process.chdir(projectRoot)

const devServerConfig = {
cypressConfig: {
projectRoot,
specPattern: 'src/**/*.cy.ts',
} as Cypress.PluginConfigOptions,
framework: 'angular',
} as AngularWebpackDevServerConfig

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)

expect(webpackConfig).to.exist
expect((webpackConfig?.entry as any).main).to.be.undefined
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))

const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)

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

process.chdir(projectRoot)

const devServerConfig = {
cypressConfig: {
projectRoot,
specPattern: 'src/**/*.cy.ts',
} as Cypress.PluginConfigOptions,
framework: 'angular',
} as AngularWebpackDevServerConfig

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)

expect(webpackConfig).to.exist
expect((webpackConfig?.entry as any).main).to.be.undefined
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))

const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)

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

process.chdir(projectRoot)

const devServerConfig = {
framework: 'angular',
cypressConfig: {
Expand All @@ -140,13 +128,11 @@ describe('angularHandler', function () {
projectConfig: customProjectConfig,
},
} as unknown as AngularWebpackDevServerConfig

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)

expect(webpackConfig).to.exist
expect((webpackConfig?.entry as any).main).to.be.undefined
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))

await expectLoadsAngularJson(projectRoot)
await expectLoadsAngularCLiModules(projectRoot)
await expectGeneratesTsConfig(devServerConfig, customProjectConfig.buildOptions)
Expand Down Expand Up @@ -181,28 +167,22 @@ const expectNormalizeProjectConfig = async (projectRoot: string) => {

return projectConfig
}

const expectLoadsAngularJson = async (projectRoot: string) => {
const angularJson = await getAngularJson(projectRoot)

expect(angularJson).to.not.be.null

await expect(getAngularJson(path.join('..', projectRoot))).to.be.rejected
}

const expectLoadsAngularCLiModules = async (projectRoot: string) => {
const angularCliModules = await getAngularCliModules(projectRoot)

expect(angularCliModules.generateBrowserWebpackConfigFromContext).to.not.be.null
expect(angularCliModules.getStylesConfig).to.not.be.null
expect(angularCliModules.getCommonConfig).to.not.be.null

await expect(getAngularCliModules(path.join('..', projectRoot))).to.be.rejected
}

const expectLoadsAngularBuildOptions = (buildOptions: BuildOptions) => {
const tsConfig = 'tsconfig.cypress.json'

let finalBuildOptions = getAngularBuildOptions(buildOptions, tsConfig)

expect(finalBuildOptions.aot).to.be.false
Expand All @@ -211,7 +191,6 @@ const expectLoadsAngularBuildOptions = (buildOptions: BuildOptions) => {
expect(finalBuildOptions.outputHashing).to.equal('none')
expect(finalBuildOptions.budgets).to.be.undefined
}

const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerConfig, buildOptions: any) => {
const { projectRoot } = devServerConfig.cypressConfig
let tsConfigPath = await generateTsConfig(devServerConfig, buildOptions)
Expand All @@ -228,11 +207,16 @@ const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerC
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')),
allowSyntheticDefaultImports: true,
skipLibCheck: true,
typeRoots: [
toPosix(path.join(projectRoot, 'node_modules')),
],
types: [
'cypress',
],
},
include: [
toPosix(path.join(projectRoot, 'src/**/*.cy.ts')),
toPosix(path.join(projectRoot, 'src/polyfills.ts')),
toPosix(path.join(projectRoot, 'node_modules/cypress/types/index.d.ts')),
],
})

Expand All @@ -256,11 +240,16 @@ const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerC
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')),
allowSyntheticDefaultImports: true,
skipLibCheck: true,
typeRoots: [
toPosix(path.join(projectRoot, 'node_modules')),
],
types: [
'cypress',
],
},
include: [
toPosix(path.join(projectRoot, 'src/**/*.cy.ts')),
toPosix(supportFile),
toPosix(path.join(projectRoot, 'node_modules/cypress/types/index.d.ts')),
],
})
}