Skip to content

Commit fb95918

Browse files
committed
chore: update
1 parent 9909939 commit fb95918

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/plugin-dts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ChildProcess, fork } from 'node:child_process';
2-
import { dirname, extname, join, relative } from 'node:path';
2+
import { dirname, extname, join } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { type RsbuildConfig, type RsbuildPlugin, logger } from '@rsbuild/core';
55
import color from 'picocolors';

packages/plugin-dts/src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ export async function cleanTsBuildInfoFile(
506506
}
507507
}
508508

509+
const windowsSlashRegex = /\\/g;
510+
export function normalizeSlash(p: string): string {
511+
return p.replace(windowsSlashRegex, '/');
512+
}
513+
509514
export function warnIfOutside(
510515
cwd: string,
511516
dir: string | undefined,
@@ -515,7 +520,7 @@ export function warnIfOutside(
515520
const relDir = relative(cwd, dir);
516521
if (relDir.startsWith('..') || relDir.startsWith('/')) {
517522
logger.warn(
518-
`The resolved ${label} ${color.cyan(dir)} is outside the project root ${color.cyan(cwd)}, please check your tsconfig file.`,
523+
`The resolved ${label} ${color.cyan(normalizeSlash(dir))} is outside the project root ${color.cyan(normalizeSlash(cwd))}, please check your tsconfig file.`,
519524
);
520525
}
521526
}

tests/integration/dts/index.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync } from 'node:fs';
2-
import { join, normalize } from 'node:path';
2+
import path, { join } from 'node:path';
33
import stripAnsi from 'strip-ansi';
44
import {
55
buildAndGetResults,
@@ -618,15 +618,23 @@ describe('check tsconfig.json field', async () => {
618618
});
619619
const logStrings = logs.map((log) => stripAnsi(log));
620620

621-
expect(files.esm).toMatchInlineSnapshot('undefined');
621+
const expectDeclarationDir = join(__dirname, 'check/tsconfig/dist')
622+
.split(path.sep)
623+
.join('/');
624+
const expectRoot = join(__dirname, 'check/outside-root')
625+
.split(path.sep)
626+
.join('/');
627+
622628
expect(
623629
logStrings.some((log) =>
624630
log.includes(
625-
`The resolved declarationDir ${normalize(join(__dirname, 'check/tsconfig/dist'))} is outside the project root ${normalize(join(__dirname, 'check/outside-root'))}, please check your tsconfig file.`,
631+
`The resolved declarationDir ${expectDeclarationDir} is outside the project root ${expectRoot}, please check your tsconfig file.`,
626632
),
627633
),
628634
).toEqual(true);
629635

636+
expect(files.esm).toMatchInlineSnapshot('undefined');
637+
630638
restore();
631639
});
632640
});

0 commit comments

Comments
 (0)