Skip to content

Commit

Permalink
fix(docs): include .npmrc in sandbox (#4951)
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong authored Feb 28, 2025
1 parent 66d2c2b commit ff8c9b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/docs/components/sandpack/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ export const postcssConfig = `module.exports = {
export const stylesConfig = `@tailwind base;
@tailwind components;
@tailwind utilities;`;

export const npmrcConfig = `public-hoist-pattern[]=*@heroui/*`;
13 changes: 12 additions & 1 deletion apps/docs/components/sandpack/use-sandpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import {useLocalStorage} from "usehooks-ts";

import {HighlightedLines} from "./types";
import {getHighlightedLines, getFileName} from "./utils";
import {stylesConfig, postcssConfig, tailwindConfig, getHtmlFile, rootFile} from "./entries";
import {
stylesConfig,
postcssConfig,
tailwindConfig,
npmrcConfig,
getHtmlFile,
rootFile,
} from "./entries";

export interface UseSandpackProps {
files?: SandpackFiles;
Expand Down Expand Up @@ -207,6 +214,10 @@ export const useSandpack = ({
code: stylesConfig,
hidden: true,
},
".npmrc": {
code: npmrcConfig,
hidden: true,
},
},
hasTypescript,
entryFile,
Expand Down
12 changes: 11 additions & 1 deletion apps/docs/hooks/use-stackblitz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ export function useStackblitz(props: UseSandpackProps) {
typescriptStrict,
});

const transformFiles = mapKeys(filesData, (_, key) => key.replace(/^\//, ""));
// in stackblitz, npm will be used to install dependencies
// it doesn't need `public-hoist-pattern[]=*@heroui/*`
const filteredFilesData = Object.keys(filesData)
.filter((k) => k !== ".npmrc")
.reduce((o, k) => {
o[k] = filesData[k];

return o;
}, {});

const transformFiles = mapKeys(filteredFilesData, (_, key) => key.replace(/^\//, ""));

const dependencies = {...customSetup.dependencies, ...customSetup.devDependencies};

Expand Down

0 comments on commit ff8c9b3

Please sign in to comment.