Skip to content

Commit

Permalink
Merge pull request #23695 from T99/next
Browse files Browse the repository at this point in the history
Fix: Added more portable path handling code to better support win32-style paths.
  • Loading branch information
valentinpalkovic authored Oct 2, 2023
2 parents 5cb3679 + 4c56698 commit e2aa53e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getFontFaceDeclarations(options: LoaderOptions, rootContex
const localFontSrc = options.props.src as LocalFontSrc;

// Parent folder relative to the root context
const parentFolder = options.filename.split('/').slice(0, -1).join('/').replace(rootContext, '');
const parentFolder = path.dirname(options.filename).replace(rootContext, '');

const { validateData } = require('../utils/local-font-utils');
const { weight, style, variable } = validateData('', options.props);
Expand All @@ -23,9 +23,13 @@ export async function getFontFaceDeclarations(options: LoaderOptions, rootContex
6
)}`;

const arePathsWin32Format = /^[a-z]:\\/iu.test(options.filename);
const cleanWin32Path = (pathString: string): string =>
arePathsWin32Format ? pathString.replace(/\\/gu, '/') : pathString;

const getFontFaceCSS = () => {
if (typeof localFontSrc === 'string') {
const localFontPath = path.join(parentFolder, localFontSrc);
const localFontPath = cleanWin32Path(path.join(parentFolder, localFontSrc));

return `@font-face {
font-family: ${id};
Expand All @@ -34,7 +38,7 @@ export async function getFontFaceDeclarations(options: LoaderOptions, rootContex
}
return localFontSrc
.map((font) => {
const localFontPath = path.join(parentFolder, font.path);
const localFontPath = cleanWin32Path(path.join(parentFolder, font.path));

return `@font-face {
font-family: ${id};
Expand Down

0 comments on commit e2aa53e

Please sign in to comment.