Skip to content

Commit a30c742

Browse files
committed
fix: styles export
1 parent d279b3b commit a30c742

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"require": "./dist/index.js",
6161
"import": "./dist/index.mjs"
6262
},
63-
"./styles": "./dist/styles.css"
63+
"./styles.css": "./dist/styles.css"
6464
},
6565
"files": ["dist"],
6666
"config": {

src/InstallCommand.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
import { Icon } from "@iconify/react";
24
import { useCallback, useEffect, useState } from "react";
35
import type { ReactNode } from "react";

tsup.config.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,40 @@ const getPackageName = async () => {
2727
return "package-name";
2828
}
2929
};
30-
3130
const _addUseStatement = async (
32-
basePath: string,
31+
pathOrFile: string,
3332
type: "server" | "client",
33+
isFile?: boolean,
3434
) => {
35-
const fullPath = path.join(__dirname, basePath);
36-
const files = fs.readdirSync(fullPath);
35+
const fullPath = path.join(__dirname, pathOrFile);
36+
37+
// Use provided isFile parameter if available, otherwise detect from extension
38+
const shouldHandleAsFile =
39+
isFile ?? (fullPath.endsWith(".js") || fullPath.endsWith(".mjs"));
3740

41+
if (shouldHandleAsFile) {
42+
// Try both .js and .mjs if no extension is provided
43+
const possiblePaths =
44+
fullPath.endsWith(".js") || fullPath.endsWith(".mjs")
45+
? [fullPath]
46+
: [`${fullPath}.js`, `${fullPath}.mjs`];
47+
48+
for (const filePath of possiblePaths) {
49+
if (fs.existsSync(filePath)) {
50+
let content = await readFile(filePath, "utf-8");
51+
content = `"use ${type}";\n${content}`;
52+
fs.writeFileSync(filePath, content, "utf-8");
53+
}
54+
}
55+
return;
56+
}
57+
58+
// Handle directory case
59+
if (!fs.existsSync(fullPath)) {
60+
throw new Error(`Directory not found: ${fullPath}`);
61+
}
62+
63+
const files = fs.readdirSync(fullPath);
3864
for (const file of files) {
3965
if (file.endsWith(".js") || file.endsWith(".mjs")) {
4066
const filePath = path.join(fullPath, file);
@@ -68,7 +94,7 @@ const linkSelf = async () => {
6894
export default defineConfig({
6995
async onSuccess() {
7096
// If you want need to add a use statement to files, you can use the following code:
71-
// await _addUseStatement('dist/react', 'client');
97+
await _addUseStatement("dist/index", "client", true);
7298

7399
await linkSelf();
74100
},

0 commit comments

Comments
 (0)