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(angular): set tsconfig paths relative to the workspace root in target options #20507

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/angular/src/builders/dev-server/dev-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { BuilderContext } from '@angular-devkit/architect';
import type { DevServerBuilderOptions } from '@angular-devkit/build-angular';
import {
joinPathFragments,
normalizePath,
parseTargetString,
readCachedProjectGraph,
} from '@nx/devkit';
Expand All @@ -11,6 +12,7 @@ import { WebpackNxBuildCoordinationPlugin } from '@nx/webpack/src/plugins/webpac
import { existsSync } from 'fs';
import { isNpmProject } from 'nx/src/project-graph/operators';
import { readCachedProjectConfiguration } from 'nx/src/project-graph/project-graph';
import { relative } from 'path';
import { from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
Expand Down Expand Up @@ -104,6 +106,9 @@ export function executeDevServerBuilder(
target: parsedBuildTarget.target,
});
dependencies = foundDependencies;
const relativeTsConfigPath = normalizePath(
relative(context.workspaceRoot, tsConfigPath)
);

// We can't just pass the tsconfig path in memory to the angular builder
// function because we can't pass the build target options to it, the build
Expand All @@ -114,15 +119,15 @@ export function executeDevServerBuilder(
const originalGetTargetOptions = context.getTargetOptions;
context.getTargetOptions = async (target) => {
const options = await originalGetTargetOptions(target);
options.tsConfig = tsConfigPath;
options.tsConfig = relativeTsConfigPath;
return options;
};

// The buildTargetConfiguration also needs to use the generated tsconfig path
// otherwise the build will fail if customWebpack function/file is referencing
// local libs. This synchronize the behavior with webpack-browser and
// webpack-server implementation.
buildTargetOptions.tsConfig = tsConfigPath;
buildTargetOptions.tsConfig = relativeTsConfigPath;
}

const delegateBuilderOptions = getDelegateBuilderOptions(options);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
joinPathFragments,
normalizePath,
ProjectGraph,
readCachedProjectGraph,
} from '@nx/devkit';
Expand All @@ -9,7 +10,7 @@ import { existsSync } from 'fs';
import { readNxJson } from 'nx/src/config/configuration';
import { isNpmProject } from 'nx/src/project-graph/operators';
import { getDependencyConfigs } from 'nx/src/tasks-runner/utils';
import { join } from 'path';
import { relative } from 'path';
import { from, Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs';
Expand Down Expand Up @@ -85,7 +86,9 @@ export function executeWebpackBrowserBuilder(
{ projectGraph }
);
dependencies = foundDependencies;
delegateBuilderOptions.tsConfig = tsConfigPath;
delegateBuilderOptions.tsConfig = normalizePath(
relative(context.workspaceRoot, tsConfigPath)
);
}

return from(import('@angular-devkit/build-angular')).pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { joinPathFragments } from '@nx/devkit';
import { joinPathFragments, normalizePath } from '@nx/devkit';
import { existsSync } from 'fs';
import { relative } from 'path';
import { Observable, from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs';
Expand Down Expand Up @@ -100,7 +101,9 @@ export function executeWebpackServerBuilder(
options.tsConfig,
context
);
options.tsConfig = tsConfigPath;
options.tsConfig = normalizePath(
relative(context.workspaceRoot, tsConfigPath)
);
}

return buildServerApp(options, context);
Expand Down