Skip to content

Commit

Permalink
feat: support node: prefix (#406)
Browse files Browse the repository at this point in the history
* feat: support `node:` prefix

* feat: update Deno version
  • Loading branch information
eduardoboucas committed May 30, 2023
1 parent abcb79d commit 0f7413f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` constant in `node/bridge.ts`.
deno-version: v1.22.0
deno-version: v1.30.0
- name: Install dependencies
run: npm ci
- name: Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` constant in `node/bridge.ts`.
deno-version: v1.22.0
deno-version: v1.30.0
- name: Setup Deno dependencies
run: deno cache https://deno.land/x/eszip@v0.40.0/eszip.ts
- name: Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/stage2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const stage2Loader = (basePath: string, functions: InputFunction[], externals: S
return inlineModule(specifier, importMapData)
}

if (specifier === PUBLIC_SPECIFIER || externals.has(specifier)) {
if (specifier === PUBLIC_SPECIFIER || externals.has(specifier) || specifier.startsWith('node:')) {
return {
kind: 'external',
specifier,
Expand Down
2 changes: 1 addition & 1 deletion node/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getLogger, Logger } from './logger.js'
import { getBinaryExtension } from './platform.js'

const DENO_VERSION_FILE = 'version.txt'
const DENO_VERSION_RANGE = '^1.22.0'
const DENO_VERSION_RANGE = '^1.30.0'

type OnBeforeDownloadHook = () => void | Promise<void>
type OnAfterDownloadHook = (error?: Error) => void | Promise<void>
Expand Down
36 changes: 36 additions & 0 deletions node/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,39 @@ test("Ignores entries in `importMapPaths` that don't point to an existing import
await cleanup()
await importMap.cleanup()
})

test('Handles imports with the `node:` prefix', async () => {
const { basePath, cleanup, distPath } = await useFixture('imports_node_specifier')
const userDirectory = join(basePath, 'netlify', 'edge-functions')
const result = await bundle([userDirectory], distPath, [], {
basePath,
importMapPaths: [join(userDirectory, 'import_map.json')],
})
const generatedFiles = await readdir(distPath)

expect(result.functions.length).toBe(1)
expect(generatedFiles.length).toBe(2)

const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8')
const manifest = JSON.parse(manifestFile)

expect(() => validateManifest(manifest)).not.toThrowError()

const { bundles, import_map: importMapURL, routes } = manifest

expect(bundles.length).toBe(1)
expect(bundles[0].format).toBe('eszip2')
expect(generatedFiles.includes(bundles[0].asset)).toBe(true)
expect(importMapURL).toBe(importMapSpecifier)
expect(routes.length).toBe(1)
expect(routes[0].function).toBe('func1')
expect(routes[0].pattern).toBe('^/func1/?$')

const bundlePath = join(distPath, bundles[0].asset)

const { func1 } = await runESZIP(bundlePath)

expect(func1).toBe('ok')

await cleanup()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import assert from 'node:assert'
import process from 'node:process'

export default () => {
Deno.env.set('NETLIFY_TEST', '12345')
assert.deepEqual(process.env.NETLIFY_TEST, '12345')

return new Response('ok')
}

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

0 comments on commit 0f7413f

Please sign in to comment.