Skip to content

Commit

Permalink
feat: show displayName for any edge function that has one being run w…
Browse files Browse the repository at this point in the history
…ith ntl dev (#5487)
  • Loading branch information
khendrikse authored Feb 20, 2023
1 parent 3412ff2 commit 50fbfb4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/lib/edge-functions/registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn, watchDebounced } from '
* @type {object}
* @property {string} function
* @property {string} path
* @property {string=} name
*/

/**
* @typedef EdgeFunctionDeclarationWithPattern
* @type {object}
* @property {string} function
* @property {string} pattern
* @property {string=} name
*/

/** @typedef {(EdgeFunctionDeclarationWithPath | EdgeFunctionDeclarationWithPattern)} EdgeFunctionDeclaration */
Expand Down Expand Up @@ -194,11 +196,11 @@ export class EdgeFunctionsRegistry {
await this.build(functionsFound)

deletedFunctions.forEach((func) => {
EdgeFunctionsRegistry.logDeletedFunction(func)
EdgeFunctionsRegistry.logDeletedFunction(func, this.findDisplayName(func.name))
})

newFunctions.forEach((func) => {
EdgeFunctionsRegistry.logAddedFunction(func)
EdgeFunctionsRegistry.logAddedFunction(func, this.findDisplayName(func.name))
})
} catch {
// no-op
Expand Down Expand Up @@ -257,7 +259,8 @@ export class EdgeFunctionsRegistry {
log(`${NETLIFYDEVLOG} ${chalk.green('Reloaded')} edge functions`)
} else {
functionNames.forEach((functionName) => {
log(`${NETLIFYDEVLOG} ${chalk.green('Reloaded')} edge function ${chalk.yellow(functionName)}`)
const displayName = this.findDisplayName(functionName)
log(`${NETLIFYDEVLOG} ${chalk.green('Reloaded')} edge function ${chalk.yellow(displayName || functionName)}`)
})
}
} catch {
Expand All @@ -282,12 +285,12 @@ export class EdgeFunctionsRegistry {
return this.initialization
}

static logAddedFunction(func) {
log(`${NETLIFYDEVLOG} ${chalk.green('Loaded')} edge function ${chalk.yellow(func.name)}`)
static logAddedFunction(func, displayName) {
log(`${NETLIFYDEVLOG} ${chalk.green('Loaded')} edge function ${chalk.yellow(displayName || func.name)}`)
}

static logDeletedFunction(func) {
log(`${NETLIFYDEVLOG} ${chalk.magenta('Removed')} edge function ${chalk.yellow(func.name)}`)
static logDeletedFunction(func, displayName) {
log(`${NETLIFYDEVLOG} ${chalk.magenta('Removed')} edge function ${chalk.yellow(displayName || func.name)}`)
}

/**
Expand Down Expand Up @@ -444,7 +447,7 @@ export class EdgeFunctionsRegistry {
const functions = await this.bundler.find(directories)

functions.forEach((func) => {
EdgeFunctionsRegistry.logAddedFunction(func)
EdgeFunctionsRegistry.logAddedFunction(func, this.findDisplayName(func.name))
})

this.functions = functions
Expand Down Expand Up @@ -481,4 +484,8 @@ export class EdgeFunctionsRegistry {

this.directoryWatchers.set(directory, watcher)
}

findDisplayName(func) {
return this.declarationsFromConfig?.find((declaration) => declaration.function === func)?.name
}
}

1 comment on commit 50fbfb4

@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

  • Package size: 263 MB

Please sign in to comment.