Skip to content

Commit f1d8ebc

Browse files
feat: read import map from functions.deno_import_map config property (#4782)
* fix(deps): update dependency @netlify/edge-bundler to v7 * chore: update test snapshots * feat: load user-defined import map * chore: update snapshots * refactor: rename config property * chore: update snapshot Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Eduardo Bouças <[email protected]>
1 parent 03a9924 commit f1d8ebc

File tree

19 files changed

+78
-52
lines changed

19 files changed

+78
-52
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@bugsnag/js": "^7.0.0",
6767
"@netlify/cache-utils": "^5.1.0",
6868
"@netlify/config": "^20.1.0",
69-
"@netlify/edge-bundler": "6.1.0",
69+
"@netlify/edge-bundler": "7.0.1",
7070
"@netlify/functions-utils": "^5.1.1",
7171
"@netlify/git-utils": "^5.1.0",
7272
"@netlify/plugins-list": "^6.59.0",

packages/build/src/plugins_core/edge_functions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const coreStep = async function ({
2828
netlifyConfig,
2929
}) {
3030
const { edge_functions: declarations = [] } = netlifyConfig
31+
const { deno_import_map: userDefinedImportMap } = netlifyConfig.functions['*']
3132
const distPath = resolve(buildDir, distDirectory)
3233
const internalSrcPath = resolve(buildDir, internalSrcDirectory)
3334
const distImportMapPath = join(dirname(internalSrcPath), IMPORT_MAP_FILENAME)
@@ -61,6 +62,7 @@ const coreStep = async function ({
6162
debug,
6263
distImportMapPath,
6364
featureFlags,
65+
importMapPaths: [userDefinedImportMap],
6466
systemLogger: featureFlags.edge_functions_system_logger ? systemLog : undefined,
6567
})
6668

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[functions]
2+
deno_import_map = "netlify/edge-functions/import-map.json"
3+
14
[[edge_functions]]
25
function = "function-1"
36
path = "/one"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default async () => new Response('Hello world')
1+
import { greet } from 'util/misc.ts'
2+
3+
export default async () => new Response(greet('friend'))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"util/": "../../util/"
4+
}
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const greet = (name: string) => `Hello, ${name}!`

packages/build/tests/edge_functions/snapshots/tests.js.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ Generated by [AVA](https://avajs.dev).
500500
────────────────────────────────────────────────────────────────␊
501501
502502
Error message␊
503-
Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {"basePath":"packages/build/tests/edge_functions/fixtures/functions_invalid","destPath":"packages/build/tests/edge_functions/fixtures/functions_invalid/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip","externals":[],"functions":[{"name":"functions-1","path":"packages/build/tests/edge_functions/fixtures/functions_invalid/netlify/edge-functions/functions-1.ts"}],"importMapData":"{/"imports/":{/"netlify:edge/":/"https://edge.netlify.com/v1.0.0/index.ts/"}}"}␊
503+
Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {"basePath":"packages/build/tests/edge_functions/fixtures/functions_invalid","destPath":"packages/build/tests/edge_functions/fixtures/functions_invalid/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip","externals":[],"functions":[{"name":"functions-1","path":"packages/build/tests/edge_functions/fixtures/functions_invalid/netlify/edge-functions/functions-1.ts"}],"importMapData":"{/"imports/":{/"netlify:edge/":/"https://edge.netlify.com/v1.0.0/index.ts/"},/"scopes/":{}}"}␊
504504
error: Uncaught (in promise) Error: The module's source code could not be parsed: Expected '{', got 'async' at /external/path␊
505505
const ret = new Error(getStringFromWasm0(arg0, arg1));␊
506506
^␊
@@ -585,6 +585,9 @@ Generated by [AVA](https://avajs.dev).
585585
edge_functions: packages/build/tests/edge_functions/fixtures/functions_user/netlify/edge-functions␊
586586
publish: packages/build/tests/edge_functions/fixtures/functions_user␊
587587
publishOrigin: default␊
588+
functions:␊
589+
'*':␊
590+
deno_import_map: packages/build/tests/edge_functions/fixtures/functions_user/netlify/edge-functions/import-map.json␊
588591
589592
> Context␊
590593
production␊
37 Bytes
Binary file not shown.

packages/build/tests/monitor/snapshots/tests.js.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ Generated by [AVA](https://avajs.dev).
17611761
────────────────────────────────────────────────────────────────␊
17621762
17631763
Error message␊
1764-
Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {"basePath":"packages/build/tests/monitor/fixtures/edge_function_error","destPath":"packages/build/tests/monitor/fixtures/edge_function_error/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip","externals":[],"functions":[{"name":"trouble","path":"packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/trouble.ts"}],"importMapData":"{/"imports/":{/"netlify:edge/":/"https://edge.netlify.com/v1.0.0/index.ts/"}}"}␊
1764+
Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {"basePath":"packages/build/tests/monitor/fixtures/edge_function_error","destPath":"packages/build/tests/monitor/fixtures/edge_function_error/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip","externals":[],"functions":[{"name":"trouble","path":"packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/trouble.ts"}],"importMapData":"{/"imports/":{/"netlify:edge/":/"https://edge.netlify.com/v1.0.0/index.ts/"},/"scopes/":{}}"}␊
17651765
error: Uncaught (in promise) Error: Error: Could not find file: packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/file.ts␊
17661766
const ret = new Error(getStringFromWasm0(arg0, arg1));␊
17671767
^␊
@@ -1779,9 +1779,9 @@ Generated by [AVA](https://avajs.dev).
17791779
Error monitoring payload:␊
17801780
{␊
17811781
"errorClass": "functionsBundling",␊
1782-
"errorMessage": "Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {/"basePath/":/"packages/build/tests/monitor/fixtures/edge_function_error",/"destPath/":/"packages/build/tests/monitor/fixtures/edge_function_error/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip",/"externals/":[],/"functions/":[{/"name/":/"trouble/",/"path/":/"packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/trouble.ts"}],/"importMapData/":/"{//"imports//":{//"netlify:edge//"://"https://edge.netlify.com/v1.0.0/index.ts//"}}/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/file.ts/n const ret = new Error(getStringFromWasm0(arg0, arg1));/n ^/n at __wbg_new_HEXADECIMAL_ID (/node_module/path)/n at <anonymous> (wasm://wasm/HEXADECIMAL_ID:1:80)/n at <anonymous> (wasm://wasm/HEXADECIMAL_ID:1:80)/n at <anonymous> (wasm://wasm/HEXADECIMAL_ID:1:80)/n at __wbg_adapter_18 (/node_module/path)/n at real (/node_module/path)",␊
1782+
"errorMessage": "Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {/"basePath/":/"packages/build/tests/monitor/fixtures/edge_function_error",/"destPath/":/"packages/build/tests/monitor/fixtures/edge_function_error/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip",/"externals/":[],/"functions/":[{/"name/":/"trouble/",/"path/":/"packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/trouble.ts"}],/"importMapData/":/"{//"imports//":{//"netlify:edge//"://"https://edge.netlify.com/v1.0.0/index.ts//"},//"scopes//":{}}/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/file.ts/n const ret = new Error(getStringFromWasm0(arg0, arg1));/n ^/n at __wbg_new_HEXADECIMAL_ID (/node_module/path)/n at <anonymous> (wasm://wasm/HEXADECIMAL_ID:1:80)/n at <anonymous> (wasm://wasm/HEXADECIMAL_ID:1:80)/n at <anonymous> (wasm://wasm/HEXADECIMAL_ID:1:80)/n at __wbg_adapter_18 (/node_module/path)/n at real (/node_module/path)",␊
17831783
"context": "Bundling of edge function failed",␊
1784-
"groupingHash": "Bundling of edge function failed/nCommand failed with exit code 0: deno run --allow-all --no-config /external/path --quiet /external/path {/"/":/"/",/"/":/"/",/"/":[],/"/":[{/"/":/"/",/"/":/"/"}],/"/":/"/"/external/path"/"/external/path"/"/external/path"/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: /external/path const ret = new Error(getStringFromWasm0(arg0, arg0));/n ^/n at __wbg_new_hex /external/path at <anonymous> /external/path at <anonymous> /external/path at <anonymous> /external/path at __wbg_adapter_0 /external/path at real /external/path",␊
1784+
"groupingHash": "Bundling of edge function failed/nCommand failed with exit code 0: deno run --allow-all --no-config /external/path --quiet /external/path {/"/":/"/",/"/":/"/",/"/":[],/"/":[{/"/":/"/",/"/":/"/"}],/"/":/"/"/external/path"/"/external/path"/"/external/path"/"/external/path"/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: /external/path const ret = new Error(getStringFromWasm0(arg0, arg0));/n ^/n at __wbg_new_hex /external/path at <anonymous> /external/path at <anonymous> /external/path at <anonymous> /external/path at __wbg_adapter_0 /external/path at real /external/path",␊
17851785
"severity": "info",␊
17861786
"unhandled": false,␊
17871787
"location": {␊
@@ -1792,7 +1792,7 @@ Generated by [AVA](https://avajs.dev).
17921792
"pluginPackageJson": false,␊
17931793
"BUILD_ID": "0",␊
17941794
"other": {␊
1795-
"groupingHash": "Bundling of edge function failed/nCommand failed with exit code 0: deno run --allow-all --no-config /external/path --quiet /external/path {/"/":/"/",/"/":/"/",/"/":[],/"/":[{/"/":/"/",/"/":/"/"}],/"/":/"/"/external/path"/"/external/path"/"/external/path"/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: /external/path const ret = new Error(getStringFromWasm0(arg0, arg0));/n ^/n at __wbg_new_hex /external/path at <anonymous> /external/path at <anonymous> /external/path at <anonymous> /external/path at __wbg_adapter_0 /external/path at real /external/path"␊
1795+
"groupingHash": "Bundling of edge function failed/nCommand failed with exit code 0: deno run --allow-all --no-config /external/path --quiet /external/path {/"/":/"/",/"/":/"/",/"/":[],/"/":[{/"/":/"/",/"/":/"/"}],/"/":/"/"/external/path"/"/external/path"/"/external/path"/"/external/path"/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: /external/path const ret = new Error(getStringFromWasm0(arg0, arg0));/n ^/n at __wbg_new_hex /external/path at <anonymous> /external/path at <anonymous> /external/path at <anonymous> /external/path at __wbg_adapter_0 /external/path at real /external/path"␊
17961796
}␊
17971797
}`
17981798

0 commit comments

Comments
 (0)