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: support custom workspaceRoot for angular CT #26030

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
19 changes: 10 additions & 9 deletions npm/webpack-dev-server/src/helpers/angularHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ export function getAngularBuildOptions (buildOptions: BuildOptions, tsConfig: st
export async function generateTsConfig (devServerConfig: AngularWebpackDevServerConfig, buildOptions: BuildOptions): Promise<string> {
const { cypressConfig } = devServerConfig
const { projectRoot } = cypressConfig
const { workspaceRoot = projectRoot } = buildOptions

const specPattern = Array.isArray(cypressConfig.specPattern) ? cypressConfig.specPattern : [cypressConfig.specPattern]

const getProjectFilePath = (...fileParts: string[]): string => toPosix(path.join(projectRoot, ...fileParts))
const getProjectFilePath = (...fileParts: string[]): string => toPosix(path.join(...fileParts))

const includePaths = [...specPattern.map((pattern) => getProjectFilePath(pattern))]
const includePaths = [...specPattern.map((pattern) => getProjectFilePath(projectRoot, pattern))]

if (cypressConfig.supportFile) {
includePaths.push(toPosix(cypressConfig.supportFile))
Expand All @@ -131,17 +132,17 @@ export async function generateTsConfig (devServerConfig: AngularWebpackDevServer
? buildOptions.polyfills.filter((p: string) => devServerConfig.options?.projectConfig.sourceRoot && p.startsWith(devServerConfig.options?.projectConfig.sourceRoot))
: [buildOptions.polyfills]

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

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

includePaths.push(cypressTypes)

const tsConfigContent = JSON.stringify({
extends: getProjectFilePath(buildOptions.tsConfig ?? 'tsconfig.json'),
extends: getProjectFilePath(projectRoot, buildOptions.tsConfig ?? 'tsconfig.json'),
compilerOptions: {
outDir: getProjectFilePath('out-tsc/cy'),
outDir: getProjectFilePath(projectRoot, 'out-tsc/cy'),
allowSyntheticDefaultImports: true,
skipLibCheck: true,
},
Expand Down Expand Up @@ -253,7 +254,7 @@ async function getAngularCliWebpackConfig (devServerConfig: AngularWebpackDevSer

const buildOptions = getAngularBuildOptions(projectConfig.buildOptions, tsConfig)

const context = createFakeContext(projectRoot, projectConfig, logging)
const context = createFakeContext(projectConfig.buildOptions.workspaceRoot || projectRoot, projectConfig, logging)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just use the buildOptions output from getAngularBuildOptions above (same on line 279)? Slightly cleaner, perhaps


const { config } = await generateBrowserWebpackConfigFromContext(
buildOptions,
Expand All @@ -275,10 +276,10 @@ async function getAngularCliWebpackConfig (devServerConfig: AngularWebpackDevSer
return
}

const root = path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot)
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 = path.join(devServerConfig.cypressConfig.projectRoot, projectConfig.sourceRoot)
loader.options.root = root
})
})
})
Expand Down