Skip to content

Commit 0942443

Browse files
committed
Use getCommonSourcesDir in all cases
1 parent 34a08f3 commit 0942443

7 files changed

Lines changed: 12 additions & 26 deletions

File tree

src/Emit.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as path from "path";
22
import * as ts from "typescript";
3-
import { CompilerOptions, LuaLibImportKind } from "./CompilerOptions";
3+
import { LuaLibImportKind } from "./CompilerOptions";
44
import { EmitHost, TranspiledFile } from "./Transpile";
55
import { normalizeSlashes, trimExtension } from "./utils";
6-
import { getProjectRootDir } from "./resolve";
76

87
export interface OutputFile {
98
name: string;
@@ -13,14 +12,14 @@ export interface OutputFile {
1312
let lualibContent: string;
1413
export function emitTranspiledFiles(
1514
program: ts.Program,
16-
options: CompilerOptions,
1715
transpiledFiles: TranspiledFile[],
1816
emitHost: EmitHost = ts.sys
1917
): OutputFile[] {
18+
const options = program.getCompilerOptions();
2019
let { outDir, luaLibImport } = options;
2120

22-
const rootDir = getProjectRootDir(program);
23-
outDir = outDir ? path.resolve(rootDir, outDir) : rootDir;
21+
const rootDir = program.getCommonSourceDirectory();
22+
outDir = outDir || rootDir;
2423

2524
const files: OutputFile[] = [];
2625
for (const { fileName, lua, sourceMap, declaration, declarationMap } of transpiledFiles) {

src/bundle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from "path";
22
import { SourceNode } from "source-map";
33
import * as ts from "typescript";
44
import { couldNotFindBundleEntryPoint } from "./diagnostics";
5-
import { getProjectRootDir, resolveFromRootDir } from "./resolve";
5+
import { resolveFromRootDir } from "./resolve";
66
import { EmitHost, TranspiledFile } from "./Transpile";
77
import { formatPathToLuaPath, trimExtension } from "./utils";
88

@@ -23,7 +23,7 @@ export function bundleTranspiledFiles(
2323
}
2424

2525
// For each file: ["<file name>"] = function() <lua content> end,
26-
const projectRootDir = getProjectRootDir(program);
26+
const projectRootDir = program.getCommonSourceDirectory();
2727
const moduleTableEntries: SourceChunk[] = transpiledFiles.map(f => moduleSourceNode(f, projectRootDir));
2828

2929
// If any of the modules contains a require for lualib_bundle, add it to the module table.
@@ -51,7 +51,7 @@ export function bundleTranspiledFiles(
5151
return [
5252
diagnostics,
5353
{
54-
fileName: path.join(getProjectRootDir(program), bundleFile),
54+
fileName: path.join(program.getCommonSourceDirectory(), bundleFile),
5555
lua: code,
5656
sourceMap: map.toString(),
5757
sourceMapNode: moduleTable,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface TranspileFilesResult {
2626
export function transpileFiles(rootNames: string[], options: CompilerOptions = {}): TranspileFilesResult {
2727
const program = ts.createProgram(rootNames, options);
2828
const { transpiledFiles, diagnostics: transpileDiagnostics } = transpile({ program });
29-
const emitResult = emitTranspiledFiles(program, program.getCompilerOptions(), transpiledFiles);
29+
const emitResult = emitTranspiledFiles(program, transpiledFiles);
3030

3131
const diagnostics = ts.sortAndDeduplicateDiagnostics([
3232
...ts.getPreEmitDiagnostics(program),

src/resolve.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ import * as path from "path";
22
import * as ts from "typescript";
33
import { normalizeSlashes } from "./utils";
44

5-
export function getProjectRootDir(program: ts.Program): string {
6-
const options = program.getCompilerOptions();
7-
const projectDir = options.configFilePath
8-
? path.dirname(options.configFilePath)
9-
: program.getCommonSourceDirectory();
10-
11-
return normalizeSlashes(options.rootDir ? path.resolve(projectDir, options.rootDir) : projectDir);
12-
}
13-
145
export const resolveFromRootDir = (program: ts.Program, pathToResolve: string) =>
156
path.isAbsolute(pathToResolve)
167
? normalizeSlashes(pathToResolve)
17-
: normalizeSlashes(path.resolve(getProjectRootDir(program), pathToResolve));
8+
: normalizeSlashes(path.resolve(program.getCommonSourceDirectory(), pathToResolve));

src/tstl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function performCompilation(
111111
...transpileDiagnostics,
112112
]);
113113

114-
const emitResult = tstl.emitTranspiledFiles(program, options, transpiledFiles);
114+
const emitResult = tstl.emitTranspiledFiles(program, transpiledFiles);
115115
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));
116116

117117
diagnostics.forEach(reportDiagnostic);
@@ -182,7 +182,7 @@ function updateWatchCompilationHost(
182182

183183
const { diagnostics: emitDiagnostics, transpiledFiles } = tstl.transpile({ program, sourceFiles });
184184

185-
const emitResult = tstl.emitTranspiledFiles(program, options, transpiledFiles);
185+
const emitResult = tstl.emitTranspiledFiles(program, transpiledFiles);
186186
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));
187187

188188
const diagnostics = ts.sortAndDeduplicateDiagnostics([

src/typescript-internal.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,4 @@ declare module "typescript" {
1515
interface Program {
1616
getCommonSourceDirectory(): string;
1717
}
18-
19-
interface CompilerOptions {
20-
configFilePath?: string;
21-
}
2218
}

test/cli/parse.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe("command line", () => {
118118

119119
["luaBundle", "foo", { luaBundle: "foo" }],
120120
["luaBundleEntry", "bar", { luaBundleEntry: "bar" }],
121-
])("{ %p: %p }", (optionName, value, expected) => {
121+
])("--%s %s", (optionName, value, expected) => {
122122
const result = tstl.parseCommandLine([`--${optionName}`, value]);
123123

124124
expect(result.errors).not.toHaveErrorDiagnostics();

0 commit comments

Comments
 (0)