Skip to content

Commit e04608f

Browse files
authored
Improve paths tests and add baseUrl requiring check when specifying paths (#1324)
* Improve paths tests and add baseUrl requiring check when specifying paths * Fix jsx test
1 parent 079f704 commit e04608f

File tree

18 files changed

+38
-22
lines changed

18 files changed

+38
-22
lines changed

src/CompilerOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,9 @@ export function validateOptions(options: CompilerOptions): ts.Diagnostic[] {
8787
diagnostics.push(diagnosticFactories.unsupportedJsxEmit());
8888
}
8989

90+
if (options.paths && !options.baseUrl) {
91+
diagnostics.push(diagnosticFactories.pathsWithoutBaseUrl());
92+
}
93+
9094
return diagnostics;
9195
}

src/transpilation/diagnostics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ export const cannotBundleLibrary = createDiagnosticFactory(
5555
);
5656

5757
export const unsupportedJsxEmit = createDiagnosticFactory(() => 'JSX is only supported with "react" jsx option.');
58+
59+
export const pathsWithoutBaseUrl = createDiagnosticFactory(
60+
() => "When configuring 'paths' in tsconfig.json, the option 'baseUrl' must also be provided."
61+
);

test/transpile/__snapshots__/module-resolution.spec.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
exports[`supports complicated paths configuration 1`] = `
44
Array [
5-
"/monorepo-complicated/dist/packages/tstl-program/packages/mypackage/src/bar.lua",
6-
"/monorepo-complicated/dist/packages/tstl-program/packages/mypackage/src/index.lua",
7-
"/monorepo-complicated/dist/packages/tstl-program/packages/myprogram/src/main.lua",
5+
"/paths-base-tsconfig/dist/packages/tstl-program/packages/mypackage/src/bar.lua",
6+
"/paths-base-tsconfig/dist/packages/tstl-program/packages/mypackage/src/index.lua",
7+
"/paths-base-tsconfig/dist/packages/tstl-program/packages/myprogram/src/main.lua",
88
]
99
`;
1010

1111
exports[`supports paths configuration 1`] = `
1212
Array [
13-
"/monorepo-with-paths/myprogram/dist/mypackage/bar.lua",
14-
"/monorepo-with-paths/myprogram/dist/mypackage/index.lua",
15-
"/monorepo-with-paths/myprogram/dist/myprogram/main.lua",
13+
"/paths-simple/myprogram/dist/mypackage/bar.lua",
14+
"/paths-simple/myprogram/dist/mypackage/index.lua",
15+
"/paths-simple/myprogram/dist/myprogram/main.lua",
1616
]
1717
`;

test/transpile/module-resolution.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as util from "../util";
44
import * as ts from "typescript";
55
import { BuildMode } from "../../src";
66
import { normalizeSlashes } from "../../src/utils";
7+
import { pathsWithoutBaseUrl } from "../../src/transpilation/diagnostics";
78

89
describe("basic module resolution", () => {
910
const projectPath = path.resolve(__dirname, "module-resolution", "project-with-node-modules");
@@ -542,7 +543,7 @@ test("lualib_module with parent directory import (#1307)", () => {
542543

543544
test("supports paths configuration", () => {
544545
// Package root
545-
const baseProjectPath = path.resolve(__dirname, "module-resolution", "monorepo-with-paths");
546+
const baseProjectPath = path.resolve(__dirname, "module-resolution", "paths-simple");
546547
// myprogram package
547548
const projectPath = path.join(baseProjectPath, "myprogram");
548549
const projectTsConfig = path.join(projectPath, "tsconfig.json");
@@ -565,7 +566,7 @@ test("supports paths configuration", () => {
565566

566567
test("supports complicated paths configuration", () => {
567568
// Package root
568-
const baseProjectPath = path.resolve(__dirname, "module-resolution", "monorepo-complicated");
569+
const baseProjectPath = path.resolve(__dirname, "module-resolution", "paths-base-tsconfig");
569570
// myprogram package
570571
const projectPath = path.join(baseProjectPath, "packages", "myprogram");
571572
const projectTsConfig = path.join(projectPath, "tsconfig.json");
@@ -586,6 +587,10 @@ test("supports complicated paths configuration", () => {
586587
.expectToEqual({ foo: 314, bar: 271 });
587588
});
588589

590+
test("paths without baseUrl is error", () => {
591+
util.testFunction``.setOptions({ paths: {} }).expectToHaveDiagnostics([pathsWithoutBaseUrl.code]);
592+
});
593+
589594
function snapshotPaths(files: tstl.TranspiledFile[]) {
590595
return files.map(f => normalizeSlashes(f.outPath).split("module-resolution")[1]).sort();
591596
}

test/transpile/module-resolution/monorepo-with-paths/myprogram/main.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/transpile/module-resolution/monorepo-with-paths/myprogram/tsconfig.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/transpile/module-resolution/monorepo-complicated/packages/mypackage/src/bar.ts renamed to test/transpile/module-resolution/paths-base-tsconfig/packages/mypackage/src/bar.ts

File renamed without changes.

test/transpile/module-resolution/monorepo-complicated/packages/mypackage/src/index.ts renamed to test/transpile/module-resolution/paths-base-tsconfig/packages/mypackage/src/index.ts

File renamed without changes.

test/transpile/module-resolution/monorepo-complicated/packages/mypackage/tsconfig.json renamed to test/transpile/module-resolution/paths-base-tsconfig/packages/mypackage/tsconfig.json

File renamed without changes.

test/transpile/module-resolution/monorepo-complicated/packages/myprogram/src/main.ts renamed to test/transpile/module-resolution/paths-base-tsconfig/packages/myprogram/src/main.ts

File renamed without changes.

0 commit comments

Comments
 (0)