Skip to content

Commit cfb8fac

Browse files
fix: fix @netlify/edge-functions exports (#289)
* fix: fix edge functions exports * fix: re-export `getURL` * chore: fix test
1 parent cdf9261 commit cfb8fac

File tree

6 files changed

+12
-42
lines changed

6 files changed

+12
-42
lines changed

packages/edge-functions/dev/deno/config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @ts-check
22

33
/**
4-
* @typedef {import('./workers/types.js').ConfigRequestMessage} ConfigRequestMessage
5-
* @typedef {import('./workers/types.js').Message} Message
4+
* @typedef {import('./workers/types.ts').ConfigRequestMessage} ConfigRequestMessage
5+
* @typedef {import('./workers/types.ts').Message} Message
66
*/
77

88
/**

packages/edge-functions/dev/shared/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import type { Context } from '@netlify/types'
2-
import type { Config } from '../../src/lib/config.ts'
3-
4-
export type EdgeFunction = { config?: Config; default: (req: Request, context: Context) => Promise<Response> }
5-
61
export interface RunOptions {
72
bootstrapURL: string
83
denoPort: number
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Context } from '@netlify/types'
2+
3+
export type EdgeFunction = (
4+
request: Request,
5+
context: Context,
6+
) => Response | Promise<Response> | URL | Promise<URL> | undefined | Promise<void>

packages/edge-functions/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export type { Context, Cookie } from '@netlify/types'
22
export type { Config, IntegrationsConfig, Manifest, ManifestFunction } from './lib/config.js'
3-
export type { EdgeFunction } from '../dev/shared/types.js'
3+
export type { EdgeFunction } from './lib/edge-function.js'
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { describe, expect, test } from 'vitest'
22

3-
import packageJSON from '../package.json' with { type: 'json' }
3+
import * as bootstrap from '@netlify/edge-functions-bootstrap/version'
44
import { getURL } from './version.js'
55

66
describe('`getURL`', () => {
77
test('Returns the URL of the bootstrap entry point', async () => {
8-
const { version } = packageJSON
9-
const branch = `v${version.split('.').join('-')}`
10-
11-
expect(await getURL()).toBe(`https://${branch}--edge.netlify.com/bootstrap/index-combined.ts`)
8+
expect(await getURL()).toBe(await bootstrap.getURL())
129
})
1310
})
Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1 @@
1-
import { promises as fs } from 'node:fs'
2-
import path from 'node:path'
3-
import { fileURLToPath } from 'node:url'
4-
5-
const packageJsonPath = path.resolve(fileURLToPath(import.meta.url), '../../package.json')
6-
7-
/**
8-
* Returns the URL of the edge functions bootstrap entry file.
9-
*
10-
* @returns {Promise<string>}
11-
*/
12-
export const getURL = async () => {
13-
try {
14-
const data = await fs.readFile(packageJsonPath, 'utf8')
15-
const { version } = JSON.parse(data) as { version: string }
16-
17-
// Releasing version 1.2.3 of the `@netlify/edge-functions` module will
18-
// make release-please create a GitHub release and corresponding tag of
19-
// `v1.2.3`. Because the `edge` Netlify site is configured to build all
20-
// branches, the tag will generate a `v1-2-3--edge.netlify.com` URL,
21-
// which serves the bootstrap for this version. We're computing that
22-
// URL here.
23-
const branch = `v${version.split('.').join('-')}`
24-
25-
return `https://${branch}--edge.netlify.com/bootstrap/index-combined.ts`
26-
} catch (error) {
27-
throw new Error(`Could not find edge bootstrap version: ${error}`)
28-
}
29-
}
1+
export { getURL } from '@netlify/edge-functions-bootstrap/version'

0 commit comments

Comments
 (0)