Skip to content

Commit b8a3c07

Browse files
committed
lint
1 parent 727b193 commit b8a3c07

File tree

2 files changed

+113
-115
lines changed

2 files changed

+113
-115
lines changed

packages/@apphosting/experimental/adapter-astro/src/index.ts

Lines changed: 86 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,115 +3,113 @@ import { stringify as yamlStringify } from "yaml";
33
import { fileURLToPath } from "url";
44
import { dirname } from "path";
55
import fsExtra from "fs-extra";
6-
import { exec } from "child_process"
7-
import { createRequire } from 'module';
8-
import path from 'path';
9-
import type { AstroAdapter, AstroIntegration } from 'astro';
10-
import { AstroError } from 'astro/errors';
11-
import type { Options, UserOptions } from './types.js';
6+
import { exec } from "child_process";
7+
import { createRequire } from "module";
8+
import path from "path";
9+
import type { AstroAdapter, AstroIntegration } from "astro";
10+
import { AstroError } from "astro/errors";
11+
import type { Options, UserOptions } from "./types.js";
1212
import { OutputBundleConfig, Availability } from "@apphosting/common";
1313
export const { move, exists, writeFile, readJson, readdir, readFileSync, existsSync, mkdir } =
14-
fsExtra;
14+
fsExtra;
1515

1616
export function getAdapter(options: Options): AstroAdapter {
1717
const require = createRequire(import.meta.url);
18-
const serverEntrypoint = path.join(require.resolve('@astrojs/node'), '../server.js');
19-
const previewEntrypoint = path.join(require.resolve('@astrojs/node'), '../preview.js');
20-
return {
18+
const serverEntrypoint = path.join(require.resolve("@astrojs/node"), "../server.js");
19+
const previewEntrypoint = path.join(require.resolve("@astrojs/node"), "../preview.js");
20+
return {
2121
name: "@apphosting/astro-adapter",
2222
serverEntrypoint: serverEntrypoint,
2323
previewEntrypoint: previewEntrypoint,
24-
exports: ['handler', 'startServer', 'options'],
25-
args: options,
26-
adapterFeatures: {
27-
buildOutput: 'server',
28-
edgeMiddleware: false,
29-
},
30-
supportedAstroFeatures: {
31-
hybridOutput: 'stable',
32-
staticOutput: 'stable',
33-
serverOutput: 'stable',
34-
sharpImageService: 'stable',
35-
i18nDomains: 'experimental',
36-
envGetSecret: 'stable',
37-
},
38-
};
24+
exports: ["handler", "startServer", "options"],
25+
args: options,
26+
adapterFeatures: {
27+
buildOutput: "server",
28+
edgeMiddleware: false,
29+
},
30+
supportedAstroFeatures: {
31+
hybridOutput: "stable",
32+
staticOutput: "stable",
33+
serverOutput: "stable",
34+
sharpImageService: "stable",
35+
i18nDomains: "experimental",
36+
envGetSecret: "stable",
37+
},
38+
};
3939
}
4040

4141
export default function createIntegration(userOptions: UserOptions): AstroIntegration {
42-
if (!userOptions?.mode) {
43-
throw new AstroError(`Setting the 'mode' option is required.`);
44-
}
42+
if (!userOptions?.mode) {
43+
throw new AstroError(`Setting the 'mode' option is required.`);
44+
}
4545

46-
let _options: Options;
47-
return {
48-
name: '@apphosting/astro-adapter',
49-
hooks: {
50-
'astro:config:setup': async ({ updateConfig, config }) => {
51-
updateConfig({
52-
image: {
53-
endpoint: config.image.endpoint ?? 'astro/assets/endpoint/node',
54-
},
55-
vite: {
56-
ssr: {
57-
noExternal: ['@apphosting/astro-adapter'],
58-
},
59-
},
60-
});
61-
},
62-
'astro:config:done': ({ setAdapter, config }) => {
63-
_options = {
64-
...userOptions,
65-
client: config.build.client?.toString(),
66-
server: config.build.server?.toString(),
67-
host: config.server.host,
68-
port: config.server.port,
69-
assets: config.build.assets,
70-
};
71-
setAdapter(getAdapter(_options));
72-
},
73-
'astro:build:done': async (config) => {
74-
await fs.mkdir("./.apphosting")
75-
const directoryName = dirname(fileURLToPath(import.meta.url));
76-
const packageJsonPath = `${directoryName}/../package.json`;
77-
if (!existsSync(packageJsonPath)) {
78-
throw new Error(`Astro adapter package.json file does not exist at ${packageJsonPath}`);
79-
}
80-
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
81-
const packageName = "astro";
82-
const packageVersion = await getPackageVersion(packageName);
83-
const outputBundle: OutputBundleConfig = {
84-
version: "v1",
85-
runConfig: {
86-
runCommand: `node dist/server/entry.mjs`,
87-
environmentVariables: [{variable:"HOST", value:"0.0.0.0", availability:[Availability.Runtime]}]
88-
},
89-
metadata: {
90-
adapterPackageName: packageJson.name,
91-
adapterVersion: packageJson.version,
92-
framework: packageName,
93-
frameworkVersion: packageVersion
94-
},
95-
};
96-
await fs.writeFile(
97-
`./.apphosting/bundle.yaml`,
98-
yamlStringify(outputBundle)
99-
);
100-
},
101-
},
102-
};
46+
let _options: Options;
47+
return {
48+
name: "@apphosting/astro-adapter",
49+
hooks: {
50+
"astro:config:setup": async ({ updateConfig, config }) => {
51+
updateConfig({
52+
image: {
53+
endpoint: config.image.endpoint ?? "astro/assets/endpoint/node",
54+
},
55+
vite: {
56+
ssr: {
57+
noExternal: ["@apphosting/astro-adapter"],
58+
},
59+
},
60+
});
61+
},
62+
"astro:config:done": ({ setAdapter, config }) => {
63+
_options = {
64+
...userOptions,
65+
client: config.build.client?.toString(),
66+
server: config.build.server?.toString(),
67+
host: config.server.host,
68+
port: config.server.port,
69+
assets: config.build.assets,
70+
};
71+
setAdapter(getAdapter(_options));
72+
},
73+
"astro:build:done": async (config) => {
74+
await fs.mkdir("./.apphosting");
75+
const directoryName = dirname(fileURLToPath(import.meta.url));
76+
const packageJsonPath = `${directoryName}/../package.json`;
77+
if (!existsSync(packageJsonPath)) {
78+
throw new Error(`Astro adapter package.json file does not exist at ${packageJsonPath}`);
79+
}
80+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
81+
const packageName = "astro";
82+
const packageVersion = await getPackageVersion(packageName);
83+
const outputBundle: OutputBundleConfig = {
84+
version: "v1",
85+
runConfig: {
86+
runCommand: `node dist/server/entry.mjs`,
87+
environmentVariables: [
88+
{ variable: "HOST", value: "0.0.0.0", availability: [Availability.Runtime] },
89+
],
90+
},
91+
metadata: {
92+
adapterPackageName: packageJson.name,
93+
adapterVersion: packageJson.version,
94+
framework: packageName,
95+
frameworkVersion: packageVersion,
96+
},
97+
};
98+
await fs.writeFile(`./.apphosting/bundle.yaml`, yamlStringify(outputBundle));
99+
},
100+
},
101+
};
103102
}
104103

105104
function getPackageVersion(packageName: string): Promise<string> {
106105
return new Promise((resolve, reject) => {
107106
exec(`npm view ${packageName} version`, (error, stdout, stderr) => {
108107
if (error) {
109-
reject(error);
108+
reject(error);
110109
return;
111110
}
112111
const version = stdout.trim();
113-
resolve(version);
112+
resolve(version);
114113
});
115114
});
116115
}
117-
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
import type { IncomingMessage, ServerResponse } from 'node:http';
2-
import type { SSRManifest } from 'astro';
3-
import type { NodeApp } from 'astro/app/node';
1+
import type { IncomingMessage, ServerResponse } from "node:http";
2+
import type { SSRManifest } from "astro";
3+
import type { NodeApp } from "astro/app/node";
44

55
export interface UserOptions {
6-
/**
7-
* Specifies the mode that the adapter builds to.
8-
*
9-
* - 'middleware' - Build to middleware, to be used within another Node.js server, such as Express.
10-
* - 'standalone' - Build to a standalone server. The server starts up just by running the built script.
11-
*/
12-
mode: 'middleware' | 'standalone';
6+
/**
7+
* Specifies the mode that the adapter builds to.
8+
*
9+
* - 'middleware' - Build to middleware, to be used within another Node.js server, such as Express.
10+
* - 'standalone' - Build to a standalone server. The server starts up just by running the built script.
11+
*/
12+
mode: "middleware" | "standalone";
1313
}
1414

1515
export interface Options extends UserOptions {
16-
host: string | boolean;
17-
port: number;
18-
server: string;
19-
client: string;
20-
assets: string;
21-
trailingSlash?: SSRManifest['trailingSlash'];
16+
host: string | boolean;
17+
port: number;
18+
server: string;
19+
client: string;
20+
assets: string;
21+
trailingSlash?: SSRManifest["trailingSlash"];
2222
}
2323

2424
export interface CreateServerOptions {
25-
app: NodeApp;
26-
assets: string;
27-
client: URL;
28-
port: number;
29-
host: string | undefined;
30-
removeBase: (pathname: string) => string;
25+
app: NodeApp;
26+
assets: string;
27+
client: URL;
28+
port: number;
29+
host: string | undefined;
30+
removeBase: (pathname: string) => string;
3131
}
3232

3333
export type RequestHandler = (...args: RequestHandlerParams) => void | Promise<void>;
3434
export type RequestHandlerParams = [
35-
req: IncomingMessage,
36-
res: ServerResponse,
37-
next?: (err?: unknown) => void,
38-
locals?: object,
39-
];
35+
req: IncomingMessage,
36+
res: ServerResponse,
37+
next?: (err?: unknown) => void,
38+
locals?: object,
39+
];

0 commit comments

Comments
 (0)