mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
update formatter config (#11640)
* update formatter config * format --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
parent
d50c12f720
commit
3c0cc4ad99
16 changed files with 50 additions and 50 deletions
|
@ -1207,7 +1207,7 @@
|
|||
{ darkMode: true },
|
||||
{
|
||||
expires: '1 month',
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const prefs = Astro.cookies.get<Prefs>('prefs').json();
|
||||
|
|
|
@ -68,7 +68,7 @@ export function getAstroImageConfig(
|
|||
imagesConfig: VercelImageConfig | undefined,
|
||||
command: string,
|
||||
devImageService: DevImageService,
|
||||
astroImageConfig: AstroConfig['image']
|
||||
astroImageConfig: AstroConfig['image'],
|
||||
) {
|
||||
let devService = '@astrojs/vercel/dev-image-service';
|
||||
|
||||
|
@ -105,7 +105,7 @@ export function getAstroImageConfig(
|
|||
export function sharedValidateOptions(
|
||||
options: ImageTransform,
|
||||
serviceConfig: Record<string, any>,
|
||||
mode: 'development' | 'production'
|
||||
mode: 'development' | 'production',
|
||||
) {
|
||||
const vercelImageOptions = serviceConfig as VercelImageConfig;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ export async function copyDependenciesToFunction(
|
|||
logger: AstroIntegrationLogger;
|
||||
},
|
||||
// we want to pass the caching by reference, and not by value
|
||||
cache: object
|
||||
cache: object,
|
||||
): Promise<{ handler: string }> {
|
||||
const entryPath = fileURLToPath(entry);
|
||||
logger.info(`Bundling function ${relativePath(fileURLToPath(outDir), entryPath)}`);
|
||||
|
@ -54,11 +54,11 @@ export async function copyDependenciesToFunction(
|
|||
|
||||
if (entryPath === file) {
|
||||
logger.debug(
|
||||
`[@astrojs/vercel] The module "${module}" couldn't be resolved. This may not be a problem, but it's worth checking.`
|
||||
`[@astrojs/vercel] The module "${module}" couldn't be resolved. This may not be a problem, but it's worth checking.`,
|
||||
);
|
||||
} else {
|
||||
logger.debug(
|
||||
`[@astrojs/vercel] The module "${module}" inside the file "${file}" couldn't be resolved. This may not be a problem, but it's worth checking.`
|
||||
`[@astrojs/vercel] The module "${module}" inside the file "${file}" couldn't be resolved. This may not be a problem, but it's worth checking.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ export async function copyDependenciesToFunction(
|
|||
const commonAncestor = await copyFilesToFolder(
|
||||
[...result.fileList].map((file) => new URL(file, base)).concat(includeFiles),
|
||||
outDir,
|
||||
excludeFiles
|
||||
excludeFiles,
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
@ -214,10 +214,10 @@ export default function vercelServerless({
|
|||
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
|
||||
if (maxDuration && maxDuration > 900) {
|
||||
logger.warn(
|
||||
`maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`
|
||||
`maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`,
|
||||
);
|
||||
logger.warn(
|
||||
`Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`
|
||||
`Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ export default function vercelServerless({
|
|||
'head-inline',
|
||||
await getInjectableWebAnalyticsContent({
|
||||
mode: command === 'dev' ? 'development' : 'production',
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (command === 'build' && speedInsights?.enabled) {
|
||||
|
@ -242,7 +242,7 @@ export default function vercelServerless({
|
|||
'\n' +
|
||||
`\tYour "vercel.json" \`trailingSlash\` configuration (set to \`true\`) will conflict with your Astro \`trailinglSlash\` configuration (set to \`"always"\`).\n` +
|
||||
`\tThis would cause infinite redirects under certain conditions and throw an \`ERR_TOO_MANY_REDIRECTS\` error.\n` +
|
||||
`\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n`
|
||||
`\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n`,
|
||||
);
|
||||
updateConfig({
|
||||
trailingSlash: 'ignore',
|
||||
|
@ -274,7 +274,7 @@ export default function vercelServerless({
|
|||
imagesConfig,
|
||||
command,
|
||||
devImageService,
|
||||
config.image
|
||||
config.image,
|
||||
),
|
||||
});
|
||||
},
|
||||
|
@ -284,12 +284,12 @@ export default function vercelServerless({
|
|||
`\n` +
|
||||
`\tVercel's hosting plans might have limits to the number of functions you can create.\n` +
|
||||
`\tMake sure to check your plan carefully to avoid incurring additional costs.\n` +
|
||||
`\tYou can set functionPerRoute: false to prevent surpassing the limit.\n`
|
||||
`\tYou can set functionPerRoute: false to prevent surpassing the limit.\n`,
|
||||
);
|
||||
}
|
||||
|
||||
setAdapter(
|
||||
getAdapter({ functionPerRoute, edgeMiddleware, middlewareSecret, skewProtection })
|
||||
getAdapter({ functionPerRoute, edgeMiddleware, middlewareSecret, skewProtection }),
|
||||
);
|
||||
|
||||
_config = config;
|
||||
|
@ -298,13 +298,13 @@ export default function vercelServerless({
|
|||
|
||||
if (config.output === 'static') {
|
||||
throw new AstroError(
|
||||
'`output: "server"` or `output: "hybrid"` is required to use the serverless adapter.'
|
||||
'`output: "server"` or `output: "hybrid"` is required to use the serverless adapter.',
|
||||
);
|
||||
}
|
||||
},
|
||||
'astro:build:ssr': async ({ entryPoints, middlewareEntryPoint }) => {
|
||||
_entryPoints = new Map(
|
||||
Array.from(entryPoints).filter(([routeData]) => !routeData.prerender)
|
||||
Array.from(entryPoints).filter(([routeData]) => !routeData.prerender),
|
||||
);
|
||||
_middlewareEntryPoint = middlewareEntryPoint;
|
||||
},
|
||||
|
@ -389,7 +389,7 @@ export default function vercelServerless({
|
|||
await builder.buildMiddlewareFolder(
|
||||
_middlewareEntryPoint,
|
||||
MIDDLEWARE_PATH,
|
||||
middlewareSecret
|
||||
middlewareSecret,
|
||||
);
|
||||
}
|
||||
const fourOhFourRoute = routes.find((route) => route.pathname === '/404');
|
||||
|
@ -464,7 +464,7 @@ class VercelBuilder {
|
|||
readonly includeFiles: URL[],
|
||||
readonly logger: AstroIntegrationLogger,
|
||||
readonly maxDuration?: number,
|
||||
readonly runtime = getRuntime(process, logger)
|
||||
readonly runtime = getRuntime(process, logger),
|
||||
) {}
|
||||
|
||||
async buildServerlessFolder(entry: URL, functionName: string) {
|
||||
|
@ -483,7 +483,7 @@ class VercelBuilder {
|
|||
excludeFiles,
|
||||
logger,
|
||||
},
|
||||
NTF_CACHE
|
||||
NTF_CACHE,
|
||||
);
|
||||
|
||||
// Enable ESM
|
||||
|
@ -505,7 +505,7 @@ class VercelBuilder {
|
|||
await this.buildServerlessFolder(entry, functionName);
|
||||
const prerenderConfig = new URL(
|
||||
`./functions/${functionName}.prerender-config.json`,
|
||||
this.config.outDir
|
||||
this.config.outDir,
|
||||
);
|
||||
// https://vercel.com/docs/build-output-api/v3/primitives#prerender-configuration-file
|
||||
await writeJson(prerenderConfig, {
|
||||
|
@ -525,7 +525,7 @@ class VercelBuilder {
|
|||
new URL(VERCEL_EDGE_MIDDLEWARE_FILE, this.config.srcDir),
|
||||
new URL('./middleware.mjs', functionFolder),
|
||||
middlewareSecret,
|
||||
this.logger
|
||||
this.logger,
|
||||
);
|
||||
|
||||
await writeJson(new URL(`./.vc-config.json`, functionFolder), {
|
||||
|
@ -544,7 +544,7 @@ function getRuntime(process: NodeJS.Process, logger: AstroIntegrationLogger): Ru
|
|||
`\n` +
|
||||
`\tThe local Node.js version (${major}) is not supported by Vercel Serverless Functions.\n` +
|
||||
`\tYour project will use Node.js 18 as the runtime instead.\n` +
|
||||
`\tConsider switching your local version to 18.\n`
|
||||
`\tConsider switching your local version to 18.\n`,
|
||||
);
|
||||
return 'nodejs18.x';
|
||||
}
|
||||
|
@ -554,26 +554,26 @@ function getRuntime(process: NodeJS.Process, logger: AstroIntegrationLogger): Ru
|
|||
if (support.status === 'retiring') {
|
||||
if (support.warnDate && new Date() >= support.warnDate) {
|
||||
logger.warn(
|
||||
`Your project is being built for Node.js ${major} as the runtime, which is retiring by ${support.removal}.`
|
||||
`Your project is being built for Node.js ${major} as the runtime, which is retiring by ${support.removal}.`,
|
||||
);
|
||||
}
|
||||
return `nodejs${major}.x`;
|
||||
}
|
||||
if (support.status === 'beta') {
|
||||
logger.warn(
|
||||
`Your project is being built for Node.js ${major} as the runtime, which is currently in beta for Vercel Serverless Functions.`
|
||||
`Your project is being built for Node.js ${major} as the runtime, which is currently in beta for Vercel Serverless Functions.`,
|
||||
);
|
||||
return `nodejs${major}.x`;
|
||||
}
|
||||
if (support.status === 'deprecated') {
|
||||
const removeDate = new Intl.DateTimeFormat(undefined, { dateStyle: 'long' }).format(
|
||||
support.removal
|
||||
support.removal,
|
||||
);
|
||||
logger.warn(
|
||||
`\n` +
|
||||
`\tYour project is being built for Node.js ${major} as the runtime.\n` +
|
||||
`\tThis version is deprecated by Vercel Serverless Functions, and scheduled to be disabled on ${removeDate}.\n` +
|
||||
`\tConsider upgrading your local version to 18.\n`
|
||||
`\tConsider upgrading your local version to 18.\n`,
|
||||
);
|
||||
return `nodejs${major}.x`;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ applyPolyfills();
|
|||
|
||||
export const createExports = (
|
||||
manifest: SSRManifest,
|
||||
{ middlewareSecret, skewProtection }: { middlewareSecret: string; skewProtection: boolean }
|
||||
{ middlewareSecret, skewProtection }: { middlewareSecret: string; skewProtection: boolean },
|
||||
) => {
|
||||
const app = new NodeApp(manifest);
|
||||
const handler = async (req: IncomingMessage, res: ServerResponse) => {
|
||||
|
|
|
@ -26,13 +26,13 @@ export async function generateEdgeMiddleware(
|
|||
vercelEdgeMiddlewareHandlerPath: URL,
|
||||
outPath: URL,
|
||||
middlewareSecret: string,
|
||||
logger: AstroIntegrationLogger
|
||||
logger: AstroIntegrationLogger,
|
||||
): Promise<URL> {
|
||||
const code = edgeMiddlewareTemplate(
|
||||
astroMiddlewareEntryPointPath,
|
||||
vercelEdgeMiddlewareHandlerPath,
|
||||
middlewareSecret,
|
||||
logger
|
||||
logger,
|
||||
);
|
||||
// https://vercel.com/docs/concepts/functions/edge-middleware#create-edge-middleware
|
||||
const bundledFilePath = fileURLToPath(outPath);
|
||||
|
@ -69,17 +69,17 @@ function edgeMiddlewareTemplate(
|
|||
astroMiddlewareEntryPointPath: URL,
|
||||
vercelEdgeMiddlewareHandlerPath: URL,
|
||||
middlewareSecret: string,
|
||||
logger: AstroIntegrationLogger
|
||||
logger: AstroIntegrationLogger,
|
||||
) {
|
||||
const middlewarePath = JSON.stringify(
|
||||
fileURLToPath(astroMiddlewareEntryPointPath).replace(/\\/g, '/')
|
||||
fileURLToPath(astroMiddlewareEntryPointPath).replace(/\\/g, '/'),
|
||||
);
|
||||
const filePathEdgeMiddleware = fileURLToPath(vercelEdgeMiddlewareHandlerPath);
|
||||
let handlerTemplateImport = '';
|
||||
let handlerTemplateCall = '{}';
|
||||
if (existsSync(filePathEdgeMiddleware + '.js') || existsSync(filePathEdgeMiddleware + '.ts')) {
|
||||
logger.warn(
|
||||
'Usage of `vercel-edge-middleware.js` is deprecated. You can now use the `waitUntil(promise)` function directly as `ctx.locals.waitUntil(promise)`.'
|
||||
'Usage of `vercel-edge-middleware.js` is deprecated. You can now use the `waitUntil(promise)` function directly as `ctx.locals.waitUntil(promise)`.',
|
||||
);
|
||||
const stringified = JSON.stringify(filePathEdgeMiddleware.replace(/\\/g, '/'));
|
||||
handlerTemplateImport = `import handler from ${stringified}`;
|
||||
|
|
|
@ -74,7 +74,7 @@ export default function vercelStatic({
|
|||
'head-inline',
|
||||
await getInjectableWebAnalyticsContent({
|
||||
mode: command === 'dev' ? 'development' : 'production',
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (command === 'build' && speedInsights?.enabled) {
|
||||
|
@ -95,7 +95,7 @@ export default function vercelStatic({
|
|||
imagesConfig,
|
||||
command,
|
||||
devImageService,
|
||||
config.image
|
||||
config.image,
|
||||
),
|
||||
});
|
||||
},
|
||||
|
|
|
@ -14,7 +14,7 @@ describe('Vercel edge middleware', () => {
|
|||
|
||||
it('an edge function is created', async () => {
|
||||
const contents = await build.readFile(
|
||||
'../.vercel/output/functions/_middleware.func/.vc-config.json'
|
||||
'../.vercel/output/functions/_middleware.func/.vc-config.json',
|
||||
);
|
||||
const contentsJSON = JSON.parse(contents);
|
||||
assert.equal(contentsJSON.runtime, 'edge');
|
||||
|
@ -26,14 +26,14 @@ describe('Vercel edge middleware', () => {
|
|||
const { routes } = JSON.parse(contents);
|
||||
assert.equal(
|
||||
routes.some((route) => route.dest === '_middleware'),
|
||||
true
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('edge sets Set-Cookie headers', async () => {
|
||||
let entry = new URL(
|
||||
'../.vercel/output/functions/_middleware.func/middleware.mjs',
|
||||
build.config.outDir
|
||||
build.config.outDir,
|
||||
);
|
||||
const module = await import(entry);
|
||||
const request = new Request('http://example.com/foo');
|
||||
|
@ -50,7 +50,7 @@ describe('Vercel edge middleware', () => {
|
|||
await fixture.build();
|
||||
const contents = await fixture.readFile(
|
||||
// this is abysmal...
|
||||
'../.vercel/output/functions/render.func/www/withastro/astro/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/dist/middleware.mjs'
|
||||
'../.vercel/output/functions/render.func/www/withastro/astro/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/dist/middleware.mjs',
|
||||
);
|
||||
console.log(contents);
|
||||
// assert.equal(contents.includes('title:')).to.be.true;
|
||||
|
@ -66,7 +66,7 @@ describe('Vercel edge middleware', () => {
|
|||
await fixture.build();
|
||||
const contents = await fixture.readFile(
|
||||
// this is abysmal...
|
||||
'../.vercel/output/functions/render.func/www/withastro/astro/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/dist/middleware.mjs'
|
||||
'../.vercel/output/functions/render.func/www/withastro/astro/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/dist/middleware.mjs',
|
||||
);
|
||||
console.log(contents);
|
||||
// assert.equal(contents.includes('title:')).to.be.false;
|
||||
|
|
|
@ -6,7 +6,7 @@ const VERCEL_TEST_URL = 'https://astro-vercel-image-test.vercel.app';
|
|||
describe('Hosted Vercel Tests', () => {
|
||||
it('Image endpoint works', async () => {
|
||||
const image = await fetch(
|
||||
VERCEL_TEST_URL + '/_image?href=%2F_astro%2Fpenguin.e9c64733.png&w=300&f=webp'
|
||||
VERCEL_TEST_URL + '/_image?href=%2F_astro%2Fpenguin.e9c64733.png&w=300&f=webp',
|
||||
);
|
||||
|
||||
assert.equal(image.status, 200);
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('ISR', () => {
|
|||
|
||||
it('generates expected prerender config', async () => {
|
||||
const vcConfig = JSON.parse(
|
||||
await fixture.readFile('../.vercel/output/functions/_isr.prerender-config.json')
|
||||
await fixture.readFile('../.vercel/output/functions/_isr.prerender-config.json'),
|
||||
);
|
||||
assert.deepEqual(vcConfig, {
|
||||
expiration: 120,
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('maxDuration', () => {
|
|||
|
||||
it('makes it to vercel function configuration', async () => {
|
||||
const vcConfig = JSON.parse(
|
||||
await fixture.readFile('../.vercel/output/functions/_render.func/.vc-config.json')
|
||||
await fixture.readFile('../.vercel/output/functions/_render.func/.vc-config.json'),
|
||||
);
|
||||
assert.equal(vcConfig.maxDuration, 60);
|
||||
});
|
||||
|
|
|
@ -77,7 +77,7 @@ describe('Redirects', () => {
|
|||
const config = await getConfig();
|
||||
assert.equal(
|
||||
config.routes.find((r) => r.src === '/'),
|
||||
undefined
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@ describe('Serverless prerender', () => {
|
|||
|
||||
it('outDir is tree-shaken if not needed', async () => {
|
||||
const [file] = await fixture.glob(
|
||||
'../.vercel/output/functions/_render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/.vercel/output/_functions/pages/_image.astro.mjs'
|
||||
'../.vercel/output/functions/_render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/.vercel/output/_functions/pages/_image.astro.mjs',
|
||||
);
|
||||
const contents = await fixture.readFile(file);
|
||||
assert.ok(!contents.includes('const outDir ='), "outDir is tree-shaken if it's not imported");
|
||||
|
@ -30,8 +30,8 @@ describe('Serverless prerender', () => {
|
|||
it.skip('includeFiles work', async () => {
|
||||
assert.ok(
|
||||
await fixture.readFile(
|
||||
'../.vercel/output/functions/render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/dist/middleware.mjs'
|
||||
)
|
||||
'../.vercel/output/functions/render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/dist/middleware.mjs',
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,10 +18,10 @@ describe('Serverless with dynamic routes', () => {
|
|||
it('build successful', async () => {
|
||||
assert.ok(await fixture.readFile('../.vercel/output/static/index.html'));
|
||||
assert.ok(
|
||||
await fixture.readFile('../.vercel/output/functions/[id]/index.astro.func/.vc-config.json')
|
||||
await fixture.readFile('../.vercel/output/functions/[id]/index.astro.func/.vc-config.json'),
|
||||
);
|
||||
assert.ok(
|
||||
await fixture.readFile('../.vercel/output/functions/api/[id].js.func/.vc-config.json')
|
||||
await fixture.readFile('../.vercel/output/functions/api/[id].js.func/.vc-config.json'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,7 +26,7 @@ describe('build: split', () => {
|
|||
assert.equal(config.routes.length, 5);
|
||||
assert.equal(
|
||||
config.routes.some((route) => route.dest === 'prerender.astro'),
|
||||
false
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('streaming', () => {
|
|||
|
||||
it('makes it to vercel function configuration', async () => {
|
||||
const vcConfig = JSON.parse(
|
||||
await fixture.readFile('../.vercel/output/functions/_render.func/.vc-config.json')
|
||||
await fixture.readFile('../.vercel/output/functions/_render.func/.vc-config.json'),
|
||||
);
|
||||
assert.equal(vcConfig.supportsResponseStreaming, true);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue