Skip to content

Fix/windows migration - #113

Merged
HendrixString merged 3 commits into
store-craft:mainfrom
nischaldoescode:fix/windows-migration
Apr 28, 2026
Merged

HendrixString merged 3 commits into
store-craft:mainfrom
nischaldoescode:fix/windows-migration

Conversation

@nischaldoescode

@nischaldoescode nischaldoescode commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Fix: #112

What this PR does

This PR fixes migration loading on Windows by ensuring file paths are converted to valid file:// URLs using Node’s built-in utilities.

Key points

  • Added a FixedFileMigrationProvider that:
    • resolves absolute file paths using path.resolve
    • converts paths using pathToFileURL
    • dynamically imports migrations in a cross-platform-safe way
  • Updated migrate.js to use this provider.
  • Removed manual string manipulation (regex) in favor of Node’s standard APIs
  • Verified locally on Windows — migrations execute successfully

Why this is needed

When using dynamic import() with file paths, Node expects properly formatted file:// URLs.

The default FileMigrationProvider works on Unix-type systems, but Windows produces malformed URLs when converting C:\path\... into file:// URLs. This results in:

ERR_UNSUPPORTED_ESM_URL_SCHEME

The custom provider ensures consistent behavior on all platforms.

This approach avoids manual URL handling and relies on Node's built-in cross-platform guarantees.

Tested on

  • Windows 12 / Node 22

@HendrixString

Copy link
Copy Markdown
Member

@nischaldoescode hello.

Did you try the other way around ?

Here is an example without regex

’’’
import { fileURLToPath } from 'url';
import path from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const filePath = path.join(__dirname, 'data', 'config.json');
’’’

The file path should be cross platform

@nischaldoescode

nischaldoescode commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@HendrixString hi,

Well I didn't test it without regex I beleive it will be best if we stick with this.

It should work cross platform did you test in Linux ?.

Do you specifically want it to be without regex, if so I am all in for that if you really want it. Then we can close this pr as accepted.

I am bit busy nowadays will be back at razorpay as soon as I have some time.

@HendrixString

HendrixString commented Apr 24, 2026 •

Copy link
Copy Markdown
Member

@nischaldoescode regex is less predictable, i propose using something more predictable. dont worry about tests, i have a github action runner that runs the tests on a cloud machine. Before pushing the patch, make sure your local Windows machine migration works

I am bit busy nowadays will be back at razorpay as soon as I have some time.
i would love to have your razor-pay support in storecraft

Thanks bro

@nischaldoescode

Copy link
Copy Markdown
Contributor Author

@HendrixString I have changed the regex with the node's native work around can you check and possibly merge it ?.
and yeah migrations work.

I would also like to request to mention about the way to use tests in the readme, We can have contributing readme then mention the fact that check how i have used it in the razorpay tests ?.

I hope you got it ...

Regards.

@HendrixString
HendrixString merged commit bf7a1d4 into store-craft:main Apr 28, 2026
8 of 9 checks passed
@HendrixString

Copy link
Copy Markdown
Member

@nischaldoescode tests have passed, I merged

@nischaldoescode

Copy link
Copy Markdown
Contributor Author

Thankyou Tomer Sir..

Hope it added some value to this project.

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.

2 participants