Skip to content

Commit 2ffdeb0

Browse files
committed
fix: use stable edge functions bootstrap package for globalThis.Netlify
1 parent 2ea5a35 commit 2ffdeb0

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

packages/edge-bundler/deno/config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// this needs to be updated whenever there's a change to globalThis.Netlify in bootstrap
2-
import { Netlify } from "https://64e8753eae24930008fac6d9--edge.netlify.app/bootstrap/index-combined.ts"
3-
4-
const [functionURL, collectorURL, rawExitCodes] = Deno.args
1+
const [functionURL, collectorURL, bootstrapURL, rawExitCodes] = Deno.args
52
const exitCodes = JSON.parse(rawExitCodes)
63

7-
globalThis.Netlify = Netlify
8-
94
let func
105

116
try {
7+
const { Netlify } = await import(bootstrapURL)
8+
globalThis.Netlify = Netlify
129
func = await import(functionURL)
1310
} catch (error) {
1411
console.error(error)

packages/edge-bundler/node/bundler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { writeManifest } from './manifest.js'
2222
import { vendorNPMSpecifiers } from './npm_dependencies.js'
2323
import { ensureLatestTypes } from './types.js'
2424
import { nonNullable } from './utils/non_nullable.js'
25+
import { getURL as getBootstrapURL } from '@netlify/edge-functions-bootstrap/version'
2526

2627
export interface BundleOptions {
2728
basePath?: string
@@ -60,6 +61,7 @@ export const bundle = async (
6061
userLogger,
6162
systemLogger,
6263
vendorDirectory,
64+
bootstrapURL = getBootstrapURL(),
6365
}: BundleOptions = {},
6466
) => {
6567
const logger = getLogger(systemLogger, userLogger, debug)
@@ -161,10 +163,10 @@ export const bundle = async (
161163
// Retrieving a configuration object for each function.
162164
// Run `getFunctionConfig` in parallel as it is a non-trivial operation and spins up deno
163165
const internalConfigPromises = internalFunctions.map(
164-
async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger })] as const,
166+
async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger, bootstrapURL })] as const,
165167
)
166168
const userConfigPromises = userFunctions.map(
167-
async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger })] as const,
169+
async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger, bootstrapURL })] as const,
168170
)
169171

170172
// Creating a hash of function names to configuration objects.

packages/edge-bundler/node/config.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { FunctionConfig, getFunctionConfig } from './config.js'
1414
import type { Declaration } from './declaration.js'
1515
import { ImportMap } from './import_map.js'
1616
import { RateLimitAction, RateLimitAggregator } from './rate_limit.js'
17+
import { getURL as getBootstrapURL } from '@netlify/edge-functions-bootstrap/version'
18+
const bootstrapURL = getBootstrapURL()
1719

1820
const importMapFile = {
1921
baseURL: new URL('file:///some/path/import-map.json'),
@@ -202,6 +204,7 @@ describe('`getFunctionConfig` extracts configuration properties from function fi
202204
importMap: new ImportMap([importMapFile]),
203205
deno,
204206
log: logger,
207+
bootstrapURL,
205208
})
206209

207210
if (func.error) {
@@ -393,6 +396,7 @@ test('Passes validation if default export exists and is a function', async () =>
393396
importMap: new ImportMap([importMapFile]),
394397
deno,
395398
log: logger,
399+
bootstrapURL,
396400
}),
397401
).resolves.not.toThrow()
398402

@@ -429,6 +433,7 @@ test('Fails validation if default export is not function', async () => {
429433
importMap: new ImportMap([importMapFile]),
430434
deno,
431435
log: logger,
436+
bootstrapURL,
432437
})
433438

434439
await expect(config).rejects.toThrowError(invalidDefaultExportErr(path))
@@ -465,6 +470,7 @@ test('Fails validation if default export is not present', async () => {
465470
importMap: new ImportMap([importMapFile]),
466471
deno,
467472
log: logger,
473+
bootstrapURL,
468474
})
469475

470476
await expect(config).rejects.toThrowError(invalidDefaultExportErr(path))

packages/edge-bundler/node/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ export const getFunctionConfig = async ({
7878
func,
7979
importMap,
8080
deno,
81+
bootstrapURL,
8182
log,
8283
}: {
8384
func: EdgeFunction
8485
importMap: ImportMap
8586
deno: DenoBridge
87+
bootstrapURL: string
8688
log: Logger
8789
}) => {
8890
// The extractor is a Deno script that will import the function and run its
@@ -117,6 +119,7 @@ export const getFunctionConfig = async ({
117119
extractorPath,
118120
pathToFileURL(func.path).href,
119121
pathToFileURL(collector.path).href,
122+
bootstrapURL,
120123
JSON.stringify(ConfigExitCode),
121124
].filter(Boolean),
122125
{ rejectOnExitCode: false },

packages/edge-bundler/node/server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const prepareServer = ({
148148

149149
if (options.getFunctionsConfig) {
150150
functionsConfig = await Promise.all(
151-
functions.map((func) => getFunctionConfig({ func, importMap, deno, log: logger })),
151+
functions.map((func) => getFunctionConfig({ func, importMap, deno, bootstrapURL, log: logger })),
152152
)
153153
}
154154

0 commit comments

Comments
 (0)