diff --git a/.changeset/gold-months-live.md b/.changeset/gold-months-live.md new file mode 100644 index 000000000..f19806bac --- /dev/null +++ b/.changeset/gold-months-live.md @@ -0,0 +1,5 @@ +--- +"@astrojs/deno": patch +--- + +Revert prerender fix diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 45d3cad0e..d4536b92c 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -36,7 +36,7 @@ export function vitePluginSSR(internals: BuildInternals, adapter: AstroAdapter): }, load(id) { if (id === resolvedVirtualModuleId) { - return `import * as _adapter from '${adapter.serverEntrypoint}'; + return `import * as adapter from '${adapter.serverEntrypoint}'; import * as _main from '${pagesVirtualModuleId}'; import { deserializeManifest as _deserializeManifest } from 'astro/app'; const _manifest = Object.assign(_deserializeManifest('${manifestReplace}'), { @@ -47,7 +47,7 @@ const _args = ${adapter.args ? JSON.stringify(adapter.args) : 'undefined'}; export * from '${pagesVirtualModuleId}'; ${ adapter.exports - ? `const _exports = _adapter.createExports(_manifest, _args); + ? `const _exports = adapter.createExports(_manifest, _args); ${adapter.exports .map((name) => { if (name === 'default') { @@ -61,15 +61,9 @@ export { _default as default };`; ` : '' } -export const adapter = _adapter -${ - adapter.name !== '@astrojs/deno' - ? ` const _start = 'start'; -if(_start in _adapter) { - _adapter[_start](_manifest, _args); -}` - : '' +if(_start in adapter) { + adapter[_start](_manifest, _args); }`; } return void 0; diff --git a/packages/integrations/deno/src/code-constant.ts b/packages/integrations/deno/src/code-constant.ts deleted file mode 100644 index c59ba30f9..000000000 --- a/packages/integrations/deno/src/code-constant.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const DEFAULTIMPORT = `import { Server } from "https://deno.land/std@0.167.0/http/server.ts"; \n import { fetch } from "https://deno.land/x/file_fetch/mod.ts";\nimport { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";`; -export const DEFAULTSTART = `const _start = 'start'; \n if(_start in adapter) { \nadapter[_start](_manifest, _args);}`; diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 91f5fd836..11f5adebf 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -3,7 +3,6 @@ import esbuild from 'esbuild'; import * as fs from 'fs'; import * as npath from 'path'; import { fileURLToPath } from 'url'; -import * as CONSTANT from './code-constant'; interface BuildConfig { server: URL; @@ -71,8 +70,7 @@ export default function createIntegration(args?: Options): AstroIntegration { 'astro:build:done': async () => { const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server); const pth = fileURLToPath(entryUrl); - const content = await fs.readFileSync(pth, 'utf8'); - await fs.writeFileSync(pth, `${CONSTANT.DEFAULTIMPORT}${content}${CONSTANT.DEFAULTSTART}`); + await esbuild.build({ target: 'es2020', platform: 'browser', diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 94dce59ce..49da3f270 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -2,13 +2,18 @@ import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; +// @ts-ignore +import { Server } from 'https://deno.land/std@0.167.0/http/server.ts'; +// @ts-ignore +import { fetch } from 'https://deno.land/x/file_fetch/mod.ts'; + + interface Options { port?: number; hostname?: string; start?: boolean; } -// @ts-ignore let _server: Server | undefined = undefined; let _startPromise: Promise | undefined = undefined; @@ -36,18 +41,7 @@ export function start(manifest: SSRManifest, options: Options) { // try to fetch a static file instead const url = new URL(request.url); const localPath = new URL('./' + app.removeBase(url.pathname), clientRoot); - const stringLocalPath = localPath.toString(); - // @ts-ignore - const extendName = fileExtension(stringLocalPath); - const fileResp = await fetch( - !extendName - ? `${ - stringLocalPath.endsWith('/') - ? `${stringLocalPath}index.html` - : `${stringLocalPath}/index.html` - }` - : stringLocalPath - ); + const fileResp = await fetch(localPath.toString()); // If the static file can't be found if (fileResp.status == 404) { @@ -68,7 +62,6 @@ export function start(manifest: SSRManifest, options: Options) { }; const port = options.port ?? 8085; - // @ts-ignore _server = new Server({ port, hostname: options.hostname ?? '0.0.0.0', diff --git a/packages/integrations/deno/test/basics.test.ts b/packages/integrations/deno/test/basics.test.ts index 240a9bd4b..d1f8907cb 100644 --- a/packages/integrations/deno/test/basics.test.ts +++ b/packages/integrations/deno/test/basics.test.ts @@ -143,23 +143,3 @@ Deno.test({ sanitizeResources: false, sanitizeOps: false, }); - -Deno.test({ - name: 'perendering', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(new URL('perendering', baseUrl)); - assertEquals(resp.status, 200); - - const html = await resp.text(); - assert(html); - - const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc!.querySelector('h1'); - assertEquals(h1!.innerText, 'test'); - }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); diff --git a/packages/integrations/deno/test/fixtures/basics/src/pages/perendering.astro b/packages/integrations/deno/test/fixtures/basics/src/pages/perendering.astro deleted file mode 100644 index ca317d38d..000000000 --- a/packages/integrations/deno/test/fixtures/basics/src/pages/perendering.astro +++ /dev/null @@ -1,9 +0,0 @@ ---- -export const prerender = true; ---- - - - -

test

- -