chore(framework): Move feature flags related resources and cleanup (#8297)

**What**
cleanup and move the feature flag related resources to manage them.

It also include some refactoring around loading and registering the flag as well as not relying on the `glob` package anymore plus some reorganization of the code itself

FIXES FRMW-2625
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-07-30 12:20:03 +00:00
1 parent 8a5751c115
commit 9b6de8c02d
21 files changed
+364 -174

No files matched your search

@@ -4,7 +4,7 @@ export async function configLoaderOverride(
entryDirectory: string,
override: { clientUrl: string; debug?: boolean }
) {
const { configManager } = await import("@medusajs/framework/config")
const { configManager } = await import("@medusajs/framework")
const { configModule, error } = getConfigFile<
ReturnType<typeof configManager.loadConfig>
>(entryDirectory, "medusa-config.js")
@@ -6,21 +6,21 @@ export async function initDb({ env = {} }: { env?: Record<any, any> }) {
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
}
const { configManager, pgConnectionLoader, container } = await import(
"@medusajs/framework"
)
const {
configManager,
pgConnectionLoader,
logger,
container,
featureFlagsLoader,
} = await import("@medusajs/framework")
const configModule = configManager.config
const pgConnection = pgConnectionLoader()
const featureFlagRouter =
require("@medusajs/medusa/dist/loaders/feature-flags").default(configModule)
await featureFlagsLoader()
container.register({
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
[ContainerRegistrationKeys.LOGGER]: asValue(console),
[ContainerRegistrationKeys.PG_CONNECTION]: asValue(pgConnection),
[ContainerRegistrationKeys.FEATURE_FLAG_ROUTER]: asValue(featureFlagRouter),
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
})
try {
@@ -379,13 +379,13 @@ export type ProjectConfigOptions = {
/**
* Configure the application's worker mode.
*
*
* Workers are processes running separately from the main application. They're useful for executing long-running or resource-heavy tasks in the background, such as importing products.
*
*
* With a worker, these tasks are offloaded to a separate process. So, they won't affect the performance of the main application.
*
*
* ![Diagram showcasing how the server and worker work together](https://res.cloudinary.com/dza7lstvk/image/upload/fl_lossy/f_auto/r_16/ar_16:9,c_pad/v1/Medusa%20Book/medusa-worker_klkbch.jpg?_a=BATFJtAA0)
*
*
* Medusa has three runtime modes:
*
* - Use `shared` to run the application in a single process.
@@ -393,7 +393,7 @@ export type ProjectConfigOptions = {
* - Use `server` to run the application server only.
*
* In production, it's recommended to deploy two instances:
*
*
* 1. One having the `workerMode` configuration set to `server`.
* 2. Another having the `workerMode` configuration set to `worker`.
*
@@ -874,7 +874,7 @@ export type ConfigModule = {
*
* :::
*/
featureFlags: Record<string, boolean | string>
featureFlags: Record<string, boolean | string | Record<string, boolean>>
}
export type PluginDetails = {
+1
View File
@@ -25,6 +25,7 @@ export * from "./get-set-difference"
export * from "./graceful-shutdown-server"
export * from "./group-by"
export * from "./handle-postgres-database-error"
export * from "./is-truthy"
export * from "./is-big-number"
export * from "./is-boolean"
export * from "./is-date"
@@ -0,0 +1,10 @@
/**
* Return true if the value is truthy and otherwise false
* @param val
*/
export function isTruthy(val: string | boolean | undefined): boolean {
if (typeof val === "string") {
return val.toLowerCase() === "true"
}
return !!val
}