Skip to content

Commit

Permalink
fix: getDirname on Windows (#555)
Browse files Browse the repository at this point in the history
* fix: getDirname on Windows

* chore: add changeset
  • Loading branch information
jbroma authored Apr 16, 2024
1 parent ed82e29 commit 8fe92be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-beds-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Fix getDirname on Windows
14 changes: 7 additions & 7 deletions packages/repack/src/webpack/utils/getDirname.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import path from 'path';
import { URL } from 'url';
import { fileURLToPath } from 'url';

/**
* Get absolute directory (without any protocol) from a `file://` URL of a module.
* Mostly useful in ESM Webpack configs, where `__dirname` is not available, but `import.meta.url` is.
* Converts a `file:///` URL to an absolute directory path.
* Useful in ESM Webpack configs where `__dirname` is unavailable.
*
* @param fileUrl String with absolute `file://` URL of a module.
* @returns Absolute dirname without `file://` of a module pointed by `fileUrl`.
* @param fileUrl The `file:///` URL of a module.
* @returns The directory path without the `file:///` prefix.
*
* @category Webpack util
*
* @example Usage in Webpack config (ESM):
* @example Usage in a Webpack ESM config:
* ```ts
* import * as Repack from '@callstack/repack';
*
Expand All @@ -22,5 +22,5 @@ import { URL } from 'url';
* ```
*/
export function getDirname(fileUrl: string) {
return path.dirname(new URL(fileUrl).pathname);
return path.dirname(fileURLToPath(fileUrl));
}

0 comments on commit 8fe92be

Please sign in to comment.