From 7afcf200841e805ed182305170df36e19284af0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 25 Sep 2023 12:49:49 +0100 Subject: [PATCH 1/7] feat: return `features` from server --- node/npm_dependencies.ts | 4 ---- node/server/server.test.ts | 5 +++-- node/server/server.ts | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/node/npm_dependencies.ts b/node/npm_dependencies.ts index c2ddb73d..44c24eb9 100644 --- a/node/npm_dependencies.ts +++ b/node/npm_dependencies.ts @@ -161,10 +161,6 @@ export const vendorNPMSpecifiers = async ({ return } - logger.user( - 'You are using npm modules in Edge Functions, which is an experimental feature. Learn more at https://ntl.fyi/edge-functions-npm.', - ) - // To bundle an entire module and all its dependencies, create a barrel file // where we re-export everything from that specifier. We do this for every // specifier, and each of these files will become entry points to esbuild. diff --git a/node/server/server.test.ts b/node/server/server.test.ts index d7dbe74f..04f6f6e7 100644 --- a/node/server/server.test.ts +++ b/node/server/server.test.ts @@ -20,7 +20,7 @@ test('Starts a server and serves requests for edge functions', async () => { const servePath = await tmpName() const server = await serve({ basePath, - bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts', + bootstrapURL: 'https://650d58f59f81ce000841fbab--edge.netlify.com/bootstrap/index-combined.ts', importMapPaths, port, servePath, @@ -44,13 +44,14 @@ test('Starts a server and serves requests for edge functions', async () => { getFunctionsConfig: true, } - const { functionsConfig, graph, success } = await server( + const { features, functionsConfig, graph, success } = await server( functions, { very_secret_secret: 'i love netlify', }, options, ) + expect(features).toEqual({}) expect(success).toBe(true) expect(functionsConfig).toEqual([{ path: '/my-function' }, {}, { path: '/global-netlify' }]) diff --git a/node/server/server.ts b/node/server/server.ts index b69bb8f2..5e177c2e 100644 --- a/node/server/server.ts +++ b/node/server/server.ts @@ -64,6 +64,7 @@ const prepareServer = ({ formatImportError, }) + const features: Record = {} const importMap = baseImportMap.clone() const vendor = await vendorNPMSpecifiers({ basePath, @@ -74,6 +75,7 @@ const prepareServer = ({ }) if (vendor) { + features.npmModules = true importMap.add(vendor.importMap) } @@ -116,6 +118,7 @@ const prepareServer = ({ const success = await waitForServer(port, processRef.ps) return { + features, functionsConfig, graph, success, From 4a2df8982b0a4ccb61bba62bc9609f98b2bc4678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 25 Sep 2023 13:35:04 +0100 Subject: [PATCH 2/7] fix: update Deno version --- .github/workflows/workflow.yml | 2 +- node/bridge.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 31cb1a5b..a4dba4a1 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,7 +29,7 @@ jobs: os: [ubuntu-latest] node-version: ['14.18.0', '*'] # Must include the minimum deno version from the `DENO_VERSION_RANGE` constant in `node/bridge.ts`. - deno-version: ['v1.32.5', 'v1.x'] + deno-version: ['v1.37.0', 'v1.x'] include: - os: macOS-latest node-version: '*' diff --git a/node/bridge.ts b/node/bridge.ts index 1712a889..348c3c32 100644 --- a/node/bridge.ts +++ b/node/bridge.ts @@ -14,7 +14,7 @@ import { getBinaryExtension } from './platform.js' const DENO_VERSION_FILE = 'version.txt' // When updating DENO_VERSION_RANGE, ensure that the deno version installed in the // build-image/buildbot does satisfy this range! -const DENO_VERSION_RANGE = '^1.32.5' +const DENO_VERSION_RANGE = '^1.37.0' type OnBeforeDownloadHook = () => void | Promise type OnAfterDownloadHook = (error?: Error) => void | Promise From cd0ee005cb8ae49f422c8269b4745b8c500abd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 25 Sep 2023 13:44:15 +0100 Subject: [PATCH 3/7] chore: revert bootstrap version locking --- node/server/server.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/server/server.test.ts b/node/server/server.test.ts index 04f6f6e7..ee92c6b7 100644 --- a/node/server/server.test.ts +++ b/node/server/server.test.ts @@ -20,7 +20,7 @@ test('Starts a server and serves requests for edge functions', async () => { const servePath = await tmpName() const server = await serve({ basePath, - bootstrapURL: 'https://650d58f59f81ce000841fbab--edge.netlify.com/bootstrap/index-combined.ts', + bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts', importMapPaths, port, servePath, From 39ffee2a8df9a1da34e2ff15f43af1a9f888c209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 25 Sep 2023 16:23:56 +0100 Subject: [PATCH 4/7] chore: add debug logging --- node/server/server.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node/server/server.ts b/node/server/server.ts index 5e177c2e..7271ce24 100644 --- a/node/server/server.ts +++ b/node/server/server.ts @@ -75,6 +75,7 @@ const prepareServer = ({ }) if (vendor) { + console.log('-> NPM vendor:', vendor) features.npmModules = true importMap.add(vendor.importMap) } From 99520c821a5535d1e75109499ac99fbf8351fb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 25 Sep 2023 16:37:58 +0100 Subject: [PATCH 5/7] fix: look for absolute paths --- node/npm_dependencies.ts | 2 +- node/server/server.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/node/npm_dependencies.ts b/node/npm_dependencies.ts index 44c24eb9..de963337 100644 --- a/node/npm_dependencies.ts +++ b/node/npm_dependencies.ts @@ -69,7 +69,7 @@ export const getDependencyTrackerPlugin = ( return { external: true } } - const isLocalImport = specifier.startsWith(path.sep) || specifier.startsWith('.') + const isLocalImport = specifier.startsWith(path.sep) || specifier.startsWith('.') || path.isAbsolute(specifier) // If this is a local import, return so that esbuild visits that path. if (isLocalImport) { diff --git a/node/server/server.ts b/node/server/server.ts index 7271ce24..5e177c2e 100644 --- a/node/server/server.ts +++ b/node/server/server.ts @@ -75,7 +75,6 @@ const prepareServer = ({ }) if (vendor) { - console.log('-> NPM vendor:', vendor) features.npmModules = true importMap.add(vendor.importMap) } From d2628514978bf94dd1e4afad544f1b5d200b4812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Tue, 26 Sep 2023 09:58:44 +0100 Subject: [PATCH 6/7] refactor: wrap npm vendoring in feature flag --- node/server/server.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/node/server/server.ts b/node/server/server.ts index 5e177c2e..953b0585 100644 --- a/node/server/server.ts +++ b/node/server/server.ts @@ -1,6 +1,7 @@ import { DenoBridge, OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef } from '../bridge.js' import { getFunctionConfig, FunctionConfig } from '../config.js' import type { EdgeFunction } from '../edge_function.js' +import type { FeatureFlags } from '../feature_flags.js' import { generateStage2 } from '../formats/javascript.js' import { ImportMap } from '../import_map.js' import { getLogger, LogFunction, Logger } from '../logger.js' @@ -18,6 +19,7 @@ interface PrepareServerOptions { distDirectory: string distImportMapPath?: string entryPoint?: string + featureFlags?: FeatureFlags flags: string[] formatExportTypeError?: FormatFunction formatImportError?: FormatFunction @@ -36,6 +38,7 @@ const prepareServer = ({ deno, distDirectory, distImportMapPath, + featureFlags, flags: denoFlags, formatExportTypeError, formatImportError, @@ -66,17 +69,20 @@ const prepareServer = ({ const features: Record = {} const importMap = baseImportMap.clone() - const vendor = await vendorNPMSpecifiers({ - basePath, - directory: distDirectory, - functions: functions.map(({ path }) => path), - importMap, - logger, - }) - if (vendor) { - features.npmModules = true - importMap.add(vendor.importMap) + if (featureFlags?.edge_functions_npm_modules) { + const vendor = await vendorNPMSpecifiers({ + basePath, + directory: distDirectory, + functions: functions.map(({ path }) => path), + importMap, + logger, + }) + + if (vendor) { + features.npmModules = true + importMap.add(vendor.importMap) + } } try { @@ -144,6 +150,7 @@ interface ServeOptions { certificatePath?: string debug?: boolean distImportMapPath?: string + featureFlags?: FeatureFlags inspectSettings?: InspectSettings importMapPaths?: string[] onAfterDownload?: OnAfterDownloadHook @@ -162,6 +169,7 @@ export const serve = async ({ debug, distImportMapPath, inspectSettings, + featureFlags, formatExportTypeError, formatImportError, importMapPaths = [], @@ -215,6 +223,7 @@ export const serve = async ({ deno, distDirectory: servePath, distImportMapPath, + featureFlags, flags, formatExportTypeError, formatImportError, From e7f474d5a4abc8f0af38267b58188b0bcb8164d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Tue, 26 Sep 2023 12:17:45 +0100 Subject: [PATCH 7/7] refactor: revert version bump --- .github/workflows/workflow.yml | 2 +- node/bridge.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a4dba4a1..31cb1a5b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,7 +29,7 @@ jobs: os: [ubuntu-latest] node-version: ['14.18.0', '*'] # Must include the minimum deno version from the `DENO_VERSION_RANGE` constant in `node/bridge.ts`. - deno-version: ['v1.37.0', 'v1.x'] + deno-version: ['v1.32.5', 'v1.x'] include: - os: macOS-latest node-version: '*' diff --git a/node/bridge.ts b/node/bridge.ts index 348c3c32..1712a889 100644 --- a/node/bridge.ts +++ b/node/bridge.ts @@ -14,7 +14,7 @@ import { getBinaryExtension } from './platform.js' const DENO_VERSION_FILE = 'version.txt' // When updating DENO_VERSION_RANGE, ensure that the deno version installed in the // build-image/buildbot does satisfy this range! -const DENO_VERSION_RANGE = '^1.37.0' +const DENO_VERSION_RANGE = '^1.32.5' type OnBeforeDownloadHook = () => void | Promise type OnAfterDownloadHook = (error?: Error) => void | Promise