diff --git a/packages/core/integration-tests/test/integration/ts-types/windows-paths/expected.d.ts b/packages/core/integration-tests/test/integration/ts-types/windows-paths/expected.d.ts new file mode 100644 index 00000000000..a1dcb1c62bc --- /dev/null +++ b/packages/core/integration-tests/test/integration/ts-types/windows-paths/expected.d.ts @@ -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 diff --git a/packages/core/integration-tests/test/integration/ts-types/windows-paths/index.ts b/packages/core/integration-tests/test/integration/ts-types/windows-paths/index.ts new file mode 100644 index 00000000000..cba18435457 --- /dev/null +++ b/packages/core/integration-tests/test/integration/ts-types/windows-paths/index.ts @@ -0,0 +1 @@ +export * from './src/index'; diff --git a/packages/core/integration-tests/test/integration/ts-types/windows-paths/package.json b/packages/core/integration-tests/test/integration/ts-types/windows-paths/package.json new file mode 100644 index 00000000000..e7879334bc0 --- /dev/null +++ b/packages/core/integration-tests/test/integration/ts-types/windows-paths/package.json @@ -0,0 +1,6 @@ +{ + "name": "ts-types-main", + "private": true, + "main": "dist/main.js", + "types": "dist/types.d.ts" +} \ No newline at end of file diff --git a/packages/core/integration-tests/test/integration/ts-types/windows-paths/src/index.ts b/packages/core/integration-tests/test/integration/ts-types/windows-paths/src/index.ts new file mode 100644 index 00000000000..ba2131c36da --- /dev/null +++ b/packages/core/integration-tests/test/integration/ts-types/windows-paths/src/index.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; + } +} diff --git a/packages/core/integration-tests/test/integration/ts-types/windows-paths/tsconfig.json b/packages/core/integration-tests/test/integration/ts-types/windows-paths/tsconfig.json new file mode 100644 index 00000000000..68dcab57b6b --- /dev/null +++ b/packages/core/integration-tests/test/integration/ts-types/windows-paths/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "removeComments": true, + "baseUrl": ".", + "paths": { + "@parcel/*": ["../../*"] + } + } +} diff --git a/packages/core/integration-tests/test/integration/ts-types/windows-paths/yarn.lock b/packages/core/integration-tests/test/integration/ts-types/windows-paths/yarn.lock new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/ts-types.js b/packages/core/integration-tests/test/ts-types.js index 8a8e02324d0..957aafae66b 100644 --- a/packages/core/integration-tests/test/ts-types.js +++ b/packages/core/integration-tests/test/ts-types.js @@ -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); + }); }); diff --git a/packages/transformers/typescript-types/package.json b/packages/transformers/typescript-types/package.json index 86ef0125087..fb25bb9e6e3 100644 --- a/packages/transformers/typescript-types/package.json +++ b/packages/transformers/typescript-types/package.json @@ -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": { diff --git a/packages/transformers/typescript-types/src/TSTypesTransformer.js b/packages/transformers/typescript-types/src/TSTypesTransformer.js index 19f3c3747b5..80473191db4 100644 --- a/packages/transformers/typescript-types/src/TSTypesTransformer.js +++ b/packages/transformers/typescript-types/src/TSTypesTransformer.js @@ -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'; @@ -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, {