-
Notifications
You must be signed in to change notification settings - Fork 181
Separate adapter builds into helper function. #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
60278c4
853cc56
bb96354
a2608fc
2290112
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||
import { spawn } from "child_process"; | ||||||
import { program } from "commander"; | ||||||
|
||||||
import { yellow, bgRed, bold } from "colorette"; | ||||||
|
||||||
export async function adapterBuild(projectRoot: string, framework: string) { | ||||||
// TODO(#382): We are using the latest framework adapter versions, but in the future | ||||||
// we should parse the framework version and use the matching adapter version. | ||||||
const adapterName = `@apphosting/adapter-${framework}`; | ||||||
const packumentResponse = await fetch(`https://registry.npmjs.org/${adapterName}`); | ||||||
if (!packumentResponse.ok) throw new Error(`Something went wrong fetching ${adapterName}`); | ||||||
|
if (!packumentResponse.ok) throw new Error(`Something went wrong fetching ${adapterName}`); | |
if (!packumentResponse.ok) throw new Error(`Failed to fetch ${adapterName}: ${packumentResponse.status} ${packumentResponse.statusText}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spawn
function can emit an 'error' event if it fails to start the process (e.g., if npx
is not found). This event is not currently handled, which could lead to an unhandled promise rejection. You should add an error handler for the child process to ensure all failure modes are caught.
await new Promise<void>((resolve, reject) => {
const child = spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
cwd: projectRoot,
shell: true,
stdio: "inherit",
});
child.on("error", reject);
child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`framework adapter build failed with error code ${code}.`));
}
resolve();
});
});
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,45 +2,31 @@ | |||||||||
import { spawn } from "child_process"; | ||||||||||
import { program } from "commander"; | ||||||||||
import { yellow, bgRed, bold } from "colorette"; | ||||||||||
|
import { spawn } from "child_process"; | |
import { program } from "commander"; | |
import { yellow, bgRed, bold } from "colorette"; | |
import { program } from "commander"; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,11 @@ import { spawn } from "child_process"; | |||||
import * as fs from "node:fs"; | ||||||
import * as path from "node:path"; | ||||||
|
||||||
// List of apphosting supported frameworks. | ||||||
export const SupportedFrameworks = ['nextjs', 'angular']; | ||||||
|
export const SupportedFrameworks = ['nextjs', 'angular']; | |
export const SupportedFrameworks = ['nextjs', 'angular'] as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github is the worst tool I have ever encountered.