Skip to content

Commit

Permalink
chore: release
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Apr 26, 2024
1 parent a1cc2ab commit 639d522
Show file tree
Hide file tree
Showing 35 changed files with 3,286 additions and 1,194 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-readers-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-istanbul-widget": minor
---

feat: add astro integration
5 changes: 5 additions & 0 deletions .changeset/healthy-planes-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"istanbul-widget": minor
---

esm bundle all and fix context-state production error
21 changes: 13 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)

const { defineConfig } = require('@minko-fe/eslint-config')
export default defineConfig([
{
ignores: ['**/packages/istanbul-widget/src/components/**/*'],
},
{
rules: {
'node/no-deprecated-api': 'off',
export default defineConfig(
[
{
ignores: ['**/packages/istanbul-widget/src/components/**/*'],
},
{
rules: {
'node/no-deprecated-api': 'off',
},
},
],
{
astro: true,
},
])
)
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"description": "istanbul toolkit",
"type": "module",
"keywords": [
"istanbul"
"istanbul",
"istanbul-toolkit",
"coverage",
"vite"
],
"license": "MIT",
"repository": {
Expand All @@ -27,7 +30,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^18.6.1",
"@commitlint/cli": "^19.3.0",
"@minko-fe/commitlint-config": "^2.0.7",
"@minko-fe/eslint-config": "^2.2.2",
"@minko-fe/prettier-config": "^2.2.0",
Expand All @@ -36,10 +39,10 @@
"eslint": "^8.57.0",
"nyc": "^15.1.0",
"simple-git-hooks": "^2.11.1",
"taze": "^0.11.4",
"taze": "^0.13.7",
"tsup": "^8.0.2",
"turbo": "^1.13.0",
"typescript": "^5.4.3"
"turbo": "^1.13.3",
"typescript": "^5.4.5"
},
"simple-git-hooks": {
"commit-msg": "npm run commitlint",
Expand Down
7 changes: 4 additions & 3 deletions packages/istanbul-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"files": [
"**"
],
"main": "./dist/istanbul-widget.esm.js",
"main": "./dist/es/istanbul-widget.js",
"module": "./dist/es/istanbul-widget.js",
"types": "./dist/istanbul-widget.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/istanbul-widget.d.ts",
"import": "./dist/es/istanbul-widget.js"
"import": "./dist/es/istanbul-widget.js",
"default": "./dist/istanbul-widget.esm.js"
},
"./components": {
"types": "./component.d.ts",
Expand Down Expand Up @@ -48,7 +49,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"consola": "^3.2.3",
"context-state": "^2.3.1",
"context-state": "^3.0.0",
"eventemitter3": "^5.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
7 changes: 3 additions & 4 deletions packages/istanbul-widget/src/core/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deepMerge, isArray, isFunction, isObject, set } from '@minko-fe/lodash-pro'
import { type ConsolaInstance, LogLevels, createConsola } from 'consola'
import { type ConsolaInstance, LogLevels, createConsola } from 'consola/browser'
import { ButtonGroupPlugin } from '@/plugins/button-group/ButtonGroupPlugin'
import { ReportPlugin } from '@/plugins/report/ReportPlugin'
import { SettingPlugin } from '@/plugins/setting/SettingPlugin'
Expand Down Expand Up @@ -44,10 +44,9 @@ export class IstanbulWidget {

public static logger: ConsolaInstance

constructor(opts: IstanbulWidgetOptions) {
constructor(opts: IstanbulWidgetOptions = {}) {
IstanbulWidget.logger = createConsola({
level: opts.debug ? LogLevels.debug : LogLevels.box,
fancy: true,
level: opts?.debug ? LogLevels.debug : LogLevels.box,
})

if (!!IstanbulWidget.instance && IstanbulWidget.instance instanceof IstanbulWidget) {
Expand Down
7 changes: 6 additions & 1 deletion packages/istanbul-widget/src/plugins/report/Report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ function Report() {
const { report } = plugin || {}

return (
<Button size='sm' onClick={() => reportFn.run()}>
<Button
size='sm'
onClick={() => {
reportFn.run()
}}
>
{report?.text || '上报'}
</Button>
)
Expand Down
1 change: 1 addition & 0 deletions packages/istanbul-widget/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@minko-fe/tsconfig/tsconfig.project",
"compilerOptions": {
"moduleResolution": "Bundler",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
Expand Down
48 changes: 24 additions & 24 deletions packages/istanbul-widget/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ const common = (option: Options): Options => ({
},
})

const esmBundle: Options = {
const esmBundle = (option: Options): Options => ({
format: 'esm',
entry: {
'istanbul-widget.esm': 'src/istanbul-widget.ts',
},
dts: {
entry: {
'istanbul-widget': 'src/istanbul-widget.ts',
},
},
banner() {
return {
js: `import './istanbul-widget.esm.css';`,
}
},
}
dts: option.watch
? false
: {
entry: {
'istanbul-widget': 'src/istanbul-widget.ts',
},
},
noExternal: Object.keys(pkg.dependencies) || [],
splitting: false,
injectStyle: true,
})

const iife: Options = {
const iife = (_option: Options): Options => ({
injectStyle: true,
format: 'iife',
entry: {
Expand All @@ -131,35 +131,35 @@ const iife: Options = {
options.logOverride!['empty-import-meta'] = 'silent'
},
dts: false,
minify: true,
}
})

const esmBundleless: Options = {
const esmBundleless = (option: Options): Options => ({
entry: ['src/**/*.{ts,tsx,css}'],
dts: {
entry: getEntry('src/**/*.{ts,tsx}'),
},
dts: option.watch
? false
: {
entry: getEntry('src/**/*.{ts,tsx}'),
},
format: 'esm',
outDir: 'dist/es',
outExtension: () => ({ js: '.js' }),
esbuildPlugins: [fileSuffixPlugin('esm')],
splitting: false,
external: ['react', 'react-dom'],
}
})

export default defineConfig((option) => {
return [
{
...common(option),
...esmBundleless,
...esmBundleless(option),
},
{
...common(option),
...esmBundle,
...esmBundle(option),
},
{
...common(option),
...iife,
...iife(option),
},
]
})
73 changes: 66 additions & 7 deletions packages/vite-plugin-istanbul-widget/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# vite-plugin-istanbul-widget

> 集成了 istanbul-widget 和 vite-plugin-istanbul 的vite插件
>
> 额外支持astro
## 安装

```bash
npm install vite-plugin-istanbul-widget --save-dev
```

## 使用
## 上手

### vite.config

[参考配置](../../playground/react-app/vite.config.ts)

```ts
import { defineConfig } from 'vite'
Expand All @@ -18,7 +24,7 @@ import { istanbulWidget } from 'vite-plugin-istanbul-widget'
export default defineConfig((env) => ({
plugins: [
istanbulWidget({
enabled: env.mode === 'test',
enabled: env.mode === 'test', // 按需启用
istanbulWidgetConfig: {
plugin: {
report: {
Expand All @@ -38,15 +44,68 @@ export default defineConfig((env) => ({
}))
```

### astro.config

[参考配置](../../playground/astro-app/astro.config.ts)

```ts
import react from '@astrojs/react'
import { defineConfig } from 'astro/config'
import { exclude, istanbulWidget } from 'vite-plugin-istanbul-widget/astro'
import { publicTypescript } from 'vite-plugin-public-typescript'

export default defineConfig({
integrations: [
istanbulWidget({
enabled: true,
istanbulWidgetConfig: {
theme: 'dark',
defaultPosition: {
x: 0,
y: 100,
},
plugin: {
report: {
async onReport(coverage: any, ...args: any[]) {
await window.__report(coverage, ...args)
},
},
setting: {
autoReport: false,
onLeavePage: true,
requireReporter: true,
},
buttonGroup: [
{
text: '自定义按钮',
onClick(...args: any[]) {
window.__customClick(...args)
},
},
],
},
debug: true,
},
fullReport: true,
}),
react({
exclude,
}),
],
vite: {
plugins: [
publicTypescript({
babel: true,
}),
],
},
})
```

## 配置项

```ts
type VitePluginIstanbulWidgetOptions = {
/**
* 入口文件
* @default 'src/main.{ts,tsx}'
*/
entry?: string
/**
* 是否开启插件
* @default false
Expand Down
1 change: 1 addition & 0 deletions packages/vite-plugin-istanbul-widget/astro.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/astro'
10 changes: 9 additions & 1 deletion packages/vite-plugin-istanbul-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./astro": {
"types": "./astro.d.ts",
"require": "./dist/astro.cjs",
"import": "./dist/astro.js",
"default": "./dist/astro.js"
},
"./client": {
"types": "./client.d.ts"
Expand All @@ -29,6 +36,7 @@
"devDependencies": {
"@types/node": "^20.11.30",
"@types/serialize-javascript": "^5.0.4",
"astro": "^4.7.0",
"serialize-javascript": "^6.0.2",
"vite": "^5.0.8"
}
Expand Down
Loading

0 comments on commit 639d522

Please sign in to comment.