-
Notifications
You must be signed in to change notification settings - Fork 283
Create apphosting-local-build command. #383
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 1 commit
1c9bfb4
19316ca
65804c7
580df00
e08251d
ee5c8a0
4a9083f
63cdee0
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,37 @@ | ||||||||||||||||
| #! /usr/bin/env node | ||||||||||||||||
| import { spawn } from "child_process"; | ||||||||||||||||
| import { program } from "commander"; | ||||||||||||||||
| import { parse as semverParse } from "semver"; | ||||||||||||||||
| import { yellow, bgRed, bold } from "colorette"; | ||||||||||||||||
| // @ts-expect-error TODO add interface | ||||||||||||||||
| import pickManifest from "npm-pick-manifest"; | ||||||||||||||||
| import { discover } from "@apphosting/discover"; | ||||||||||||||||
|
|
||||||||||||||||
| program | ||||||||||||||||
| // TODO: add framework option later. For now we support nextjs only. | ||||||||||||||||
| .argument("<directory>", "path to the project's root directory") | ||||||||||||||||
| .action(async () => { | ||||||||||||||||
|
|
||||||||||||||||
| const projectRoot = program.args[0]; | ||||||||||||||||
|
||||||||||||||||
| .action(async () => { | |
| const projectRoot = program.args[0]; | |
| .action(async (directory: string) => { | |
| const projectRoot = directory; |
Outdated
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.
Accessing packument["dist-tags"]["canary"] directly can lead to a runtime error if the dist-tags property or the canary tag doesn't exist in the packument response. It's safer to add checks to ensure the properties exist before accessing them.
| const packument = await packumentResponse.json(); | |
| const adapterVersion = packument["dist-tags"]["canary"]; | |
| const packument = await packumentResponse.json(); | |
| const adapterVersion = packument?.["dist-tags"]?.["canary"]; | |
| if (!adapterVersion) { | |
| throw new Error(`Could not find 'canary' dist-tag for ${adapterName}.`); | |
| } |
Outdated
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 call is not awaited, which means the script will exit immediately without waiting for the npx build process to complete. This can lead to silent failures where the build fails but the script reports success. The child process should be awaited, and its exit code should be checked to determine if the build was successful.
await new Promise<void>((resolve, reject) => {
const child = spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
cwd: projectRoot,
shell: true,
stdio: "inherit",
});
child.on("close", (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Build process exited with code ${code}`));
}
});
child.on("error", (err) => {
reject(err);
});
});
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.
There are several unused imports (
semverParse,pickManifest,discover). These should be removed to keep the code clean. The associated// @ts-expect-errorcomment for the unusedpickManifestimport can also be removed.