fix(framework): migration scripts regexp (#11072)

FIXES FRMW-2879

**What**
The exclusion regexp was broken and instead use the ignore options of the glob sync function to properly ignore definition files
This commit is contained in:
Adrien de Peretti
2025-01-21 10:34:57 +01:00
committed by GitHub
parent d4e042e9ad
commit 13fe2f6776
7 changed files with 45 additions and 11 deletions

View File

@@ -0,0 +1,3 @@
export default function test() {
console.log("test")
}

View File

@@ -1,8 +1,8 @@
import { MedusaContainer } from "@medusajs/types"
import { MigrationScriptsMigrator } from "../run-migration-scripts"
import { jest } from "@jest/globals"
import path from "path"
import { MedusaContainer } from "@medusajs/types"
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
import path from "path"
import { MigrationScriptsMigrator } from "../run-migration-scripts"
const mockPgConnection = {
raw: jest.fn(),
@@ -171,4 +171,29 @@ describe("MigrationScriptsMigrator", () => {
)
})
})
describe("loadMigrationFiles", () => {
it("should load migration files correctly", async () => {
const result = await migrator.loadMigrationFiles([
path.join(
__dirname,
"..",
"__fixtures__",
"project",
"migration-scripts"
),
])
expect(result).toHaveLength(1)
expect(result[0]).toEqual(
path.join(
__dirname,
"..",
"__fixtures__",
"project",
"migration-scripts",
"test.ts"
)
)
})
})
})

View File

@@ -1,9 +1,9 @@
import { join } from "path"
import { glob } from "glob"
import { logger } from "../logger"
import { MedusaContainer } from "@medusajs/types"
import { ContainerRegistrationKeys } from "../utils"
import { Knex } from "@mikro-orm/knex"
import { glob } from "glob"
import { join } from "path"
import { logger } from "../logger"
import { ContainerRegistrationKeys } from "../utils"
export abstract class Migrator {
protected abstract migration_table_name: string
@@ -135,9 +135,9 @@ export abstract class Migrator {
}
try {
const scriptFiles = glob.sync("*.{js,(!d.)ts}", {
const scriptFiles = glob.sync("*.{js,ts}", {
cwd: basePath,
ignore: ["**/index.{js,ts}"],
ignore: ["**/index.{js,ts}", "**/*.d.ts"],
})
if (!scriptFiles?.length) {