Skip to content

Commit

Permalink
fix: exit process with a status code when build fails (#11206)
Browse files Browse the repository at this point in the history
Fixes: FRMW-2897
CLOSES CLO-434

Still need the frontend Admin bundler to provide some way to know if the build has failed or not.
  • Loading branch information
thetutlage authored Jan 29, 2025
1 parent 1e6f47d commit 716de2c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .changeset/nice-actors-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"@medusajs/framework": patch
---

fix: exit process with a status code when build fails
18 changes: 9 additions & 9 deletions packages/core/framework/src/build-tools/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ export class Compiler {
this.#logger.warn(
`Backend build completed with errors (${tracker.getSeconds()}s)`
)
} else {
this.#logger.info(
`Backend build completed successfully (${tracker.getSeconds()}s)`
)
return false
}

this.#logger.info(
`Backend build completed successfully (${tracker.getSeconds()}s)`
)
return true
}

Expand Down Expand Up @@ -359,7 +359,7 @@ export class Compiler {
this.#logger.info(
"Skipping admin build, since its disabled inside the medusa-config file"
)
return false
return true
}

/**
Expand Down Expand Up @@ -435,12 +435,12 @@ export class Compiler {
this.#logger.warn(
`Plugin build completed with errors (${tracker.getSeconds()}s)`
)
} else {
this.#logger.info(
`Plugin build completed successfully (${tracker.getSeconds()}s)`
)
return false
}

this.#logger.info(
`Plugin build completed successfully (${tracker.getSeconds()}s)`
)
return true
}

Expand Down
15 changes: 10 additions & 5 deletions packages/medusa/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ export default async function build({
}: {
directory: string
adminOnly: boolean
}): Promise<boolean> {
}) {
logger.info("Starting build...")
const compiler = new Compiler(directory, logger)

const tsConfig = await compiler.loadTSConfigFile()
if (!tsConfig) {
logger.error("Unable to compile application")
return false
process.exit(1)
}

const promises: Promise<any>[] = []
const promises: Promise<boolean>[] = []
if (!adminOnly) {
promises.push(compiler.buildAppBackend(tsConfig))
}

const bundler = await import("@medusajs/admin-bundler")
promises.push(compiler.buildAppFrontend(adminOnly, tsConfig, bundler))
await Promise.all(promises)
return true
const responses = await Promise.all(promises)

if (responses.every((response) => response === true)) {
process.exit(0)
} else {
process.exit(1)
}
}
21 changes: 12 additions & 9 deletions packages/medusa/src/commands/plugin/build.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { Compiler } from "@medusajs/framework/build-tools"
import { logger } from "@medusajs/framework/logger"
export default async function build({
directory,
}: {
directory: string
}): Promise<boolean> {
export default async function build({ directory }: { directory: string }) {
logger.info("Starting build...")
const compiler = new Compiler(directory, logger)

const tsConfig = await compiler.loadTSConfigFile()
if (!tsConfig) {
logger.error("Unable to compile plugin")
return false
process.exit(1)
}

const bundler = await import("@medusajs/admin-bundler")
await compiler.buildPluginBackend(tsConfig)
await compiler.buildPluginAdminExtensions(bundler)
return true
const responses = await Promise.all([
compiler.buildPluginBackend(tsConfig),
compiler.buildPluginAdminExtensions(bundler),
])

if (responses.every((response) => response === true)) {
process.exit(0)
} else {
process.exit(1)
}
}

0 comments on commit 716de2c

Please sign in to comment.