[ci] format

This commit is contained in:
bholmesdev 2022-07-08 20:57:10 +00:00 committed by fredkbot
parent b012ee55b1
commit ec392589f6
7 changed files with 60 additions and 31 deletions

View file

@ -49,12 +49,12 @@ module.exports = {
}\n`; }\n`;
const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record<string, string> = { const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record<string, string> = {
'netlify': '@astrojs/netlify/functions', netlify: '@astrojs/netlify/functions',
'vercel': '@astrojs/vercel/serverless', vercel: '@astrojs/vercel/serverless',
'cloudflare': '@astrojs/cloudflare', cloudflare: '@astrojs/cloudflare',
'node': '@astrojs/node', node: '@astrojs/node',
'deno': '@astrojs/deno', deno: '@astrojs/deno',
} };
export default async function add(names: string[], { cwd, flags, logging, telemetry }: AddOptions) { export default async function add(names: string[], { cwd, flags, logging, telemetry }: AddOptions) {
if (flags.help || names.length === 0) { if (flags.help || names.length === 0) {
@ -142,7 +142,11 @@ export default async function add(names: string[], { cwd, flags, logging, teleme
info( info(
logging, logging,
null, null,
`\n ${magenta(`Check our deployment docs for ${bold(integration.packageName)} to update your "adapter" config.`)}` `\n ${magenta(
`Check our deployment docs for ${bold(
integration.packageName
)} to update your "adapter" config.`
)}`
); );
} }
} else { } else {
@ -264,8 +268,10 @@ export default async function add(names: string[], { cwd, flags, logging, teleme
} }
} }
function isAdapter(integration: IntegrationInfo): integration is IntegrationInfo & { type: 'adapter' } { function isAdapter(
return integration.type === 'adapter'; integration: IntegrationInfo
): integration is IntegrationInfo & { type: 'adapter' } {
return integration.type === 'adapter';
} }
async function parseAstroConfig(configURL: URL): Promise<t.File> { async function parseAstroConfig(configURL: URL): Promise<t.File> {
@ -356,10 +362,7 @@ async function setAdapter(ast: t.File, adapter: IntegrationInfo, exportName: str
ensureImport( ensureImport(
ast, ast,
t.importDeclaration( t.importDeclaration([t.importDefaultSpecifier(adapterId)], t.stringLiteral(exportName))
[t.importDefaultSpecifier(adapterId)],
t.stringLiteral(exportName)
)
); );
visit(ast, { visit(ast, {
@ -384,9 +387,7 @@ async function setAdapter(ast: t.File, adapter: IntegrationInfo, exportName: str
const adapterCall = t.callExpression(adapterId, []); const adapterCall = t.callExpression(adapterId, []);
if (!adapterProp) { if (!adapterProp) {
configObject.properties.push( configObject.properties.push(t.objectProperty(t.identifier('adapter'), adapterCall));
t.objectProperty(t.identifier('adapter'), adapterCall)
);
return; return;
} }
@ -465,7 +466,11 @@ async function updateAstroConfig({
info( info(
logging, logging,
null, null,
magenta(` For complete deployment options, visit\n ${bold('https://docs.astro.build/en/guides/deploy/')}\n`) magenta(
` For complete deployment options, visit\n ${bold(
'https://docs.astro.build/en/guides/deploy/'
)}\n`
)
); );
} }
@ -570,9 +575,13 @@ async function tryToInstallIntegrations({
} }
} }
async function fetchPackageJson(scope: string | undefined, name: string, tag: string): Promise<object | Error> { async function fetchPackageJson(
scope: string | undefined,
name: string,
tag: string
): Promise<object | Error> {
const packageName = `${scope ? `@${scope}/` : ''}${name}`; const packageName = `${scope ? `@${scope}/` : ''}${name}`;
const res = await fetch(`https://registry.npmjs.org/${packageName}/${tag}`) const res = await fetch(`https://registry.npmjs.org/${packageName}/${tag}`);
if (res.status === 404) { if (res.status === 404) {
return new Error(); return new Error();
} else { } else {
@ -597,7 +606,9 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
if (!scope) { if (!scope) {
const firstPartyPkgCheck = await fetchPackageJson('astrojs', name, tag); const firstPartyPkgCheck = await fetchPackageJson('astrojs', name, tag);
if (firstPartyPkgCheck instanceof Error) { if (firstPartyPkgCheck instanceof Error) {
spinner.warn(yellow(`${bold(integration)} is not an official Astro package. Use at your own risk!`)); spinner.warn(
yellow(`${bold(integration)} is not an official Astro package. Use at your own risk!`)
);
const response = await prompts({ const response = await prompts({
type: 'confirm', type: 'confirm',
name: 'askToContinue', name: 'askToContinue',
@ -605,7 +616,11 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
initial: true, initial: true,
}); });
if (!response.askToContinue) { if (!response.askToContinue) {
throw new Error(`No problem! Find our official integrations at ${cyan('https://astro.build/integrations')}`); throw new Error(
`No problem! Find our official integrations at ${cyan(
'https://astro.build/integrations'
)}`
);
} }
spinner.start('Resolving with third party packages...'); spinner.start('Resolving with third party packages...');
pkgType = 'third-party'; pkgType = 'third-party';
@ -616,9 +631,7 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
if (pkgType === 'third-party') { if (pkgType === 'third-party') {
const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag); const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag);
if (thirdPartyPkgCheck instanceof Error) { if (thirdPartyPkgCheck instanceof Error) {
throw new Error( throw new Error(`Unable to fetch ${bold(integration)}. Does the package exist?`);
`Unable to fetch ${bold(integration)}. Does the package exist?`,
);
} else { } else {
pkgJson = thirdPartyPkgCheck as any; pkgJson = thirdPartyPkgCheck as any;
} }
@ -645,7 +658,11 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
integrationType = 'adapter'; integrationType = 'adapter';
} else { } else {
throw new Error( throw new Error(
`${bold(packageName)} doesn't appear to be an integration or an adapter. Find our official integrations at ${cyan('https://astro.build/integrations')}` `${bold(
packageName
)} doesn't appear to be an integration or an adapter. Find our official integrations at ${cyan(
'https://astro.build/integrations'
)}`
); );
} }

View file

@ -11,7 +11,9 @@
"url": "https://github.com/withastro/astro.git", "url": "https://github.com/withastro/astro.git",
"directory": "packages/integrations/cloudflare" "directory": "packages/integrations/cloudflare"
}, },
"keywords": ["astro-adapter"], "keywords": [
"astro-adapter"
],
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {

View file

@ -11,7 +11,9 @@
"url": "https://github.com/withastro/astro.git", "url": "https://github.com/withastro/astro.git",
"directory": "packages/integrations/deno" "directory": "packages/integrations/deno"
}, },
"keywords": ["astro-adapter"], "keywords": [
"astro-adapter"
],
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {

View file

@ -11,7 +11,9 @@
"url": "https://github.com/withastro/astro.git", "url": "https://github.com/withastro/astro.git",
"directory": "packages/integrations/netlify" "directory": "packages/integrations/netlify"
}, },
"keywords": ["astro-adapter"], "keywords": [
"astro-adapter"
],
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {

View file

@ -11,7 +11,9 @@
"url": "https://github.com/withastro/astro.git", "url": "https://github.com/withastro/astro.git",
"directory": "packages/integrations/node" "directory": "packages/integrations/node"
}, },
"keywords": ["astro-adapter"], "keywords": [
"astro-adapter"
],
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {

View file

@ -11,7 +11,9 @@
"url": "https://github.com/withastro/astro.git", "url": "https://github.com/withastro/astro.git",
"directory": "packages/astro-prefetch" "directory": "packages/astro-prefetch"
}, },
"keywords": ["astro-integration"], "keywords": [
"astro-integration"
],
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {

View file

@ -10,7 +10,9 @@
"url": "https://github.com/withastro/astro.git", "url": "https://github.com/withastro/astro.git",
"directory": "packages/integrations/vercel" "directory": "packages/integrations/vercel"
}, },
"keywords": ["astro-adapter"], "keywords": [
"astro-adapter"
],
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {