Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 0 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/commands/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
accountId,
functionsRegistry,
repositoryRoot,
watchIgnore: devConfig.watchIgnore ?? [],
deployEnvironment,
})

Expand Down
1 change: 1 addition & 0 deletions src/commands/dev/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type DevConfig = NonNullable<NetlifyTOML['dev']> & {
jwtSecret?: string | undefined
jwtRolePath?: string | undefined
pollingStrategies?: string[] | undefined
watchIgnore?: string[] | undefined
}
1 change: 1 addition & 0 deletions src/commands/serve/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export const serve = async (options: OptionValues, command: BaseCommand) => {
siteInfo,
state,
accountId,
watchIgnore: devConfig.watchIgnore ?? [],
deployEnvironment: [],
})

Expand Down
10 changes: 10 additions & 0 deletions src/lib/edge-functions/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const initializeProxy = async ({
settings,
siteInfo,
state,
watchIgnore,
deployEnvironment,
}: {
accountId: string
Expand All @@ -117,6 +118,7 @@ export const initializeProxy = async ({
settings: ServerSettings
siteInfo: $TSFixMe
state: LocalState
watchIgnore: string[]
deployEnvironment: { key: string; value: string; isSecret: boolean; scopes: string[] }[]
}) => {
const isolatePort = await getAvailablePort()
Expand All @@ -139,7 +141,9 @@ export const initializeProxy = async ({
inspectSettings,
port: isolatePort,
projectDir,
publishDir: settings.dist,
repositoryRoot,
watchIgnore,
deployEnvironment,
})
return async (req: ExtendedIncomingMessage) => {
Expand Down Expand Up @@ -214,7 +218,9 @@ const prepareServer = async ({
inspectSettings,
port,
projectDir,
publishDir,
repositoryRoot,
watchIgnore,
deployEnvironment,
}: {
aiGatewayContext?: AIGatewayContext | null
Expand All @@ -228,7 +234,9 @@ const prepareServer = async ({
inspectSettings: Parameters<typeof bundler.serve>[0]['inspectSettings']
port: number
projectDir: string
publishDir: string
repositoryRoot?: string
watchIgnore: string[]
deployEnvironment: { key: string; value: string; isSecret: boolean; scopes: string[] }[]
}) => {
try {
Expand Down Expand Up @@ -267,8 +275,10 @@ const prepareServer = async ({
getUpdatedConfig,
importMapFromTOML: config.functions?.['*'].deno_import_map,
projectDir,
publishDir,
runIsolate,
servePath,
watchIgnore,
deployEnvironment: deployEnvironment
.filter(({ scopes }) => scopes.includes('functions'))
// Scopes should be opaque to the functions registry: We just filtered down to only variables
Expand Down
29 changes: 27 additions & 2 deletions src/lib/edge-functions/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile } from 'fs/promises'
import { join } from 'path'
import { statSync } from 'fs'
import { join, resolve } from 'path'
import { fileURLToPath } from 'url'

import type { Declaration, EdgeFunction, FunctionConfig, Manifest, ModuleGraph } from '@netlify/edge-bundler'
Expand Down Expand Up @@ -48,8 +49,10 @@ interface EdgeFunctionsRegistryOptions {
getUpdatedConfig: () => Promise<NormalizedCachedConfigConfig>
importMapFromTOML?: string
projectDir: string
publishDir: string
runIsolate: RunIsolate
servePath: string
watchIgnore: string[]
deployEnvironment: { key: string; value: string; isSecret: boolean }[]
}

Expand Down Expand Up @@ -143,6 +146,8 @@ export class EdgeFunctionsRegistryImpl implements EdgeFunctionsRegistry {
private routes: Route[] = []
private runIsolate: RunIsolate
private servePath: string
private publishDir: string
private watchIgnore: string[]
private projectDir: string
private command: BaseCommand

Expand All @@ -157,8 +162,10 @@ export class EdgeFunctionsRegistryImpl implements EdgeFunctionsRegistry {
getUpdatedConfig,
importMapFromTOML,
projectDir,
publishDir,
runIsolate,
servePath,
watchIgnore,
deployEnvironment,
}: EdgeFunctionsRegistryOptions) {
this.aiGatewayContext = aiGatewayContext
Expand All @@ -169,6 +176,8 @@ export class EdgeFunctionsRegistryImpl implements EdgeFunctionsRegistry {
this.getUpdatedConfig = getUpdatedConfig
this.runIsolate = runIsolate
this.servePath = servePath
this.publishDir = resolve(projectDir, publishDir)
this.watchIgnore = watchIgnore.map((p) => resolve(projectDir, p))
this.projectDir = projectDir

this.importMapFromTOML = importMapFromTOML
Expand Down Expand Up @@ -719,7 +728,23 @@ export class EdgeFunctionsRegistryImpl implements EdgeFunctionsRegistry {
}

private async setupWatcherForDirectory() {
const ignored = [`${this.servePath}/**`, this.internalImportMapPath]
const toIgnoredRegex = (dir: string) => new RegExp(`^${dir.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(/|$)`)

const toIgnoredEntry = (p: string): string | RegExp => {
try {
if (statSync(p).isFile()) return p
} catch {
// path doesn't exist yet (e.g. publish dir before first build) — treat as directory
}
return toIgnoredRegex(p)
}

const ignored: (string | RegExp)[] = [
toIgnoredRegex(this.servePath),
...(this.publishDir !== this.projectDir ? [toIgnoredRegex(this.publishDir)] : []),
...this.watchIgnore.map(toIgnoredEntry),
this.internalImportMapPath,
]
const watcher = await watchDebounced(this.projectDir, {
ignored,
onAdd: () => this.checkForAddedOrDeletedFunctions(),
Expand Down
3 changes: 3 additions & 0 deletions src/utils/proxy-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const startProxyServer = async ({
site,
siteInfo,
state,
watchIgnore,
deployEnvironment,
}: {
accountId: string | undefined
Expand All @@ -90,6 +91,7 @@ export const startProxyServer = async ({
projectDir: string
repositoryRoot?: string
state: LocalState
watchIgnore: string[]
functionsRegistry?: FunctionsRegistry
deployEnvironment: { key: string; value: string; isSecret: boolean; scopes: string[] }[]
}) => {
Expand All @@ -116,6 +118,7 @@ export const startProxyServer = async ({
accountId,
repositoryRoot,
api,
watchIgnore,
deployEnvironment,
})
if (!url) {
Expand Down
Loading
Loading