Skip to content

Commit

Permalink
chore: separate config files and use inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-solanki committed Apr 20, 2023
1 parent 88d3817 commit e4523d2
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 102 deletions.
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"yzhang.markdown-all-in-one",
"streetsidesoftware.code-spell-checker",
"matijao.vue-nuxt-snippets",
"webhint.vscode-webhint"
"webhint.vscode-webhint",
"johnsoncodehk.vscode-tsconfig-helper"
]
}
}
45 changes: 10 additions & 35 deletions packages/anu-vue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,34 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"outDir": "dist/types",
"lib": [
"esnext",
"dom"
],
"skipLibCheck": true,
"paths": {
"@/*": [
"*"
],
"anu-vue": [
"."
]
},
"types": [
"vitest/globals",
"unplugin-vue-macros/macros-global"
]
},
"vueCompilerOptions": {
"target": 3,
"plugins": [
"@vue-macros/volar/define-options",
"@vue-macros/volar/define-models",
"@vue-macros/volar/define-props",
"@vue-macros/volar/define-props-refs",
"@vue-macros/volar/short-vmodel",
"@vue-macros/volar/define-slots",
"@vue-macros/volar/export-props"
]
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"auto-imports.d.ts",
"shims.d.ts",
"volar.d.ts"
"./src/**/*.ts",
"./src/**/*.d.ts",
"./src/**/*.tsx",
"./src/**/*.vue",
"./auto-imports.d.ts",
"./shims.d.ts",
"./volar.d.ts"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
}
2 changes: 1 addition & 1 deletion packages/anu-vue/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"include": [
"vite.config.ts"
]
}
}
53 changes: 4 additions & 49 deletions packages/anu-vue/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { resolve } from 'node:path'
import { URL, fileURLToPath } from 'node:url'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import VueMacros from 'unplugin-vue-macros/vite'
import { defineConfig } from 'vitest/config'

function noop() {}
import { defineConfig, mergeConfig } from 'vitest/config'
import viteBaseConfig from '../../vite.config'

const externals = [
'vue',
Expand All @@ -16,7 +11,7 @@ const externals = [
]

// https://vitejs.dev/config/
export default defineConfig({
export default mergeConfig(viteBaseConfig, defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
Expand All @@ -42,51 +37,11 @@ export default defineConfig({
},
},
plugins: [
VueMacros({
plugins: {
vue: vue(),
},
}),
vueJsx(),
AutoImport({
imports: ['vue', '@vueuse/core'],
}),
],
resolve: {
dedupe: ['vue'],
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
optimizeDeps: {
include: [
...externals,
],
},
test: {
open: !process.env.HEADLESS,
isolate: false,
browser: {
enabled: true,

// @ts-expect-error ignore, we don't have the type here
enableUI: true,
name: 'chrome',
headless: !!process.env.HEADLESS,
provider: 'webdriverio',
},
reporters: ['json', {
onInit: noop,
onPathsCollected: noop,
onCollected: noop,
onFinished: noop,
onTaskUpdate: noop,
onTestRemoved: noop,
onWatcherStart: noop,
onWatcherRerun: noop,
onServerRestart: noop,
onUserConsoleLog: noop,
}, 'default'],
setupFiles: ['./test/setup.vitest.ts'],
},
})
}))
19 changes: 19 additions & 0 deletions packages/anu-vue/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig, mergeConfig } from 'vitest/config'
import vitestBaseConfig from '../../vitest.config'
import viteConfig from './vite.config'

const vitestConfig = mergeConfig(vitestBaseConfig, defineConfig({
test: {
browser: {
enabled: true,

// @ts-expect-error ignore, we don't have the type here
enableUI: true,
name: 'chrome',
headless: !!process.env.HEADLESS,
provider: 'webdriverio',
},
},
}))

export default mergeConfig(viteConfig, vitestConfig)
19 changes: 9 additions & 10 deletions packages/preset-theme-default/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"types": [
"node"
]
},
"include": [
"src/**/*",
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": [
"node"
]
}
},
"include": [
"src/**/*"
]
}
9 changes: 6 additions & 3 deletions scripts/paths.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import path from 'path'
import * as url from 'url'
import path from 'node:path'
import * as url from 'node:url'

const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

export const repoRoot = path.join(__dirname, '..')
export const anuVuePkgRoot = path.join(__dirname, '..', 'packages', 'anu-vue')
export const packagesDir = path.join(repoRoot, 'packages')

export const anuVuePkgRoot = path.join(packagesDir, 'anu-vue')
export const anuVueSrc = path.join(anuVuePkgRoot, 'src')
export const anuVueComponentsDir = path.join(anuVuePkgRoot, 'src', 'components')
26 changes: 24 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "esnext",
"module": "esnext",
"lib": [
Expand All @@ -9,6 +10,7 @@
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
Expand All @@ -17,7 +19,27 @@
"types": [
"node",
"unplugin-vue-macros/macros-global"
]
],
"paths": {
"@/*": [
"./packages/anu-vue/src/*"
],
"@anu-vue/core": [
"./packages/anu-vue/src/index.ts"
],
"@anu-vue/core/*": [
"./packages/anu-vue/src/*"
],
"@anu-vue/preset-theme-default": [
"./packages/preset-theme-default/src/index.ts"
],
"@anu-vue/preset-theme-default/*": [
"./packages/preset-theme-default/src/*"
],
"@anu-vue/nuxt": [
"./packages/anu-nuxt/src/module.ts"
]
}
},
"vueCompilerOptions": {
"target": 3,
Expand All @@ -36,4 +58,4 @@
"**/node_modules/**",
"**/playground/**"
]
}
}
37 changes: 37 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueMacros from 'unplugin-vue-macros/vite'
import { defineConfig } from 'vite'
import { anuVueSrc, packagesDir } from './scripts/paths'

const externals = [
'vue',
'@floating-ui/vue',
'colord',
'defu',
]

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
VueMacros({
plugins: {
vue: vue(),
},
}),
vueJsx(),
],
resolve: {
dedupe: ['vue'],
alias: {
// TODO: This should be `repoRoot`. We will update it in internal refactor task.
'@': anuVueSrc,
'@anu-vue': packagesDir,
},
},
optimizeDeps: {
include: [
...externals,
],
},
})
25 changes: 25 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { join } from 'node:path'
import { defineConfig } from 'vitest/config'
import { anuVuePkgRoot } from './scripts/paths'

function noop() {}

export default defineConfig({
test: {
open: !process.env.HEADLESS,
isolate: false,
reporters: ['json', {
onInit: noop,
onPathsCollected: noop,
onCollected: noop,
onFinished: noop,
onTaskUpdate: noop,
onTestRemoved: noop,
onWatcherStart: noop,
onWatcherRerun: noop,
onServerRestart: noop,
onUserConsoleLog: noop,
}, 'default'],
setupFiles: [join(anuVuePkgRoot, 'test', 'setup.vitest.ts')],
},
})

0 comments on commit e4523d2

Please sign in to comment.