[ci] format

This commit is contained in:
matthewp 2022-04-19 15:23:07 +00:00 committed by github-actions[bot]
parent 4cf54c60aa
commit 13b1bdd972
7 changed files with 38 additions and 42 deletions

View file

@ -1,8 +1,3 @@
export {
netlifyFunctions,
netlifyFunctions as default
} from './integration-functions.js';
export { netlifyFunctions, netlifyFunctions as default } from './integration-functions.js';
export {
netlifyEdgeFunctions
} from './integration-edge-functions.js';
export { netlifyEdgeFunctions } from './integration-edge-functions.js';

View file

@ -23,7 +23,9 @@ interface NetlifyEdgeFunctionManifestFunctionPattern {
pattern: string;
}
type NetlifyEdgeFunctionManifestFunction = NetlifyEdgeFunctionManifestFunctionPath | NetlifyEdgeFunctionManifestFunctionPattern;
type NetlifyEdgeFunctionManifestFunction =
| NetlifyEdgeFunctionManifestFunctionPath
| NetlifyEdgeFunctionManifestFunctionPattern;
interface NetlifyEdgeFunctionManifest {
functions: NetlifyEdgeFunctionManifestFunction[];
@ -32,28 +34,28 @@ interface NetlifyEdgeFunctionManifest {
async function createEdgeManifest(routes: RouteData[], entryFile: string, dir: URL) {
const functions: NetlifyEdgeFunctionManifestFunction[] = [];
for(const route of routes) {
if(route.pathname) {
functions.push({
function: entryFile,
path: route.pathname
});
} else {
functions.push({
function: entryFile,
pattern: route.pattern.source
});
}
}
for (const route of routes) {
if (route.pathname) {
functions.push({
function: entryFile,
path: route.pathname,
});
} else {
functions.push({
function: entryFile,
pattern: route.pattern.source,
});
}
}
const manifest: NetlifyEdgeFunctionManifest = {
functions,
version: 1
};
const manifest: NetlifyEdgeFunctionManifest = {
functions,
version: 1,
};
const manifestURL = new URL('./manifest.json', dir);
const _manifest = JSON.stringify(manifest, null, ' ');
await fs.promises.writeFile(manifestURL, _manifest, 'utf-8');
const manifestURL = new URL('./manifest.json', dir);
const _manifest = JSON.stringify(manifest, null, ' ');
await fs.promises.writeFile(manifestURL, _manifest, 'utf-8');
}
export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}): AstroIntegration {
@ -86,13 +88,10 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
}
},
'astro:build:done': async ({ routes, dir }) => {
await createEdgeManifest(routes, entryFile, new URL('./edge-functions/', dir));
},
},
};
}
export {
netlifyEdgeFunctions as default
}
export { netlifyEdgeFunctions as default };

View file

@ -6,15 +6,15 @@ export function createExports(manifest: SSRManifest) {
const app = new App(manifest);
const handler = async (request: Request): Promise<Response> => {
if(app.match(request)) {
if (app.match(request)) {
return app.render(request);
}
return new Response(null, {
status: 404,
statusText: 'Not found'
statusText: 'Not found',
});
};
return { 'default': handler };
return { default: handler };
}

View file

@ -8,7 +8,9 @@ Deno.test({
name: 'Edge Basics',
async fn() {
let close = await runBuild('./fixtures/edge-basic/');
const { default: handler } = await import('./fixtures/edge-basic/dist/edge-functions/entry.mjs');
const { default: handler } = await import(
'./fixtures/edge-basic/dist/edge-functions/entry.mjs'
);
const response = await handler(new Request('http://example.com/'));
assertEquals(response.status, 200);
const html = await response.text();

View file

@ -18,7 +18,7 @@ describe('Cookies', () => {
dist: new URL('./fixtures/cookies/dist/', import.meta.url),
}),
site: `http://example.com`,
integrations: [ testIntegration() ]
integrations: [testIntegration()],
});
await fixture.build();
});

View file

@ -16,7 +16,7 @@ describe('Dynamic pages', () => {
dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url),
}),
site: `http://example.com`,
integrations: [ testIntegration() ]
integrations: [testIntegration()],
});
await fixture.build();
});

View file

@ -4,14 +4,14 @@ import { fileURLToPath } from 'url';
export * from '../../../../astro/test/test-utils.js';
/**
*
*
* @returns {import('../../../../astro/dist/types/@types/astro').AstroIntegration}
*/
export function testIntegration() {
return {
name: '@astrojs/netlify/test-integration',
hooks: {
'astro:config:setup':({ updateConfig }) => {
'astro:config:setup': ({ updateConfig }) => {
updateConfig({
vite: {
resolve: {
@ -23,7 +23,7 @@ export function testIntegration() {
},
},
});
}
}
},
},
};
}