Skip to content

Commit

Permalink
fix(rspack): add useTsconfigPaths to NxAppRspackPluginOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Dec 11, 2024
1 parent b859795 commit 42879c8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/rspack/src/executors/rspack/lib/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
RspackExecutorSchema,
NormalizedRspackExecutorSchema,
} from '../schema';
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

export function normalizeOptions(
options: RspackExecutorSchema,
Expand All @@ -17,6 +18,7 @@ export function normalizeOptions(
): NormalizedRspackExecutorSchema {
const normalizedOptions = {
...options,
useTsconfigPaths: !isUsingTsSolutionSetup(),
root,
projectRoot,
sourceRoot,
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/src/executors/rspack/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ export interface NormalizedRspackExecutorSchema extends RspackExecutorSchema {
root: string;
projectRoot: string;
sourceRoot: string;
useTsconfigPaths: boolean;
}
4 changes: 3 additions & 1 deletion packages/rspack/src/plugins/utils/apply-base-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ function applyNxDependentConfig(
root: options.root,
};

plugins.push(new NxTsconfigPathsRspackPlugin({ ...options, tsConfig }));
if (options.useTsconfigPaths) {
plugins.push(new NxTsconfigPathsRspackPlugin({ ...options, tsConfig }));
}

// New TS Solution already has a typecheck target
if (!options?.skipTypeChecking && !isUsingTsSolutionSetup()) {
Expand Down
4 changes: 4 additions & 0 deletions packages/rspack/src/plugins/utils/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export interface NxAppRspackPluginOptions {
* List of TypeScript Compiler Transformers Plugins.
*/
transformers?: TransformerEntry[];
/**
* Use tsconfig-paths-webpack-plugin to resolve modules using paths in the tsconfig file.
*/
useTsconfigPaths?: boolean;
/**
* Generate a separate vendor chunk for 3rd party packages.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
NxAppRspackPluginOptions,
NormalizedNxAppRspackPluginOptions,
} from '../models';
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

export function normalizeOptions(
options: NxAppRspackPluginOptions
Expand All @@ -38,6 +39,10 @@ export function normalizeOptions(
const projectNode = projectGraph.nodes[projectName];
const targetConfig = projectNode.data.targets[targetName];

// If the project is using ts solutions setup, the paths are not in tsconfig and we should not use the plugin's paths.
options.useTsconfigPaths =
options.useTsconfigPaths ?? !isUsingTsSolutionSetup();

normalizeRelativePaths(projectNode.data.root, options);

// Merge options from `@nx/rspack:rspack` into plugin options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
NormalizedWebpackExecutorOptions,
WebpackExecutorOptions,
} from '../schema';
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

export function normalizeOptions(
options: WebpackExecutorOptions,
Expand All @@ -17,6 +18,7 @@ export function normalizeOptions(
): NormalizedWebpackExecutorOptions {
const normalizedOptions = {
...options,
useTsconfigPaths: !isUsingTsSolutionSetup(),
root,
projectRoot,
sourceRoot,
Expand Down
1 change: 1 addition & 0 deletions packages/webpack/src/executors/webpack/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ export interface NormalizedWebpackExecutorOptions
root: string;
projectRoot: string;
sourceRoot: string;
useTsconfigPaths: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function normalizeOptions(

const projectNode = projectGraph.nodes[projectName];
const targetConfig = projectNode.data.targets[targetName];

// If the project is using ts solutions setup, the paths are not in tsconfig and we should not use the plugin's paths.
options.useTsconfigPaths =
options.useTsconfigPaths ?? !isUsingTsSolutionSetup();

Expand Down

0 comments on commit 42879c8

Please sign in to comment.