unplugin-docubook 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -108
- package/dist/astro.cjs +1 -1
- package/dist/astro.cjs.map +1 -1
- package/dist/astro.js +1 -1
- package/dist/astro.js.map +1 -1
- package/dist/bun.cjs +1 -1
- package/dist/bun.cjs.map +1 -1
- package/dist/bun.js +1 -1
- package/dist/bun.js.map +1 -1
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.js +1 -1
- package/dist/esbuild.js.map +1 -1
- package/dist/farm.cjs +1 -1
- package/dist/farm.cjs.map +1 -1
- package/dist/farm.js +1 -1
- package/dist/farm.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.cjs.map +1 -1
- package/dist/next.js +1 -1
- package/dist/next.js.map +1 -1
- package/dist/nuxt.cjs +1 -1
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.js +1 -1
- package/dist/nuxt.js.map +1 -1
- package/dist/rolldown.cjs +1 -1
- package/dist/rolldown.cjs.map +1 -1
- package/dist/rolldown.js +1 -1
- package/dist/rolldown.js.map +1 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.js +1 -1
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +1 -1
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.js +1 -1
- package/dist/rspack.js.map +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.js +1 -1
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/esbuild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/esbuild.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createEsbuildPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,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EA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAhF7C;AAiFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,kBAAQ,oBAAoB,eAAe;","names":["registry","names"]}
|
|
1
|
+
{"version":3,"sources":["../src/esbuild.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createEsbuildPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,2BAA2B;;;ACEpC,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAA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,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF/FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,kBAAQ,oBAAoB,eAAe;","names":["registry","names"]}
|
package/dist/farm.cjs
CHANGED
|
@@ -129,7 +129,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
129
129
|
for (const name of componentNames) {
|
|
130
130
|
const meta = registry[name];
|
|
131
131
|
if (!meta) continue;
|
|
132
|
-
const fullPath = `${importSource}${meta.path}
|
|
132
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
133
133
|
if (!pathToExports.has(fullPath)) {
|
|
134
134
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
135
135
|
}
|
package/dist/farm.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/farm.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createFarmPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAiC;;;ACEjC,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GA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AAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,mBAAQ,mCAAiB,eAAe;","names":["import_unplugin","registry","names","exports"]}
|
|
1
|
+
{"version":3,"sources":["../src/farm.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createFarmPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAiC;;;ACEjC,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAA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AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,mBAAQ,mCAAiB,eAAe;","names":["import_unplugin","registry","names","exports"]}
|
package/dist/farm.js
CHANGED
|
@@ -108,7 +108,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
108
108
|
for (const name of componentNames) {
|
|
109
109
|
const meta = registry[name];
|
|
110
110
|
if (!meta) continue;
|
|
111
|
-
const fullPath = `${importSource}${meta.path}
|
|
111
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
112
112
|
if (!pathToExports.has(fullPath)) {
|
|
113
113
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
114
114
|
}
|
package/dist/farm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/farm.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createFarmPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,wBAAwB;;;ACEjC,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,S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5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,eAAQ,iBAAiB,eAAe;","names":["registry","names"]}
|
|
1
|
+
{"version":3,"sources":["../src/farm.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createFarmPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,wBAAwB;;;ACEjC,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,SAAS;AAAA,IAC9C,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,MAAM,SAAS;AAAA,IAClD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,OAAO,EAAE,SAAS,CAAC,OAAO,GAAG,MAAM,SAAS;AAAA,IAC5C,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,SAAS;AAAA,IAC9C,MAAM,E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AEA,QAAM,QAAkB,CAAC;AACzB,aAAW,CAAC,MAAM,OAAO,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAK,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AArF7C;AAsFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF/FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,eAAQ,iBAAiB,eAAe;","names":["registry","names"]}
|
package/dist/index.cjs
CHANGED
|
@@ -128,7 +128,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
128
128
|
for (const name of componentNames) {
|
|
129
129
|
const meta = registry[name];
|
|
130
130
|
if (!meta) continue;
|
|
131
|
-
const fullPath = `${importSource}${meta.path}
|
|
131
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
132
132
|
if (!pathToExports.has(fullPath)) {
|
|
133
133
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
134
134
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";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ClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAhF7C;AAiFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,oDAAe,eAAe;AAEtE,IAAO,gBAAQ;","names":["registry","names","exports"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC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AC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF/FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,oDAAe,eAAe;AAEtE,IAAO,gBAAQ;","names":["registry","names","exports"]}
|
package/dist/index.js
CHANGED
|
@@ -105,7 +105,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
105
105
|
for (const name of componentNames) {
|
|
106
106
|
const meta = registry[name];
|
|
107
107
|
if (!meta) continue;
|
|
108
|
-
const fullPath = `${importSource}${meta.path}
|
|
108
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
109
109
|
if (!pathToExports.has(fullPath)) {
|
|
110
110
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
111
111
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAEA,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,G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1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,+BAAe,eAAe;AAEtE,IAAO,gBAAQ;","names":["registry","names"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAEA,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,SAAS;AAAA,IAC9C,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,MAAM,SAAS;AAAA,IAClD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,OAAO,E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,IAAI,CAAC;AAAA,IACzC;AACA,eAAW,OAAO,KAAK,SAAS;AAC5B,oBAAc,IAAI,QAAQ,EAAG,IAAI,GAAG;AAAA,IACxC;AAAA,EACJ;AAEA,QAAM,QAAkB,CAAC;AACzB,aAAW,CAAC,MAAM,OAAO,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAK,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AArF7C;AAsFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF/FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,+BAAe,eAAe;AAEtE,IAAO,gBAAQ;","names":["registry","names"]}
|
package/dist/next.cjs
CHANGED
|
@@ -129,7 +129,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
129
129
|
for (const name of componentNames) {
|
|
130
130
|
const meta = registry[name];
|
|
131
131
|
if (!meta) continue;
|
|
132
|
-
const fullPath = `${importSource}${meta.path}
|
|
132
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
133
133
|
if (!pathToExports.has(fullPath)) {
|
|
134
134
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
135
135
|
}
|
package/dist/next.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/next.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAoC;;;ACEpC,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,SAAS;AAAA,IAC9C,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,MAAM,SAAS;AAAA,IAClD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAA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ACzC;AACA,eAAW,OAAO,KAAK,SAAS;AAC5B,oBAAc,IAAI,QAAQ,EAAG,IAAI,GAAG;AAAA,IACxC;AAAA,EACJ;AAEA,QAAM,QAAkB,CAAC;AACzB,aAAW,CAAC,MAAMC,QAAO,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAKA,QAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAhF7C;AAiFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,mBAAQ,sCAAoB,eAAe;","names":["import_unplugin","registry","names","exports"]}
|
|
1
|
+
{"version":3,"sources":["../src/next.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,m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AAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AArF7C;AAsFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF/FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,mBAAQ,sCAAoB,eAAe;","names":["import_unplugin","registry","names","exports"]}
|
package/dist/next.js
CHANGED
|
@@ -108,7 +108,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
108
108
|
for (const name of componentNames) {
|
|
109
109
|
const meta = registry[name];
|
|
110
110
|
if (!meta) continue;
|
|
111
|
-
const fullPath = `${importSource}${meta.path}
|
|
111
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
112
112
|
if (!pathToExports.has(fullPath)) {
|
|
113
113
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
114
114
|
}
|
package/dist/next.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/next.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,2BAA2B;;;ACEpC,SAAS,sBAAsB;;;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AAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAhF7C;AAiFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,eAAQ,oBAAoB,eAAe;","names":["registry","names"]}
|
|
1
|
+
{"version":3,"sources":["../src/next.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,2BAA2B;;;ACEpC,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW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1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF/FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,eAAQ,oBAAoB,eAAe;","names":["registry","names"]}
|
package/dist/nuxt.cjs
CHANGED
|
@@ -132,7 +132,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
132
132
|
for (const name of componentNames) {
|
|
133
133
|
const meta = registry[name];
|
|
134
134
|
if (!meta) continue;
|
|
135
|
-
const fullPath = `${importSource}${meta.path}
|
|
135
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
136
136
|
if (!pathToExports.has(fullPath)) {
|
|
137
137
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
138
138
|
}
|
package/dist/nuxt.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nuxt.ts","../src/vite.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts","../src/webpack.ts"],"sourcesContent":["import type { Options } from './types'\nimport { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'\nimport vite from './vite'\nimport webpack from './webpack'\n\nexport default defineNuxtModule<Options>({\n meta: {\n name: 'nuxt-unplugin-docubook',\n configKey: 'docubookMdx',\n },\n defaults: {},\n setup(options, _nuxt) {\n addVitePlugin(() => vite(options))\n addWebpackPlugin(() => webpack(options))\n },\n})\n","import { createVitePlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createVitePlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n","import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(unpluginFactory)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAkE;;;ACDlE,IAAAA,mBAAiC;;;ACEjC,sBAA+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;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAhF7C;AAiFI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,WAAW,QAAQ,gBAAgB;AAEjF,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,WAAW,QAAQ,gBAAgB;AAE1G,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AF1FO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,mBAAQ,mCAAiB,eAAe;;;AIH/C,IAAAC,mBAAoC;AAGpC,IAAO,sBAAQ,sCAAoB,eAAe;;;ALElD,IAAO,mBAAQ,6BAA0B;AAAA,EACrC,MAAM;AAAA,IACF,MAAM;AAAA,IACN,WAAW;AAAA,EACf;AAAA,EACA,UAAU,CAAC;AAAA,EACX,MAAM,SAAS,OAAO;AAClB,kCAAc,MAAM,aAAK,OAAO,CAAC;AACjC,qCAAiB,MAAM,gBAAQ,OAAO,CAAC;AAAA,EAC3C;AACJ,CAAC;","names":["import_unplugin","registry","names","exports","import_unplugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/nuxt.ts","../src/vite.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts","../src/webpack.ts"],"sourcesContent":["import type { Options } from './types'\nimport { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'\nimport vite from './vite'\nimport webpack from './webpack'\n\nexport default defineNuxtModule<Options>({\n meta: {\n name: 'nuxt-unplugin-docubook',\n configKey: 'docubookMdx',\n },\n defaults: {},\n setup(options, _nuxt) {\n addVitePlugin(() => vite(options))\n addWebpackPlugin(() => webpack(options))\n },\n})\n","import { createVitePlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createVitePlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nconst registryCache = new Map<Framework, Record<string, ComponentMeta>>()\nconst regexCache = new Map<Framework, RegExp>()\n\nexport function getComponentRegistry(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): Record<string, ComponentMeta> {\n if (!customComponents || Object.keys(customComponents).length === 0) {\n const cached = registryCache.get(framework)\n if (cached) return cached\n const registry = createRegistry(framework)\n registryCache.set(framework, registry)\n return registry\n }\n // Merge custom components with built-in (custom overrides built-in)\n return { ...createRegistry(framework), ...customComponents }\n}\n\nexport function buildComponentDetectionRegex(\n framework: Framework = 'react',\n customComponents?: Record<string, ComponentMeta>,\n): RegExp {\n // Custom components: always build fresh regex (not cached)\n if (customComponents && Object.keys(customComponents).length > 0) {\n const registry = getComponentRegistry(framework, customComponents)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n }\n\n const cached = regexCache.get(framework)\n if (cached) {\n cached.lastIndex = 0 // Reset regex state because of /g flag\n return cached\n }\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n const regex = new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n regexCache.set(framework, regex)\n return regex\n}\n","import type { Options, Framework } from '../types'\nimport type { ComponentMeta } from './registry'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\n/**\n * Strip content zones where component tags should NOT be detected:\n * - Fenced code blocks (triple backticks)\n * - Inline code (single backticks)\n * - MDX comments\n * - HTML comments\n * - Existing import/export statements\n */\nfunction stripIgnoredZones(code: string): string {\n return code\n .replace(/```[\\s\\S]*?```/g, '') // fenced code blocks\n .replace(/`[^`]+`/g, '') // inline code\n .replace(/\\{\\/\\*[\\s\\S]*?\\*\\/\\}/g, '') // MDX comments {/* */}\n .replace(/<!--[\\s\\S]*?-->/g, '') // HTML comments\n .replace(/^import\\s.+$/gm, '') // existing imports\n .replace(/^export\\s.+$/gm, '') // exports\n}\n\nexport function detectComponents(\n code: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string[] {\n const strippedCode = stripIgnoredZones(code)\n const regex = buildComponentDetectionRegex(framework, customComponents)\n const registry = getComponentRegistry(framework, customComponents)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(strippedCode)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n customComponents?: Record<string, ComponentMeta>,\n): string {\n const registry = getComponentRegistry(framework, customComponents)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n // If path starts with '/', it's relative to importSource.\n // Otherwise, it's a full import path (e.g. '@/components/MyComp' or 'my-lib')\n const fullPath = meta.path.startsWith('/')\n ? `${importSource}${meta.path}`\n : meta.path\n\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework, options.customComponents)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework, options.customComponents)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n\n","import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(unpluginFactory)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAkE;;;ACDlE,IAAAA,mBAAiC;;;ACEjC,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,SAAS;AAAA,IAC9C,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,MAAM,SAAS;AAAA,IAClD,WAAW,EAA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BAAQ,6BAA0B;AAAA,EACrC,MAAM;AAAA,IACF,MAAM;AAAA,IACN,WAAW;AAAA,EACf;AAAA,EACA,UAAU,CAAC;AAAA,EACX,MAAM,SAAS,OAAO;AAClB,kCAAc,MAAM,aAAK,OAAO,CAAC;AACjC,qCAAiB,MAAM,gBAAQ,OAAO,CAAC;AAAA,EAC3C;AACJ,CAAC;","names":["import_unplugin","registry","names","exports","import_unplugin"]}
|
package/dist/nuxt.js
CHANGED
|
@@ -111,7 +111,7 @@ function generateImports(componentNames, importSource, framework = DEFAULT_FRAME
|
|
|
111
111
|
for (const name of componentNames) {
|
|
112
112
|
const meta = registry[name];
|
|
113
113
|
if (!meta) continue;
|
|
114
|
-
const fullPath = `${importSource}${meta.path}
|
|
114
|
+
const fullPath = meta.path.startsWith("/") ? `${importSource}${meta.path}` : meta.path;
|
|
115
115
|
if (!pathToExports.has(fullPath)) {
|
|
116
116
|
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
117
117
|
}
|