Skip to content

Commit d494d6f

Browse files
committed
Error on resolution to script files that aren't included in the project
1 parent 0695475 commit d494d6f

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/transpilation/diagnostics.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ export const usingLuaBundleWithInlineMightGenerateDuplicateCode = createSerialDi
3939
"It is recommended to use 'luaLibImport: \"require\"'.",
4040
}));
4141

42-
export const unresolvableRequirePath = createDiagnosticFactory(
43-
(path: string) => `Cannot create require path. Module '${path}' does not exist within --rootDir.`
44-
);
45-
4642
const sourceFileStub = ts.createSourceFile("", "", ts.ScriptTarget.ES3);
4743
export const createResolutionErrorDiagnostic = createSerialDiagnosticFactory(
4844
(messageText: string, request: string, fileName: string) => {

src/transpilation/transpiler.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,23 @@ class Transpilation {
112112
return { error: error.message };
113113
}
114114

115-
this.handleProcessedFile({
116-
fileName: resolvedPath,
117-
code: cast(this.emitHost.readFile(resolvedPath), isNonNull),
118-
// TODO: Load source map files
119-
});
115+
if (!this.seenFiles.has(resolvedPath)) {
116+
if (
117+
this.scriptExtensions.some(extension => resolvedPath.endsWith(extension)) ||
118+
resolvedPath.endsWith(".json")
119+
) {
120+
const message = `Resolved source file '${resolvedPath}' is not a part of the project.`;
121+
this.diagnostics.push(createResolutionErrorDiagnostic(message, request, file.fileName));
122+
return { error: message };
123+
} else {
124+
this.seenFiles.add(resolvedPath);
125+
this.handleProcessedFile({
126+
fileName: resolvedPath,
127+
code: cast(this.emitHost.readFile(resolvedPath), isNonNull),
128+
// TODO: Load source map files
129+
});
130+
}
131+
}
120132

121133
return this.toRequireParameter(this.toGeneratedFileName(resolvedPath));
122134
};
@@ -133,8 +145,9 @@ class Transpilation {
133145
this.files.push(file);
134146
}
135147

148+
private readonly scriptExtensions = [".ts", ".tsx", ".js", ".jsx"];
136149
protected resolver = ResolverFactory.createResolver({
137-
extensions: [".lua", ".ts", ".tsx", ".js", ".jsx"],
150+
extensions: [".lua", ...this.scriptExtensions],
138151
conditionNames: ["lua", `lua:${this.options.luaTarget ?? LuaTarget.Universal}`],
139152
fileSystem: this.emitHost.resolutionFileSystem ?? fs,
140153
useSyncFileSystemCalls: true,

0 commit comments

Comments
 (0)