Skip to content

Commit

Permalink
fix: support npm modules + edge functions in monorepos (#6130)
Browse files Browse the repository at this point in the history
* fix: support npm modules + edge functions in monorepos

* fix: skip build when no functions

* feat: add `ModuleGraph` type
  • Loading branch information
eduardoboucas authored Nov 8, 2023
1 parent f0338d1 commit e19c049
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 319 deletions.
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.1.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

2 comments on commit e19c049

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,339
  • Package size: 402 MB

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,339
  • Package size: 402 MB

Please sign in to comment.