From e7c11ec0215d3ab7f7ba2163bc687ea9c6671e9e Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Thu, 13 Feb 2025 12:32:49 +0800 Subject: [PATCH] fix: include export statements when resolving imports (#3140) --- internal/functions/deploy/testdata/shared/whatever.ts | 4 +++- internal/functions/deploy/upload.go | 2 +- internal/functions/deploy/upload_test.go | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/functions/deploy/testdata/shared/whatever.ts b/internal/functions/deploy/testdata/shared/whatever.ts index aad3bc023..879e79cb3 100644 --- a/internal/functions/deploy/testdata/shared/whatever.ts +++ b/internal/functions/deploy/testdata/shared/whatever.ts @@ -1 +1,3 @@ -import * from '../nested/index.ts'; +import * as _ from "../nested/index.ts"; + +export * from "./mod.ts"; diff --git a/internal/functions/deploy/upload.go b/internal/functions/deploy/upload.go index e9a425b88..3e38855ed 100644 --- a/internal/functions/deploy/upload.go +++ b/internal/functions/deploy/upload.go @@ -162,7 +162,7 @@ func writeForm(form *multipart.Writer, meta api.FunctionDeployMetadata, fsys afe } // Ref: https://regex101.com/r/DfBdJA/1 -var importPathPattern = regexp.MustCompile(`(?i)import\s+(?:{[^{}]+}|.*?)\s*(?:from)?\s*['"](.*?)['"]|import\(\s*['"](.*?)['"]\)`) +var importPathPattern = regexp.MustCompile(`(?i)(?:import|export)\s+(?:{[^{}]+}|.*?)\s*(?:from)?\s*['"](.*?)['"]|import\(\s*['"](.*?)['"]\)`) func walkImportPaths(srcPath string, importMap utils.ImportMap, readFile func(curr string, w io.Writer) error) error { seen := map[string]struct{}{} diff --git a/internal/functions/deploy/upload_test.go b/internal/functions/deploy/upload_test.go index cbd549459..1698e0bd6 100644 --- a/internal/functions/deploy/upload_test.go +++ b/internal/functions/deploy/upload_test.go @@ -66,6 +66,7 @@ func TestImportPaths(t *testing.T) { fsys.On("ReadFile", "testdata/modules/imports.ts").Once() fsys.On("ReadFile", "testdata/geometries/Geometries.js").Once() fsys.On("ReadFile", "testdata/shared/whatever.ts").Once() + fsys.On("ReadFile", "testdata/shared/mod.ts").Once() fsys.On("ReadFile", "testdata/nested/index.ts").Once() // Run test im := utils.ImportMap{Imports: map[string]string{