Skip to content

Commit

Permalink
refactor: cleanup package exports (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored May 5, 2024
1 parent b3ed7ba commit 3da1720
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 65 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"clean": "rm -rf packages/*/dist",
"dev": "pnpm run /^dev:/",
"build": "pnpm -r build",
"build": "pnpm -r '--filter=!*example*' build",
"tsc": "tsc -b packages/*/tsconfig.json packages/*/examples/*/tsconfig.json",
"dev:tsc": "pnpm tsc --watch --preserveWatchOutput",
"test": "pnpm -r --sequential test run",
Expand All @@ -26,7 +26,6 @@
"@hiogawa/utils": "workspace:*",
"@hiogawa/utils-node": "workspace:*",
"@playwright/test": "^1.41.2",
"@swc/core": "^1.3.95",
"@tsconfig/strictest": "^2.0.3",
"@types/node": "^20.11.19",
"@vitest/ui": "^1.3.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/tiny-react/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { themeScriptPlugin } from "@hiogawa/theme-script/dist/vite";
import { tinyReactVitePlugin } from "@hiogawa/tiny-react/dist/plugins/vite";
import { tinyReactVitePlugin } from "@hiogawa/tiny-react/vite";
import unocss from "unocss/vite";
import { defineConfig } from "vite";

export default defineConfig({
build: {
outDir: "./dist/vite",
minify: true, // set `false` to verify transpilated output easily
minify: true, // set `false` to verify transpiled output easily
},
plugins: [tinyReactVitePlugin(), unocss(), themeScriptPlugin()],
});
2 changes: 1 addition & 1 deletion packages/tiny-react/examples/server/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import { tinyReactVitePlugin } from "@hiogawa/tiny-react/dist/plugins/vite";
import { tinyReactVitePlugin } from "@hiogawa/tiny-react/vite";
import {
vitePluginLogger,
vitePluginSsrMiddleware,
Expand Down
2 changes: 1 addition & 1 deletion packages/tiny-react/examples/ssr/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { themeScriptPlugin } from "@hiogawa/theme-script/dist/vite";
import { tinyReactVitePlugin } from "@hiogawa/tiny-react/dist/plugins/vite";
import { tinyReactVitePlugin } from "@hiogawa/tiny-react/vite";
import { importDevServerPlugin } from "@hiogawa/vite-import-dev-server";
import { viteNullExportPlugin } from "@hiogawa/vite-null-export";
import { vitePluginSsrMiddleware } from "@hiogawa/vite-plugin-ssr-middleware";
Expand Down
6 changes: 3 additions & 3 deletions packages/tiny-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"require": "./dist/hmr/index.cjs",
"types": "./dist/hmr/index.d.ts"
},
"./dist/plugins/vite": {
"./vite": {
"import": "./dist/plugins/vite.js",
"require": "./dist/plugins/vite.cjs",
"types": "./dist/plugins/vite.d.ts"
Expand All @@ -44,10 +44,10 @@
],
"scripts": {
"dev": "tsup --watch",
"build": "tsup --clean",
"build": "tsup",
"test": "vitest",
"lint": "icheck-ts $(find src -name '*.ts')",
"prepack": "pnpm --filter @hiogawa/tiny-react... build",
"prepack": "tsup --clean",
"release": "pnpm publish --no-git-checks --access public"
},
"devDependencies": {
Expand Down
36 changes: 16 additions & 20 deletions packages/tiny-react/src/plugins/vite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { vitePluginTinyRefresh } from "@hiogawa/tiny-refresh/dist/vite";
import { typedBoolean } from "@hiogawa/utils";
import { type FilterPattern, type Plugin } from "vite";
import { vitePluginTinyRefresh } from "@hiogawa/tiny-refresh/vite";
import { type FilterPattern, type PluginOption } from "vite";

// cf.
// https://github.com/preactjs/preset-vite
Expand All @@ -20,7 +19,7 @@ interface TinyReactVitePluginOptions {

export function tinyReactVitePlugin(
options?: TinyReactVitePluginOptions
): Plugin[] {
): PluginOption {
return [
!options?.hmr?.disable &&
vitePluginTinyRefresh({
Expand All @@ -29,22 +28,19 @@ export function tinyReactVitePlugin(
runtime: "@hiogawa/tiny-react",
refreshRuntime: "@hiogawa/tiny-react/hmr",
}),
!options?.alias?.disable && aliasPlugin(),
].filter(typedBoolean);
}

function aliasPlugin(): Plugin {
return {
name: "@hiogawa/tiny-react:alias",
config(_config, _env) {
// https://github.com/preactjs/preset-vite/blob/4dfecb379c17fbb2f442987a8ff95536ff290cbd/src/index.ts#L184C1-L190
return {
resolve: {
alias: {
react: "@hiogawa/tiny-react",
// https://github.com/preactjs/preset-vite/blob/4dfecb379c17fbb2f442987a8ff95536ff290cbd/src/index.ts#L184C1-L190
{
name: "@hiogawa/tiny-react:alias",
apply: () => !options?.alias?.disable,
config(_config, _env) {
return {
resolve: {
alias: {
react: "@hiogawa/tiny-react",
},
},
},
};
};
},
},
};
];
}
2 changes: 1 addition & 1 deletion packages/tiny-refresh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This simplified runtime architecture is inspired by [`solid-refresh`](https://gi
// vite.config.ts
//
import { defineConfig } from "vite";
import { vitePluginTinyRefresh } from "@hiogawa/tiny-refresh/dist/vite";
import { vitePluginTinyRefresh } from "@hiogawa/tiny-refresh/vite";

export default defineConfig({
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion packages/tiny-refresh/examples/react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import process from "node:process";
import { vitePluginTinyRefresh } from "@hiogawa/tiny-refresh/dist/vite";
import { vitePluginTinyRefresh } from "@hiogawa/tiny-refresh/vite";
import unocss from "unocss/vite";
import { defineConfig } from "vite";

Expand Down
20 changes: 7 additions & 13 deletions packages/tiny-refresh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@
"type": "module",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./dist/vite": {
"import": "./dist/vite.js",
"require": "./dist/vite.cjs",
"types": "./dist/vite.d.ts"
},
"./dist/webpack": {
"import": "./dist/webpack.js",
"require": "./dist/webpack.cjs",
"types": "./dist/webpack.d.ts"
"./vite": {
"types": "./dist/vite.d.ts",
"default": "./dist/vite.js"
}
},
"main": "./dist/index.js",
Expand All @@ -33,9 +26,10 @@
"dist"
],
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"test": "vitest",
"prepack": "pnpm build",
"prepack": "tsup --clean",
"release": "pnpm publish --no-git-checks --access public"
},
"devDependencies": {
Expand Down
12 changes: 0 additions & 12 deletions packages/tiny-refresh/src/webpack.ts

This file was deleted.

6 changes: 2 additions & 4 deletions packages/tiny-refresh/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/index.ts", "src/vite.ts", "src/webpack.ts"],
format: ["esm", "cjs"],
// support old webpack 4
target: "es5",
entry: ["src/index.ts", "src/vite.ts"],
format: ["esm"],
dts: true,
splitting: false,
});
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3da1720

Please sign in to comment.