Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support npm modules + edge functions in monorepos #6130

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
382 changes: 191 additions & 191 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@netlify/build": "29.25.0",
"@netlify/build-info": "7.10.2",
"@netlify/config": "20.9.0",
"@netlify/edge-bundler": "9.4.1",
"@netlify/edge-bundler": "^10.0.0",
"@netlify/local-functions-proxy": "1.1.1",
"@netlify/zip-it-and-ship-it": "9.25.7",
"@octokit/rest": "19.0.13",
Expand Down
1 change: 1 addition & 0 deletions src/commands/dev/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ const dev = async (options, command) => {
geoCountry: options.country,
accountId,
functionsRegistry,
repositoryRoot,
})

if (devConfig.autoLaunch !== false) {
Expand Down
24 changes: 7 additions & 17 deletions src/lib/edge-functions/proxy.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @ts-check
import { Buffer } from 'buffer'
import { rm } from 'fs/promises'
import { join, relative, resolve } from 'path'
import { join, resolve } from 'path'

// eslint-disable-next-line import/no-namespace
import * as bundler from '@netlify/edge-bundler'
import getAvailablePort from 'get-port'

import { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error as printError, log } from '../../utils/command-helpers.mjs'
import { NETLIFYDEVERR, chalk, error as printError } from '../../utils/command-helpers.mjs'
import { getGeoLocation } from '../geo-location.mjs'
import { getPathInProject } from '../settings.mjs'
import { startSpinner, stopSpinner } from '../spinner.mjs'
Expand Down Expand Up @@ -99,6 +99,7 @@ export const initializeProxy = async ({
offline,
passthroughPort,
projectDir,
repositoryRoot,
settings,
siteInfo,
state,
Expand Down Expand Up @@ -132,6 +133,7 @@ export const initializeProxy = async ({
internalFunctions,
port: isolatePort,
projectDir,
repositoryRoot,
})
const hasEdgeFunctions = userFunctionsPath !== undefined || internalFunctionsPath

Expand Down Expand Up @@ -162,21 +164,7 @@ export const initializeProxy = async ({
await registry.initialize()

const url = new URL(req.url, `http://${LOCAL_HOST}:${mainPort}`)
const { functionNames, invocationMetadata, orphanedDeclarations } = registry.matchURLPath(url.pathname, req.method)

// If the request matches a config declaration for an Edge Function without
// a matching function file, we warn the user.
orphanedDeclarations.forEach((functionName) => {
log(
`${NETLIFYDEVWARN} Request to ${chalk.yellow(
url.pathname,
)} matches declaration for edge function ${chalk.yellow(
functionName,
)}, but there's no matching function file in ${chalk.yellow(
relative(projectDir, userFunctionsPath),
)}. Please visit ${chalk.blue('https://ntl.fyi/edge-create')} for more information.`,
)
})
const { functionNames, invocationMetadata } = registry.matchURLPath(url.pathname, req.method)

if (functionNames.length === 0) {
return
Expand Down Expand Up @@ -217,6 +205,7 @@ const prepareServer = async ({
internalFunctions,
port,
projectDir,
repositoryRoot,
}) => {
// Merging internal with user-defined import maps.
const importMapPaths = [...importMaps, config.functions['*'].deno_import_map]
Expand All @@ -243,6 +232,7 @@ const prepareServer = async ({
importMapPaths,
inspectSettings,
port,
rootPath: repositoryRoot,
servePath,
})
const registry = new EdgeFunctionsRegistry({
Expand Down
Loading
Loading