fix: Commands loading entrypoints (#7404)

* fix: enable worker mode when executing user and migrate commands

* refactor: do not enable worker mode for migrate command

* refactor: auto detect is application is using ts-node

* refactor: remove directories node from config

* style: update comments next to enabling worker mode
This commit is contained in:
Harminder Virk
2024-05-22 19:31:13 +05:30
committed by GitHub
parent c198e2329c
commit 965a50d483
5 changed files with 18 additions and 25 deletions
-1
View File
@@ -42,7 +42,6 @@ const runLinkMigrations = async (directory) => {
const main = async function ({ directory }) {
const args = process.argv
args.shift()
args.shift()
args.shift()
+6
View File
@@ -20,6 +20,12 @@ export default async function ({
track("CLI_USER", { with_id: !!id })
const app = express()
try {
/**
* Enabling worker mode to prevent discovering/loading
* of API routes from the starter kit
*/
process.env.MEDUSA_WORKER_MODE = "worker"
const { container } = await loaders({
directory,
expressApp: app,
-3
View File
@@ -102,8 +102,5 @@ export default (rootDirectory: string): ConfigModule => {
modules: configModule.modules ?? {},
featureFlags: configModule?.featureFlags ?? {},
plugins: configModule?.plugins ?? [],
directories: configModule?.directories ?? {
srcDir: "dist",
},
}
}
@@ -106,10 +106,7 @@ function resolvePlugin(pluginName: string): {
export function getResolvedPlugins(
rootDirectory: string,
configModule: {
plugins: ConfigModule["plugins"]
directories?: ConfigModule["directories"]
},
configModule: ConfigModule,
isMedusaProject = false
): undefined | PluginDetails[] {
if (isMedusaProject) {
@@ -117,10 +114,14 @@ export function getResolvedPlugins(
* Grab directory for loading resources inside a starter kit from
* the medusa-config file.
*
* This is because, we do not have a "dist" directory inside a starter
* kit. Instead we discover resources from the "src" directory.
* When using ts-node we will read resources from "src" directory
* otherwise from "dist" directory.
*/
const extensionDirectoryPath = configModule.directories?.srcDir ?? "dist"
const extensionDirectoryPath = process[
Symbol.for("ts-node.register.instance")
]
? "src"
: "dist"
const extensionDirectory = path.join(rootDirectory, extensionDirectoryPath)
return [
{