|
| 1 | +import { ResolverFactory } from "enhanced-resolve"; |
| 2 | +import * as fs from "fs"; |
1 | 3 | import * as path from "path"; |
2 | | -import * as resolve from "resolve"; |
3 | 4 | import * as ts from "typescript"; |
4 | 5 | import { CompilerOptions, isBundleEnabled, LuaTarget } from "../CompilerOptions"; |
5 | 6 | import { getLuaLibBundle } from "../LuaLib"; |
@@ -53,9 +54,6 @@ export class Transpiler { |
53 | 54 | } |
54 | 55 | } |
55 | 56 |
|
56 | | -// TODO: JIT -> jit? |
57 | | -type PackageLuaField = string | Record<LuaTarget, string>; |
58 | | - |
59 | 57 | class Transpilation { |
60 | 58 | public readonly diagnostics: ts.Diagnostic[] = []; |
61 | 59 | private seenFiles = new Set<string>(); |
@@ -130,37 +128,17 @@ class Transpilation { |
130 | 128 | this.files.push(file); |
131 | 129 | } |
132 | 130 |
|
133 | | - protected resolveRequest(request: string, issuer: string) { |
134 | | - const resolved = resolve.sync(request, { |
135 | | - basedir: path.dirname(issuer), |
136 | | - extensions: [".lua", ".ts", ".tsx", ".js", ".jsx"], |
137 | | - packageFilter: (pkg, pkgFile) => { |
138 | | - delete pkg.main; |
139 | | - |
140 | | - const lua: PackageLuaField = pkg.lua; |
141 | | - if (lua !== undefined) { |
142 | | - if (typeof lua === "string") { |
143 | | - pkg.main = lua; |
144 | | - } else if (typeof lua === "object") { |
145 | | - const luaTarget = this.options.luaTarget ?? LuaTarget.Universal; |
146 | | - pkg.main = lua[luaTarget]; |
147 | | - if (pkg.main === undefined) { |
148 | | - throw new Error(`${pkgFile} not supports Lua ${luaTarget} target.`); |
149 | | - } |
150 | | - } else { |
151 | | - throw new Error(`${pkgFile} has invalid "lua" field value.`); |
152 | | - } |
153 | | - } |
154 | | - |
155 | | - return pkg; |
156 | | - }, |
157 | | - }); |
158 | | - |
159 | | - if (resolve.isCore(resolved)) { |
160 | | - throw new Error(`"${resolved}" is builtin Node.js module.`); |
161 | | - } |
| 131 | + protected resolver = ResolverFactory.createResolver({ |
| 132 | + extensions: [".lua", ".ts", ".tsx", ".js", ".jsx"], |
| 133 | + conditionNames: ["lua", `lua:${this.options.luaTarget ?? LuaTarget.Universal}`], |
| 134 | + fileSystem: this.emitHost.fileSystem ?? fs, |
| 135 | + useSyncFileSystemCalls: true, |
| 136 | + }); |
162 | 137 |
|
163 | | - return resolved; |
| 138 | + protected resolveRequest(request: string, issuer: string) { |
| 139 | + const result = this.resolver.resolveSync({}, path.dirname(issuer), request); |
| 140 | + assert(typeof result === "string"); |
| 141 | + return result; |
164 | 142 | } |
165 | 143 |
|
166 | 144 | protected toGeneratedFileName(fileName: string) { |
|
0 commit comments