Skip to content

fix(kit): use path.basename/dirname in embeddedMigrations to fix Windows path separators#5518

Open
sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor:fix-5514
Open

fix(kit): use path.basename/dirname in embeddedMigrations to fix Windows path separators#5518
sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor:fix-5514

Conversation

@sleitor
Copy link
Copy Markdown

@sleitor sleitor commented Mar 21, 2026

Problem

Fixes #5514.

On Windows, snapshot file paths use backslash separators (e.g. C:\project\drizzle\20260320055809_initial\snapshot.json). The previous implementation used entry.split('/')[...length - 2] to extract the migration folder name. Since Windows paths contain only backslashes, split('/') returns a single-element array and [length - 2] is undefined, causing migrations.js to import from './undefined/migration.sql'.

Fix

Replace the slash-split approach with path.basename(path.dirname(entry)), which correctly extracts the parent directory name on all platforms (POSIX and Windows).

// Before
const prefix = entry.split('/')[entry.split('/').length - 2];

// After
const prefix = path.basename(path.dirname(entry));

path is already imported in this file. The path module automatically handles both forward-slash and backslash separators on Windows via path.dirname/path.basename.

…ows path separators

On Windows, path.join() produces backslash-separated paths. The previous
implementation used entry.split('/') which always splits on forward slash,
causing the parent directory name (migration folder name) to be undefined
on Windows, resulting in 'undefined' appearing in the generated migrations.js.

Fixes drizzle-team#5514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant