Skip to content

Commit

Permalink
fix: force the use of posix path separators for ts module graphs (#8149)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeeWizWow committed Jun 13, 2022
1 parent 3f02a9a commit 58bd6d7
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 3 deletions.
@@ -0,0 +1,18 @@
type Params = {
hello: number;
};
interface Hello {
yo: string;
}
export class Test {
test(hello: Hello): string;
}
export function test(params: Params): number;
export function foo(): number;
export var x: number;
export var hi: number;
export declare module mod {
function bar(): number;
}

//# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
export * from './src/index';
@@ -0,0 +1,6 @@
{
"name": "ts-types-main",
"private": true,
"main": "dist/main.js",
"types": "dist/types.d.ts"
}
@@ -0,0 +1,31 @@
type Params = {
hello: number;
};

interface Hello {
yo: string;
}

export class Test {
test(hello: Hello) {
return hello.yo;
}
}

export function test(params: Params) {
return params.hello;
}

export function foo() {
return 2;
}

var x = 2;
var p = x + 2, q = 3;
export {p as hi, x};

export module mod {
export function bar() {
return 2;
}
}
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"removeComments": true,
"baseUrl": ".",
"paths": {
"@parcel/*": ["../../*"]
}
}
}
Empty file.
22 changes: 22 additions & 0 deletions packages/core/integration-tests/test/ts-types.js
Expand Up @@ -388,4 +388,26 @@ describe('typescript types', function () {
);
assert.equal(dist, expected);
});

it('should handle a tsconfig file with paths on windows', async function () {
await bundle(
path.join(__dirname, '/integration/ts-types/windows-paths/index.ts'),
);

let dist = (
await outputFS.readFile(
path.join(
__dirname,
'/integration/ts-types/windows-paths/dist/types.d.ts',
),
'utf8',
)
).replace(/\r\n/g, '\n');

let expected = await inputFS.readFile(
path.join(__dirname, '/integration/ts-types/windows-paths/expected.d.ts'),
'utf8',
);
assert.equal(dist, expected);
});
});
1 change: 1 addition & 0 deletions packages/transformers/typescript-types/package.json
Expand Up @@ -24,6 +24,7 @@
"@parcel/plugin": "2.6.0",
"@parcel/source-map": "^2.0.0",
"@parcel/ts-utils": "2.6.0",
"@parcel/utils": "2.6.0",
"nullthrows": "^1.1.1"
},
"devDependencies": {
Expand Down
Expand Up @@ -8,6 +8,7 @@ import type {CompilerOptions} from 'typescript';

import ts from 'typescript';
import {CompilerHost, loadTSConfig} from '@parcel/ts-utils';
import {normalizeSeparators} from '@parcel/utils';
import {escapeMarkdown} from '@parcel/diagnostic';
import {TSModuleGraph} from './TSModuleGraph';
import nullthrows from 'nullthrows';
Expand Down Expand Up @@ -51,9 +52,11 @@ export default (new Transformer({
}
}

let mainModuleName = path
.relative(program.getCommonSourceDirectory(), asset.filePath)
.slice(0, -path.extname(asset.filePath).length);
let mainModuleName = normalizeSeparators(
path
.relative(program.getCommonSourceDirectory(), asset.filePath)
.slice(0, -path.extname(asset.filePath).length),
);
let moduleGraph = new TSModuleGraph(mainModuleName);

let emitResult = program.emit(undefined, undefined, undefined, true, {
Expand Down

0 comments on commit 58bd6d7

Please sign in to comment.