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

Revert vercel adapter to v1 filesystem API #3149

Merged
merged 2 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/quiet-terms-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Revert to v1 filesystem API
53 changes: 29 additions & 24 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { relative } from 'path';
import { fileURLToPath } from 'url';
import esbuild from 'esbuild';

// By writing to .output, we opt in to the Vercel filesystem API:
// https://vercel.com/docs/file-system-api
const VERCEL_OUTPUT = '.output';
const dir = '.vercel_build_output';

/** @type {import('.')} **/
export default function () {
Expand All @@ -15,17 +13,24 @@ export default function () {
async adapt(builder) {
const tmp = builder.getBuildDirectory('vercel-tmp');

builder.rimraf(VERCEL_OUTPUT);
builder.rimraf(dir);
builder.rimraf(tmp);

const files = fileURLToPath(new URL('./files', import.meta.url));

const dirs = {
static: `${dir}/static`,
lambda: `${dir}/functions/node/render`
};

builder.log.minor('Prerendering static pages...');

await builder.prerender({
dest: `${VERCEL_OUTPUT}/static`
dest: `${dir}/static`
});

builder.log.minor('Generating serverless function...');

const files = fileURLToPath(new URL('./files', import.meta.url));
const relativePath = relative(tmp, builder.getServerDirectory());

builder.copy(files, tmp, {
Expand All @@ -44,33 +49,33 @@ export default function () {

await esbuild.build({
entryPoints: [`${tmp}/entry.js`],
outfile: `${VERCEL_OUTPUT}/server/pages/__render.js`,
outfile: `${dirs.lambda}/index.js`,
target: 'node14',
bundle: true,
platform: 'node'
});

writeFileSync(
`${VERCEL_OUTPUT}/server/pages/package.json`,
JSON.stringify({ type: 'commonjs' })
);
writeFileSync(`${dirs.lambda}/package.json`, JSON.stringify({ type: 'commonjs' }));

builder.log.minor('Copying assets...');
builder.writeClient(`${VERCEL_OUTPUT}/static`);
builder.writeStatic(`${VERCEL_OUTPUT}/static`);

builder.log.minor('Writing manifests...');
builder.writeStatic(dirs.static);
builder.writeClient(dirs.static);

builder.log.minor('Writing routes...');

builder.mkdirp(`${dir}/config`);
writeFileSync(
`${VERCEL_OUTPUT}/routes-manifest.json`,
JSON.stringify({
version: 3,
dynamicRoutes: [
{
page: '/__render',
regex: '^/.*'
}
]
})
`${dir}/config/routes.json`,
JSON.stringify([
{
handle: 'filesystem'
},
{
src: '/.*',
dest: '.vercel/functions/render'
}
])
);
}
};
Expand Down