@sveltejs/adapter-vercel 5.8.1 → 5.9.0
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 +59 -7
- package/package.json +3 -3
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';
|
|
@@ -93,13 +94,18 @@ const plugin = function (defaults = {}) {
|
|
|
93
94
|
const dir = `${dirs.functions}/${name}.func`;
|
|
94
95
|
|
|
95
96
|
const relativePath = path.posix.relative(tmp, builder.getServerDirectory());
|
|
96
|
-
|
|
97
97
|
builder.copy(`${files}/serverless.js`, `${tmp}/index.js`, {
|
|
98
98
|
replace: {
|
|
99
99
|
SERVER: `${relativePath}/index.js`,
|
|
100
100
|
MANIFEST: './manifest.js'
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
|
+
if (builder.hasServerInstrumentationFile()) {
|
|
104
|
+
builder.instrument({
|
|
105
|
+
entrypoint: `${tmp}/index.js`,
|
|
106
|
+
instrumentation: `${builder.getServerDirectory()}/instrumentation.server.js`
|
|
107
|
+
});
|
|
108
|
+
}
|
|
103
109
|
|
|
104
110
|
write(
|
|
105
111
|
`${tmp}/manifest.js`,
|
|
@@ -136,9 +142,9 @@ const plugin = function (defaults = {}) {
|
|
|
136
142
|
);
|
|
137
143
|
|
|
138
144
|
try {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
const outdir = `${dirs.functions}/${name}.func`;
|
|
146
|
+
/** @type {BuildOptions} */
|
|
147
|
+
const esbuild_config = {
|
|
142
148
|
// minimum Node.js version supported is v14.6.0 that is mapped to ES2019
|
|
143
149
|
// https://edge-runtime.vercel.app/features/polyfills
|
|
144
150
|
// TODO verify the latest ES version the edge runtime supports
|
|
@@ -168,10 +174,36 @@ const plugin = function (defaults = {}) {
|
|
|
168
174
|
'.eot': 'copy',
|
|
169
175
|
'.otf': 'copy'
|
|
170
176
|
}
|
|
177
|
+
};
|
|
178
|
+
const result = await esbuild.build({
|
|
179
|
+
entryPoints: [`${tmp}/edge.js`],
|
|
180
|
+
outfile: `${outdir}/index.js`,
|
|
181
|
+
...esbuild_config
|
|
171
182
|
});
|
|
172
183
|
|
|
173
|
-
|
|
174
|
-
|
|
184
|
+
let instrumentation_result;
|
|
185
|
+
if (builder.hasServerInstrumentationFile()) {
|
|
186
|
+
instrumentation_result = await esbuild.build({
|
|
187
|
+
entryPoints: [`${builder.getServerDirectory()}/instrumentation.server.js`],
|
|
188
|
+
outfile: `${outdir}/instrumentation.server.js`,
|
|
189
|
+
...esbuild_config
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
builder.instrument({
|
|
193
|
+
entrypoint: `${outdir}/index.js`,
|
|
194
|
+
instrumentation: `${outdir}/instrumentation.server.js`,
|
|
195
|
+
module: {
|
|
196
|
+
generateText: generate_traced_edge_module
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const warnings = instrumentation_result
|
|
202
|
+
? [...result.warnings, ...instrumentation_result.warnings]
|
|
203
|
+
: result.warnings;
|
|
204
|
+
|
|
205
|
+
if (warnings.length > 0) {
|
|
206
|
+
const formatted = await esbuild.formatMessages(warnings, {
|
|
175
207
|
kind: 'warning',
|
|
176
208
|
color: true
|
|
177
209
|
});
|
|
@@ -477,7 +509,8 @@ const plugin = function (defaults = {}) {
|
|
|
477
509
|
}
|
|
478
510
|
|
|
479
511
|
return true;
|
|
480
|
-
}
|
|
512
|
+
},
|
|
513
|
+
instrumentation: () => true
|
|
481
514
|
}
|
|
482
515
|
};
|
|
483
516
|
};
|
|
@@ -804,4 +837,23 @@ function is_prerendered(route) {
|
|
|
804
837
|
);
|
|
805
838
|
}
|
|
806
839
|
|
|
840
|
+
/**
|
|
841
|
+
* @param {{ instrumentation: string; start: string }} opts
|
|
842
|
+
*/
|
|
843
|
+
function generate_traced_edge_module({ instrumentation, start }) {
|
|
844
|
+
return `\
|
|
845
|
+
import './${instrumentation}';
|
|
846
|
+
const promise = import('./${start}');
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* @param {import('http').IncomingMessage} req
|
|
850
|
+
* @param {import('http').ServerResponse} res
|
|
851
|
+
*/
|
|
852
|
+
export default async (req, res) => {
|
|
853
|
+
const { default: handler } = await promise;
|
|
854
|
+
return handler(req, res);
|
|
855
|
+
}
|
|
856
|
+
`;
|
|
857
|
+
}
|
|
858
|
+
|
|
807
859
|
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.0",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Vercel app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/sveltejs/kit",
|
|
15
|
+
"url": "git+https://github.com/sveltejs/kit.git",
|
|
16
16
|
"directory": "packages/adapter-vercel"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
@@ -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.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@sveltejs/kit": "^2.4.0"
|