Skip to content
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

Skip double custom build #7423

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {

this.#customBuildWatcher = watch(pathsToWatch, {
persistent: true,
// TODO: add comments re this ans ready
// The initial custom build is always done in getEntry()
ignoreInitial: true,
});
this.#customBuildWatcher.on("ready", () => {
Expand Down
34 changes: 28 additions & 6 deletions packages/wrangler/src/deployment-bundle/run-custom-build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { existsSync, statSync } from "node:fs";
import path from "node:path";
import { Writable } from "node:stream";
import chalk from "chalk";
import { execaCommand } from "execa";
import { configFileName } from "../config";
import { UserError } from "../errors";
Expand All @@ -19,17 +21,37 @@ export async function runCustomBuild(
configPath: string | undefined
) {
if (build.command) {
logger.log("Running custom build:", build.command);
logger.log(chalk.blue("[custom build]"), "Running:", build.command);
try {
await execaCommand(build.command, {
const res = execaCommand(build.command, {
shell: true,
// we keep these two as "inherit" so that
// logs are still visible.
stdout: "inherit",
stderr: "inherit",
...(build.cwd && { cwd: build.cwd }),
});
res.stdout?.pipe(
new Writable({
write(chunk: Buffer, _, callback) {
const lines = chunk.toString().split("\n");
for (const line of lines) {
logger.log(chalk.blue("[custom build]"), line);
}
callback();
},
})
);
res.stderr?.pipe(
new Writable({
write(chunk: Buffer, _, callback) {
const lines = chunk.toString().split("\n");
for (const line of lines) {
logger.log(chalk.red("[custom build]"), line);
}
callback();
},
})
);
await res;
} catch (e) {
logger.error(e);
throw new UserError(
`Running custom build \`${build.command}\` failed. There are likely more logs from your build command above.`,
{
Expand Down
Loading