diff --git a/src/manifest.ts b/src/manifest.ts index a05543031..bf853f201 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -36,12 +36,12 @@ const createManifest = async ({ functions, path }: { functions: FunctionResult[] await writeFile(path, JSON.stringify(payload)) } -const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }: FunctionResult): ManifestFunction => ({ +const formatFunctionForManifest = ({ mainFile, name, path, runtime, schedule }: FunctionResult): ManifestFunction => ({ mainFile, name, path: resolve(path), runtime, - schedule: config.schedule, + schedule, }) export { createManifest } diff --git a/src/utils/format_result.ts b/src/utils/format_result.ts index 98b7f5415..50b2174f1 100644 --- a/src/utils/format_result.ts +++ b/src/utils/format_result.ts @@ -3,13 +3,14 @@ import { RuntimeName } from '../runtimes/runtime' import { removeUndefined } from './remove_undefined' -type FunctionResult = Omit & { runtime: RuntimeName } +type FunctionResult = Omit & { runtime: RuntimeName; schedule?: string } // Takes the result of zipping a function and formats it for output. const formatZipResult = (archive: FunctionArchive) => { const functionResult: FunctionResult = { ...archive, runtime: archive.runtime.name, + schedule: archive?.config?.schedule, } return removeUndefined(functionResult) diff --git a/tests/fixtures/with-schedule/func-1.js b/tests/fixtures/with-schedule/func-1.js new file mode 100644 index 000000000..99465a109 --- /dev/null +++ b/tests/fixtures/with-schedule/func-1.js @@ -0,0 +1,3 @@ +module.exports.handler = () => { + return true +} diff --git a/tests/main.js b/tests/main.js index 5086da2ab..3fae1d1f3 100644 --- a/tests/main.js +++ b/tests/main.js @@ -2353,6 +2353,35 @@ testMany( }, ) +testMany( + 'Should surface schedule declarations on a top-level `schedule` property', + ['bundler_default', 'bundler_default_nft', 'bundler_esbuild', 'bundler_nft'], + async (options, t) => { + const schedule = '* * * * *' + const fixtureName = 'with-schedule' + const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' }) + const manifestPath = join(tmpDir, 'manifest.json') + const opts = merge(options, { + basePath: join(FIXTURES_DIR, fixtureName), + config: { + '*': { + schedule, + }, + }, + manifest: manifestPath, + }) + const { files } = await zipNode(t, fixtureName, { opts }) + + files.every((file) => t.is(file.schedule, schedule)) + + const manifest = require(manifestPath) + + manifest.functions.forEach((fn) => { + t.is(fn.schedule, schedule) + }) + }, +) + test('Generates a sourcemap for any transpiled files when `nodeSourcemap: true`', async (t) => { const fixtureName = 'esm-throwing-error' const basePath = join(FIXTURES_DIR, fixtureName)