@qualcomm-ui/mdx-vite 2.17.1 → 2.17.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/dist/cli.js CHANGED
@@ -3504,7 +3504,7 @@ var {
3504
3504
  // src/ai-knowledge/env.ts
3505
3505
  import { config } from "dotenv";
3506
3506
  import { existsSync } from "node:fs";
3507
- import { join as join2, resolve } from "node:path";
3507
+ import { join as join2, resolve as resolve2 } from "node:path";
3508
3508
 
3509
3509
  // src/docs-plugin/internal/config-loader.ts
3510
3510
  import { cosmiconfigSync } from "cosmiconfig";
@@ -3946,43 +3946,41 @@ import chalk from "chalk";
3946
3946
  import { execSync } from "node:child_process";
3947
3947
  import { createHash } from "node:crypto";
3948
3948
  import { readFileSync } from "node:fs";
3949
- import { relative } from "node:path";
3949
+ import { resolve } from "node:path";
3950
3950
  import remarkFrontmatter from "remark-frontmatter";
3951
3951
  import remarkParse2 from "remark-parse";
3952
3952
  import remarkParseFrontmatter from "remark-parse-frontmatter";
3953
3953
  import remarkStringify2 from "remark-stringify";
3954
3954
  import { unified as unified2 } from "unified";
3955
- function getRepoRoot() {
3956
- return execSync("git rev-parse --show-toplevel", {
3957
- encoding: "utf-8"
3958
- }).trim();
3959
- }
3960
- function getGitMetadata(filePath, mode) {
3955
+ function buildGitMetadataMap(srcDir, mode) {
3956
+ const map = /* @__PURE__ */ new Map();
3961
3957
  if (mode === "off") {
3962
- return {};
3958
+ return map;
3963
3959
  }
3964
3960
  try {
3965
- const repoRoot = getRepoRoot();
3966
- const relativePath = relative(repoRoot, filePath);
3967
- const format = mode === "user-and-timestamp" ? "%cI%n%aN" : "%cI";
3968
- const result = execSync(
3969
- `git log -1 --format=${format} -- "${relativePath}"`,
3970
- {
3971
- encoding: "utf-8",
3972
- stdio: ["pipe", "pipe", "pipe"]
3961
+ const repoRoot = execSync("git rev-parse --show-toplevel", {
3962
+ encoding: "utf-8"
3963
+ }).trim();
3964
+ const format = mode === "user-and-timestamp" ? "%cI%x09%aN" : "%cI";
3965
+ const output = execSync(
3966
+ `git log --format="COMMIT%x09${format}" --name-only -- "${srcDir}/**/*.mdx"`,
3967
+ { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }
3968
+ );
3969
+ let currentMetadata = {};
3970
+ for (const line of output.split("\n")) {
3971
+ if (line.startsWith("COMMIT ")) {
3972
+ const parts = line.split(" ");
3973
+ currentMetadata = mode === "user-and-timestamp" ? { updatedBy: parts[2], updatedOn: parts[1] } : { updatedOn: parts[1] };
3974
+ } else if (line.trim()) {
3975
+ const absolutePath = resolve(repoRoot, line.trim());
3976
+ if (!map.has(absolutePath)) {
3977
+ map.set(absolutePath, currentMetadata);
3978
+ }
3973
3979
  }
3974
- ).trim();
3975
- if (!result) {
3976
- return {};
3977
- }
3978
- if (mode === "user-and-timestamp") {
3979
- const [updatedOn, updatedBy] = result.split("\n");
3980
- return { updatedBy, updatedOn };
3981
3980
  }
3982
- return { updatedOn: result };
3983
3981
  } catch {
3984
- return {};
3985
3982
  }
3983
+ return map;
3986
3984
  }
3987
3985
  var MarkdownFileReader = class {
3988
3986
  constructor(enabled, pageTimestampMetadata = "off") {
@@ -3990,6 +3988,7 @@ var MarkdownFileReader = class {
3990
3988
  this.pageTimestampMetadata = pageTimestampMetadata;
3991
3989
  }
3992
3990
  cachedFileCount = 0;
3991
+ gitMetadataMap = /* @__PURE__ */ new Map();
3993
3992
  logWarnings = true;
3994
3993
  mdxCache = {};
3995
3994
  hash(input) {
@@ -4056,7 +4055,7 @@ var MarkdownFileReader = class {
4056
4055
  const existingCache = this.mdxCache[filepath];
4057
4056
  const shouldFetchGitMetadata = !this.enabled || !existingCache;
4058
4057
  if (shouldFetchGitMetadata) {
4059
- const gitMetadata = getGitMetadata(filepath, this.pageTimestampMetadata);
4058
+ const gitMetadata = this.gitMetadataMap.get(filepath) ?? {};
4060
4059
  if (!frontmatter.updatedOn && gitMetadata.updatedOn) {
4061
4060
  frontmatter.updatedOn = gitMetadata.updatedOn;
4062
4061
  }
@@ -5363,6 +5362,10 @@ var SearchIndexer = class {
5363
5362
  this.config.routingStrategy
5364
5363
  );
5365
5364
  this._mdxFileCount = mdxFileGlob.length;
5365
+ this.fileCache.gitMetadataMap = buildGitMetadataMap(
5366
+ this.config.srcDir,
5367
+ this.fileCache.pageTimestampMetadata
5368
+ );
5366
5369
  const compiledFiles = mdxFileGlob.map((file) => this.compileMdxFile(file));
5367
5370
  const mdxIndex = compiledFiles.map((fileData) => fileData.pageSections).flat();
5368
5371
  filterFileGlob(
@@ -5418,7 +5421,7 @@ function loadKnowledgeConfigFromEnv(options) {
5418
5421
  resolvedConfig.appDirectory,
5419
5422
  resolvedConfig.pageDirectory
5420
5423
  );
5421
- if (!existsSync(resolve(routeDir))) {
5424
+ if (!existsSync(resolve2(routeDir))) {
5422
5425
  throw new Error(`Route directory ${routeDir} does not exist`);
5423
5426
  }
5424
5427
  const cliMetadata = parseCliMetadata(options.metadata);
@@ -5455,7 +5458,7 @@ function loadEnvironmentConfigs(options = {}) {
5455
5458
  resolvedConfig.appDirectory,
5456
5459
  resolvedConfig.pageDirectory
5457
5460
  );
5458
- if (!existsSync(resolve(routeDir))) {
5461
+ if (!existsSync(resolve2(routeDir))) {
5459
5462
  throw new Error(`Route directory ${routeDir} does not exist`);
5460
5463
  }
5461
5464
  if (!environments || environments.length === 0 || options.cliOptions?.outputPath) {
@@ -5502,7 +5505,7 @@ import AdmZip from "adm-zip";
5502
5505
  import chalk4 from "chalk";
5503
5506
  import { minimatch } from "minimatch";
5504
5507
  import { mkdir, readdir, readFile as readFile4, rm, stat, writeFile } from "node:fs/promises";
5505
- import { basename as basename2, dirname as dirname3, join as join7, relative as relative2, resolve as resolve5 } from "node:path";
5508
+ import { basename as basename2, dirname as dirname3, join as join7, relative, resolve as resolve6 } from "node:path";
5506
5509
  import remarkFrontmatter3 from "remark-frontmatter";
5507
5510
  import remarkMdx3 from "remark-mdx";
5508
5511
  import remarkParse4 from "remark-parse";
@@ -5533,7 +5536,7 @@ import { kebabCase } from "@qualcomm-ui/utils/change-case";
5533
5536
  // src/ai-knowledge/generator/utils.ts
5534
5537
  import { createHash as createHash2 } from "node:crypto";
5535
5538
  import { access, readFile } from "node:fs/promises";
5536
- import { dirname, join as join3, resolve as resolve2 } from "node:path";
5539
+ import { dirname, join as join3, resolve as resolve3 } from "node:path";
5537
5540
  import ts from "typescript";
5538
5541
  async function exists(dirPath) {
5539
5542
  return access(dirPath).then(() => true).catch(() => false);
@@ -5579,7 +5582,7 @@ function extractRelativeImports(content) {
5579
5582
  }
5580
5583
  async function resolveModulePath(importPath, fromFile) {
5581
5584
  const fromDir = dirname(fromFile);
5582
- const baseResolved = resolve2(fromDir, importPath);
5585
+ const baseResolved = resolve3(fromDir, importPath);
5583
5586
  const extensions = [".ts", ".tsx", ".js", ".jsx", ""];
5584
5587
  for (const ext of extensions) {
5585
5588
  const fullPath = baseResolved + ext;
@@ -5747,7 +5750,7 @@ function formatDemos(demosFolder) {
5747
5750
 
5748
5751
  // src/ai-knowledge/generator/doc-props-plugin.ts
5749
5752
  import { readFile as readFile3 } from "node:fs/promises";
5750
- import { dirname as dirname2, join as join5, resolve as resolve3 } from "node:path";
5753
+ import { dirname as dirname2, join as join5, resolve as resolve4 } from "node:path";
5751
5754
  import { visit as visit7 } from "unist-util-visit";
5752
5755
  function extractBestType(propInfo) {
5753
5756
  const type = propInfo.resolvedType?.prettyType || propInfo.type;
@@ -5791,7 +5794,7 @@ var PropFormatter = class {
5791
5794
  return this.docProps;
5792
5795
  }
5793
5796
  const config3 = getConfig();
5794
- const resolvedDocPropsPath = config3.docPropsPath ? await exists(config3.docPropsPath) ? config3.docPropsPath : resolve3(process.cwd(), config3.docPropsPath) : join5(dirname2(config3.routeDir), "doc-props.json");
5797
+ const resolvedDocPropsPath = config3.docPropsPath ? await exists(config3.docPropsPath) ? config3.docPropsPath : resolve4(process.cwd(), config3.docPropsPath) : join5(dirname2(config3.routeDir), "doc-props.json");
5795
5798
  if (!await exists(resolvedDocPropsPath)) {
5796
5799
  if (config3.verbose) {
5797
5800
  console.log(`Doc props file not found at: ${resolvedDocPropsPath}`);
@@ -6005,7 +6008,7 @@ import chalk3 from "chalk";
6005
6008
  import chokidar from "chokidar";
6006
6009
  import { glob } from "glob";
6007
6010
  import { readFileSync as readFileSync2 } from "node:fs";
6008
- import { join as join6, resolve as resolve4 } from "node:path";
6011
+ import { join as join6, resolve as resolve5 } from "node:path";
6009
6012
  import prettyMilliseconds from "pretty-ms";
6010
6013
  var isDev = process.env.NODE_ENV === "development";
6011
6014
  var VIRTUAL_MODULE_ID = "\0@qualcomm-ui/mdx-vite-plugin";
@@ -6066,12 +6069,12 @@ var PluginState = class {
6066
6069
  createIndexer(config3) {
6067
6070
  this.config = config3;
6068
6071
  this.configFilePath = config3.filePath;
6069
- this.docPropsFilePath = config3.typeDocProps ? fixPath(resolve4(this.cwd, config3.typeDocProps)) : "";
6070
- this.routesDir = fixPath(resolve4(config3.appDirectory, config3.pageDirectory));
6072
+ this.docPropsFilePath = config3.typeDocProps ? fixPath(resolve5(this.cwd, config3.typeDocProps)) : "";
6073
+ this.routesDir = fixPath(resolve5(config3.appDirectory, config3.pageDirectory));
6071
6074
  this.knowledgeConfig = config3.knowledge;
6072
6075
  this.indexer = new SearchIndexer({
6073
6076
  ...config3,
6074
- srcDir: fixPath(resolve4(this.cwd, config3.appDirectory)),
6077
+ srcDir: fixPath(resolve5(this.cwd, config3.appDirectory)),
6075
6078
  typeDocProps: this.resolveDocProps()
6076
6079
  });
6077
6080
  const exportsConfig = config3.knowledge?.global?.exports;
@@ -6659,7 +6662,7 @@ var KnowledgeGenerator = class {
6659
6662
  if (excludePatterns.length === 0) {
6660
6663
  return false;
6661
6664
  }
6662
- const relativePath = relative2(this.config.routeDir, absolutePath);
6665
+ const relativePath = relative(this.config.routeDir, absolutePath);
6663
6666
  return excludePatterns.some(
6664
6667
  (pattern) => minimatch(relativePath, pattern, { matchBase: true })
6665
6668
  );
@@ -6668,7 +6671,7 @@ var KnowledgeGenerator = class {
6668
6671
  if (shouldExclude(dirPath)) {
6669
6672
  if (this.config.verbose) {
6670
6673
  console.log(
6671
- `Excluding directory: ${relative2(this.config.routeDir, dirPath)}`
6674
+ `Excluding directory: ${relative(this.config.routeDir, dirPath)}`
6672
6675
  );
6673
6676
  }
6674
6677
  return;
@@ -6906,7 +6909,7 @@ var KnowledgeGenerator = class {
6906
6909
  lines.push("");
6907
6910
  const fileContent = lines.join("\n");
6908
6911
  const fileName = `${kebabCase3(extraFile.id)}.md`;
6909
- const outfile = `${resolve5(this.config.outputPath)}/${fileName}`;
6912
+ const outfile = `${resolve6(this.config.outputPath)}/${fileName}`;
6910
6913
  await writeFile(outfile, fileContent, "utf-8");
6911
6914
  const stats = await stat(outfile);
6912
6915
  totalSize += stats.size / 1024;
@@ -7009,7 +7012,7 @@ var KnowledgeGenerator = class {
7009
7012
  lines.push("");
7010
7013
  const fileContent = lines.join("\n");
7011
7014
  const fileName = `${kebabCase3(page.id || page.name)}.md`;
7012
- const outfile = `${resolve5(this.config.outputPath)}/${fileName}`;
7015
+ const outfile = `${resolve6(this.config.outputPath)}/${fileName}`;
7013
7016
  await writeFile(outfile, fileContent, "utf-8");
7014
7017
  const stats = await stat(outfile);
7015
7018
  totalSize += stats.size / 1024;
@@ -7171,7 +7174,7 @@ Generated knowledge for ${configs.length} environment(s)`
7171
7174
  // src/ai-knowledge/open-web-ui/download-knowledge.ts
7172
7175
  import dotenv from "dotenv";
7173
7176
  import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
7174
- import { resolve as resolve6 } from "node:path";
7177
+ import { resolve as resolve7 } from "node:path";
7175
7178
 
7176
7179
  // src/ai-knowledge/open-web-ui/api.ts
7177
7180
  function isErrorResponse(response) {
@@ -7282,7 +7285,7 @@ var FilesApi = class {
7282
7285
  if (status.status === "completed" || status.status === "failed") {
7283
7286
  return status;
7284
7287
  }
7285
- await new Promise((resolve11) => setTimeout(resolve11, intervalMs));
7288
+ await new Promise((resolve12) => setTimeout(resolve12, intervalMs));
7286
7289
  }
7287
7290
  throw new Error(`File processing timed out after ${maxAttempts} attempts`);
7288
7291
  }
@@ -7496,7 +7499,7 @@ function addDownloadKnowledgeCommand() {
7496
7499
  const content = await filesApi.getDataContent(file.id);
7497
7500
  if (content?.content) {
7498
7501
  await writeFile2(
7499
- resolve6(opts.outputDir, fileName),
7502
+ resolve7(opts.outputDir, fileName),
7500
7503
  content.content,
7501
7504
  "utf-8"
7502
7505
  );
@@ -7512,7 +7515,7 @@ function addDownloadKnowledgeCommand() {
7512
7515
  import { createHash as createHash3 } from "node:crypto";
7513
7516
  import { writeFileSync } from "node:fs";
7514
7517
  import { access as access2, readdir as readdir2, readFile as readFile5, stat as stat2 } from "node:fs/promises";
7515
- import { resolve as resolve7 } from "node:path";
7518
+ import { resolve as resolve8 } from "node:path";
7516
7519
  import { setTimeout as setTimeout2 } from "node:timers/promises";
7517
7520
  import ora from "ora";
7518
7521
 
@@ -7719,7 +7722,7 @@ var Uploader = class {
7719
7722
  const files = await Promise.all(
7720
7723
  fileNames.map(async (name) => ({
7721
7724
  contents: await readFile5(
7722
- resolve7(this.config.knowledgeFilePath, name),
7725
+ resolve8(this.config.knowledgeFilePath, name),
7723
7726
  "utf-8"
7724
7727
  ),
7725
7728
  name
@@ -7771,7 +7774,7 @@ var Uploader = class {
7771
7774
  try {
7772
7775
  const fileId = knowledgeFile.id;
7773
7776
  const fileString = await readFile5(
7774
- resolve7(this.config.knowledgeFilePath, name),
7777
+ resolve8(this.config.knowledgeFilePath, name),
7775
7778
  "utf-8"
7776
7779
  );
7777
7780
  const spinner2 = ora(`Updating ${name}`).start();
@@ -7786,7 +7789,7 @@ var Uploader = class {
7786
7789
  }
7787
7790
  const spinner = ora(`Uploading ${name}`).start();
7788
7791
  const fileBuffer = await readFile5(
7789
- resolve7(this.config.knowledgeFilePath, name)
7792
+ resolve8(this.config.knowledgeFilePath, name)
7790
7793
  );
7791
7794
  let uploadedFileId = void 0;
7792
7795
  try {
@@ -7824,7 +7827,7 @@ var Uploader = class {
7824
7827
  }
7825
7828
  }
7826
7829
  async uploadKnowledge() {
7827
- const resolvedPath = resolve7(this.config.knowledgeFilePath);
7830
+ const resolvedPath = resolve8(this.config.knowledgeFilePath);
7828
7831
  if (!await access2(resolvedPath).then(() => true).catch(() => false)) {
7829
7832
  throw new Error(`File or folder not found at ${resolvedPath}`);
7830
7833
  }
@@ -7911,7 +7914,7 @@ Uploaded to ${successCount} integration(s)${failureCount > 0 ? `, ${failureCount
7911
7914
  const files = await uploader.filesApi.search("*");
7912
7915
  console.debug(`found ${files.length} files`);
7913
7916
  writeFileSync(
7914
- resolve7(uploader.config.knowledgeFilePath, "files.json"),
7917
+ resolve8(uploader.config.knowledgeFilePath, "files.json"),
7915
7918
  JSON.stringify(files, null, 2),
7916
7919
  "utf-8"
7917
7920
  );
@@ -7956,7 +7959,7 @@ Uploaded to ${successCount} integration(s)${failureCount > 0 ? `, ${failureCount
7956
7959
  // src/docs-plugin/generate-page-map.ts
7957
7960
  import { glob as glob2 } from "glob";
7958
7961
  import { writeFile as writeFile3 } from "node:fs/promises";
7959
- import { resolve as resolve8 } from "node:path";
7962
+ import { resolve as resolve9 } from "node:path";
7960
7963
  import { cwd } from "node:process";
7961
7964
  function addGeneratePageMapCommand() {
7962
7965
  program.command("generate-page-map").description(
@@ -7977,11 +7980,11 @@ function addGeneratePageMapCommand() {
7977
7980
  const configLoader = new ConfigLoader({ configFile: options.configFile });
7978
7981
  const resolvedConfig = configLoader.loadConfig();
7979
7982
  const routesDir = fixPath(
7980
- resolve8(resolvedConfig.appDirectory, resolvedConfig.pageDirectory)
7983
+ resolve9(resolvedConfig.appDirectory, resolvedConfig.pageDirectory)
7981
7984
  );
7982
7985
  const indexer = new SearchIndexer({
7983
7986
  ...resolvedConfig,
7984
- srcDir: fixPath(resolve8(cwd(), resolvedConfig.appDirectory)),
7987
+ srcDir: fixPath(resolve9(cwd(), resolvedConfig.appDirectory)),
7985
7988
  typeDocProps: {}
7986
7989
  });
7987
7990
  const files = glob2.sync(
@@ -7993,7 +7996,7 @@ function addGeneratePageMapCommand() {
7993
7996
  );
7994
7997
  indexer.buildIndex(files, true);
7995
7998
  await writeFile3(
7996
- resolve8(cwd(), options.output),
7999
+ resolve9(cwd(), options.output),
7997
8000
  JSON.stringify(indexer.pageMap, null, 2),
7998
8001
  "utf-8"
7999
8002
  );
@@ -8011,17 +8014,17 @@ function addGeneratePageMapCommand() {
8011
8014
  import { glob as glob3 } from "glob";
8012
8015
  import { uniqBy } from "lodash-es";
8013
8016
  import { writeFile as writeFile4 } from "node:fs/promises";
8014
- import { resolve as resolve10 } from "node:path";
8017
+ import { resolve as resolve11 } from "node:path";
8015
8018
  import { dedent as dedent2 } from "@qualcomm-ui/utils/dedent";
8016
8019
 
8017
8020
  // src/react-demo-plugin/demo-plugin-utils.ts
8018
8021
  import chalk5 from "chalk";
8019
8022
  import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
8020
- import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve9, sep } from "node:path";
8023
+ import { dirname as dirname4, join as join8, relative as relative2, resolve as resolve10, sep } from "node:path";
8021
8024
  import * as ts2 from "typescript";
8022
8025
  import { pascalCase } from "@qualcomm-ui/utils/change-case";
8023
8026
  function extractPageId(filePath, routesDir) {
8024
- const relativePath = relative3(routesDir, filePath);
8027
+ const relativePath = relative2(routesDir, filePath);
8025
8028
  const pathParts = relativePath.split(sep);
8026
8029
  if (pathParts.includes("demos")) {
8027
8030
  const demosIndex = pathParts.indexOf("demos");
@@ -8074,7 +8077,7 @@ function generateLazyDemoLoader(demoPages) {
8074
8077
  }
8075
8078
  async function generateLazyDemoMap(options) {
8076
8079
  const routesDir = options.routesDir;
8077
- const outputPath = resolve10(options.output);
8080
+ const outputPath = resolve11(options.output);
8078
8081
  console.log(`Scanning for demo pages in: ${routesDir}`);
8079
8082
  const demoPages = await scanForDemoPages({ routesDir });
8080
8083
  console.log(`Found ${demoPages.length} pages with demos`);