feat(utils): define file config (#13283)
** What
- Allow auto-loaded Medusa files to export a config object.
- Currently supports isDisabled to control loading.
- new instance `FeatureFlag` exported by `@medusajs/framework/utils`
- `feature-flags` is now a supported folder for medusa projects, modules, providers and plugins. They will be loaded and added to `FeatureFlag`
** Why
- Enables conditional loading of routes, migrations, jobs, subscribers, workflows, and other files based on feature flags.
```ts
// /src/feature-flags
import { FlagSettings } from "@medusajs/framework/feature-flags"
const CustomFeatureFlag: FlagSettings = {
key: "custom_feature",
default_val: false,
env_key: "FF_MY_CUSTOM_FEATURE",
description: "Enable xyz",
}
export default CustomFeatureFlag
```
```ts
// /src/modules/my-custom-module/migration/Migration20250822135845.ts
import { FeatureFlag } from "@medusajs/framework/utils"
export class Migration20250822135845 extends Migration {
override async up(){ }
override async down(){ }
}
defineFileConfig({
isDisabled: () => !FeatureFlag.isFeatureEnabled("custom_feature")
})
```
This commit is contained in:
committed by
GitHub
parent
4cda412243
commit
e413cfefc2
@@ -1,3 +1,4 @@
|
||||
import { CustomDBMigrator } from "../../dal/mikro-orm/custom-db-migrator"
|
||||
import { defineMikroOrmCliConfig } from "../mikro-orm-cli-config-builder"
|
||||
|
||||
const moduleName = "myTestService"
|
||||
@@ -28,6 +29,7 @@ describe("defineMikroOrmCliConfig", () => {
|
||||
generator: expect.any(Function),
|
||||
snapshotName: ".snapshot-medusa-my-test",
|
||||
},
|
||||
extensions: [CustomDBMigrator],
|
||||
})
|
||||
})
|
||||
|
||||
@@ -47,6 +49,7 @@ describe("defineMikroOrmCliConfig", () => {
|
||||
generator: expect.any(Function),
|
||||
snapshotName: ".snapshot-medusa-my-test",
|
||||
},
|
||||
extensions: [CustomDBMigrator],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,9 +2,9 @@ import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
import { EOL } from "os"
|
||||
import { resolve } from "path"
|
||||
import { dynamicImport, isFileSkipped } from "../../common"
|
||||
import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
import { dynamicImport } from "../../common"
|
||||
|
||||
/**
|
||||
* Utility function to build a seed script that will insert the seed data.
|
||||
@@ -52,6 +52,10 @@ export function buildSeedScript({
|
||||
}
|
||||
)
|
||||
|
||||
if (isFileSkipped(dataSeed)) {
|
||||
return
|
||||
}
|
||||
|
||||
const dbData = loadDatabaseConfig(moduleName, options)!
|
||||
const entities = Object.values(models) as unknown as EntitySchema[]
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
} from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { kebabCase } from "../common"
|
||||
import { CustomTsMigrationGenerator } from "../dal"
|
||||
import { CustomDBMigrator, CustomTsMigrationGenerator } from "../dal"
|
||||
import { DmlEntity, toMikroOrmEntities } from "../dml"
|
||||
|
||||
type Options = Partial<Omit<MikroORMOptions, "entities" | "entitiesTs">> & {
|
||||
@@ -65,5 +65,6 @@ export function defineMikroOrmCliConfig(
|
||||
generator: CustomTsMigrationGenerator,
|
||||
...options.migrations,
|
||||
},
|
||||
extensions: [CustomDBMigrator],
|
||||
}) as ReturnedOptions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user