@sveltejs/adapter-vercel 5.8.2 → 5.9.1
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/index.js +74 -11
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @import { BuildOptions } from 'esbuild' */
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import process from 'node:process';
|
|
@@ -7,6 +8,17 @@ import esbuild from 'esbuild';
|
|
|
7
8
|
import { get_pathname, pattern_to_src } from './utils.js';
|
|
8
9
|
import { VERSION } from '@sveltejs/kit';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @template T
|
|
13
|
+
* @template {keyof T} K
|
|
14
|
+
* @typedef {Partial<Omit<T, K>> & Required<Pick<T, K>>} PartialExcept
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* We use a custom `Builder` type here to support the minimum version of SvelteKit.
|
|
19
|
+
* @typedef {PartialExcept<import('@sveltejs/kit').Builder, 'log' | 'rimraf' | 'mkdirp' | 'config' | 'prerendered' | 'routes' | 'createEntries' | 'findServerAssets' | 'generateFallback' | 'generateEnvModule' | 'generateManifest' | 'getBuildDirectory' | 'getClientDirectory' | 'getServerDirectory' | 'getAppPath' | 'writeClient' | 'writePrerendered' | 'writePrerendered' | 'writeServer' | 'copy' | 'compress'>} Builder2_4_0
|
|
20
|
+
*/
|
|
21
|
+
|
|
10
22
|
const name = '@sveltejs/adapter-vercel';
|
|
11
23
|
const INTERNAL = '![-]'; // this name is guaranteed not to conflict with user routes
|
|
12
24
|
|
|
@@ -47,7 +59,7 @@ const plugin = function (defaults = {}) {
|
|
|
47
59
|
|
|
48
60
|
return {
|
|
49
61
|
name,
|
|
50
|
-
|
|
62
|
+
/** @param {Builder2_4_0} builder */
|
|
51
63
|
async adapt(builder) {
|
|
52
64
|
if (!builder.routes) {
|
|
53
65
|
throw new Error(
|
|
@@ -93,13 +105,18 @@ const plugin = function (defaults = {}) {
|
|
|
93
105
|
const dir = `${dirs.functions}/${name}.func`;
|
|
94
106
|
|
|
95
107
|
const relativePath = path.posix.relative(tmp, builder.getServerDirectory());
|
|
96
|
-
|
|
97
108
|
builder.copy(`${files}/serverless.js`, `${tmp}/index.js`, {
|
|
98
109
|
replace: {
|
|
99
110
|
SERVER: `${relativePath}/index.js`,
|
|
100
111
|
MANIFEST: './manifest.js'
|
|
101
112
|
}
|
|
102
113
|
});
|
|
114
|
+
if (builder.hasServerInstrumentationFile?.()) {
|
|
115
|
+
builder.instrument?.({
|
|
116
|
+
entrypoint: `${tmp}/index.js`,
|
|
117
|
+
instrumentation: `${builder.getServerDirectory()}/instrumentation.server.js`
|
|
118
|
+
});
|
|
119
|
+
}
|
|
103
120
|
|
|
104
121
|
write(
|
|
105
122
|
`${tmp}/manifest.js`,
|
|
@@ -136,9 +153,9 @@ const plugin = function (defaults = {}) {
|
|
|
136
153
|
);
|
|
137
154
|
|
|
138
155
|
try {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
const outdir = `${dirs.functions}/${name}.func`;
|
|
157
|
+
/** @type {BuildOptions} */
|
|
158
|
+
const esbuild_config = {
|
|
142
159
|
// minimum Node.js version supported is v14.6.0 that is mapped to ES2019
|
|
143
160
|
// https://edge-runtime.vercel.app/features/polyfills
|
|
144
161
|
// TODO verify the latest ES version the edge runtime supports
|
|
@@ -168,10 +185,36 @@ const plugin = function (defaults = {}) {
|
|
|
168
185
|
'.eot': 'copy',
|
|
169
186
|
'.otf': 'copy'
|
|
170
187
|
}
|
|
188
|
+
};
|
|
189
|
+
const result = await esbuild.build({
|
|
190
|
+
entryPoints: [`${tmp}/edge.js`],
|
|
191
|
+
outfile: `${outdir}/index.js`,
|
|
192
|
+
...esbuild_config
|
|
171
193
|
});
|
|
172
194
|
|
|
173
|
-
|
|
174
|
-
|
|
195
|
+
let instrumentation_result;
|
|
196
|
+
if (builder.hasServerInstrumentationFile?.()) {
|
|
197
|
+
instrumentation_result = await esbuild.build({
|
|
198
|
+
entryPoints: [`${builder.getServerDirectory()}/instrumentation.server.js`],
|
|
199
|
+
outfile: `${outdir}/instrumentation.server.js`,
|
|
200
|
+
...esbuild_config
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
builder.instrument?.({
|
|
204
|
+
entrypoint: `${outdir}/index.js`,
|
|
205
|
+
instrumentation: `${outdir}/instrumentation.server.js`,
|
|
206
|
+
module: {
|
|
207
|
+
generateText: generate_traced_edge_module
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const warnings = instrumentation_result
|
|
213
|
+
? [...result.warnings, ...instrumentation_result.warnings]
|
|
214
|
+
: result.warnings;
|
|
215
|
+
|
|
216
|
+
if (warnings.length > 0) {
|
|
217
|
+
const formatted = await esbuild.formatMessages(warnings, {
|
|
175
218
|
kind: 'warning',
|
|
176
219
|
color: true
|
|
177
220
|
});
|
|
@@ -477,7 +520,8 @@ const plugin = function (defaults = {}) {
|
|
|
477
520
|
}
|
|
478
521
|
|
|
479
522
|
return true;
|
|
480
|
-
}
|
|
523
|
+
},
|
|
524
|
+
instrumentation: () => true
|
|
481
525
|
}
|
|
482
526
|
};
|
|
483
527
|
};
|
|
@@ -510,7 +554,7 @@ function write(file, data) {
|
|
|
510
554
|
|
|
511
555
|
// This function is duplicated in adapter-static
|
|
512
556
|
/**
|
|
513
|
-
* @param {
|
|
557
|
+
* @param {Builder2_4_0} builder
|
|
514
558
|
* @param {import('./index.js').Config} config
|
|
515
559
|
* @param {string} dir
|
|
516
560
|
*/
|
|
@@ -625,7 +669,7 @@ function static_vercel_config(builder, config, dir) {
|
|
|
625
669
|
}
|
|
626
670
|
|
|
627
671
|
/**
|
|
628
|
-
* @param {
|
|
672
|
+
* @param {Builder2_4_0} builder
|
|
629
673
|
* @param {string} entry
|
|
630
674
|
* @param {string} dir
|
|
631
675
|
* @param {import('./index.js').ServerlessConfig} config
|
|
@@ -747,7 +791,7 @@ async function create_function_bundle(builder, entry, dir, config) {
|
|
|
747
791
|
|
|
748
792
|
/**
|
|
749
793
|
*
|
|
750
|
-
* @param {
|
|
794
|
+
* @param {Builder2_4_0} builder
|
|
751
795
|
* @param {any} vercel_config
|
|
752
796
|
*/
|
|
753
797
|
function validate_vercel_json(builder, vercel_config) {
|
|
@@ -804,4 +848,23 @@ function is_prerendered(route) {
|
|
|
804
848
|
);
|
|
805
849
|
}
|
|
806
850
|
|
|
851
|
+
/**
|
|
852
|
+
* @param {{ instrumentation: string; start: string }} opts
|
|
853
|
+
*/
|
|
854
|
+
function generate_traced_edge_module({ instrumentation, start }) {
|
|
855
|
+
return `\
|
|
856
|
+
import './${instrumentation}';
|
|
857
|
+
const promise = import('./${start}');
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* @param {import('http').IncomingMessage} req
|
|
861
|
+
* @param {import('http').ServerResponse} res
|
|
862
|
+
*/
|
|
863
|
+
export default async (req, res) => {
|
|
864
|
+
const { default: handler } = await promise;
|
|
865
|
+
return handler(req, res);
|
|
866
|
+
}
|
|
867
|
+
`;
|
|
868
|
+
}
|
|
869
|
+
|
|
807
870
|
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.1",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Vercel app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/node": "^18.19.119",
|
|
43
43
|
"typescript": "^5.3.3",
|
|
44
44
|
"vitest": "^3.2.3",
|
|
45
|
-
"@sveltejs/kit": "^2.
|
|
45
|
+
"@sveltejs/kit": "^2.31.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@sveltejs/kit": "^2.4.0"
|