Skip to content

Commit 7442b80

Browse files
authored
fix(win): include drive letter (#364)
1 parent cbc2a99 commit 7442b80

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/generators/web/constants.mjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import { parse, relative, sep, dirname } from 'node:path';
2-
import { resolve } from 'node:path/posix';
1+
import { resolve, dirname } from 'node:path';
32
import { fileURLToPath } from 'node:url';
43

5-
// Convert the current module's URL to a filesystem path,
6-
// then calculate the relative path from the system root directory
7-
// to this file. This relative path uses platform-specific separators,
8-
// so replace them with forward slashes ("/") for consistency and web compatibility.
9-
// Finally, prepend a leading slash to form an absolute root-relative path string.
10-
//
11-
// This produces a POSIX-style absolute path, even on Windows systems.
12-
const dir = dirname(fileURLToPath(import.meta.url));
13-
export const ROOT = '/' + relative(parse(dir).root, dir).replaceAll(sep, '/');
4+
export const ROOT = dirname(fileURLToPath(import.meta.url));
145

156
/**
167
* @typedef {Object} JSXImportConfig

src/generators/web/utils/generate.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolve } from 'node:path/posix';
1+
import { resolve } from 'node:path';
22

33
import { JSX_IMPORTS, ROOT } from '../constants.mjs';
44

@@ -14,6 +14,10 @@ export const createImportDeclaration = (
1414
source,
1515
useDefault = true
1616
) => {
17+
// '\' characters shouldn't escape the next character,
18+
// but rather be treated as slashes.
19+
source = source.replaceAll('\\', '\\\\');
20+
1721
// Side-effect-only import (CSS)
1822
if (!importName) {
1923
return `import "${source}";`;

0 commit comments

Comments
 (0)