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

feat: handle getStylesConfig returning a Promise in Angular 16 #26559

Merged
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
37 changes: 21 additions & 16 deletions npm/webpack-dev-server/src/helpers/angularHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,33 @@ async function getAngularCliWebpackConfig (devServerConfig: AngularWebpackDevSer
buildOptions,
context,
(wco: any) => {
const stylesConfig = getStylesConfig(wco)

// We modify resolve-url-loader and set `root` to be `projectRoot` + `sourceRoot` to ensure
// imports in scss, sass, etc are correctly resolved.
// https://github.com/cypress-io/cypress/issues/24272
stylesConfig.module.rules.forEach((rule: RuleSetRule) => {
rule.rules?.forEach((ruleSet) => {
if (!Array.isArray(ruleSet.use)) {
return
}

ruleSet.use.map((loader) => {
if (typeof loader !== 'object' || typeof loader.options !== 'object' || !loader.loader?.includes('resolve-url-loader')) {
// Starting in Angular 16, the `getStylesConfig` function returns a `Promise`.
// We wrap it with `Promise.resolve` so we support older version of Angular
// returning a non-Promise result.
const stylesConfig = Promise.resolve(getStylesConfig(wco)).then((config) => {
// We modify resolve-url-loader and set `root` to be `projectRoot` + `sourceRoot` to ensure
// imports in scss, sass, etc are correctly resolved.
// https://github.com/cypress-io/cypress/issues/24272
config.module.rules.forEach((rule: RuleSetRule) => {
rule.rules?.forEach((ruleSet) => {
if (!Array.isArray(ruleSet.use)) {
return
}

const root = projectConfig.buildOptions.workspaceRoot || path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot)
ruleSet.use.map((loader) => {
if (typeof loader !== 'object' || typeof loader.options !== 'object' || !loader.loader?.includes('resolve-url-loader')) {
return
}

debug('Adding root %s to resolve-url-loader options', root)
loader.options.root = root
const root = projectConfig.buildOptions.workspaceRoot || path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot)

debug('Adding root %s to resolve-url-loader options', root)
loader.options.root = root
})
})
})

return config
})

return [getCommonConfig(wco), stylesConfig]
Expand Down