Skip to content

Commit 466959b

Browse files
make netlify do the thing
1 parent 7f18fc0 commit 466959b

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

packages/adapter-netlify/index.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,26 @@ async function generate_edge_functions({ builder }) {
196196
external: builtinModules.map((id) => `node:${id}`),
197197
alias: Object.fromEntries(builtinModules.map((id) => [id, `node:${id}`]))
198198
};
199-
await esbuild.build({
200-
entryPoints: [`${tmp}/entry.js`],
201-
outfile: '.netlify/edge-functions/render.js',
202-
...esbuild_config
203-
});
204-
await esbuild.build({
205-
entryPoints: [`${builder.getServerDirectory()}/tracing.server.js`],
206-
outfile: '.netlify/edge-functions/tracing.server.js',
207-
...esbuild_config
208-
});
199+
await Promise.all([
200+
esbuild.build({
201+
entryPoints: [`${tmp}/entry.js`],
202+
outfile: '.netlify/edge-functions/render.js',
203+
...esbuild_config
204+
}),
205+
builder.hasServerTracingFile() &&
206+
esbuild.build({
207+
entryPoints: [`${builder.getServerDirectory()}/tracing.server.js`],
208+
outfile: '.netlify/edge/tracing.server.js',
209+
...esbuild_config
210+
})
211+
]);
212+
209213
if (builder.hasServerTracingFile()) {
210214
builder.trace({
211215
entrypoint: '.netlify/edge-functions/render.js',
212-
tracing: '.netlify/edge-functions/tracing.server.js',
213-
tla: false
216+
tracing: '.netlify/edge/tracing.server.js',
217+
tla: false,
218+
start: '.netlify/edge/start.js'
214219
});
215220
}
216221

@@ -294,7 +299,7 @@ function generate_lambda_functions({ builder, publish, split }) {
294299
builder.trace({
295300
entrypoint: `.netlify/functions-internal/${name}.mjs`,
296301
tracing: '.netlify/server/tracing.server.js',
297-
start: `${name}.start.mjs`,
302+
start: `.netlify/functions-start/${name}.start.mjs`,
298303
exports: ['handler']
299304
});
300305
}
@@ -316,6 +321,7 @@ function generate_lambda_functions({ builder, publish, split }) {
316321
builder.trace({
317322
entrypoint: `.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`,
318323
tracing: '.netlify/server/tracing.server.js',
324+
start: `.netlify/functions-start/${FUNCTION_PREFIX}render.start.mjs`,
319325
exports: ['handler']
320326
});
321327
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('loaded');

packages/kit/src/core/adapt/builder.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,13 @@ export function create_builder({
240240
return existsSync(`${config.kit.outDir}/output/server/tracing.server.js`);
241241
},
242242

243-
trace({ entrypoint, tracing, start = 'start.js', tla = true, exports = ['default'] }) {
243+
trace({
244+
entrypoint,
245+
tracing,
246+
start = join(dirname(entrypoint), 'start.js'),
247+
tla = true,
248+
exports = ['default']
249+
}) {
244250
if (!existsSync(tracing)) {
245251
throw new Error(
246252
`Tracing file ${tracing} not found. This is probably a bug in your adapter.`
@@ -252,10 +258,9 @@ export function create_builder({
252258
);
253259
}
254260

255-
const start_path = join(dirname(entrypoint), start);
256-
copy(entrypoint, start_path);
261+
copy(entrypoint, start);
257262
if (existsSync(`${entrypoint}.map`)) {
258-
copy(`${entrypoint}.map`, `${start_path}.map`);
263+
copy(`${entrypoint}.map`, `${start}.map`);
259264
}
260265

261266
rimraf(entrypoint);
@@ -299,6 +304,7 @@ async function compress_file(file, format = 'gz') {
299304
*/
300305
function create_tracing_facade({ entrypoint, tracing, start, exports, tla }) {
301306
const relative_tracing = relative(dirname(entrypoint), tracing);
307+
const relative_start = relative(dirname(entrypoint), start);
302308
const import_tracing = `import './${relative_tracing}';`;
303309

304310
let alias_index = 0;
@@ -349,8 +355,8 @@ function create_tracing_facade({ entrypoint, tracing, start, exports, tla }) {
349355
const default_alias = aliases.get('default');
350356
const entrypoint_facade = [
351357
tla
352-
? `const { ${import_statements.join(', ')} } = await import('./${start}');`
353-
: `import { ${import_statements.join(', ')} } from './${start}';`,
358+
? `const { ${import_statements.join(', ')} } = await import('./${relative_start}');`
359+
: `import { ${import_statements.join(', ')} } from './${relative_start}';`,
354360
default_alias ? `export default ${default_alias};` : '',
355361
export_statements.length > 0 ? `export { ${export_statements.join(', ')} };` : ''
356362
]

0 commit comments

Comments
 (0)