Conversation
|
Pull Request Test Coverage Report for Build 16060387221Details
💛 - Coveralls |
There was a problem hiding this comment.
Pull Request Overview
This PR adds TypeScript native support by introducing a new useTsx configuration option that allows the system to run TypeScript files directly without transpilation using the tsx package.
- Adds
useTsxboolean configuration option to enable native TypeScript execution - Conditionally skips transpilation and cache management when
useTsxis enabled - Adds
tsxpackage dependency for native TypeScript execution
Reviewed Changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/server/config.ts |
Adds useTsx boolean field to the Config interface |
src/app.ts |
Modifies compilation path logic and conditionally disables transpiler when useTsx is enabled |
src/server/determine-module-kind.ts |
Treats .ts files as ES modules when determining module kind |
package.json |
Adds tsx dependency for native TypeScript execution |
| const compiledPathsDirectory = nodePath | ||
| .join(modulesPath, ".cache") | ||
| .join(modulesPath, config.useTsx ? "routes" : ".cache") | ||
| .replaceAll("\\", "/"); |
There was a problem hiding this comment.
Using a hardcoded "routes" path when useTsx is true creates an inconsistency. This should use a more descriptive path or variable to clarify that this is the source directory rather than a compiled output directory.
There was a problem hiding this comment.
Nope, that's what we want. If we're using tsx we want to read the source code form the routes directory. Otherwise read the compiled code from the .cache directory.
There was a problem hiding this comment.
I had some updates to this PR pending but never pushed them up and the laptop went bust. So I need to get it cleaned up again. The updates were making it more generic instead of specifically referring to tsx. I think my approach should also work with the new node option for --experimental-strip-types. Also, it might work with ts-node. So I'm making it useNativeTypescript or something like that.
There was a problem hiding this comment.
How about we detect if either the runtime is tsnode or it's node with the type stripping flag enabled?
There was a problem hiding this comment.
That's compelling. I'll try that out.
| nodePath.join(modulesPath, "routes").replaceAll("\\", "/"), | ||
| compiledPathsDirectory, | ||
| "commonjs", | ||
| "module", |
There was a problem hiding this comment.
The module type is hardcoded to "module" but should be conditional based on config.useTsx. When useTsx is false, this should remain "commonjs" to maintain backward compatibility with the transpiled code.
| "module", | |
| config.useTsx ? "module" : "commonjs", |
There was a problem hiding this comment.
Good catch, Copilot. You're probably right.
|
I would love to finish this. Rather than a config option, we can test whether type stripping is supported at runtime. import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
export async function runtimeCanExecuteErasableTs() {
const dir = mkdtempSync(join(tmpdir(), "ts-probe-"));
const file = join(dir, "probe.ts");
// “erasable” TS: type annotation only.
writeFileSync(
file,
'const x: string = "ok"; export default x;\n',
"utf8"
);
try {
const mod = await import(pathToFileURL(file).href);
return mod?.default === "ok";
} catch {
return false;
} finally {
rmSync(dir, { recursive: true, force: true });
}
} |
That's a great idea. This is still on my agenda. It's starting to rise back up on my list. hopefully 1st quarter here. |
The goal is to allow running Counterfact with no transpilation at all. In my tests so far you can run this with TSX directly against the
routesfolder, no need for.cache.