Skip to content

Commit ffe2f83

Browse files
committed
fix(win): include drive letter
1 parent cbc2a99 commit ffe2f83

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/generators/web/constants.mjs

Lines changed: 6 additions & 15 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
@@ -26,19 +17,19 @@ export const ROOT = '/' + relative(parse(dir).root, dir).replaceAll(sep, '/');
2617
export const JSX_IMPORTS = {
2718
NavBar: {
2819
name: 'NavBar',
29-
source: resolve(ROOT, './ui/components/NavBar'),
20+
source: resolve(ROOT, './ui/components/NavBar').replaceAll('\\', '\\\\'),
3021
},
3122
SideBar: {
3223
name: 'SideBar',
33-
source: resolve(ROOT, './ui/components/SideBar'),
24+
source: resolve(ROOT, './ui/components/SideBar').replaceAll('\\', '\\\\'),
3425
},
3526
MetaBar: {
3627
name: 'MetaBar',
37-
source: resolve(ROOT, './ui/components/MetaBar'),
28+
source: resolve(ROOT, './ui/components/MetaBar').replaceAll('\\', '\\\\'),
3829
},
3930
CodeBox: {
4031
name: 'CodeBox',
41-
source: resolve(ROOT, './ui/components/CodeBox'),
32+
source: resolve(ROOT, './ui/components/CodeBox').replaceAll('\\', '\\\\'),
4233
},
4334
CodeTabs: {
4435
name: 'CodeTabs',

src/generators/web/utils/generate.mjs

Lines changed: 5 additions & 2 deletions
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

@@ -56,7 +56,10 @@ export default () => {
5656
// Import client-side CSS styles.
5757
// This ensures that styles used in the rendered app are loaded on the client.
5858
// The use of `new URL(...).pathname` resolves the absolute path for `entrypoint.jsx`.
59-
createImportDeclaration(null, resolve(ROOT, './ui/index.css')),
59+
createImportDeclaration(
60+
null,
61+
resolve(ROOT, './ui/index.css').replaceAll('\\', '\\\\')
62+
),
6063

6164
// Import `hydrate()` from Preact — needed to attach to server-rendered HTML.
6265
// This is a named import (not default), hence `false` as the third argument.

0 commit comments

Comments
 (0)