Skip to content

Commit c89d81a

Browse files
netlify-team-account-1karagulamos
andauthoredJan 31, 2022
fix: dont show warning message for toml-defined scheduled functions (#4162)
* chore: add reproduction test co-authored-by: Alexander Karagulamos <alex-contractor@netlify.com> * fix: respect netlify.toml-configured schedule co-authored-by: Alexander Karagulamos <alex-contractor@netlify.com> * refactor: prevent user-provided netlify-toml from being injected into ZISI * fix: test Co-authored-by: Netlify Team Account 1 <netlify-team-account-1@users.noreply.github.com> Co-authored-by: Alexander Karagulamos <alex-contractor@netlify.com>
1 parent 0550e60 commit c89d81a

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed
 

‎src/commands/functions/functions-invoke.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const functionsInvoke = async (nameArgument, options, command) => {
156156
console.warn(`${NETLIFYDEVWARN} "port" flag was not specified. Attempting to connect to localhost:8888 by default`)
157157
const port = options.port || DEFAULT_PORT
158158

159-
const functions = await getFunctions(functionsDir)
159+
const functions = await getFunctions(functionsDir, config)
160160
const functionToTrigger = await getNameFromArgs(functions, options, nameArgument)
161161
const functionObj = functions.find((func) => func.name === functionToTrigger)
162162

‎src/utils/functions/get-functions.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ const addFunctionProps = ({ mainFile, name, runtime, schedule }) => {
1313

1414
const JS = 'js'
1515

16-
const getFunctions = async (functionsSrcDir) => {
16+
/**
17+
* @param {Record<string, { schedule?: string }>} functionConfigRecord
18+
* @returns {Record<string, { schedule?: string }>}
19+
*/
20+
const extractSchedule = (functionConfigRecord) =>
21+
Object.fromEntries(Object.entries(functionConfigRecord).map(([name, { schedule }]) => [name, { schedule }]))
22+
23+
const getFunctions = async (functionsSrcDir, config = {}) => {
1724
if (!(await fileExistsAsync(functionsSrcDir))) {
1825
return []
1926
}
@@ -22,6 +29,7 @@ const getFunctions = async (functionsSrcDir) => {
2229
// eslint-disable-next-line node/global-require
2330
const { listFunctions } = require('@netlify/zip-it-and-ship-it')
2431
const functions = await listFunctions(functionsSrcDir, {
32+
config: config.functions ? extractSchedule(config.functions) : undefined,
2533
parseISC: true,
2634
})
2735
const functionsWithProps = functions.filter(({ runtime }) => runtime === JS).map((func) => addFunctionProps(func))

‎tests/command.functions.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,29 @@ test('should serve helpful tips and tricks', async (t) => {
643643
})
644644
})
645645

646+
test('should detect netlify-toml defined scheduled functions', async (t) => {
647+
await withSiteBuilder('site-with-netlify-toml-ping-function', async (builder) => {
648+
await builder
649+
.withNetlifyToml({
650+
config: { functions: { directory: 'functions', 'test-1': { schedule: '@daily' } } },
651+
})
652+
.withFunction({
653+
path: 'test-1.js',
654+
handler: async () => ({
655+
statusCode: 200,
656+
}),
657+
})
658+
.buildAsync()
659+
660+
await withDevServer({ cwd: builder.directory }, async (server) => {
661+
const stdout = await callCli(['functions:invoke', 'test-1', `--port=${server.port}`], {
662+
cwd: builder.directory,
663+
})
664+
t.is(stdout, '')
665+
})
666+
})
667+
})
668+
646669
test('should detect file changes to scheduled function', async (t) => {
647670
await withSiteBuilder('site-with-isc-ping-function', async (builder) => {
648671
await builder

1 commit comments

Comments
 (1)

github-actions[bot] commented on Jan 31, 2022

@github-actions[bot]

📊 Benchmark results

Package size: 360 MB

Please sign in to comment.