Skip to content

Commit 067fde4

Browse files
committed
Posix paths
1 parent 86c80f0 commit 067fde4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/typescript/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
2525

2626
let program: import('typescript').Watch<unknown> | null = null;
2727

28+
function normalizePath(fileName: string) {
29+
return fileName.split(path.win32.sep).join(path.posix.sep);
30+
}
31+
2832
return {
2933
name: 'typescript',
3034

@@ -62,7 +66,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
6266
if (!importer) return null;
6367

6468
// Convert path from windows separators to posix separators
65-
const containingFile = importer.split(path.win32.sep).join(path.posix.sep);
69+
const containingFile = normalizePath(importer);
6670

6771
const resolved = resolveModule(importee, containingFile);
6872

@@ -89,7 +93,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
8993
if (code) {
9094
this.emitFile({
9195
type: 'asset',
92-
fileName: path.relative(outputOptions.dir!, id),
96+
fileName: normalizePath(path.relative(outputOptions.dir!, id)),
9397
source: code
9498
});
9599
}
@@ -99,7 +103,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
99103
if (tsBuildInfoPath) {
100104
this.emitFile({
101105
type: 'asset',
102-
fileName: path.relative(outputOptions.dir!, tsBuildInfoPath),
106+
fileName: normalizePath(path.relative(outputOptions.dir!, tsBuildInfoPath)),
103107
source: emittedFiles.get(tsBuildInfoPath)
104108
});
105109
}

packages/typescript/test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test('supports creating declaration files', async (t) => {
5454
['main.js', 'main.d.ts']
5555
);
5656

57-
t.is(output[1].source, 'declare const answer = 42;\n');
57+
t.true(output[1].source.includes('declare const answer = 42;'), output[1].source);
5858
});
5959

6060
test('supports creating declaration files in subfolder', async (t) => {
@@ -197,7 +197,7 @@ test('relative paths in tsconfig.json are resolved relative to the file', async
197197
['main.js', 'main.d.ts']
198198
);
199199

200-
t.is(output[1].source, 'declare const answer = 42;\n');
200+
t.true(output[1].source.includes('declare const answer = 42;'), output[1].source);
201201
});
202202

203203
test('throws for unsupported module types', async (t) => {

0 commit comments

Comments
 (0)