Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: force the use of posix path separators for ts module graphs #8149

Merged
merged 8 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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/*": ["../../*"]
}
}
}
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