Skip to content

Commit

Permalink
fix: correct path for detecting vue version
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Mar 22, 2023
1 parent e200ba8 commit ceb4fba
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/yellow-jokes-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@vue-macros/setup-component': patch
'@vue-macros/common': patch
'unplugin-vue-macros': patch
---

correct path for detecting vue version
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ coverage
.idea
dev-dist
docs/.vitepress/cache
.vercel
.vite-inspect

.DS_Store
.pnpm-debug.log*
.eslintcache
.vercel
4 changes: 2 additions & 2 deletions packages/common/src/dep.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getPackageInfoSync } from 'local-pkg'

export function detectVueVersion(): 2 | 3 {
const vuePkg = getPackageInfoSync('vue')
export function detectVueVersion(root: string = process.cwd()): 2 | 3 {
const vuePkg = getPackageInfoSync('vue', { paths: [root] })
if (vuePkg) {
return +vuePkg.version.slice(0, 1) as 2 | 3
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function resolveOptions({
}

root = root || process.cwd()
version = version || detectVueVersion()
version = version || detectVueVersion(root)
isProduction = isProduction ?? process.env.NODE_ENV === 'production'

return {
Expand Down
5 changes: 3 additions & 2 deletions packages/setup-component/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export type OptionsResolved = MarkRequired<
>

function resolveOption(options: Options): OptionsResolved {
const version = options.version || detectVueVersion()
const root = options.root || process.cwd()
const version = options.version || detectVueVersion(root)
return {
include: [REGEX_SRC_FILE],
exclude: [REGEX_SETUP_SFC, REGEX_VUE_SUB, REGEX_NODE_MODULES],
root: process.cwd(),
...options,
root,
version,
}
}
Expand Down
3 changes: 2 additions & 1 deletion playground/vue2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true
"skipLibCheck": true,
"customConditions": ["dev"]
},
"vueCompilerOptions": {
"target": 2.7,
Expand Down
6 changes: 4 additions & 2 deletions playground/vue2/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
},
plugins: [
VueMacros({
version: 2,
// version: 2,
plugins: {
vue: Vue({
include: [/\.vue$/, /\.setup\.[cm]?[jt]sx?$/],
Expand All @@ -19,6 +19,8 @@ export default defineConfig({
},
}),

Inspect(),
Inspect({
build: true,
}),
],
})
4 changes: 3 additions & 1 deletion playground/vue3/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default defineConfig({
},
}),

Inspect(),
Inspect({
build: true,
}),
],
})

0 comments on commit ceb4fba

Please sign in to comment.