Skip to content

Commit 52429d2

Browse files
authored
fix: use esbuild inject api to ensure exec order & polyfill (#104)
1 parent e4b759a commit 52429d2

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/files/handler.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unassigned-import
2-
31
// TODO: hardcoding the relative location makes this brittle
42
import {init, render} from '../output/server/app.js';
53

src/files/shims.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {fetch, Response, Request, Headers} from '@sveltejs/kit/install-fetch';

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,16 @@ async function prepareEntrypoint({utils, serverOutputDir}) {
158158
utils.rimraf(temporaryDir);
159159
utils.rimraf(serverOutputDir);
160160

161-
const handlerSource = path.join(fileURLToPath(new URL('./files', import.meta.url)), 'handler.js');
161+
const files = fileURLToPath(new URL('./files', import.meta.url));
162+
const handlerSource = path.join(files, 'handler.js');
162163
const handlerDest = path.join(temporaryDir, 'handler.js');
163164
utils.copy(handlerSource, handlerDest);
164165

165166
await esbuild.build({
166167
entryPoints: [path.join(temporaryDir, 'handler.js')],
167168
outfile: path.join(serverOutputDir, 'index.js'),
168169
bundle: true,
170+
inject: [path.join(files, 'shims.js')],
169171
platform: 'node',
170172
target: ['node12']
171173
});

0 commit comments

Comments
 (0)