Skip to content

Commit

Permalink
manually run format
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy authored Dec 23, 2024
1 parent a51c76c commit c8e1c63
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
18 changes: 11 additions & 7 deletions package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ export function getAdapter(args: InternalOptions): AstroAdapter {

export default (options?: Options): AstroIntegration => {
if (options) {
if (options.cluster && typeof options.cluster !== "boolean") {
throw new Error(`[${packageName}] options.cluster must be a boolean, but the adapter was provided with ${options.cluster} instead.`)
if (options.cluster && typeof options.cluster !== 'boolean') {
throw new Error(
`[${packageName}] options.cluster must be a boolean, but the adapter was provided with ${options.cluster} instead.`,
);
}
if (options.unix && typeof options.unix !== "string") {
throw new Error(`[${packageName}] options.unix must be a string, but the adapter was provided with ${options.unix} instead.`)
if (options.unix && typeof options.unix !== 'string') {
throw new Error(
`[${packageName}] options.unix must be a string, but the adapter was provided with ${options.unix} instead.`,
);
}
}
return {
name: packageName,
hooks: {
'astro:config:done': params => {
'astro:config:done': (params) => {
params.setAdapter(
getAdapter({
cluster: options?.cluster,
Expand All @@ -53,5 +57,5 @@ export default (options?: Options): AstroIntegration => {
);
},
},
}
}
};
};
41 changes: 19 additions & 22 deletions package/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import type { Server } from 'bun';

import type { CreateExports, InternalOptions } from '~/types.ts';

export function createExports(manifest: SSRManifest, options: InternalOptions): CreateExports {
export function createExports(
manifest: SSRManifest,
options: InternalOptions,
): CreateExports {
return {
handle: handler(manifest, options),
running: () => _server !== null,
Expand All @@ -29,7 +32,7 @@ let _server: Server | null = null;
export function start(manifest: SSRManifest, options: InternalOptions): void {
const hostname = process.env.HOST ?? extractHostname(options.host);
const port = process.env.PORT ? Number.parseInt(process.env.PORT) : options.port;
const unix = process.env.UNIX ?? options.unix
const unix = process.env.UNIX ?? options.unix;

if (cluster.isPrimary && options.cluster) {
const numCPUs = os.cpus().length;
Expand All @@ -44,27 +47,21 @@ export function start(manifest: SSRManifest, options: InternalOptions): void {
const app = new App(manifest);
const logger = app.getAdapterLogger();

if (unix) {
_server = Bun.serve({
error: (error) =>
new Response(`<pre>${error}\n${error.stack}</pre>`, {
headers: { 'Content-Type': 'text/html' },
}),
fetch: handler(manifest, options),
unix,
});
}
else {
_server = Bun.serve({
error: (error) =>
new Response(`<pre>${error}\n${error.stack}</pre>`, {
headers: { 'Content-Type': 'text/html' },
_server = Bun.serve({
error: (error) =>
new Response(`<pre>${error}\n${error.stack}</pre>`, {
headers: { 'Content-Type': 'text/html' },
}),
fetch: handler(manifest, options),
...(unix
? {
unix,
}
: {
hostname,
port,
}),
fetch: handler(manifest, options),
hostname,
port,
});
}
});

function exit(): void {
if (_server) _server.stop();
Expand Down
35 changes: 17 additions & 18 deletions package/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ export interface Options {
/**
* Create a cluster of bun servers listening on the same port,
* and automatically load-balance incoming requests across them.
*
*
* Example:
* ```ts
* export default defineConfig({
* adapter: bun({ cluster: true })
* })
* ```
*
*
* Defaults to `false`
*/
cluster?: boolean
cluster?: boolean;
/**
* The path to the unix socket on which to host the server.
*
*
* This can provide better performance when Bun is running alongside
* a local reverse proxy that supports unix sockets.
*
*
* When a unix socket is provided, Bun does not bind to a TCP port,
* and the options and environment variables for the hostname and port
* are ignored.
*
*
* Example:
* ```ts
* export default defineConfig({
* adapter: bun({ unix: "/tmp/my-socket.sock" })
* })
* ```
*/
unix?: string
unix?: string;
}

// options provided by the user combined with other
Expand All @@ -44,43 +44,42 @@ export interface InternalOptions extends Options {
/**
* Name of the publicly exposed directory where all
* static assets are put.
*
*
* Astro defaults to `"_astro"`.
*/
assets: AstroConfig["build"]["assets"],
assets: AstroConfig['build']['assets'];
/**
* The full file URL to where astro is configured to put
* the client bundle and assets such as images, fonts,
* stylesheets, and static html.
*
*
* Astro defaults to `"<project root>/dist/client/"`.
*/
client: AstroConfig["build"]["server"]["href"],
client: AstroConfig['build']['server']['href'];
/**
* The full file URL to where astro is configured to put
* the server bundle.
*
*
* Astro defaults to `"<project root>/dist/server/""`.
*/
server: AstroConfig["build"]["server"]["href"],
server: AstroConfig['build']['server']['href'];
/**
* Network address where the astro dev server is
* configured to listen for requests in addition to
* `localhost`.
*
*
* Astro defaults to `false`.
*/
host: AstroConfig["server"]["host"],
host: AstroConfig['server']['host'];
/**
* Network port where the astro dev server is
* configured to listen for requests.
*
*
* Astro default to `4321`.
*/
port: AstroConfig["server"]["port"],
port: AstroConfig['server']['port'];
}


export enum CreateExportsEnum {
HANDLE = 'handle',
RUNNING = 'running',
Expand Down

0 comments on commit c8e1c63

Please sign in to comment.