Skip to content

Commit

Permalink
Remove nested package imports (#168)
Browse files Browse the repository at this point in the history
Fixes: #169

`@llm-ui/react/{core,examples,throttle}` -> `@llm-ui/react`
`@llm-ui/code/shikiBundles/{allLangs,allThemes}` -> `@llm-ui/code`

Removes exports more than one level deep (e.g. `@llm-ui/react/core`)
since they don't work with older moduleResolution settings in TypeScript
(which react-script uses by default).
  • Loading branch information
richardgill authored May 12, 2024
1 parent 9f452fb commit 999004c
Show file tree
Hide file tree
Showing 35 changed files with 98 additions and 119 deletions.
9 changes: 9 additions & 0 deletions .changeset/sweet-bats-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@llm-ui/code": minor
"@llm-ui/react": minor
---

@llm-ui/react/{core,examples,throttle} -> @llm-ui/react
@llm-ui/code/shikiBundles/{allLangs,allThemes} -> @llm-ui/code

Removes exports more than one level deep (e.g. @llm-ui/react/core) since they don't work with older moduleResolution settings in TypeScript (which react-script uses by default).
2 changes: 1 addition & 1 deletion apps/www/src/components/examples/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
findPartialButtons,
parseCompleteButtons,
} from "@llm-ui/buttons";
import type { LLMOutputBlock, LLMOutputComponent } from "@llm-ui/react/core";
import type { LLMOutputBlock, LLMOutputComponent } from "@llm-ui/react";
import { Button } from "../ui/Button";

type OnClick = (buttonText: string) => void;
Expand Down
5 changes: 1 addition & 4 deletions apps/www/src/components/examples/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {
findPartialCodeBlock,
parseCompleteMarkdownCodeBlock,
} from "@llm-ui/code";
import {
type LLMOutputBlock,
type LLMOutputComponent,
} from "@llm-ui/react/core";
import { type LLMOutputBlock, type LLMOutputComponent } from "@llm-ui/react";
import { CodeBlock } from "../ui/custom/CodeBlock";

const ShikiBlockComponent: LLMOutputComponent = ({ blockMatch }) => {
Expand Down
10 changes: 4 additions & 6 deletions apps/www/src/components/examples/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { multipleStars } from "@/animations/stars";
import { cn, delay } from "@/lib/utils";
import { markdownLookBack } from "@llm-ui/markdown";
import {
stringToTokenArray,
useLLMOutput,
useStreamTokenArray,
type BlockMatch,
type LLMOutputBlock,
type UseLLMOutputReturn,
} from "@llm-ui/react/core";
import {
stringToTokenArray,
useStreamTokenArray,
type TokenWithDelay,
type UseLLMOutputReturn,
type UseStreamTokenArrayOptions,
type UseStreamWithProbabilitiesOptions,
} from "@llm-ui/react/examples";
} from "@llm-ui/react";
import React, {
Fragment,
useCallback,
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/examples/ExampleMdx.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from "@/lib/utils";
import type { UseStreamWithProbabilitiesOptions } from "@llm-ui/react/examples";
import type { UseStreamWithProbabilitiesOptions } from "@llm-ui/react";
import {
ExampleSideBySide as ExampleSideBySideOriginal,
ExampleTabs as ExampleTabsOriginal,
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/examples/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from "@/lib/utils";
import { type LLMOutputComponent } from "@llm-ui/react/core";
import { type LLMOutputComponent } from "@llm-ui/react";
import ReactMarkdown, { type Options } from "react-markdown";
import remarkGfm from "remark-gfm";

Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/examples/contants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ProbabilityOptions } from "@llm-ui/react/examples";
import type { ProbabilityOptions } from "@llm-ui/react";

export const defaultExampleProbs: ProbabilityOptions = {
delayMsProbabilities: [{ delayMs: 90, prob: 1 }],
Expand Down
5 changes: 1 addition & 4 deletions apps/www/src/components/examples/examples.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { HIDDEN_CHAR } from "@/constants/constants";
import {
stringToTokenArray,
type TokenWithDelay,
} from "@llm-ui/react/examples";
import { stringToTokenArray, type TokenWithDelay } from "@llm-ui/react";
import { defaultExampleProbs } from "./contants";

const ctaBeforePause = `# llm-ui
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/examples/throttle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { throttleBasic } from "@llm-ui/react/throttle";
import { throttleBasic } from "@llm-ui/react";

export type ThrottleType = "buffered" | "low-lag";

Expand Down
3 changes: 1 addition & 2 deletions apps/www/src/components/shikiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ShikiProps } from "@llm-ui/code";
import { loadHighlighter } from "@llm-ui/code";
import { allLangs, allLangsAlias } from "@llm-ui/code/shikiBundles/allLangs";
import { allLangs, allLangsAlias, loadHighlighter } from "@llm-ui/code";
import { getHighlighterCore } from "shiki/core";
import githubDark from "shiki/themes/github-dark.mjs";
import githubLight from "shiki/themes/github-light.mjs";
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/content/docs/advanced/example-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Example:
<CodeBlockInline>

```ts
import { useStreamExample } from "@llm-ui/react/examples";
import { useStreamExample } from "@llm-ui/react";

const Example = () => {
const example = "# Hello llm-ui!";
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/content/docs/advanced/throttle-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ llm-ui comes with a built-in throttle function:
`throttleBasic` is the default throttle function for llm-ui.

```ts
import { throttleBasic } from "@llm-ui/react/throttle";
import { throttleBasic } from "@llm-ui/react";

const throttle = throttleBasic({
readAheadChars: 10,
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/content/docs/blocks/code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Change the import:

```tsx
// Before:
import { allThemes } from "@llm-ui/code/shikiBundles/allThemes";
import { allThemes } from "@llm-ui/code";

// After:
import githubDark from "shiki/themes/github-dark.mjs";
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/content/docs/llm-output-hook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Example:
<CodeBlockInline>

```typescript
import { useLLMOutput } from "@llm-ui/react/core";
import { useLLMOutput } from "@llm-ui/react";

const { blockMatches } = useLLMOutput({
llmOutput: "llm output",
Expand Down
12 changes: 6 additions & 6 deletions apps/www/src/snippets/markdownBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default Example`.replaceAll("STEP1", step1Replace);

const step2Imports = `import {
useLLMOutput,
} from "@llm-ui/react/core";
} from "@llm-ui/react";
import { markdownLookBack } from "@llm-ui/markdown";
import { useStreamExample } from "@llm-ui/react/examples";
import { useStreamExample } from "@llm-ui/react";
`;

export const markdownStep1 = markdownQuickStart;
Expand All @@ -48,12 +48,12 @@ export const markdownStep2 = `${step2Imports}\n\n${getLlmUiOutputUsage("// from

export const fullImports = `import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { type LLMOutputComponent } from "@llm-ui/react/core";
import {
useLLMOutput,
} from "@llm-ui/react/core";
import { markdownLookBack } from "@llm-ui/markdown";
import { useStreamExample } from "@llm-ui/react/examples";`;
useStreamExample,
type LLMOutputComponent
} from "@llm-ui/react";
import { markdownLookBack } from "@llm-ui/markdown";`;

const step1Comment = "// -------Step 1: Create a markdown component-------";
const step2Comment = "// -------Step 2: Render markdown with llm-ui-------";
Expand Down
31 changes: 18 additions & 13 deletions apps/www/src/snippets/quickStart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const markdownImports = `import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { type LLMOutputComponent } from "@llm-ui/react/core";
import { type LLMOutputComponent } from "@llm-ui/react";
`;

export const markdownComponent = `// Customize this component with your own styling
Expand All @@ -12,12 +12,16 @@ const MarkdownComponent: LLMOutputComponent = ({ blockMatch }) => {
export const markdownQuickStart = `${markdownImports}\n\n${markdownComponent}`;

export const codeblockImports = `import type { CodeToHtmlOptions } from "@llm-ui/code";
import { loadHighlighter, useCodeBlockToHtml } from "@llm-ui/code";
import { allLangs, allLangsAlias } from "@llm-ui/code/shikiBundles/allLangs";
// WARNING: Importing allThemes increases your bundle size
// see: https://llm-ui.com/docs/blocks/code#bundle-size
import { allThemes } from "@llm-ui/code/shikiBundles/allThemes";
import { type LLMOutputComponent } from "@llm-ui/react/core";
import {
loadHighlighter,
useCodeBlockToHtml,
allLangs,
allLangsAlias,
// WARNING: Importing allThemes increases your bundle size
// see: https://llm-ui.com/docs/blocks/code#bundle-size
allThemes
} from "@llm-ui/code";
import { type LLMOutputComponent } from "@llm-ui/react";
import parseHtml from "html-react-parser";
import { getHighlighterCore } from "shiki/core";
import getWasm from "shiki/wasm";`;
Expand Down Expand Up @@ -61,8 +65,7 @@ export const llmUiOutputImports = `import {
findPartialCodeBlock,
} from "@llm-ui/code";
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput } from "@llm-ui/react/core";
import { useStreamExample } from "@llm-ui/react/examples";`;
import { useLLMOutput, useStreamExample } from "@llm-ui/react";`;

export const introExampleHidden = `## Python
Expand Down Expand Up @@ -148,12 +151,14 @@ import {
findPartialCodeBlock,
loadHighlighter,
useCodeBlockToHtml,
allLangs,
allLangsAlias,
// WARNING: Importing allThemes will increase your bundle size
// See: https://llm-ui.com/docs/blocks/code#bundle-size
allThemes,
} from "@llm-ui/code";
import { allLangs, allLangsAlias } from "@llm-ui/code/shikiBundles/allLangs";
import { allThemes } from "@llm-ui/code/shikiBundles/allThemes"; // WARNING: This import will increase your bundle size, see: https://llm-ui.com/docs/blocks/code#bundle-size
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput, type LLMOutputComponent } from "@llm-ui/react/core";
import { useStreamExample } from "@llm-ui/react/examples";
import { useLLMOutput, type LLMOutputComponent, useStreamExample } from "@llm-ui/react";
import parseHtml from "html-react-parser";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
Expand Down
7 changes: 5 additions & 2 deletions examples/nextjs/src/app/examples/buttons/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
parseCompleteButtons,
} from "@llm-ui/buttons";
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput, type LLMOutputComponent } from "@llm-ui/react/core";
import { useStreamExample } from "@llm-ui/react/examples";
import {
useLLMOutput,
useStreamExample,
type LLMOutputComponent,
} from "@llm-ui/react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";

Expand Down
14 changes: 10 additions & 4 deletions examples/nextjs/src/app/examples/code-block/example.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
"use client";
import type { CodeToHtmlOptions } from "@llm-ui/code";
import {
allLangs,
allLangsAlias,
// WARNING: Importing allThemes will increase your bundle size
// see: https://llm-ui.com/docs/blocks/code#bundle-size
allThemes,
codeBlockLookBack,
findCompleteCodeBlock,
findPartialCodeBlock,
loadHighlighter,
useCodeBlockToHtml,
} from "@llm-ui/code";
import { allLangs, allLangsAlias } from "@llm-ui/code/shikiBundles/allLangs";
import { allThemes } from "@llm-ui/code/shikiBundles/allThemes"; // WARNING: This import will increase your bundle size, see: https://llm-ui.com/docs/blocks/code#bundle-size
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput, type LLMOutputComponent } from "@llm-ui/react/core";
import { useStreamExample } from "@llm-ui/react/examples";
import {
useLLMOutput,
useStreamExample,
type LLMOutputComponent,
} from "@llm-ui/react";
import parseHtml from "html-react-parser";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
Expand Down
7 changes: 5 additions & 2 deletions examples/nextjs/src/app/examples/markdown/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"use client";
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput, type LLMOutputComponent } from "@llm-ui/react/core";
import { useStreamExample } from "@llm-ui/react/examples";
import {
useLLMOutput,
useStreamExample,
type LLMOutputComponent,
} from "@llm-ui/react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";

Expand Down
9 changes: 6 additions & 3 deletions examples/nextjs/src/app/examples/openai/example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
import { MARKDOWN_PROMPT, NEWLINE } from "@/constants";
import type { CodeToHtmlOptions } from "@llm-ui/code";
import {
allLangs,
allLangsAlias,
// WARNING: Importing allThemes will increase your bundle size
// see: https://llm-ui.com/docs/blocks/code#bundle-size
allThemes,
codeBlockLookBack,
findCompleteCodeBlock,
findPartialCodeBlock,
loadHighlighter,
useCodeBlockToHtml,
} from "@llm-ui/code";
import { allLangs, allLangsAlias } from "@llm-ui/code/shikiBundles/allLangs";
import { allThemes } from "@llm-ui/code/shikiBundles/allThemes"; // WARNING: This import will increase your bundle size, see: https://llm-ui.com/docs/blocks/code#bundle-size
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput, type LLMOutputComponent } from "@llm-ui/react/core";
import { useLLMOutput, type LLMOutputComponent } from "@llm-ui/react";
import parseHtml from "html-react-parser";
import { useCallback, useState } from "react";
import ReactMarkdown from "react-markdown";
Expand Down
2 changes: 1 addition & 1 deletion packages/buttons/src/lookBack.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LookBack } from "@llm-ui/react/core";
import { LookBack } from "@llm-ui/react";
import { describe, expect, it } from "vitest";
import { buttonsLookBack } from "./lookBack";

Expand Down
2 changes: 1 addition & 1 deletion packages/buttons/src/lookBack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LookBackFunction } from "@llm-ui/react/core";
import { LookBackFunction } from "@llm-ui/react";
import { Button, parseCompleteButtons } from "./parse";

const buttonsToVisibleText = (buttons: string[] | undefined): string =>
Expand Down
2 changes: 1 addition & 1 deletion packages/buttons/src/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LLMOutputMatcher } from "@llm-ui/react/core";
import { LLMOutputMatcher } from "@llm-ui/react";
import { regexMatcher } from "@llm-ui/shared";

export const findCompleteButtons = (): LLMOutputMatcher => {
Expand Down
20 changes: 0 additions & 20 deletions packages/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./shikiBundles/allLangs": {
"import": {
"types": "./dist/shikiBundles/allLangs.d.ts",
"default": "./dist/shikiBundles/allLangs.js"
},
"require": {
"types": "./dist/shikiBundles/allLangs.d.cts",
"default": "./dist/shikiBundles/allLangs.cjs"
}
},
"./shikiBundles/allThemes": {
"import": {
"types": "./dist/shikiBundles/allThemes.d.ts",
"default": "./dist/shikiBundles/allThemes.js"
},
"require": {
"types": "./dist/shikiBundles/allThemes.d.cts",
"default": "./dist/shikiBundles/allThemes.cjs"
}
}
},
"files": [
Expand Down
4 changes: 4 additions & 0 deletions packages/code/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export type { UseCodeToHtmlParams } from "./hooks/useCodeToHtml";
export { loadHighlighter } from "./hooks/useLoadHighlighter";

export type { CodeToHtmlOptions, LLMUIHighlighter, ShikiProps } from "./types";

export { allLangs, allLangsAlias } from "./shikiBundles/allLangs";

export { allThemes } from "./shikiBundles/allThemes";
2 changes: 1 addition & 1 deletion packages/code/src/lookBack.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LookBack } from "@llm-ui/react/core";
import { LookBack } from "@llm-ui/react";
import { describe, expect, it } from "vitest";
import { codeBlockLookBack } from "./lookBack";
import { CodeBlockOptions } from "./options";
Expand Down
2 changes: 1 addition & 1 deletion packages/code/src/lookBack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LookBackFunction } from "@llm-ui/react/core";
import { LookBackFunction } from "@llm-ui/react";
import { CodeBlockOptions, getOptions } from "./options";
import {
parseCompleteMarkdownCodeBlock,
Expand Down
2 changes: 1 addition & 1 deletion packages/code/src/matchers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MaybeLLMOutputMatch } from "@llm-ui/react/core";
import { MaybeLLMOutputMatch } from "@llm-ui/react";
import { describe, expect, it } from "vitest";
import { findCompleteCodeBlock, findPartialCodeBlock } from "./matchers";
import { CodeBlockOptions } from "./options";
Expand Down
2 changes: 1 addition & 1 deletion packages/code/src/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LLMOutputMatcher } from "@llm-ui/react/core";
import { LLMOutputMatcher } from "@llm-ui/react";
import { CodeBlockOptions, getOptions } from "./options";

import { regexMatcher } from "@llm-ui/shared";
Expand Down
6 changes: 1 addition & 5 deletions packages/code/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: [
"src/index.ts",
"src/shikiBundles/allLangs.ts",
"src/shikiBundles/allThemes.ts",
],
entry: ["src/index.ts"],
splitting: false,
sourcemap: true,
clean: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/src/lookBack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LookBackFunction } from "@llm-ui/react/core";
import { LookBackFunction } from "@llm-ui/react";
import {
markdownToVisibleText,
markdownWithVisibleChars,
Expand Down
Loading

0 comments on commit 999004c

Please sign in to comment.