Skip to content

Commit

Permalink
fix: use esbuild inject api to ensure exec order & polyfill (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus authored Jul 7, 2021
1 parent e4b759a commit 52429d2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/files/handler.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
1 change: 1 addition & 0 deletions src/files/shims.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {fetch, Response, Request, Headers} from '@sveltejs/kit/install-fetch';
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ 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);

await esbuild.build({
entryPoints: [path.join(temporaryDir, 'handler.js')],
outfile: path.join(serverOutputDir, 'index.js'),
bundle: true,
inject: [path.join(files, 'shims.js')],
platform: 'node',
target: ['node12']
});
Expand Down

0 comments on commit 52429d2

Please sign in to comment.