Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 396de8a

Browse files
committedFeb 28, 2023
fix: install method is assigned twice
1 parent fc83914 commit 396de8a

File tree

5 files changed

+936
-328
lines changed

5 files changed

+936
-328
lines changed
 

‎auto-imports.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// Generated by 'unplugin-auto-import'
1+
/* eslint-disable */
2+
/* prettier-ignore */
3+
// @ts-nocheck
4+
// Generated by unplugin-auto-import
25
export {}
36
declare global {
47
const EffectScope: typeof import('vue')['EffectScope']
@@ -36,7 +39,6 @@ declare global {
3639
const readonly: typeof import('vue')['readonly']
3740
const ref: typeof import('vue')['ref']
3841
const resolveComponent: typeof import('vue')['resolveComponent']
39-
const resolveDirective: typeof import('vue')['resolveDirective']
4042
const shallowReactive: typeof import('vue')['shallowReactive']
4143
const shallowReadonly: typeof import('vue')['shallowReadonly']
4244
const shallowRef: typeof import('vue')['shallowRef']
@@ -54,3 +56,8 @@ declare global {
5456
const watchPostEffect: typeof import('vue')['watchPostEffect']
5557
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
5658
}
59+
// for type re-export
60+
declare global {
61+
// @ts-ignore
62+
export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode } from 'vue'
63+
}

‎package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"PascalCasedName": "JsonEditorVue",
44
"version": "0.10.5",
55
"private": false,
6-
"packageManager": "pnpm@7.26.3",
6+
"packageManager": "pnpm@7.28.0",
77
"description": "JSON editor & viewer for Vue 2.6/2.7/3 & Nuxt 2/3.",
88
"author": "Cloyd Lau",
99
"license": "MIT",
@@ -68,10 +68,8 @@
6868
"@commitlint/config-conventional": "latest",
6969
"@types/lodash-es": "latest",
7070
"@types/node": "latest",
71-
"@vitejs/plugin-vue": "latest",
7271
"@vitest/coverage-c8": "latest",
7372
"@vitest/ui": "latest",
74-
"@vue/compiler-sfc": "latest",
7573
"@vue/test-utils": "latest",
7674
"case-police": "latest",
7775
"happy-dom": "latest",
@@ -88,7 +86,9 @@
8886
"vitepress": "latest",
8987
"vitest": "latest",
9088
"vue": "latest",
91-
"zhlint": "latest"
89+
"zhlint": "latest",
90+
"@vitejs/plugin-vue": "latest",
91+
"@vue/compiler-sfc": "latest"
9292
},
9393
"lint-staged": {
9494
"{src,__tests__}/**.*": "rome check",
@@ -100,4 +100,4 @@
100100
"publishConfig": {
101101
"registry": "https://registry.npmjs.org"
102102
}
103-
}
103+
}

‎pnpm-lock.yaml

Lines changed: 906 additions & 294 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

‎src/install.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
11
import { resolveConfig } from 'vue-global-config'
2-
import type { Plugin, install } from 'vue-demi'
3-
import Component from './Component'
4-
import type { Mode } from './Component'
2+
import type { App, Component } from 'vue-demi'
3+
import component from './component'
4+
import type { Mode } from './component'
55

6-
type SFCWithInstall<T> = T & Plugin & { install: typeof install }
6+
const globalProps: Record<string | symbol, any> = {}
7+
const globalAttrs: Record<string | symbol, any> = {}
78

8-
const withInstall = <T, E extends Record<string, any>>(main: T, extra?: E) => {
9-
;(main as SFCWithInstall<T>).install = (app): void => {
10-
for (const comp of [main, ...Object.values(extra ?? {})]) {
11-
app?.component(comp.name, comp)
12-
}
13-
}
14-
15-
if (extra) {
16-
for (const [key, comp] of Object.entries(extra)) {
17-
;(main as any)[key] = comp
18-
}
19-
}
20-
return main as SFCWithInstall<T> & E
9+
type SFCWithInstall = Component & {
10+
install: (app: App, options?: Record<string | symbol, any>) => void
2111
}
2212

23-
const globalProps: Record<string, any> = {}
24-
const globalAttrs: Record<string, any> = {}
25-
26-
const ComponentWithInstall = withInstall(Component)
13+
function withInstall(sfc: Component): SFCWithInstall {
14+
;(sfc as SFCWithInstall).install = (app: App, options = {}): void => {
15+
const { props, attrs } = resolveConfig(options, component.props)
16+
Object.assign(globalProps, props)
17+
Object.assign(globalAttrs, attrs)
18+
app.component(sfc.name as string, sfc as Object)
19+
}
2720

28-
ComponentWithInstall.install = (app: any, options = {}) => {
29-
const { props, attrs } = resolveConfig(options, Component.props)
30-
Object.assign(globalProps, props)
31-
Object.assign(globalAttrs, attrs)
32-
app.component(ComponentWithInstall.name, ComponentWithInstall)
21+
return sfc as SFCWithInstall
3322
}
3423

3524
export { globalProps, globalAttrs, Mode }
36-
export default ComponentWithInstall
25+
export default withInstall(component)

0 commit comments

Comments
 (0)
Please sign in to comment.