Home / Function/ rehypeNpmCommand() — ui Function Reference

rehypeNpmCommand() — ui Function Reference

Architecture documentation for the rehypeNpmCommand() function in rehype-npm-command.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  35d9ad6a_3613_d958_87c5_5df2ab7a7e35["rehypeNpmCommand()"]
  fd3c35e5_783f_b703_3e23_80ad367b4a7a["rehype-npm-command.ts"]
  35d9ad6a_3613_d958_87c5_5df2ab7a7e35 -->|defined in| fd3c35e5_783f_b703_3e23_80ad367b4a7a
  style 35d9ad6a_3613_d958_87c5_5df2ab7a7e35 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

deprecated/www/lib/rehype-npm-command.ts lines 4–99

export function rehypeNpmCommand() {
  return (tree: UnistTree) => {
    visit(tree, (node: UnistNode) => {
      if (node.type !== "element" || node?.tagName !== "pre") {
        return
      }

      // npm install.
      if (node.properties?.["__rawString__"]?.startsWith("npm install")) {
        const npmCommand = node.properties?.["__rawString__"]
        node.properties["__npmCommand__"] = npmCommand
        node.properties["__yarnCommand__"] = npmCommand.replace(
          "npm install",
          "yarn add"
        )
        node.properties["__pnpmCommand__"] = npmCommand.replace(
          "npm install",
          "pnpm add"
        )
        node.properties["__bunCommand__"] = npmCommand.replace(
          "npm install",
          "bun add"
        )
      }

      // npx create-.
      if (node.properties?.["__rawString__"]?.startsWith("npx create-")) {
        const npmCommand = node.properties?.["__rawString__"]
        node.properties["__npmCommand__"] = npmCommand
        node.properties["__yarnCommand__"] = npmCommand.replace(
          "npx create-",
          "yarn create "
        )
        node.properties["__pnpmCommand__"] = npmCommand.replace(
          "npx create-",
          "pnpm create "
        )
        node.properties["__bunCommand__"] = npmCommand.replace(
          "npx",
          "bunx --bun"
        )
      }

      // npm create.
      if (node.properties?.["__rawString__"]?.startsWith("npm create")) {
        const npmCommand = node.properties?.["__rawString__"]
        node.properties["__npmCommand__"] = npmCommand
        node.properties["__yarnCommand__"] = npmCommand.replace(
          "npm create",
          "yarn create"
        )
        node.properties["__pnpmCommand__"] = npmCommand.replace(
          "npm create",
          "pnpm create"
        )
        node.properties["__bunCommand__"] = npmCommand.replace(
          "npm create",
          "bun create"
        )
      }

      // npx.
      if (
        node.properties?.["__rawString__"]?.startsWith("npx") &&
        !node.properties?.["__rawString__"]?.startsWith("npx create-")
      ) {
        const npmCommand = node.properties?.["__rawString__"]
        node.properties["__npmCommand__"] = npmCommand
        node.properties["__yarnCommand__"] = npmCommand
        node.properties["__pnpmCommand__"] = npmCommand.replace(
          "npx",
          "pnpm dlx"
        )
        node.properties["__bunCommand__"] = npmCommand.replace(
          "npx",
          "bunx --bun"
        )
      }

      // npm run.
      if (node.properties?.["__rawString__"]?.startsWith("npm run")) {

Subdomains

Frequently Asked Questions

What does rehypeNpmCommand() do?
rehypeNpmCommand() is a function in the ui codebase, defined in deprecated/www/lib/rehype-npm-command.ts.
Where is rehypeNpmCommand() defined?
rehypeNpmCommand() is defined in deprecated/www/lib/rehype-npm-command.ts at line 4.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free