fix: migrate error on windows (#7759)

handle windows compatible file names when reading migrations

---------

Co-authored-by: Alessio Gravili <alessio@gravili.de>
This commit is contained in:
Dan Ribbens
2024-08-19 15:46:40 -04:00
committed by GitHub
parent ab09f2aff5
commit bb09da08c2
2 changed files with 8 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import fs from 'fs'
import { pathToFileURL } from 'node:url'
import path from 'path'
import type { Payload } from '../../index.js'
@@ -36,9 +37,10 @@ export const readMigrationFiles = async ({
return Promise.all(
files.map(async (filePath) => {
// eval used to circumvent errors bundling
let migration = await eval(
`${typeof require === 'function' ? 'require' : 'import'}('${filePath.replaceAll('\\', '/')}')`,
)
let migration =
typeof require === 'function'
? await eval(`require('${filePath.replaceAll('\\', '/')}')`)
: await eval(`import('${pathToFileURL(filePath).href}')`)
if ('default' in migration) migration = migration.default
const result: Migration = {