Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(core-plugin): detect package manager for codegen and skip in non-dev environments #827 (#836)

Jakub Sieradzkia265d3d18f06
diff --git a/packages/core-plugin/src/modules/codegen/services/codegen-module-service.ts b/packages/core-plugin/src/modules/codegen/services/codegen-module-service.ts
index d8a6a4a99..9b8c664aa 100644
--- a/packages/core-plugin/src/modules/codegen/services/codegen-module-service.ts
+++ b/packages/core-plugin/src/modules/codegen/services/codegen-module-service.ts
@@ -1,4 +1,6 @@
import { exec } from "child_process"
+import { existsSync } from "fs"
+import { join } from "path"
import { Logger } from "@medusajs/medusa"
export default class CodegenModuleService {
@@ -15,6 +17,10 @@ export default class CodegenModuleService {
}
async onApplicationStart(): Promise<void> {
+ if (process.env.NODE_ENV !== "development") {
+ return
+ }
+
try {
await this.runCodegen_()
} catch (error) {
@@ -22,9 +28,23 @@ export default class CodegenModuleService {
}
}
+ private detectPackageRunner_(): string {
+ const cwd = process.cwd()
+ const lockfiles: [string, string][] = [
+ ["bun.lockb", "bunx"],
+ ["bun.lock", "bunx"],
+ ["pnpm-lock.yaml", "pnpm exec"],
+ ["yarn.lock", "yarn"],
+ ]
+
+ const runner = lockfiles.find(([file]) => existsSync(join(cwd, file)))
+ return `${runner ? runner[1] : "npx"} @mercurjs/cli codegen`
+ }
+
private runCodegen_(): Promise<void> {
return new Promise((resolve, reject) => {
- exec("npx mercurjs codegen", { cwd: process.cwd() }, (error, _stdout, stderr) => {
+ const command = this.detectPackageRunner_()
+ exec(command, { cwd: process.cwd() }, (error, _stdout, stderr) => {
if (error) {
reject(stderr || error.message)
return
diff --git a/templates/basic/packages/api/medusa-config.ts b/templates/basic/packages/api/medusa-config.ts
index 06e5bd416..3ceb46ba9 100644
--- a/templates/basic/packages/api/medusa-config.ts
+++ b/templates/basic/packages/api/medusa-config.ts
@@ -25,7 +25,7 @@ module.exports = defineConfig({
options: {
appDir: path.join(__dirname, '../../apps/admin'),
path: '/dashboard',
- disable: true
+ disable: false
} as DashboardModuleOptions
},
{
@@ -33,7 +33,7 @@ module.exports = defineConfig({
options: {
appDir: path.join(__dirname, '../../apps/vendor'),
path: '/seller',
- disable: true
+ disable: false
} as DashboardModuleOptions
},
],