[ci] format
This commit is contained in:
parent
4cf54c60aa
commit
13b1bdd972
7 changed files with 38 additions and 42 deletions
|
@ -1,8 +1,3 @@
|
||||||
export {
|
export { netlifyFunctions, netlifyFunctions as default } from './integration-functions.js';
|
||||||
netlifyFunctions,
|
|
||||||
netlifyFunctions as default
|
|
||||||
} from './integration-functions.js';
|
|
||||||
|
|
||||||
export {
|
export { netlifyEdgeFunctions } from './integration-edge-functions.js';
|
||||||
netlifyEdgeFunctions
|
|
||||||
} from './integration-edge-functions.js';
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ interface NetlifyEdgeFunctionManifestFunctionPattern {
|
||||||
pattern: string;
|
pattern: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetlifyEdgeFunctionManifestFunction = NetlifyEdgeFunctionManifestFunctionPath | NetlifyEdgeFunctionManifestFunctionPattern;
|
type NetlifyEdgeFunctionManifestFunction =
|
||||||
|
| NetlifyEdgeFunctionManifestFunctionPath
|
||||||
|
| NetlifyEdgeFunctionManifestFunctionPattern;
|
||||||
|
|
||||||
interface NetlifyEdgeFunctionManifest {
|
interface NetlifyEdgeFunctionManifest {
|
||||||
functions: NetlifyEdgeFunctionManifestFunction[];
|
functions: NetlifyEdgeFunctionManifestFunction[];
|
||||||
|
@ -32,28 +34,28 @@ interface NetlifyEdgeFunctionManifest {
|
||||||
|
|
||||||
async function createEdgeManifest(routes: RouteData[], entryFile: string, dir: URL) {
|
async function createEdgeManifest(routes: RouteData[], entryFile: string, dir: URL) {
|
||||||
const functions: NetlifyEdgeFunctionManifestFunction[] = [];
|
const functions: NetlifyEdgeFunctionManifestFunction[] = [];
|
||||||
for(const route of routes) {
|
for (const route of routes) {
|
||||||
if(route.pathname) {
|
if (route.pathname) {
|
||||||
functions.push({
|
functions.push({
|
||||||
function: entryFile,
|
function: entryFile,
|
||||||
path: route.pathname
|
path: route.pathname,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
functions.push({
|
functions.push({
|
||||||
function: entryFile,
|
function: entryFile,
|
||||||
pattern: route.pattern.source
|
pattern: route.pattern.source,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const manifest: NetlifyEdgeFunctionManifest = {
|
const manifest: NetlifyEdgeFunctionManifest = {
|
||||||
functions,
|
functions,
|
||||||
version: 1
|
version: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const manifestURL = new URL('./manifest.json', dir);
|
const manifestURL = new URL('./manifest.json', dir);
|
||||||
const _manifest = JSON.stringify(manifest, null, ' ');
|
const _manifest = JSON.stringify(manifest, null, ' ');
|
||||||
await fs.promises.writeFile(manifestURL, _manifest, 'utf-8');
|
await fs.promises.writeFile(manifestURL, _manifest, 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}): AstroIntegration {
|
export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}): AstroIntegration {
|
||||||
|
@ -86,13 +88,10 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'astro:build:done': async ({ routes, dir }) => {
|
'astro:build:done': async ({ routes, dir }) => {
|
||||||
|
|
||||||
await createEdgeManifest(routes, entryFile, new URL('./edge-functions/', dir));
|
await createEdgeManifest(routes, entryFile, new URL('./edge-functions/', dir));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export { netlifyEdgeFunctions as default };
|
||||||
netlifyEdgeFunctions as default
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,15 +6,15 @@ export function createExports(manifest: SSRManifest) {
|
||||||
const app = new App(manifest);
|
const app = new App(manifest);
|
||||||
|
|
||||||
const handler = async (request: Request): Promise<Response> => {
|
const handler = async (request: Request): Promise<Response> => {
|
||||||
if(app.match(request)) {
|
if (app.match(request)) {
|
||||||
return app.render(request);
|
return app.render(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 404,
|
status: 404,
|
||||||
statusText: 'Not found'
|
statusText: 'Not found',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return { 'default': handler };
|
return { default: handler };
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@ Deno.test({
|
||||||
name: 'Edge Basics',
|
name: 'Edge Basics',
|
||||||
async fn() {
|
async fn() {
|
||||||
let close = await runBuild('./fixtures/edge-basic/');
|
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/'));
|
const response = await handler(new Request('http://example.com/'));
|
||||||
assertEquals(response.status, 200);
|
assertEquals(response.status, 200);
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
|
|
|
@ -18,7 +18,7 @@ describe('Cookies', () => {
|
||||||
dist: new URL('./fixtures/cookies/dist/', import.meta.url),
|
dist: new URL('./fixtures/cookies/dist/', import.meta.url),
|
||||||
}),
|
}),
|
||||||
site: `http://example.com`,
|
site: `http://example.com`,
|
||||||
integrations: [ testIntegration() ]
|
integrations: [testIntegration()],
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe('Dynamic pages', () => {
|
||||||
dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url),
|
dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url),
|
||||||
}),
|
}),
|
||||||
site: `http://example.com`,
|
site: `http://example.com`,
|
||||||
integrations: [ testIntegration() ]
|
integrations: [testIntegration()],
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,14 +4,14 @@ import { fileURLToPath } from 'url';
|
||||||
export * from '../../../../astro/test/test-utils.js';
|
export * from '../../../../astro/test/test-utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @returns {import('../../../../astro/dist/types/@types/astro').AstroIntegration}
|
* @returns {import('../../../../astro/dist/types/@types/astro').AstroIntegration}
|
||||||
*/
|
*/
|
||||||
export function testIntegration() {
|
export function testIntegration() {
|
||||||
return {
|
return {
|
||||||
name: '@astrojs/netlify/test-integration',
|
name: '@astrojs/netlify/test-integration',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup':({ updateConfig }) => {
|
'astro:config:setup': ({ updateConfig }) => {
|
||||||
updateConfig({
|
updateConfig({
|
||||||
vite: {
|
vite: {
|
||||||
resolve: {
|
resolve: {
|
||||||
|
@ -23,7 +23,7 @@ export function testIntegration() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue