X Tutup
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/transpilation/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CompilerOptions } from "../CompilerOptions";
import { escapeString, tstlHeader } from "../LuaPrinter";
import { cast, formatPathToLuaPath, isNonNull, trimExtension } from "../utils";
import { couldNotFindBundleEntryPoint } from "./diagnostics";
import { getEmitOutDir, getEmitPathRelativeToOutDir, getSourceDir } from "./transpiler";
import { getEmitOutDir, getEmitPathRelativeToOutDir, getProjectRoot } from "./transpiler";
import { EmitFile, ProcessedFile } from "./utils";

const createModulePath = (pathToResolve: string, program: ts.Program) =>
Expand Down Expand Up @@ -85,10 +85,12 @@ export function getBundleResult(program: ts.Program, files: ProcessedFile[]): [t
const entryModule = cast(options.luaBundleEntry, isNonNull);

// Resolve project settings relative to project file.
const resolvedEntryModule = path.resolve(getSourceDir(program), entryModule);
const resolvedEntryModule = path.resolve(getProjectRoot(program), entryModule);
const outputPath = path.resolve(getEmitOutDir(program), bundleFile);
const entryModuleFilePath =
program.getSourceFile(entryModule)?.fileName ?? program.getSourceFile(resolvedEntryModule)?.fileName;

if (program.getSourceFile(resolvedEntryModule) === undefined && program.getSourceFile(entryModule) === undefined) {
if (entryModuleFilePath === undefined) {
diagnostics.push(couldNotFindBundleEntryPoint(entryModule));
}

Expand All @@ -99,7 +101,7 @@ export function getBundleResult(program: ts.Program, files: ProcessedFile[]): [t
const moduleTable = createModuleTableNode(moduleTableEntries);

// return require("<entry module path>")
const entryPoint = `return require(${createModulePath(entryModule, program)}, ...)\n`;
const entryPoint = `return require(${createModulePath(entryModuleFilePath ?? entryModule, program)}, ...)\n`;

const footers: string[] = [];
if (options.sourceMapTraceback) {
Expand Down
X Tutup