Skip to content

Commit

Permalink
chore: release
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Apr 23, 2024
1 parent 44c2542 commit 8138a32
Show file tree
Hide file tree
Showing 42 changed files with 2,025 additions and 1,220 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"prepare": "simple-git-hooks",
"commitlint": "commitlint -e",
"up": "taze -I -w",
"bump": "changeset",
"changeset": "changeset",
"version": "changeset version && changeset tag",
"report": "nyc report --excludeAfterRemap=false"
},
Expand All @@ -37,7 +37,7 @@
"nyc": "^15.1.0",
"simple-git-hooks": "^2.11.1",
"taze": "^0.11.4",
"tsup": "^6.7.0",
"tsup": "^8.0.2",
"turbo": "^1.13.0",
"typescript": "^5.4.3"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/istanbul-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# istanbul-widget

## 1.3.0

### Minor Changes

- feat: support plugin

## 1.2.0

### Minor Changes
Expand Down
1 change: 1 addition & 0 deletions packages/istanbul-widget/components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/es/components/ui/index'
16 changes: 0 additions & 16 deletions packages/istanbul-widget/dev.ts

This file was deleted.

48 changes: 48 additions & 0 deletions packages/istanbul-widget/dev.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Button } from './src/components/ui'
import { IstanbulWidget } from './src/istanbul-widget'

function MyPlugin() {
return <Button size={'sm'}>this is my Plugin</Button>
}

// 自定义插件

const myPlugin = new IstanbulWidget.IstanbulWidgetReactPlugin('my_plugin', 'My Plugin', MyPlugin)

myPlugin.event.on('init', () => {
console.log('my plugin inited')
})

const istanbulWidget = new IstanbulWidget({
defaultPosition: {
x: -100,
y: 100,
},
plugin: {
report: {
onReport(coverage) {
console.log('上报', coverage)
throw new Error('上报失败')
},
},
setting: {
requireReporter: true,
},
buttonGroup: [
{
text: '额外按钮 - 1',
onClick() {
console.log('1')
},
},
{
text: '额外按钮 - 2',
onClick() {
console.log('2')
},
},
],
},
})

istanbulWidget.addPlugin(myPlugin)
2 changes: 1 addition & 1 deletion packages/istanbul-widget/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<body>
<div id="root"></div>
<script type="module" src="/dev.ts"></script>
<script type="module" src="/dev.tsx"></script>
</body>

</html>
49 changes: 35 additions & 14 deletions packages/istanbul-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
{
"name": "istanbul-widget",
"version": "1.2.0",
"version": "1.3.0",
"type": "module",
"files": [
"**"
],
"main": "./dist/istanbul-widget.min.js",
"module": "./dist/istanbul-widget.esm.js",
"types": "./dist/istanbul-widget.min.d.ts",
"sideEffects": false,
"module": "./dist/es/istanbul-widget.js",
"types": "./dist/istanbul-widget.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/istanbul-widget.d.ts",
"require": "./dist/istanbul-widget.min.js",
"import": "./dist/es/istanbul-widget.js"
},
"./components": {
"types": "./component.d.ts",
"import": "./dist/es/components/ui/index.js",
"default": "./dist/es/components/ui/index.js"
},
"./*": "./*"
},
"sideEffects": [
"**/*.css"
],
"scripts": {
"dev": "vite",
"build:dev": "vite build --mode devlopment --watch",
"build:test": "REPORT=true vite build --mode test",
"build": "vite build",
"dev": "tsup --watch",
"build": "tsup",
"vite": "vite",
"report": "NODE_ENV=production REPORT=true vite build --mode production",
"lint": "eslint . --fix",
"preview": "vite preview"
},
"dependencies": {
"@iconify-json/vscode-icons": "^1.1.33",
"@minko-fe/lodash-pro": "^0.2.4",
"@minko-fe/react-hook": "^0.2.7",
"@minko-fe/lodash-pro": "^0.3.0",
"@minko-fe/react-hook": "^0.3.1",
"@neodrag/react": "^2.0.3",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-dialog": "^1.0.5",
Expand All @@ -30,9 +48,10 @@
"@radix-ui/react-toast": "^1.1.5",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"destr": "^2.0.3",
"context-state": "^2.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"strict-event-emitter": "^0.5.1",
"tailwind-merge": "^2.2.2",
"tailwind-variants": "^0.2.1",
"tailwindcss-animate": "^1.0.7"
Expand All @@ -41,19 +60,21 @@
"@babel/preset-env": "^7.24.4",
"@iconify/tailwind": "^0.1.4",
"@rollup/plugin-babel": "^6.0.4",
"@swc/core": "^1.4.17",
"@types/node": "^20.11.30",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.23",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"bundle-require": "^4.0.3",
"fast-glob": "^3.3.2",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.38",
"rollup-plugin-visualizer": "^5.12.0",
"strip-dirs": "^3.0.0",
"tailwindcss": "3.2.7",
"tailwindcss-rem-to-px": "^0.1.0",
"terser": "^5.30.3",
"vite": "^5.0.8",
"vite-plugin-css-injected-by-js": "^3.5.0",
"vite-plugin-dts": "^3.8.1",
"vite-plugin-istanbul": "^6.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/istanbul-widget/shims.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'strip-dirs' {
export default (path: string, length: number) => string
}
10 changes: 10 additions & 0 deletions packages/istanbul-widget/src/components/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export * from './alert-dialog'
export * from './button'
export * from './dialog'
export * from './input'
export * from './label'
export * from './popover'
export * from './switch'
export * from './toast'
export * from './toaster'
export * from './use-toast'
4 changes: 2 additions & 2 deletions packages/istanbul-widget/src/components/ui/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ const PopoverContent = React.forwardRef<
React.ElementRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Portal container={document.querySelector(`#${ISTANBUL_WIDGET_ID}`) as HTMLElement}>
<PopoverPrimitive.Portal container={document.querySelector(`#${ISTANBUL_WIDGET_ID}`) as HTMLElement} forceMount>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
"iw-z-50 iw-w-fit iw-rounded-md iw-border iw-bg-popover iw-text-popover-foreground iw-shadow-md iw-outline-none data-[state=open]:iw-animate-in data-[state=closed]:iw-animate-out data-[state=closed]:iw-fade-out-0 data-[state=open]:iw-fade-in-0 data-[state=closed]:iw-zoom-out-95 data-[state=open]:iw-zoom-in-95 data-[side=bottom]:iw-slide-in-from-top-2 data-[side=left]:iw-slide-in-from-right-2 data-[side=right]:iw-slide-in-from-left-2 data-[side=top]:iw-slide-in-from-bottom-2",
"iw-z-50 iw-w-fit iw-rounded-md iw-border iw-bg-popover iw-text-popover-foreground iw-shadow-md iw-outline-none data-[state=open]:iw-animate-in data-[state=closed]:iw-animate-out data-[state=closed]:iw-fade-out-0 data-[state=open]:iw-fade-in-0 data-[state=closed]:iw-zoom-out-95 data-[state=open]:iw-zoom-in-95 data-[side=bottom]:iw-slide-in-from-top-2 data-[side=left]:iw-slide-in-from-right-2 data-[side=right]:iw-slide-in-from-left-2 data-[side=top]:iw-slide-in-from-bottom-2 data-[state=closed]:iw-hidden",
className
)}
{...props}
Expand Down
88 changes: 88 additions & 0 deletions packages/istanbul-widget/src/core/Context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { useDebounceFn, useLatest, useSetState } from '@minko-fe/react-hook'
import { createContainer } from 'context-state'
import { useToast } from '@/components/ui'
import { type IstanbulWidgetOptions, type PluginName, type PluginType, type ReportParams } from './options.interface'

export type InitialWidgetProps = IstanbulWidgetOptions & {
/**
* 插件
*/
pluginList: { [id: string]: PluginType }
}

function useContext(initialValues: InitialWidgetProps) {
/* ------------------- 上报 ------------------- */
type Action = {
id: string
fn: (params: ReportParams, ...args: any[]) => Promise<void> | void
}
const [reportActions, setReportActions] = useSetState<{
before: Action[]
on: Action[]
after: Action[]
}>({
before: [],
on: [],
after: [],
})

const { toast } = useToast()

const { beforeReport, onReport, afterReport } = initialValues.plugin?.report || {}

/**
* 额外参数,上报触发时代入
*/
const [_params, setReportFnParams] = useSetState<{
[key in PluginName]?: any
}>({})

const params = useLatest(_params)

const reportFn = useDebounceFn(
async (showToast: boolean = true) => {
const latestParams = params.current
try {
// before report
await Promise.all(reportActions.before.map(async (action) => await action.fn(latestParams)))
await beforeReport?.(window.__coverage__, latestParams)

await Promise.all(reportActions.on.map(async (action) => await action.fn(latestParams)))
await onReport?.(window.__coverage__, latestParams)
showToast &&
toast({
description: '上报成功',
})
} catch (e) {
showToast &&
toast({
description: '上报失败,请打开控制台查看原因',
variant: 'destructive',
})
console.error('[istanbul-widget]:', e)
} finally {
// after report
await Promise.all(reportActions.after.map(async (action) => await action.fn(latestParams)))
await afterReport?.(window.__coverage__, latestParams)
}
},
{
wait: 300,
leading: true,
trailing: false,
},
)

return {
...initialValues,
reportActions,
setReportActions,
reportFn,
setReportFnParams,
reportFnparams: params.current,
}
}

const Context = createContainer(useContext)

export default Context
Loading

0 comments on commit 8138a32

Please sign in to comment.