Skip to content

fix(webpack-dev-server): handle polyfills array for upcoming angular 15 change #24064

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

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/angular.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference path="../support/e2e.ts" />
import type { ProjectFixtureDir } from '@tooling/system-tests/lib/fixtureDirs'

const WEBPACK_REACT: ProjectFixtureDir[] = ['angular-13', 'angular-14']
const WEBPACK_REACT: ProjectFixtureDir[] = ['angular-13', 'angular-14', 'angular-15']

// Add to this list to focus on a particular permutation
const ONLY_PROJECTS: ProjectFixtureDir[] = []
Expand Down
12 changes: 9 additions & 3 deletions npm/webpack-dev-server/src/helpers/angularHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ export async function generateTsConfig (devServerConfig: AngularWebpackDevServer
}

if (buildOptions.polyfills) {
const polyfills = getProjectFilePath(buildOptions.polyfills)
const polyfills = Array.isArray(buildOptions.polyfills)
? buildOptions.polyfills.filter((p: string) => devServerConfig.options?.projectConfig.sourceRoot && p.startsWith(devServerConfig.options?.projectConfig.sourceRoot))
: [buildOptions.polyfills]

includePaths.push(polyfills)
includePaths.push(...polyfills.map((p: string) => getProjectFilePath(p)))
}

const cypressTypes = getProjectFilePath('node_modules', 'cypress', 'types', 'index.d.ts')
Expand Down Expand Up @@ -202,7 +204,11 @@ export async function getAngularJson (projectRoot: string): Promise<AngularJson>

function createFakeContext (projectRoot: string, defaultProjectConfig: Cypress.AngularDevServerProjectConfig) {
const logger = {
createChild: () => ({}),
createChild: () => {
return {
warn: () => {},
}
},
}

const context = {
Expand Down
27 changes: 27 additions & 0 deletions npm/webpack-dev-server/test/handlers/angularHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ describe('angularHandler', function () {
expectLoadsAngularBuildOptions(buildOptions)
})

it('sources the config from angular-15', async () => {
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)
await expectLoadsAngularCLiModules(projectRoot)
await expectGeneratesTsConfig(devServerConfig, buildOptions)
expectLoadsAngularBuildOptions(buildOptions)
})

it('allows custom project config', async () => {
const customProjectConfig = {
root: '',
Expand Down
31 changes: 31 additions & 0 deletions system-tests/projects/angular-15/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "angular-15",
"version": "0.0.0",
"private": true,
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development"
},
"dependencies": {
"@angular/animations": "^15.0.0-next.4",
"@angular/common": "^15.0.0-next.4",
"@angular/compiler": "^15.0.0-next.4",
"@angular/core": "^15.0.0-next.4",
"@angular/forms": "^15.0.0-next.4",
"@angular/platform-browser": "^15.0.0-next.4",
"@angular/platform-browser-dynamic": "^15.0.0-next.4",
"@angular/router": "^15.0.0-next.4",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.0-next.3",
"@angular/cli": "~15.0.0-next.3",
"@angular/compiler-cli": "^15.0.0-next.4",
"typescript": "~4.8.4"
},
"projectFixtureDirectory": "angular"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { StandaloneComponent } from './standalone.component'

describe('StandaloneComponent', () => {
it('can mount a standalone component', () => {
cy.mount(StandaloneComponent, {
componentProperties: {
name: 'Angular',
},
})

cy.get('h1').contains('Hello Angular')
})

it('can mount a standalone component using template', () => {
cy.mount('<app-standalone name="Angular"></app-standalone>', {
imports: [StandaloneComponent],
})

cy.get('h1').contains('Hello Angular')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, Input } from '@angular/core'

@Component({
standalone: true,
selector: 'app-standalone',
template: `<h1>Hello {{ name }}</h1>`,
})
export class StandaloneComponent {
@Input() name!: string
}
Loading