@sveltejs/adapter-vercel 1.0.0-next.32 → 1.0.0-next.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -31
- package/files/entry.js +7 -8
- package/index.d.ts +1 -6
- package/index.js +63 -38
- package/package.json +2 -2
- package/files/routes.json +0 -9
- package/files/shims.js +0 -1
package/README.md
CHANGED
|
@@ -19,37 +19,6 @@ export default {
|
|
|
19
19
|
};
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
## Advanced Configuration
|
|
23
|
-
|
|
24
|
-
### esbuild
|
|
25
|
-
|
|
26
|
-
As an escape hatch, you may optionally specify a function which will receive the final esbuild options generated by this adapter and returns a modified esbuild configuration. The result of this function will be passed as-is to esbuild. The function can be async.
|
|
27
|
-
|
|
28
|
-
For example, you may wish to add a plugin:
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
adapterVercel({
|
|
32
|
-
esbuild(defaultOptions) {
|
|
33
|
-
return {
|
|
34
|
-
...defaultOptions,
|
|
35
|
-
plugins: []
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
The default options for this version are as follows:
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
{
|
|
45
|
-
entryPoints: ['.svelte-kit/vercel/entry.js'],
|
|
46
|
-
outfile: `pathToLambdaFolder/index.js`,
|
|
47
|
-
bundle: true,
|
|
48
|
-
inject: ['pathTo/shims.js'],
|
|
49
|
-
platform: 'node'
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
22
|
## Changelog
|
|
54
23
|
|
|
55
24
|
[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-vercel/CHANGELOG.md).
|
package/files/entry.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
|
|
1
2
|
import { getRawBody } from '@sveltejs/kit/node';
|
|
3
|
+
import { App } from 'APP';
|
|
4
|
+
import { manifest } from 'MANIFEST';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
import { init, render } from '../output/server/app.js';
|
|
6
|
+
__fetch_polyfill();
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const app = new App(manifest);
|
|
7
9
|
|
|
8
10
|
export default async (req, res) => {
|
|
9
|
-
const { pathname, searchParams } = new URL(req.url || '', 'http://localhost');
|
|
10
|
-
|
|
11
11
|
let body;
|
|
12
12
|
|
|
13
13
|
try {
|
|
@@ -17,11 +17,10 @@ export default async (req, res) => {
|
|
|
17
17
|
return res.end(err.reason || 'Invalid request body');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const rendered = await render({
|
|
20
|
+
const rendered = await app.render({
|
|
21
|
+
url: req.url,
|
|
21
22
|
method: req.method,
|
|
22
23
|
headers: req.headers,
|
|
23
|
-
path: pathname,
|
|
24
|
-
query: searchParams,
|
|
25
24
|
rawBody: body
|
|
26
25
|
});
|
|
27
26
|
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { Adapter } from '@sveltejs/kit';
|
|
2
|
-
import { BuildOptions } from 'esbuild';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
esbuild?: (options: BuildOptions) => Promise<BuildOptions> | BuildOptions;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
declare function plugin(options?: AdapterOptions): Adapter;
|
|
3
|
+
declare function plugin(): Adapter;
|
|
9
4
|
export = plugin;
|
package/index.js
CHANGED
|
@@ -1,63 +1,88 @@
|
|
|
1
1
|
import { writeFileSync } from 'fs';
|
|
2
|
-
import {
|
|
2
|
+
import { posix } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import esbuild from 'esbuild';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* @typedef {import('esbuild').BuildOptions} BuildOptions
|
|
8
|
-
*/
|
|
6
|
+
const dir = '.vercel_build_output';
|
|
9
7
|
|
|
10
8
|
/** @type {import('.')} **/
|
|
11
|
-
export default function (
|
|
9
|
+
export default function () {
|
|
12
10
|
return {
|
|
13
11
|
name: '@sveltejs/adapter-vercel',
|
|
14
12
|
|
|
15
|
-
async adapt(
|
|
16
|
-
const
|
|
17
|
-
|
|
13
|
+
async adapt(builder) {
|
|
14
|
+
const tmp = builder.getBuildDirectory('vercel-tmp');
|
|
15
|
+
|
|
16
|
+
builder.rimraf(dir);
|
|
17
|
+
builder.rimraf(tmp);
|
|
18
18
|
|
|
19
19
|
const files = fileURLToPath(new URL('./files', import.meta.url));
|
|
20
20
|
|
|
21
21
|
const dirs = {
|
|
22
|
-
static:
|
|
23
|
-
lambda:
|
|
22
|
+
static: `${dir}/static`,
|
|
23
|
+
lambda: `${dir}/functions/node/render`
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
// rather than hardcoding '.svelte-kit/vercel/entry.js', and the
|
|
28
|
-
// relative import from that file to output/server/app.js
|
|
29
|
-
// would be controlled. at the moment we're exposing
|
|
30
|
-
// implementation details that could change
|
|
31
|
-
utils.log.minor('Generating serverless function...');
|
|
32
|
-
utils.copy(join(files, 'entry.js'), '.svelte-kit/vercel/entry.js');
|
|
33
|
-
|
|
34
|
-
/** @type {BuildOptions} */
|
|
35
|
-
const default_options = {
|
|
36
|
-
entryPoints: ['.svelte-kit/vercel/entry.js'],
|
|
37
|
-
outfile: join(dirs.lambda, 'index.js'),
|
|
38
|
-
bundle: true,
|
|
39
|
-
inject: [join(files, 'shims.js')],
|
|
40
|
-
platform: 'node'
|
|
41
|
-
};
|
|
26
|
+
builder.log.minor('Prerendering static pages...');
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
await builder.prerender({
|
|
29
|
+
dest: `${dir}/static`
|
|
30
|
+
});
|
|
45
31
|
|
|
46
|
-
|
|
32
|
+
builder.log.minor('Generating serverless function...');
|
|
47
33
|
|
|
48
|
-
|
|
34
|
+
const relativePath = posix.relative(tmp, builder.getServerDirectory());
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
builder.copy(files, tmp, {
|
|
37
|
+
replace: {
|
|
38
|
+
APP: `${relativePath}/app.js`,
|
|
39
|
+
MANIFEST: './manifest.js'
|
|
40
|
+
}
|
|
53
41
|
});
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
writeFileSync(
|
|
44
|
+
`${tmp}/manifest.js`,
|
|
45
|
+
`export const manifest = ${builder.generateManifest({
|
|
46
|
+
relativePath
|
|
47
|
+
})};\n`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
await esbuild.build({
|
|
51
|
+
entryPoints: [`${tmp}/entry.js`],
|
|
52
|
+
outfile: `${dirs.lambda}/index.js`,
|
|
53
|
+
target: 'node14',
|
|
54
|
+
bundle: true,
|
|
55
|
+
platform: 'node'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
writeFileSync(`${dirs.lambda}/package.json`, JSON.stringify({ type: 'commonjs' }));
|
|
59
|
+
|
|
60
|
+
builder.log.minor('Copying assets...');
|
|
61
|
+
|
|
62
|
+
builder.writeStatic(dirs.static);
|
|
63
|
+
builder.writeClient(dirs.static);
|
|
64
|
+
|
|
65
|
+
builder.log.minor('Writing routes...');
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
builder.mkdirp(`${dir}/config`);
|
|
68
|
+
writeFileSync(
|
|
69
|
+
`${dir}/config/routes.json`,
|
|
70
|
+
JSON.stringify([
|
|
71
|
+
{
|
|
72
|
+
src: `/${builder.appDir}/.+`,
|
|
73
|
+
headers: {
|
|
74
|
+
'cache-control': 'public, immutable, max-age=31536000'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
handle: 'filesystem'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
src: '/.*',
|
|
82
|
+
dest: '.vercel/functions/render'
|
|
83
|
+
}
|
|
84
|
+
])
|
|
85
|
+
);
|
|
61
86
|
}
|
|
62
87
|
};
|
|
63
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.36",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"esbuild": "^0.13.15"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@sveltejs/kit": "1.0.0-next.
|
|
28
|
+
"@sveltejs/kit": "1.0.0-next.218"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
|
package/files/routes.json
DELETED
package/files/shims.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch';
|