Skip to content

Commit dd66b88

Browse files
committed
Fix windows tests
1 parent fbb9f23 commit dd66b88

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/transpilation/transpilation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SourceNode } from "source-map";
55
import * as ts from "typescript";
66
import { CompilerOptions, isBundleEnabled, LuaTarget } from "../CompilerOptions";
77
import { getLuaLibBundle } from "../LuaLib";
8-
import { assert, cast, isNonNull, trimExtension } from "../utils";
8+
import { assert, cast, isNonNull, normalizeSlashes, trimExtension } from "../utils";
99
import { Chunk, modulesToBundleChunks, modulesToChunks } from "./chunk";
1010
import { createResolutionErrorDiagnostic } from "./diagnostics";
1111
import { buildModule, Module } from "./module";
@@ -88,7 +88,7 @@ export class Transpilation {
8888
const result = this.resolver.resolveSync({}, path.dirname(issuer), request);
8989
assert(typeof result === "string", `Invalid resolution result: ${result}`);
9090
// https://github.com/webpack/enhanced-resolve#escaping
91-
resolvedPath = result.replace(/\0#/g, "#");
91+
resolvedPath = normalizeSlashes(result.replace(/\0#/g, "#"));
9292
} catch (error) {
9393
if (!isResolveError(error)) throw error;
9494
return { error: error.message };
@@ -98,6 +98,10 @@ export class Transpilation {
9898
if (!module) {
9999
if (!resolvedPath.endsWith(".lua")) {
100100
const messageText = `Resolved source file '${resolvedPath}' is not a part of the project.`;
101+
console.log(
102+
resolvedPath,
103+
this.modules.map(m => m.request)
104+
);
101105
return { error: messageText };
102106
}
103107

src/transpilation/transpile/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ts from "typescript";
33
import { CompilerOptions, validateOptions } from "../../CompilerOptions";
44
import { LuaPrinter } from "../../LuaPrinter";
55
import { createVisitorMap, transformSourceFile } from "../../transformation";
6-
import { assert, isNonNull } from "../../utils";
6+
import { assert, isNonNull, normalizeSlashes } from "../../utils";
77
import { applySinglePlugin } from "../plugins";
88
import { Transpilation } from "../transpilation";
99
import { getTransformers } from "./transformers";
@@ -65,7 +65,7 @@ export function emitProgramModules(
6565
const currentDirectory = transpilation.host.getCurrentDirectory();
6666
// Having no absolute path in path.resolve would make it fallback to real cwd
6767
assert(path.isAbsolute(currentDirectory), `Invalid path: ${currentDirectory}`);
68-
request = path.resolve(currentDirectory, sourceFile.fileName);
68+
request = normalizeSlashes(path.resolve(currentDirectory, sourceFile.fileName));
6969
}
7070

7171
transpilation.modules.push({ request, isBuilt: false, source, sourceFiles: [sourceFile] });

test/util.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ export abstract class TestBuilder {
256256

257257
const host: tstl.TranspilerHost = { ...ts.sys };
258258
if (!this.nativeFileSystem) {
259-
const virtualFS = Volume.fromJSON({ ...this.extraRawFiles, ...this.getSourceFiles() }, "/");
259+
const cwd = process.platform === "win32" ? path.parse(__dirname).root : "/";
260+
const virtualFS = Volume.fromJSON({ ...this.extraRawFiles, ...this.getSourceFiles() }, cwd);
260261
host.resolutionFileSystem = virtualFS;
261-
host.getCurrentDirectory = () => "/";
262+
host.getCurrentDirectory = () => cwd;
262263
host.readFile = (fileName, encoding = "utf8") =>
263-
fileName.includes("/lualib/")
264+
/[\\/]lualib[\\/]/.test(fileName)
264265
? ts.sys.readFile(fileName, encoding)
265266
: (virtualFS.readFileSync(fileName, encoding) as string);
266267
}

0 commit comments

Comments
 (0)