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

feat: show displayName for any edge function that has one being run with netlify dev #5487

Merged
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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about optional parameters in JSDoc types!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Saaaaaaameee

*/

/** @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
}
}