From 4aa1860f35209ea496618f43719564228a517a76 Mon Sep 17 00:00:00 2001 From: schwankeith <96555606+schwankeith@users.noreply.github.com> Date: Sun, 25 Oct 2026 14:55:54 -0600 Subject: [PATCH 1/2] Fix #112: Broken imports after moving files --- .../transpile-file/imports-transformer.ts | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/core/src/misc/transpile-file/imports-transformer.ts b/core/src/misc/transpile-file/imports-transformer.ts index 9e7f824fa..a83928b72 100644 --- a/core/src/misc/transpile-file/imports-transformer.ts +++ b/core/src/misc/transpile-file/imports-transformer.ts @@ -1,18 +1,31 @@ import * as ts from "typescript"; +import * as path from "path"; -export function importToGlobalTransformer(): ts.TransformerFactory { +/** + * Transforms ES module imports into accesses on a global __imports object. + * Additionally, resolves relative import specifiers to absolute paths based on the + * source file location. This ensures that after a file is moved, the import still + * points to the correct module. + */ +export function importToGlobalTransformer(fileName?: string): ts.TransformerFactory { return (context) => { const visit: ts.Visitor = (node) => { if (ts.isImportDeclaration(node)) { - const moduleName = node.moduleSpecifier.getText().slice(1, -1); // Remove quotes + // Extract the raw module specifier string (without quotes) + let moduleName = node.moduleSpecifier.getText().slice(1, -1); + // Resolve relative paths to absolute paths based on the file location + if (fileName && (moduleName.startsWith("./") || moduleName.startsWith("../"))) { + const dir = path.dirname(fileName); + const resolved = path.resolve(dir, moduleName); + // Use POSIX style for consistency (VS Code works with forward slashes) + moduleName = resolved.split(path.sep).join("/"); + } const importClause = node.importClause; const declarations: ts.VariableDeclaration[] = []; if (importClause) { - // Handle default imports // Skip over 'import type' statements - if (importClause.isTypeOnly) { return node; } @@ -41,9 +54,7 @@ export function importToGlobalTransformer(): ts.TransformerFactory { const name = el.name.getText(); - const propertyName = el.propertyName - ? el.propertyName.getText() - : name; + const propertyName = el.propertyName ? el.propertyName.getText() : name; declarations.push( ts.factory.createVariableDeclaration( name, @@ -80,10 +91,7 @@ export function importToGlobalTransformer(): ts.TransformerFactory Date: Sun, 25 Oct 2026 14:55:55 -0600 Subject: [PATCH 2/2] Fix #112: Broken imports after moving files --- core/src/misc/transpile-file/transpile-file.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/misc/transpile-file/transpile-file.ts b/core/src/misc/transpile-file/transpile-file.ts index 02845f090..05b779db3 100644 --- a/core/src/misc/transpile-file/transpile-file.ts +++ b/core/src/misc/transpile-file/transpile-file.ts @@ -11,7 +11,8 @@ export function transpileFile(fileName: string, content: string) { }, transformers: { before: [ - importToGlobalTransformer(), + // Pass the file name so that relative imports can be resolved to absolute paths. + importToGlobalTransformer(fileName), stripTypesTransformer(), exportToGlobalTransformer(fileName), ],