From 52429d23809c08dd8027e6b0ce8c2e04b6b41136 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Wed, 7 Jul 2021 14:49:33 +1000 Subject: [PATCH] fix: use esbuild inject api to ensure exec order & polyfill (#104) --- src/files/handler.js | 2 -- src/files/shims.js | 1 + src/index.js | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 src/files/shims.js diff --git a/src/files/handler.js b/src/files/handler.js index 4d4fd86..61a5941 100644 --- a/src/files/handler.js +++ b/src/files/handler.js @@ -1,5 +1,3 @@ -import '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unassigned-import - // TODO: hardcoding the relative location makes this brittle import {init, render} from '../output/server/app.js'; diff --git a/src/files/shims.js b/src/files/shims.js new file mode 100644 index 0000000..29d9c09 --- /dev/null +++ b/src/files/shims.js @@ -0,0 +1 @@ +export {fetch, Response, Request, Headers} from '@sveltejs/kit/install-fetch'; diff --git a/src/index.js b/src/index.js index a066bb7..8c9bb50 100644 --- a/src/index.js +++ b/src/index.js @@ -158,7 +158,8 @@ async function prepareEntrypoint({utils, serverOutputDir}) { utils.rimraf(temporaryDir); utils.rimraf(serverOutputDir); - const handlerSource = path.join(fileURLToPath(new URL('./files', import.meta.url)), 'handler.js'); + const files = fileURLToPath(new URL('./files', import.meta.url)); + const handlerSource = path.join(files, 'handler.js'); const handlerDest = path.join(temporaryDir, 'handler.js'); utils.copy(handlerSource, handlerDest); @@ -166,6 +167,7 @@ async function prepareEntrypoint({utils, serverOutputDir}) { entryPoints: [path.join(temporaryDir, 'handler.js')], outfile: path.join(serverOutputDir, 'index.js'), bundle: true, + inject: [path.join(files, 'shims.js')], platform: 'node', target: ['node12'] });