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 0f40005
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/next/plugins/component-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Able to find CT project, ${!!ctProjectConfig}.`);
projectRoot: ctProjectConfig.root,
sourceRoot: ctProjectConfig.sourceRoot,
main: '',
useTsconfigPaths: undefined,
fileReplacements: buildFileReplacements,
assets: buildAssets,
outputPath: buildOuputPath,
Expand Down
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;
}
10 changes: 8 additions & 2 deletions packages/rspack/src/plugins/utils/apply-base-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ function applyNxDependentConfig(
const tsConfig = options.tsConfig ?? getRootTsConfigPath();
const plugins: RspackPluginInstance[] = [];

const isUsingTsSolution = isUsingTsSolutionSetup();

const executorContext: Partial<ExecutorContext> = {
projectName: options.projectName,
targetName: options.targetName,
Expand All @@ -225,10 +227,14 @@ function applyNxDependentConfig(
root: options.root,
};

plugins.push(new NxTsconfigPathsRspackPlugin({ ...options, tsConfig }));
options.useTsconfigPaths ??= !isUsingTsSolution;
// If the project is using ts solutions setup, the paths are not in tsconfig and we should not use the plugin's paths.
if (options.useTsconfigPaths) {
plugins.push(new NxTsconfigPathsRspackPlugin({ ...options, tsConfig }));
}

// New TS Solution already has a typecheck target
if (!options?.skipTypeChecking && !isUsingTsSolutionSetup()) {
if (!options?.skipTypeChecking && !isUsingTsSolution) {
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
plugins.push(
new ForkTsCheckerWebpackPlugin({
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
1 change: 1 addition & 0 deletions packages/rspack/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function ensureNxRspackExecutionContext(ctx: NxRspackExecutionContext): void {
outputFileName: undefined,
outputPath: undefined,
rspackConfig: undefined,
useTsconfigPaths: undefined,
};
ctx.context ??= {
projectName,
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/src/utils/read-rspack-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function readRspackOptions(
tsConfig: '',
outputPath: '',
rspackConfig: '',
useTsconfigPaths: undefined,
},
context: {
root: workspaceRoot,
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 @@ -231,12 +231,16 @@ function applyNxDependentConfig(
root: options.root,
};

const isUsingTsSolution = isUsingTsSolutionSetup();
options.useTsconfigPaths ??= !isUsingTsSolution;

// If the project is using ts solutions setup, the paths are not in tsconfig and we should not use the plugin's paths.
if (options.useTsconfigPaths) {
plugins.push(new NxTsconfigPathsWebpackPlugin({ ...options, tsConfig }));
}

// New TS Solution already has a typecheck target
if (!options?.skipTypeChecking && !isUsingTsSolutionSetup()) {
if (!options?.skipTypeChecking && !isUsingTsSolution) {
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
plugins.push(
new ForkTsCheckerWebpackPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
NormalizedNxAppWebpackPluginOptions,
NxAppWebpackPluginOptions,
} from '../nx-app-webpack-plugin-options';
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

export function normalizeOptions(
options: NxAppWebpackPluginOptions
Expand All @@ -38,8 +37,6 @@ export function normalizeOptions(

const projectNode = projectGraph.nodes[projectName];
const targetConfig = projectNode.data.targets[targetName];
options.useTsconfigPaths =
options.useTsconfigPaths ?? !isUsingTsSolutionSetup();

normalizeRelativePaths(projectNode.data.root, options);

Expand Down
1 change: 1 addition & 0 deletions packages/webpack/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function ensureNxWebpackExecutionContext(ctx: NxWebpackExecutionContext): void {
outputPath: undefined,
tsConfig: undefined,
outputFileName: undefined,
useTsconfigPaths: undefined,
};
ctx.context ??= {
projectName,
Expand Down
1 change: 1 addition & 0 deletions packages/webpack/src/utils/webpack/read-webpack-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function readWebpackOptions(
outputFileName: undefined,
outputPath: undefined,
assets: undefined,
useTsconfigPaths: undefined,
},
context: {
root: workspaceRoot,
Expand Down

0 comments on commit 0f40005

Please sign in to comment.