sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.79k stars 1.96k forks source link

Sveltekit vercel adapter ignores cron jobs #10071

Open alexbjorlig opened 1 year ago

alexbjorlig commented 1 year ago

Describe the bug

When using the vercel-adapter, cron jobs are ignored.

CleanShot 2023-05-31 at 20 35 56@2x

Reproduction

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/adapter-vercel: ^3.0.0 => 3.0.0 
    @sveltejs/kit: ^1.5.0 => 1.20.0 
    svelte: ^3.54.0 => 3.59.1 
    vite: ^4.3.0 => 4.3.9

Severity

blocking an upgrade

Additional Information

There seems to also be a warning when building about the endpoint not being there, but it's there.

I might be missing something obvious, but I'm not sure what...

elliott-with-the-longest-name-on-github commented 1 year ago

The warning in the build output is erroneous -- I'm about to push a fix. But the "not writing them to .vercel/output/config.json" is intended -- we don't need to copy them over; Vercel will pick them up from vercel.json. We only actually validate the paths at all as a courtesy. As long as they're in your vercel.json, they'll be published to your project when your site builds on Vercel.

alexbjorlig commented 1 year ago

The warning in the build output is erroneous -- I'm about to push a fix. But the "not writing them to .vercel/output/config.json" is intended -- we don't need to copy them over; Vercel will pick them up from vercel.json. We only actually validate the paths at all as a courtesy. As long as they're in your vercel.json, they'll be published to your project when your site builds on Vercel.

That might be true if using Vercel git integration, but we deploy with the vercel deploy --prebuilt, and in that case the CRON config is not working 😱

Fixed it with a small workaround, but would be amazing not having to do this

const vercelAsJson = JSON.parse(readFileSync('./vercel.json'));

const vercelConfig = JSON.parse(readFileSync('.vercel/output/config.json'));

const merged = { ...vercelConfig, ...vercelAsJson };

writeFileSync('.vercel/output/config.json', JSON.stringify(merged, null, 2));

process.exit(0);
elliott-with-the-longest-name-on-github commented 1 year ago

but we deploy with the vercel deploy --prebuilt

Out of curiosity, why

@Rich-Harris

For users that aren't using the Git integration, could we expose a copyVercelJson config from @sveltejs/adapter-vercel? It could basically just do what he's doing above. Default to false since most users don't need it.

alexbjorlig commented 1 year ago

Because Vercel does not have any tools built in for running db-migrations etc.

So to do that, the recommended way is to deploy from a github action (or similar) 🙃

elliott-with-the-longest-name-on-github commented 1 year ago

Reopening to answer the above question

Rich-Harris commented 1 year ago

Yeah, I use --prebuilt from time to time, especially if I'm testing unreleased libraries etc.

Do we need copyVercelJson? Is there any downside in just always copying the relevant parts?

elliott-with-the-longest-name-on-github commented 1 year ago

Looks like only the crons key of vercel.json is valid in config.json. Maybe a more-targeted, less-likely-to-break solution is to only copy that key over if it's present. I'll open a PR for it.