Files
klz-cables.com/.pnpm-store/v10/files/f7/b1b7710c4ed2d5093fb216599c905d65cda580fa833ea6a1a651aa8fd126a70d9da6d6dcf36c381dd0961bbf35c03e8a7933f584c1a5dbb275752dcc261515
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

56 lines
2.4 KiB
Plaintext

import crypto from 'crypto';
import path from 'path';
import { parsePayloadComponent } from './parsePayloadComponent.js';
/**
* Normalizes the component path based on the import map's base directory path.
*/ function getAdjustedComponentPath(importMapToBaseDirPath, componentPath) {
// Normalize input paths to use forward slashes
const normalizedBasePath = importMapToBaseDirPath.replace(/\\/g, '/');
const normalizedComponentPath = componentPath.replace(/\\/g, '/');
// Base path starts with './' - preserve the './' prefix
// => import map is in a subdirectory of the base directory, or in the same directory as the base directory
if (normalizedBasePath.startsWith('./')) {
// Remove './' from component path if it exists
const cleanComponentPath = normalizedComponentPath.startsWith('./') ? normalizedComponentPath.substring(2) : normalizedComponentPath;
// Join the paths to preserve the './' prefix
return `${normalizedBasePath}${cleanComponentPath}`;
}
return path.posix.join(normalizedBasePath, normalizedComponentPath);
}
/**
* Adds a payload component to the import map.
*/ export function addPayloadComponentToImportMap({ importMap, importMapToBaseDirPath, imports, payloadComponent }) {
if (!payloadComponent) {
return null;
}
const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent);
if (importMap[componentPath + '#' + exportName]) {
return null;
}
const importIdentifier = exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex');
importMap[componentPath + '#' + exportName] = importIdentifier;
const isRelativePath = componentPath.startsWith('.') || componentPath.startsWith('/');
if (isRelativePath) {
const adjustedComponentPath = getAdjustedComponentPath(importMapToBaseDirPath, componentPath);
imports[importIdentifier] = {
path: adjustedComponentPath,
specifier: exportName
};
return {
path: adjustedComponentPath,
specifier: exportName
};
} else {
// Tsconfig alias or package import, e.g. '@payloadcms/ui' or '@/components/MyComponent'
imports[importIdentifier] = {
path: componentPath,
specifier: exportName
};
return {
path: componentPath,
specifier: exportName
};
}
}
//# sourceMappingURL=addPayloadComponentToImportMap.js.map