Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nuxt-module): add critical packages to module's dependencies #531

Merged
merged 18 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 9.0.5
version: 9.1.2
run_install: false

- name: Get pnpm store directory
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
"ofetch": "^1.3.4",
"ora": "^8.0.1",
"pathe": "^1.1.2",
"pkg-types": "^1.1.0",
"prompts": "^2.4.2",
"radix-vue": "^1.7.3",
"semver": "^7.6.0",
"ts-morph": "^22.0.0",
"tsconfig-paths": "^4.2.0",
"zod": "^3.23.3"
Expand Down
18 changes: 15 additions & 3 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { z } from 'zod'
import { addDependency, addDevDependency } from 'nypm'
import { consola } from 'consola'
import { colors } from 'consola/utils'
import { gte } from 'semver'
import { getProjectInfo } from '../utils/get-project-info'
import * as templates from '../utils/templates'
import {
getRegistryBaseColor,
Expand Down Expand Up @@ -239,6 +241,15 @@ export async function promptForConfig(
export async function runInit(cwd: string, config: Config) {
const spinner = ora('Initializing project...')?.start()

// Check in in a Nuxt project.
const { isNuxt, shadcnNuxt } = await getProjectInfo()
if (isNuxt) {
consola.log('')
shadcnNuxt
? consola.info(`Detected a Nuxt project with 'shadcn-nuxt' v${shadcnNuxt.version}...`)
: consola.warn(`Detected a Nuxt project without 'shadcn-nuxt' module. It's recommended to install it.`)
}

// Ensure all resolved paths directories exist.
for (const [key, resolvedPath] of Object.entries(config.resolvedPaths)) {
// Determine if the path is a file or directory.
Expand Down Expand Up @@ -299,9 +310,10 @@ export async function runInit(cwd: string, config: Config) {
// Install dependencies.
const dependenciesSpinner = ora('Installing dependencies...')?.start()

const deps = PROJECT_DEPENDENCIES.base.concat(
config.style === 'new-york' ? ['@radix-icons/vue'] : ['lucide-vue-next'],
).filter(Boolean)
// Starting from `shadcn-nuxt` version 0.10.4, Base dependencies are handled by the module so no need to re-add them by the CLI
const baseDeps = gte(shadcnNuxt?.version || '0.0.0', '0.10.4') ? [] : PROJECT_DEPENDENCIES.base
const iconsDep = config.style === 'new-york' ? ['@radix-icons/vue'] : ['lucide-vue-next']
const deps = baseDeps.concat(iconsDep).filter(Boolean)

await Promise.allSettled(
[
Expand Down
21 changes: 20 additions & 1 deletion packages/cli/src/utils/get-project-info.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { existsSync } from 'node:fs'
import path from 'pathe'
import fs from 'fs-extra'
import { readPackageJSON } from 'pkg-types'
import type { PackageJson } from 'pkg-types'

export async function getProjectInfo() {
const info = {
tsconfig: null,
isNuxt: false,
shadcnNuxt: undefined,
isVueVite: false,
srcDir: false,
componentsUiDir: false,
Expand All @@ -15,9 +18,13 @@ export async function getProjectInfo() {
try {
const tsconfig = await getTsConfig()

const isNuxt = existsSync(path.resolve('./nuxt.config.js')) || existsSync(path.resolve('./nuxt.config.ts'))
const shadcnNuxt = isNuxt ? await getShadcnNuxtInfo() : undefined

return {
tsconfig,
isNuxt: existsSync(path.resolve('./nuxt.config.js')) || existsSync(path.resolve('./nuxt.config.ts')),
isNuxt,
shadcnNuxt,
isVueVite: existsSync(path.resolve('./vite.config.js')) || existsSync(path.resolve('./vite.config.ts')),
srcDir: existsSync(path.resolve('./src')),
srcComponentsUiDir: existsSync(path.resolve('./src/components/ui')),
Expand All @@ -29,6 +36,18 @@ export async function getProjectInfo() {
}
}

async function getShadcnNuxtInfo() {
let nuxtModule: PackageJson | undefined
try {
nuxtModule = await readPackageJSON('shadcn-nuxt')
}
catch (error) {
nuxtModule = undefined
}

return nuxtModule
}

export async function getTsConfig() {
try {
const tsconfigPath = path.join('tsconfig.json')
Expand Down
5 changes: 4 additions & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
},
"dependencies": {
"@nuxt/kit": "^3.11.2",
"@oxc-parser/wasm": "^0.1.0"
"@oxc-parser/wasm": "^0.1.0",
"class-variance-authority": "^0.7.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.3.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/module/playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/tailwindcss', '../src/module'],
modules: ['@nuxtjs/tailwindcss', 'shadcn-nuxt'],
MuhammadM1998 marked this conversation as resolved.
Show resolved Hide resolved
shadcn: {
prefix: 'Ui',
},
Expand Down
12 changes: 4 additions & 8 deletions packages/module/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"generate": "nuxi generate"
},
"dependencies": {
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"embla-carousel": "8.0.0-rc19",
"@nuxtjs/tailwindcss": "^6.10.1",
"embla-carousel-vue": "8.0.0-rc19",
"lucide-vue-next": "^0.276.0",
"radix-vue": "^1.7.2",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7"
"lucide-vue-next": "^0.276.0"
},
"devDependencies": {
"@nuxtjs/tailwindcss": "^6.12.0",
"nuxt": "latest"
"nuxt": "latest",
"shadcn-nuxt": "file:.."
}
}
2 changes: 1 addition & 1 deletion packages/module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UTILS } from '../../cli/src/utils/templates'
// Module options TypeScript interface definition
export interface ModuleOptions {
/**
* Prefix for all the imported component
* Prefix for all the imported component.
*/
prefix?: string
/**
Expand Down