From f2b63771ef27260577a727baceb6174c3b58c950 Mon Sep 17 00:00:00 2001 From: Geoffrey Sechter Date: Fri, 9 Jan 2026 18:01:37 -0700 Subject: [PATCH 1/2] fix(function): support multiline import type statements in import scanning The regex pattern `.*?` does not match newlines, causing multiline `import type { X }` statements to be skipped during bind-mount file scanning. This results in type-only imports not being mounted in the Docker container, causing runtime errors like: worker boot error: Module not found "file:///.../types/MyType.ts" Changed `.*?` to `[\s\S]*?` to match any character including newlines, consistent with the `{[^{}]+}` pattern used for braced imports. This fix enables proper handling of Deno 2.x style multiline type imports: ```typescript import type { MyType, OtherType, } from './types.ts' ``` Includes test case to prevent regression. --- pkg/function/deno.go | 3 ++- pkg/function/deno_test.go | 15 +++++++++++++++ pkg/function/testdata/modules/import_types.ts | 19 +++++++++++++++++++ pkg/function/testdata/types/database.ts | 11 +++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pkg/function/testdata/modules/import_types.ts create mode 100644 pkg/function/testdata/types/database.ts diff --git a/pkg/function/deno.go b/pkg/function/deno.go index ec785c246..ce0434edb 100644 --- a/pkg/function/deno.go +++ b/pkg/function/deno.go @@ -111,7 +111,8 @@ func resolveHostPath(jsonPath, hostPath string) string { } // Ref: https://regex101.com/r/DfBdJA/1 -var importPathPattern = regexp.MustCompile(`(?i)(?:import|export)\s+(?:{[^{}]+}|.*?)\s*(?:from)?\s*['"](.*?)['"]|import\(\s*['"](.*?)['"]\)`) +// Note: Using [\s\S]*? instead of .*? to match newlines in multiline import type statements +var importPathPattern = regexp.MustCompile(`(?i)(?:import|export)\s+(?:{[^{}]+}|[\s\S]*?)\s*(?:from)?\s*['"](.*?)['"]|import\(\s*['"](.*?)['"]\)`) func (importMap *ImportMap) WalkImportPaths(srcPath string, readFile func(curr string, w io.Writer) error) error { seen := map[string]struct{}{} diff --git a/pkg/function/deno_test.go b/pkg/function/deno_test.go index ee3ac7795..c9114499e 100644 --- a/pkg/function/deno_test.go +++ b/pkg/function/deno_test.go @@ -86,6 +86,21 @@ func TestImportPaths(t *testing.T) { assert.NoError(t, err) fsys.AssertExpectations(t) }) + + t.Run("iterates multiline import type statements", func(t *testing.T) { + // This test verifies that multiline import type statements are correctly parsed + // The regex must use [\s\S]*? instead of .*? to match newlines + // Setup in-memory fs + fsys := MockFS{} + fsys.On("ReadFile", "testdata/modules/import_types.ts").Once() + fsys.On("ReadFile", "testdata/types/database.ts").Once() + // Run test + im := ImportMap{} + err := im.WalkImportPaths("testdata/modules/import_types.ts", fsys.ReadFile) + // Check error + assert.NoError(t, err) + fsys.AssertExpectations(t) + }) } func TestResolveImports(t *testing.T) { diff --git a/pkg/function/testdata/modules/import_types.ts b/pkg/function/testdata/modules/import_types.ts new file mode 100644 index 000000000..d6c0d9ef5 --- /dev/null +++ b/pkg/function/testdata/modules/import_types.ts @@ -0,0 +1,19 @@ +// Test file for multiline import type statements +// This pattern was broken before the [\s\S]*? fix + +// Multiline import type - should be matched by the regex +import type { + Database, + Json +} from '../types/database.ts' + +// Single line import type - should also work +import type { Database as DB } from '../types/database.ts' + +// Re-export type to verify export pattern +export type { Database } from '../types/database.ts' + +// Multiline export type +export type { + Json +} from '../types/database.ts' diff --git a/pkg/function/testdata/types/database.ts b/pkg/function/testdata/types/database.ts new file mode 100644 index 000000000..4c49d8e2d --- /dev/null +++ b/pkg/function/testdata/types/database.ts @@ -0,0 +1,11 @@ +export type Database = { + public: { + Tables: { + users: { + Row: { id: string; name: string } + } + } + } +} + +export type Json = string | number | boolean | null | { [key: string]: Json } | Json[] From 93d8c8a257b3a70a4e57df65c63eef8f1ca87dee Mon Sep 17 00:00:00 2001 From: Geoffrey Sechter Date: Wed, 18 Feb 2026 18:03:21 -0700 Subject: [PATCH 2/2] test(function): add non-braced default type import to fixture Cover `import type Foo from '...'` pattern in the multiline import type test. This form also routes through the `[\s\S]*?` branch and was previously untested. --- pkg/function/testdata/modules/import_types.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/function/testdata/modules/import_types.ts b/pkg/function/testdata/modules/import_types.ts index d6c0d9ef5..6fdcbd9bd 100644 --- a/pkg/function/testdata/modules/import_types.ts +++ b/pkg/function/testdata/modules/import_types.ts @@ -17,3 +17,6 @@ export type { Database } from '../types/database.ts' export type { Json } from '../types/database.ts' + +// Non-braced default type import - exercises the [\s\S]*? branch on single-line +import type Database from '../types/database.ts'