Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/generators/web/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { parse, relative, sep, dirname } from 'node:path';
import { resolve } from 'node:path/posix';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

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

/**
* @typedef {Object} JSXImportConfig
Expand Down
6 changes: 5 additions & 1 deletion src/generators/web/utils/generate.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'node:path/posix';
import { resolve } from 'node:path';

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

Expand All @@ -14,6 +14,10 @@ export const createImportDeclaration = (
source,
useDefault = true
) => {
// '\' characters shouldn't escape the next character,
// but rather be treated as slashes.
source = source.replaceAll('\\', '\\\\');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to PATH or something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backslashes (Windows paths), when evaluated via Function, escape the next character, so we need to escape them.


// Side-effect-only import (CSS)
if (!importName) {
return `import "${source}";`;
Expand Down
Loading