Skip to content

Commit 5724462

Browse files
committed
chore: update
1 parent fb95918 commit 5724462

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

packages/plugin-dts/src/utils.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,21 +506,18 @@ 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-
514509
export function warnIfOutside(
515510
cwd: string,
516511
dir: string | undefined,
517512
label: string,
518513
): void {
519514
if (dir) {
520-
const relDir = relative(cwd, dir);
521-
if (relDir.startsWith('..') || relDir.startsWith('/')) {
515+
const normalizedCwd = normalize(cwd);
516+
const normalizedDir = normalize(dir);
517+
const relDir = relative(normalizedCwd, normalizedDir);
518+
if (relDir.startsWith('..') || relDir.startsWith(path.sep)) {
522519
logger.warn(
523-
`The resolved ${label} ${color.cyan(normalizeSlash(dir))} is outside the project root ${color.cyan(normalizeSlash(cwd))}, please check your tsconfig file.`,
520+
`The resolved ${label} ${color.cyan(normalizedDir)} is outside the project root ${color.cyan(normalizedCwd)}, please check your tsconfig file.`,
524521
);
525522
}
526523
}

tests/integration/dts/index.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync } from 'node:fs';
2-
import path, { join } from 'node:path';
2+
import { join, normalize } from 'node:path';
33
import stripAnsi from 'strip-ansi';
44
import {
55
buildAndGetResults,
@@ -617,13 +617,12 @@ describe('check tsconfig.json field', async () => {
617617
type: 'dts',
618618
});
619619
const logStrings = logs.map((log) => stripAnsi(log));
620+
restore();
620621

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('/');
622+
const expectDeclarationDir = normalize(
623+
join(__dirname, 'check/tsconfig/dist'),
624+
);
625+
const expectRoot = normalize(join(__dirname, 'check/outside-root'));
627626

628627
expect(
629628
logStrings.some((log) =>
@@ -634,7 +633,5 @@ describe('check tsconfig.json field', async () => {
634633
).toEqual(true);
635634

636635
expect(files.esm).toMatchInlineSnapshot('undefined');
637-
638-
restore();
639636
});
640637
});

0 commit comments

Comments
 (0)