From 5e5cdb8d6955917e6e6b60c9e1cd6508059f449f Mon Sep 17 00:00:00 2001 From: Tamago Date: Fri, 20 Sep 2024 14:31:32 +0800 Subject: [PATCH 1/6] refactor: pnpm monorepo --- .npmignore | 3 +- package.json | 25 +- packages/core/package.json | 19 + .../core/src}/components/hero-provider.tsx | 0 .../core/src}/components/hero.tsx | 0 .../core/src}/composables/use-hero-context.ts | 0 .../core/src}/composables/use-hero.ts | 0 {src => packages/core/src}/constants.ts | 0 {src => packages/core/src}/directive/index.ts | 0 {src => packages/core/src}/index.ts | 2 +- {src => packages/core/src}/types.ts | 0 packages/core/tsconfig.json | 3 + .../core/tsup.config.ts | 29 +- packages/nuxt/package.json | 23 + {src => packages/nuxt/src}/module.ts | 7 +- .../nuxt/src}/runtime/components/Hero.vue | 4 +- {src => packages/nuxt/src}/shims.d.ts | 0 packages/nuxt/tsconfig.json | 3 + playgrounds/nuxt/nuxt.config.ts | 2 +- playgrounds/nuxt/package.json | 2 +- playgrounds/vite/package.json | 3 +- pnpm-lock.yaml | 1342 +---------------- pnpm-workspace.yaml | 1 + tsconfig.json | 8 +- 24 files changed, 142 insertions(+), 1334 deletions(-) create mode 100644 packages/core/package.json rename {src => packages/core/src}/components/hero-provider.tsx (100%) rename {src => packages/core/src}/components/hero.tsx (100%) rename {src => packages/core/src}/composables/use-hero-context.ts (100%) rename {src => packages/core/src}/composables/use-hero.ts (100%) rename {src => packages/core/src}/constants.ts (100%) rename {src => packages/core/src}/directive/index.ts (100%) rename {src => packages/core/src}/index.ts (60%) rename {src => packages/core/src}/types.ts (100%) create mode 100644 packages/core/tsconfig.json rename tsup.config.ts => packages/core/tsup.config.ts (95%) create mode 100644 packages/nuxt/package.json rename {src => packages/nuxt/src}/module.ts (70%) rename {src => packages/nuxt/src}/runtime/components/Hero.vue (84%) rename {src => packages/nuxt/src}/shims.d.ts (100%) create mode 100644 packages/nuxt/tsconfig.json diff --git a/.npmignore b/.npmignore index 37d2d04..189aee8 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ -src playgrounds .vscode +.zed +.github diff --git a/package.json b/package.json index 222c459..19504f9 100644 --- a/package.json +++ b/package.json @@ -22,26 +22,22 @@ ], "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" + "types": "./packages/core/dist/index.d.ts", + "import": "./packages/core/dist/index.js", + "require": "./packages/core/dist/index.cjs" }, "./nuxt": { - "types": "./dist/nuxt/types.d.ts", - "import": "./dist/nuxt/module.mjs", - "require": "./dist/nuxt/module.cjs" + "types": "./packages/nuxt/dist/types.d.ts", + "import": "./packages/nuxt/dist/module.mjs", + "require": "./packages/nuxt/dist/module.cjs" } }, - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", "scripts": { - "dev": "tsup --watch", + "dev": "pnpm --filter @hero-motion/* dev", "play": "pnpm play:vite", "play:vite": "cd playgrounds/vite && pnpm dev", "play:nuxt": "cd playgrounds/nuxt && pnpm dev", - "build": "pnpm build:nuxt || tsup", - "build:nuxt": "nuxt-module-build build --outDir ./dist/nuxt", + "build": "pnpm --filter @hero-motion/* build", "lint": "eslint .", "lint:fix": "eslint . --fix", "test": "vitest" @@ -56,15 +52,10 @@ }, "devDependencies": { "@antfu/eslint-config": "^3.6.2", - "@nuxt/kit": "^3.13.2", - "@nuxt/module-builder": "^0.8.4", - "@nuxtjs/eslint-config-typescript": "^12.1.0", "@vue/tsconfig": "^0.5.1", - "@vueuse/motion": "^2.2.5", "eslint": "^9.10.0", "tsup": "^8.3.0", "typescript": "^5.6.2", - "unplugin-vue-jsx": "^0.4.0", "vitest": "^2.1.1", "vue": "^3.5.6" } diff --git a/packages/core/package.json b/packages/core/package.json new file mode 100644 index 0000000..8667047 --- /dev/null +++ b/packages/core/package.json @@ -0,0 +1,19 @@ +{ + "name": "@hero-motion/core", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "scripts": { + "dev": "tsup-node --watch", + "build": "tsup-node" + }, + "devDependencies": { + "@vueuse/motion": "^2.2.5", + "unplugin-vue-jsx": "^0.4.0" + } +} diff --git a/src/components/hero-provider.tsx b/packages/core/src/components/hero-provider.tsx similarity index 100% rename from src/components/hero-provider.tsx rename to packages/core/src/components/hero-provider.tsx diff --git a/src/components/hero.tsx b/packages/core/src/components/hero.tsx similarity index 100% rename from src/components/hero.tsx rename to packages/core/src/components/hero.tsx diff --git a/src/composables/use-hero-context.ts b/packages/core/src/composables/use-hero-context.ts similarity index 100% rename from src/composables/use-hero-context.ts rename to packages/core/src/composables/use-hero-context.ts diff --git a/src/composables/use-hero.ts b/packages/core/src/composables/use-hero.ts similarity index 100% rename from src/composables/use-hero.ts rename to packages/core/src/composables/use-hero.ts diff --git a/src/constants.ts b/packages/core/src/constants.ts similarity index 100% rename from src/constants.ts rename to packages/core/src/constants.ts diff --git a/src/directive/index.ts b/packages/core/src/directive/index.ts similarity index 100% rename from src/directive/index.ts rename to packages/core/src/directive/index.ts diff --git a/src/index.ts b/packages/core/src/index.ts similarity index 60% rename from src/index.ts rename to packages/core/src/index.ts index cc1264e..c3d47f7 100644 --- a/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,4 @@ export { Hero } from './components/hero' -export { HeroProvider } from './components/hero-provider' +export { HeroProvider, type HeroProviderProps } from './components/hero-provider' export { useHero } from './composables/use-hero' export { directive } from './directive' diff --git a/src/types.ts b/packages/core/src/types.ts similarity index 100% rename from src/types.ts rename to packages/core/src/types.ts diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json new file mode 100644 index 0000000..70cd8fa --- /dev/null +++ b/packages/core/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +} diff --git a/tsup.config.ts b/packages/core/tsup.config.ts similarity index 95% rename from tsup.config.ts rename to packages/core/tsup.config.ts index ed53c3c..54b0e0d 100644 --- a/tsup.config.ts +++ b/packages/core/tsup.config.ts @@ -1,14 +1,15 @@ -import { defineConfig } from 'tsup' -import VueJSX from 'unplugin-vue-jsx/esbuild' - -export default defineConfig(options => ({ - entry: ['./src/index.ts'], - splitting: true, - treeshake: true, - dts: true, - format: ['esm', 'cjs'], - minify: !options.watch, - esbuildPlugins: [ - VueJSX({}), - ], -})) +import { defineConfig } from 'tsup' +import VueJSX from 'unplugin-vue-jsx/esbuild' + +export default defineConfig(options => ({ + entry: ['./src/index.ts'], + splitting: true, + treeshake: true, + clean: true, + dts: true, + format: ['esm', 'cjs'], + minify: !options.watch, + esbuildPlugins: [ + VueJSX({}), + ], +})) diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json new file mode 100644 index 0000000..243a6b9 --- /dev/null +++ b/packages/nuxt/package.json @@ -0,0 +1,23 @@ +{ + "name": "@hero-motion/nuxt", + "type": "module", + "exports": { + ".": { + "types": "./dist/types.d.ts", + "import": "./dist/module.mjs", + "require": "./dist/module.cjs" + } + }, + "scripts": { + "dev": "nuxt-module-build build --watch", + "build": "nuxt-module-build build" + }, + "dependencies": { + "defu": "^6.1.4" + }, + "devDependencies": { + "@hero-motion/core": "workspace:*", + "@nuxt/kit": "^3.13.2", + "@nuxt/module-builder": "^0.8.4" + } +} diff --git a/src/module.ts b/packages/nuxt/src/module.ts similarity index 70% rename from src/module.ts rename to packages/nuxt/src/module.ts index 6735ab6..948a44b 100644 --- a/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -1,12 +1,9 @@ -import type { HeroProviderProps } from './components/hero-provider' import { addComponent, createResolver, defineNuxtModule } from '@nuxt/kit' import { defu } from 'defu' -export interface ModuleOptions extends Omit {} +export type NuxtModule = ReturnType> -export type NuxtModule = ReturnType> - -const module: any = defineNuxtModule({ +const module: any = defineNuxtModule({ meta: { name: 'hero-motion/nuxt', configKey: 'hero', diff --git a/src/runtime/components/Hero.vue b/packages/nuxt/src/runtime/components/Hero.vue similarity index 84% rename from src/runtime/components/Hero.vue rename to packages/nuxt/src/runtime/components/Hero.vue index 671df96..dd917a3 100644 --- a/src/runtime/components/Hero.vue +++ b/packages/nuxt/src/runtime/components/Hero.vue @@ -1,9 +1,11 @@