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

This commit is contained in:
Muhammad Mahmoud 2024-05-24 16:33:48 +03:00 committed by GitHub
parent 63bb21808f
commit bd0a8206ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 1371 additions and 1389 deletions

View File

@ -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

View File

@ -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"

View File

@ -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,
@ -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.
@ -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(
[

View File

@ -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,
@ -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')),
@ -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')

View File

@ -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",

View File

@ -1,5 +1,5 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/tailwindcss', '../src/module'],
modules: ['@nuxtjs/tailwindcss', 'shadcn-nuxt'],
shadcn: {
prefix: 'Ui',
},

View File

@ -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:.."
}
}

View File

@ -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
/**

File diff suppressed because it is too large Load Diff