diff options
Diffstat (limited to 'packages/integrations/deno/src')
-rw-r--r-- | packages/integrations/deno/src/index.ts | 32 | ||||
-rw-r--r-- | packages/integrations/deno/src/server.ts | 6 |
2 files changed, 36 insertions, 2 deletions
diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index aef1f8383..6fd19e53e 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -1,4 +1,8 @@ import type { AstroAdapter, AstroIntegration } from 'astro'; +import { fileURLToPath } from 'url'; +import esbuild from 'esbuild'; +import * as npath from 'path'; +import * as fs from 'fs'; interface Options { port?: number; @@ -15,14 +19,20 @@ export function getAdapter(args?: Options): AstroAdapter { } export default function createIntegration(args?: Options): AstroIntegration { + let _buildConfig: any; + let _vite: any; return { name: '@astrojs/deno', hooks: { 'astro:config:done': ({ setAdapter }) => { setAdapter(getAdapter(args)); }, + 'astro:build:start': ({ buildConfig }) => { + _buildConfig = buildConfig; + }, 'astro:build:setup': ({ vite, target }) => { if (target === 'server') { + _vite = vite; vite.resolve = vite.resolve || {}; vite.resolve.alias = vite.resolve.alias || {}; @@ -41,6 +51,28 @@ export default function createIntegration(args?: Options): AstroIntegration { }; } }, + 'astro:build:done': async () => { + const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server); + const pth = fileURLToPath(entryUrl); + await esbuild.build({ + target: 'es2020', + platform: 'browser', + entryPoints: [pth], + outfile: pth, + allowOverwrite: true, + format: 'esm', + bundle: true, + external: [ "@astrojs/markdown-remark"] + }); + + // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash. + try { + const chunkFileNames = _vite?.build?.rollupOptions?.output?.chunkFileNames ?? 'chunks/chunk.[hash].mjs'; + const chunkPath = npath.dirname(chunkFileNames); + const chunksDirUrl = new URL(chunkPath + '/', _buildConfig.server); + await fs.promises.rm(chunksDirUrl, { recursive: true, force: true }); + } catch {} + } }, }; } diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 157d06751..d1bed9aec 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -32,13 +32,15 @@ export function start(manifest: SSRManifest, options: Options) { return fetch(localPath.toString()); }; + const port = options.port ?? 8085; _server = new Server({ - port: options.port ?? 8085, + port, hostname: options.hostname ?? '0.0.0.0', handler, }); - _startPromise = _server.listenAndServe(); + _startPromise = Promise.resolve(_server.listenAndServe()); + console.error(`Server running on port ${port}`); } export function createExports(manifest: SSRManifest, options: Options) { |