[ci] format

This commit is contained in:
matthewp 2023-02-17 18:21:11 +00:00 committed by fredkbot
parent 61113dd731
commit ff70614083
4 changed files with 23 additions and 24 deletions

View file

@ -1,6 +1,6 @@
// This file is a shim for any Deno-specific imports! // This file is a shim for any Deno-specific imports!
// It will be replaced in the final Deno build. // It will be replaced in the final Deno build.
// //
// This allows us to prerender pages in Node. // This allows us to prerender pages in Node.
export class Server { export class Server {
listenAndServe() {} listenAndServe() {}

View file

@ -20,15 +20,15 @@ const SHIM = `globalThis.process = {
env: Deno.env.toObject(), env: Deno.env.toObject(),
};`; };`;
const DENO_VERSION = `0.177.0` const DENO_VERSION = `0.177.0`;
// We shim deno-specific imports so we can run the code in Node // We shim deno-specific imports so we can run the code in Node
// to prerender pages. In the final Deno build, this import is // to prerender pages. In the final Deno build, this import is
// replaced with the Deno-specific contents listed below. // replaced with the Deno-specific contents listed below.
const DENO_IMPORTS_SHIM = `@astrojs/deno/__deno_imports.js`; const DENO_IMPORTS_SHIM = `@astrojs/deno/__deno_imports.js`;
const DENO_IMPORTS = `export { Server } from "https://deno.land/std@${DENO_VERSION}/http/server.ts" const DENO_IMPORTS = `export { Server } from "https://deno.land/std@${DENO_VERSION}/http/server.ts"
export { serveFile } from 'https://deno.land/std@${DENO_VERSION}/http/file_server.ts'; export { serveFile } from 'https://deno.land/std@${DENO_VERSION}/http/file_server.ts';
export { fromFileUrl } from "https://deno.land/std@${DENO_VERSION}/path/mod.ts";` export { fromFileUrl } from "https://deno.land/std@${DENO_VERSION}/path/mod.ts";`;
export function getAdapter(args?: Options): AstroAdapter { export function getAdapter(args?: Options): AstroAdapter {
return { return {
@ -40,16 +40,16 @@ export function getAdapter(args?: Options): AstroAdapter {
} }
const denoImportsShimPlugin = { const denoImportsShimPlugin = {
name: '@astrojs/deno:shim', name: '@astrojs/deno:shim',
setup(build: esbuild.PluginBuild) { setup(build: esbuild.PluginBuild) {
build.onLoad({ filter: /__deno_imports\.js$/ }, async (args) => { build.onLoad({ filter: /__deno_imports\.js$/ }, async (args) => {
return { return {
contents: DENO_IMPORTS, contents: DENO_IMPORTS,
loader: 'js', loader: 'js',
} };
}) });
}, },
} };
export default function createIntegration(args?: Options): AstroIntegration { export default function createIntegration(args?: Options): AstroIntegration {
let _buildConfig: BuildConfig; let _buildConfig: BuildConfig;
@ -91,9 +91,12 @@ export default function createIntegration(args?: Options): AstroIntegration {
}; };
if (Array.isArray(vite.build.rollupOptions.external)) { if (Array.isArray(vite.build.rollupOptions.external)) {
vite.build.rollupOptions.external.push(DENO_IMPORTS_SHIM); vite.build.rollupOptions.external.push(DENO_IMPORTS_SHIM);
} else if (typeof vite.build.rollupOptions.external !== 'function') { } else if (typeof vite.build.rollupOptions.external !== 'function') {
vite.build.rollupOptions.external = [vite.build.rollupOptions.external, DENO_IMPORTS_SHIM] vite.build.rollupOptions.external = [
vite.build.rollupOptions.external,
DENO_IMPORTS_SHIM,
];
} }
} }
}, },
@ -110,9 +113,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
format: 'esm', format: 'esm',
bundle: true, bundle: true,
external: ['@astrojs/markdown-remark'], external: ['@astrojs/markdown-remark'],
plugins: [ plugins: [denoImportsShimPlugin],
denoImportsShimPlugin
],
banner: { banner: {
js: SHIM, js: SHIM,
}, },

View file

@ -3,7 +3,7 @@ import type { SSRManifest } from 'astro';
import { App } from 'astro/app'; import { App } from 'astro/app';
// @ts-ignore // @ts-ignore
import { Server, serveFile, fromFileUrl } from '@astrojs/deno/__deno_imports.js'; import { fromFileUrl, serveFile, Server } from '@astrojs/deno/__deno_imports.js';
interface Options { interface Options {
port?: number; port?: number;
@ -18,9 +18,9 @@ async function* getPrerenderedFiles(clientRoot: URL): AsyncGenerator<URL> {
// @ts-ignore // @ts-ignore
for await (const ent of Deno.readDir(clientRoot)) { for await (const ent of Deno.readDir(clientRoot)) {
if (ent.isDirectory) { if (ent.isDirectory) {
yield* getPrerenderedFiles(new URL(`./${ent.name}/`, clientRoot)) yield* getPrerenderedFiles(new URL(`./${ent.name}/`, clientRoot));
} else if (ent.name.endsWith('.html')) { } else if (ent.name.endsWith('.html')) {
yield new URL(`./${ent.name}`, clientRoot) yield new URL(`./${ent.name}`, clientRoot);
} }
} }
} }
@ -67,7 +67,6 @@ export function start(manifest: SSRManifest, options: Options) {
} }
} }
// If the static file can't be found // If the static file can't be found
if (fileResp.status == 404) { if (fileResp.status == 404) {
// Render the astro custom 404 page // Render the astro custom 404 page

View file

@ -144,7 +144,6 @@ Deno.test({
sanitizeOps: false, sanitizeOps: false,
}); });
Deno.test({ Deno.test({
name: 'perendering', name: 'perendering',
permissions: defaultTestPermissions, permissions: defaultTestPermissions,