Skip to content

Commit 3ff4a57

Browse files
fix(deps): update dependency @netlify/edge-bundler to v7 (#5325)
* fix(deps): update dependency @netlify/edge-bundler to v7 * refactor: simplify import map loading * chore: fix test * refactor: remove unnecessary property Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Eduardo Bouças <[email protected]>
1 parent bb16cec commit 3ff4a57

File tree

5 files changed

+17
-49
lines changed

5 files changed

+17
-49
lines changed

npm-shrinkwrap.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
"dependencies": {
233233
"@netlify/build": "^29.2.0",
234234
"@netlify/config": "^20.2.0",
235-
"@netlify/edge-bundler": "^6.1.0",
235+
"@netlify/edge-bundler": "^7.1.0",
236236
"@netlify/framework-info": "^9.5.3",
237237
"@netlify/local-functions-proxy": "^1.1.1",
238238
"@netlify/zip-it-and-ship-it": "^8.2.0",

src/lib/edge-functions/internal.mjs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,11 @@
22
import { readFile, stat } from 'fs/promises'
33
import { dirname, join, resolve } from 'path'
44
import { cwd } from 'process'
5-
import { pathToFileURL } from 'url'
65

7-
import { warn } from '../../utils/command-helpers.mjs'
86
import { getPathInProject } from '../settings.cjs'
97

108
import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.mjs'
119

12-
/**
13-
* Reads an import map from a path and returns the parsed data, if it exists
14-
* and is valid. Otherwise, it returns null.
15-
*
16-
* @param {string} importMapPath
17-
* @returns {Promise<object | null>}
18-
*/
19-
const getImportMap = async (importMapPath) => {
20-
try {
21-
const data = await readFile(importMapPath)
22-
const importMap = JSON.parse(data)
23-
24-
return importMap
25-
} catch {
26-
warn(`Could not read the import map file for Edge Functions at ${importMapPath}`)
27-
28-
return null
29-
}
30-
}
31-
3210
export const getInternalFunctions = async () => {
3311
const path = join(cwd(), getPathInProject([INTERNAL_EDGE_FUNCTIONS_FOLDER]))
3412

@@ -59,18 +37,7 @@ export const getInternalFunctions = async () => {
5937
}
6038

6139
if (manifest.import_map) {
62-
const importMapPath = resolve(dirname(manifestPath), manifest.import_map)
63-
const importMap = await getImportMap(importMapPath)
64-
65-
if (importMap !== null) {
66-
return {
67-
...data,
68-
importMap: {
69-
baseURL: pathToFileURL(importMapPath),
70-
...importMap,
71-
},
72-
}
73-
}
40+
data.importMap = resolve(dirname(manifestPath), manifest.import_map)
7441
}
7542

7643
return data

src/lib/edge-functions/proxy.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ const prepareServer = async ({
160160
port,
161161
projectDir,
162162
}) => {
163+
// Merging internal with user-defined import maps.
164+
const importMapPaths = [...importMaps, config.functions['*'].deno_import_map]
165+
163166
try {
164167
const bundler = await import('@netlify/edge-bundler')
165168
const distImportMapPath = getPathInProject([DIST_IMPORT_MAP_PATH])
166169
const runIsolate = await bundler.serve({
167170
...getDownloadUpdateFunctions(),
168-
basePath: projectDir,
169171
certificatePath,
170172
debug: env.NETLIFY_DENO_DEBUG === 'true',
171173
distImportMapPath,
@@ -175,7 +177,7 @@ const prepareServer = async ({
175177
)}. The file does not seem to have a function as the default export.`,
176178
formatImportError: (name) =>
177179
`${NETLIFYDEVERR} ${chalk.red('Failed')} to run Edge Function ${chalk.yellow(name)}:`,
178-
importMaps,
180+
importMapPaths,
179181
inspectSettings,
180182
port,
181183
})

tests/integration/100.command.dev.test.cjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ test('should respect in-source configuration from internal edge functions', asyn
780780
})
781781
})
782782

783-
test('Serves edge functions with import maps coming from the Deno config file and from the internal manifest', async (t) => {
783+
test('Serves edge functions with import maps coming from the `functions.deno_import_map` config property and from the internal manifest', async (t) => {
784784
await withSiteBuilder('site-with-edge-functions-and-import-maps', async (builder) => {
785785
const internalEdgeFunctionsDir = path.join('.netlify', 'edge-functions')
786786

@@ -790,6 +790,9 @@ test('Serves edge functions with import maps coming from the Deno config file an
790790
build: {
791791
publish: 'public',
792792
},
793+
functions: {
794+
deno_import_map: 'import_map.json',
795+
},
793796
},
794797
})
795798
.withEdgeFunction({
@@ -809,10 +812,6 @@ test('Serves edge functions with import maps coming from the Deno config file an
809812
content: 'export const greet = (name: string) => `Hello, ${name}!`',
810813
path: 'greeter.ts',
811814
},
812-
{
813-
content: JSON.stringify({ importMap: 'import_map.json' }),
814-
path: 'deno.json',
815-
},
816815
{
817816
content: JSON.stringify({ imports: { greeter: './greeter.ts' } }),
818817
path: 'import_map.json',

0 commit comments

Comments
 (0)