Skip to content

Commit

Permalink
feat: support @netlify/edge-functions specifier (#459)
Browse files Browse the repository at this point in the history
* feat: support `@netlify/edge-functions` specifier

* chore: fix test
  • Loading branch information
eduardoboucas committed Aug 25, 2023
1 parent aa4d4ab commit 3340ac6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion deno/lib/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const PUBLIC_SPECIFIER = 'netlify:edge'
export const LEGACY_PUBLIC_SPECIFIER = 'netlify:edge'
export const PUBLIC_SPECIFIER = '@netlify/edge-functions'
export const STAGE1_SPECIFIER = 'netlify:bootstrap-stage1'
export const STAGE2_SPECIFIER = 'netlify:bootstrap-stage2'
export const virtualRoot = 'file:///root/'
9 changes: 7 additions & 2 deletions deno/lib/stage2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'https://deno.land/std@0.177.0/path/mod.ts'

import type { InputFunction, WriteStage2Options } from '../../shared/stage2.ts'
import { importMapSpecifier, virtualRoot } from '../../shared/consts.ts'
import { PUBLIC_SPECIFIER, STAGE2_SPECIFIER } from './consts.ts'
import { LEGACY_PUBLIC_SPECIFIER, PUBLIC_SPECIFIER, STAGE2_SPECIFIER } from './consts.ts'
import { inlineModule, loadFromVirtualRoot, loadWithRetry } from './common.ts'

interface FunctionReference {
Expand Down Expand Up @@ -75,7 +75,12 @@ const stage2Loader = (basePath: string, functions: InputFunction[], externals: S
return inlineModule(specifier, importMapData)
}

if (specifier === PUBLIC_SPECIFIER || externals.has(specifier) || specifier.startsWith('node:')) {
if (
specifier === LEGACY_PUBLIC_SPECIFIER ||
specifier === PUBLIC_SPECIFIER ||
externals.has(specifier) ||
specifier.startsWith('node:')
) {
return {
kind: 'external',
specifier,
Expand Down
2 changes: 2 additions & 0 deletions node/import_map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('Returns the fully resolved import map', () => {
specifier3: 'file:///different/full/path/file3.js',
specifier2: 'file:///some/full/path/file2.js',
specifier1: 'file:///some/full/path/file.js',
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
'netlify:edge': 'https://edge.netlify.com/v1/index.ts',
})

Expand All @@ -104,6 +105,7 @@ describe('Returns the fully resolved import map', () => {
specifier3: 'file:///vendor/full/path/file3.js',
specifier2: 'file:///root/full/path/file2.js',
specifier1: 'file:///root/full/path/file.js',
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
'netlify:edge': 'https://edge.netlify.com/v1/index.ts',
})

Expand Down
1 change: 1 addition & 0 deletions node/import_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Logger } from './logger.js'
import { isFileNotFoundError } from './utils/error.js'

const INTERNAL_IMPORTS = {
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
'netlify:edge': 'https://edge.netlify.com/v1/index.ts',
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Config } from '@netlify/edge-functions'
import { greet } from 'alias:helper'

// Accessing `Deno.env` in the global scope
Expand All @@ -11,6 +12,6 @@ export default async () => {
return new Response(greeting)
}

export const config = {
export const config: Config = {
path: '/user-func1',
}

0 comments on commit 3340ac6

Please sign in to comment.