UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

29 lines (28 loc) 1.72 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { findAndRemoveImports } from '../mdx/snippets/findAndRemoveImports.js'; export const enhanceSnippetsWithImportNames = (ast, snippets) => __awaiter(void 0, void 0, void 0, function* () { const { importMap } = yield findAndRemoveImports(structuredClone(ast)); return snippets.map((snippet) => { if (snippet.importNames && snippet.importNames.length > 0) { return snippet; } let importSpecifiers = importMap[snippet.path]; if (!importSpecifiers) { const pathWithSlash = snippet.path.startsWith('/') ? snippet.path : `/${snippet.path}`; const pathWithoutSlash = snippet.path.startsWith('/') ? snippet.path.slice(1) : snippet.path; importSpecifiers = importMap[pathWithSlash] || importMap[pathWithoutSlash]; } if (importSpecifiers && importSpecifiers.length > 0) { return Object.assign(Object.assign({}, snippet), { importNames: importSpecifiers.map((spec) => spec.name) }); } return snippet; }); });