Skip to content

Commit e6a6b3b

Browse files
authored
Fix transformPaths transformer (roblox-ts#2800)
`transformPaths` broke because `resolver.moduleExportsSomeValue()` no longer exists in TypeScript (and is not trivial to copy from an old version). Originally, I tried to just `npm install` the latest version, but this had a few issues: - TypeScript wasn't able to find types because of how the package.json is setup, I was able to hack around this with a `// @ts-ignore` - Newest version seems to not respect just `baseUrl`, it requires you have a `paths` in your tsconfig.json (and many roblox-ts projects don't) I also can't just copy over the latest file from the repo because it has a bunch of imports. Instead, I found a slightly newer version which doesn't use `moduleExportsSomeValue` and is still a single file. This required a few small fixes i.e. removing non-ts.factory APIs. --- The first commit in this PR is copying the new version of the transformer The second (+ subsequent) commit is the required fixes.
1 parent 7167c9c commit e6a6b3b

File tree

2 files changed

+196
-266
lines changed

2 files changed

+196
-266
lines changed

Diff for: src/Project/functions/compileFiles.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from "path";
66
import { checkFileName } from "Project/functions/checkFileName";
77
import { checkRojoConfig } from "Project/functions/checkRojoConfig";
88
import { createNodeModulesPathMapping } from "Project/functions/createNodeModulesPathMapping";
9-
import { transformPaths } from "Project/transformers/builtin/transformPaths";
9+
import transformPathsTransformer from "Project/transformers/builtin/transformPaths";
1010
import { transformTypeReferenceDirectives } from "Project/transformers/builtin/transformTypeReferenceDirectives";
1111
import { createTransformerList, flattenIntoTransformers } from "Project/transformers/createTransformerList";
1212
import { createTransformerWatcher } from "Project/transformers/createTransformerWatcher";
@@ -187,6 +187,9 @@ export function compileFiles(
187187
const emittedFiles = new Array<string>();
188188
if (fileWriteQueue.length > 0) {
189189
benchmarkIfVerbose("writing compiled files", () => {
190+
const afterDeclarations = compilerOptions.declaration
191+
? [transformTypeReferenceDirectives, transformPathsTransformer(program, {})]
192+
: undefined;
190193
for (const { sourceFile, source } of fileWriteQueue) {
191194
const outPath = pathTranslator.getOutputPath(sourceFile.fileName);
192195
if (
@@ -198,9 +201,7 @@ export function compileFiles(
198201
emittedFiles.push(outPath);
199202
}
200203
if (compilerOptions.declaration) {
201-
proxyProgram.emit(sourceFile, ts.sys.writeFile, undefined, true, {
202-
afterDeclarations: [transformTypeReferenceDirectives, transformPaths],
203-
});
204+
proxyProgram.emit(sourceFile, ts.sys.writeFile, undefined, true, { afterDeclarations });
204205
}
205206
}
206207
});

0 commit comments

Comments
 (0)