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

Overhaul adapter API #2931

Merged
merged 108 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
2ba38e8
start fiddling about with code-split server code
Rich-Harris Nov 25, 2021
0f62263
generate build data
Rich-Harris Nov 26, 2021
78652d9
Merge branch 'master' into function-per-page
Rich-Harris Nov 26, 2021
7301352
working, minus adapters
Rich-Harris Nov 26, 2021
2dda44a
prerendering
Rich-Harris Nov 26, 2021
be773cb
WIP
Rich-Harris Nov 27, 2021
e04303e
tidy some stuff up
Rich-Harris Nov 28, 2021
3fcbdad
fix prefixes
Rich-Harris Nov 28, 2021
9b82b0b
adapter-node working
Rich-Harris Nov 28, 2021
89420d4
tidy up
Rich-Harris Nov 28, 2021
0d13e4c
tidy
Rich-Harris Nov 28, 2021
0ac7c8d
make copy opts optional
Rich-Harris Nov 28, 2021
44f53c7
tidy
Rich-Harris Nov 28, 2021
17e24fc
netlify working albeit with single function
Rich-Harris Nov 29, 2021
f0ee8fa
expose route data to adapters
Rich-Harris Nov 29, 2021
ea3eee1
some progress
Rich-Harris Nov 29, 2021
a0a66d1
lint
Rich-Harris Nov 29, 2021
c36c55f
remove sandbox example from PR
Rich-Harris Nov 29, 2021
785153b
implement createEntries API
Rich-Harris Nov 30, 2021
b3b1c3c
fix some tests
Rich-Harris Nov 30, 2021
5466250
AMP fix
Rich-Harris Nov 30, 2021
e51deba
tests all passing
Rich-Harris Nov 30, 2021
8828f11
update gitignore
Rich-Harris Nov 30, 2021
1407e57
disable adapter-node tests for now
Rich-Harris Nov 30, 2021
11e3b91
typechecking
Rich-Harris Dec 1, 2021
4328dae
always create prerendered output directory
Rich-Harris Dec 1, 2021
158964b
manifest -> generateManifest, add utils-level method
Rich-Harris Dec 1, 2021
a1a2e70
spread -> rest
Rich-Harris Dec 1, 2021
3a63cbb
finesse return value of copy helper
Rich-Harris Dec 1, 2021
786f5b0
no need to pass config through to adapter
Rich-Harris Dec 1, 2021
1f6f45a
Update packages/kit/src/core/build/index.js
Rich-Harris Dec 1, 2021
1fc9ab4
Merge branch 'function-per-page' of github.com:sveltejs/kit into func…
Rich-Harris Dec 1, 2021
4b18f16
fix
Rich-Harris Dec 1, 2021
53e05b4
refactor out method extraction
Rich-Harris Dec 1, 2021
078be6c
add comment to resolve separate routes/components entry point detection
Rich-Harris Dec 1, 2021
5895f75
remove out of date comment
Rich-Harris Dec 1, 2021
4a158f0
nicer rollup output types
Rich-Harris Dec 1, 2021
1158649
actually that caused chaos, doing this instead
Rich-Harris Dec 1, 2021
80256a1
fix tests
Rich-Harris Dec 1, 2021
39c83af
update adapter-cloudflare
Rich-Harris Dec 1, 2021
0b6e0c8
merge master -> funtion-per-page
Rich-Harris Dec 1, 2021
0b04e81
refactor build functions into client/server/service worker modules
Rich-Harris Dec 1, 2021
4f2ae17
make build_server more readable
Rich-Harris Dec 1, 2021
b58eb43
oops
Rich-Harris Dec 1, 2021
32006b4
gah
Rich-Harris Dec 1, 2021
5d12522
windows fix
Rich-Harris Dec 1, 2021
28a5054
split manifest into public and private parts, so we can use manifest.…
Rich-Harris Dec 1, 2021
317111e
lint
Rich-Harris Dec 1, 2021
9c45146
prevent duplication of asset list in functions
Rich-Harris Dec 1, 2021
dc6314f
exclude prerendered pages from functions
Rich-Harris Dec 1, 2021
9f3ee18
lint
Rich-Harris Dec 1, 2021
c0e6abf
get vercel adapter working (with v1 filesystem API)
Rich-Harris Dec 2, 2021
2f68be1
target node14
Rich-Harris Dec 3, 2021
d2dc49d
rename utils -> builder
Rich-Harris Dec 3, 2021
bd03083
add methods for getting directories instead of hardcoding .svelte-kit…
Rich-Harris Dec 3, 2021
22ffd4d
fix lockfile
Rich-Harris Dec 3, 2021
d758024
update cloudflare adapters
Rich-Harris Dec 3, 2021
485bb27
update readmes
Rich-Harris Dec 3, 2021
4f12eb4
tidy up
Rich-Harris Dec 3, 2021
31dd184
tweak docs
Rich-Harris Dec 3, 2021
d4a9c12
remove sandbox from workspace
Rich-Harris Dec 3, 2021
b2e2d4f
try pinning version
Dec 3, 2021
373a165
Update packages/kit/src/core/build/build_server.js
Rich-Harris Dec 3, 2021
150ee18
remove redundant strict fs stuff
Dec 3, 2021
6836f42
Merge branch 'function-per-page' of github.com:sveltejs/kit into func…
Dec 3, 2021
628f625
remove sandbox from gitignore
Dec 3, 2021
91de58a
merge master -> function-per-page
Rich-Harris Dec 26, 2021
17d3fea
merge master -> function-per-page
Rich-Harris Dec 26, 2021
ebf1f1f
lint
Rich-Harris Dec 26, 2021
f7a8115
fix cloudflare pages handling of prerendered pages
Rich-Harris Dec 27, 2021
bdc64ff
support esm and cjs manifests
Rich-Harris Dec 27, 2021
608fd3d
force createEntries to follow prerender
Rich-Harris Dec 27, 2021
fc17a67
fix types
Rich-Harris Dec 27, 2021
275628e
fix adapter-netlify
Rich-Harris Dec 27, 2021
a522611
separate App from InternalApp
Rich-Harris Dec 27, 2021
d257702
Update packages/kit/types/internal.d.ts
Rich-Harris Dec 27, 2021
64be780
expose SSRManifest
Rich-Harris Dec 27, 2021
c7958ba
fall back to HTTP fetch if endpoint is missing
Rich-Harris Dec 27, 2021
c49e4cd
app.render should not be passed a host string
Rich-Harris Dec 27, 2021
5233b25
default hostHeader to host in config
Rich-Harris Dec 27, 2021
dd40079
fix types
Rich-Harris Dec 27, 2021
21dfb9b
replace page.host with page.origin
Rich-Harris Dec 27, 2021
e7aaf32
fix host stuff
Rich-Harris Dec 27, 2021
57a8464
make SSR route splitting optional
Rich-Harris Dec 27, 2021
0d20729
simplify createEntries
Rich-Harris Dec 27, 2021
351674c
these are no longer generic
Rich-Harris Dec 27, 2021
c32df77
implement .json heuristic
Rich-Harris Dec 28, 2021
d057b0d
lint
Rich-Harris Dec 28, 2021
b459265
changesets
Rich-Harris Dec 28, 2021
7ebc950
changeset
Rich-Harris Dec 28, 2021
6f4c36e
merge master -> function-per-page
Rich-Harris Dec 28, 2021
a9093c8
Update packages/adapter-netlify/index.js
Rich-Harris Dec 28, 2021
d481e09
Update packages/adapter-node/README.md
Rich-Harris Dec 28, 2021
de897a2
this.server -> this.vite
Rich-Harris Dec 28, 2021
b6613c9
Merge branch 'function-per-page' of github.com:sveltejs/kit into func…
Rich-Harris Dec 28, 2021
ace5f35
give a bare-bones description of createEntries
Rich-Harris Dec 28, 2021
246b88c
lint
Rich-Harris Dec 28, 2021
5d810ec
merge master -> function-per-page
Rich-Harris Dec 28, 2021
c51641b
add missing origin
Rich-Harris Dec 28, 2021
c096dfa
remove TODO
Rich-Harris Dec 28, 2021
ed75d52
replace ts-ignore with ts-expect-error
Rich-Harris Dec 28, 2021
f1c84a6
Update packages/kit/src/core/adapt/builder.js
Rich-Harris Dec 28, 2021
cd60fae
document AdapterEntry
Rich-Harris Dec 28, 2021
77486c0
Merge branch 'function-per-page' of github.com:sveltejs/kit into func…
Rich-Harris Dec 28, 2021
052dbf7
Update packages/kit/types/config.d.ts
Rich-Harris Dec 28, 2021
53d0007
merge master -> function-per-page
Rich-Harris Dec 29, 2021
d4d071e
oops
Rich-Harris Dec 29, 2021
0de1aa3
manifest -> vite_manifest
Rich-Harris Dec 29, 2021
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
Prev Previous commit
Next Next commit
get vercel adapter working (with v1 filesystem API)
  • Loading branch information
Rich-Harris committed Dec 2, 2021
commit c0e6abf96d562d767fa83e265eb4785e019abc83
10 changes: 6 additions & 4 deletions packages/adapter-vercel/files/entry.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
import { getRawBody } from '@sveltejs/kit/node';
import { App } from 'APP';
import { manifest } from 'MANIFEST';

// TODO hardcoding the relative location makes this brittle
import { init, render } from '../output/server/app.js';
__fetch_polyfill();

init();
const app = new App(manifest);

export default async (req, res) => {
const { pathname, searchParams } = new URL(req.url || '', 'http://localhost');
Expand All @@ -17,7 +19,7 @@ export default async (req, res) => {
return res.end(err.reason || 'Invalid request body');
}

const rendered = await render({
const rendered = await app.render({
method: req.method,
headers: req.headers,
path: pathname,
Expand Down
9 changes: 0 additions & 9 deletions packages/adapter-vercel/files/routes.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/adapter-vercel/files/shims.js

This file was deleted.

7 changes: 1 addition & 6 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Adapter } from '@sveltejs/kit';
import { BuildOptions } from 'esbuild';

interface AdapterOptions {
esbuild?: (options: BuildOptions) => Promise<BuildOptions> | BuildOptions;
}

declare function plugin(options?: AdapterOptions): Adapter;
declare function plugin(): Adapter;
export = plugin;
60 changes: 37 additions & 23 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,70 @@ import esbuild from 'esbuild';
*/

/** @type {import('.')} **/
export default function (options) {
export default function () {
return {
name: '@sveltejs/adapter-vercel',

async adapt(utils) {
const dir = '.vercel_build_output';
const dir = '.output';
utils.rimraf(dir);

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

const dirs = {
static: join(dir, 'static'),
lambda: join(dir, 'functions/node/render')
lambda: join(dir, 'server/pages')
};

utils.log.minor('Prerendering static pages...');
await utils.prerender({
dest: dirs.static
});

// TODO ideally we'd have something like utils.tmpdir('vercel')
// rather than hardcoding '.svelte-kit/vercel/entry.js', and the
// relative import from that file to output/server/app.js
// would be controlled. at the moment we're exposing
// implementation details that could change
utils.log.minor('Generating serverless function...');
utils.copy(join(files, 'entry.js'), '.svelte-kit/vercel/entry.js');
utils.copy(files, '.svelte-kit/vercel', {
replace: {
APP: '../output/server/app.js',
MANIFEST: './manifest.js'
}
});

/** @type {BuildOptions} */
const default_options = {
writeFileSync(
'.svelte-kit/vercel/manifest.js',
`export const manifest = ${utils.generateManifest({ relativePath: '../output/server' })};\n`
);

await esbuild.build({
entryPoints: ['.svelte-kit/vercel/entry.js'],
outfile: join(dirs.lambda, 'index.js'),
outfile: join(dirs.lambda, '__render.js'),
bundle: true,
inject: [join(files, 'shims.js')],
platform: 'node'
};

const build_options =
options && options.esbuild ? await options.esbuild(default_options) : default_options;

await esbuild.build(build_options);
});

writeFileSync(join(dirs.lambda, 'package.json'), JSON.stringify({ type: 'commonjs' }));

utils.log.minor('Prerendering static pages...');
await utils.prerender({
dest: dirs.static
});

utils.log.minor('Copying assets...');
utils.copy_static_files(dirs.static);
utils.copy_client_files(dirs.static);
utils.writeClient(dirs.static);
utils.writeStatic(dirs.static);

utils.log.minor('Writing routes...');
utils.copy(join(files, 'routes.json'), join(dir, 'config/routes.json'));
utils.log.minor('Writing manifests...');
writeFileSync(
join(dir, 'routes-manifest.json'),
JSON.stringify({
version: 3,
dynamicRoutes: [
{
page: '/__render',
regex: '^/.*'
}
]
})
);
}
};
}
2 changes: 1 addition & 1 deletion packages/adapter-vercel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": ["./index.js", "src"]
"include": ["./index.js", "files"]
}