Skip to content

Commit

Permalink
Make default better 💞 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
willnguyen1312 authored Jan 15, 2024
1 parent d3b3de4 commit fc4d7d9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brave-cars-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@namnode/vite-plugin-inspect-react": minor
---

Make default better 💞
1 change: 1 addition & 0 deletions packages/vite-plugin-inspect-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
},
"dependencies": {
"@babel/core": "^7.23.7",
"@babel/plugin-proposal-decorators": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
Expand Down
16 changes: 15 additions & 1 deletion packages/vite-plugin-inspect-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { propName } from "./_internal"

type InspecType = "devtool" | "dom"

const defaultFormatDataInspectId = (id: string) => {
return id.substring(__dirname.length + 1)
}

export type Options = {
predicate?: (node: Node) => boolean
plugins?: PluginItem[]
Expand Down Expand Up @@ -36,6 +40,10 @@ export function inspectReact(options: Options): Plugin {
options.propName = propName
}

if (!options.formatDataInspectId) {
options.formatDataInspectId = defaultFormatDataInspectId
}

return {
name: "vite-plugin-inspect-react",

Expand All @@ -62,12 +70,18 @@ export function inspectReact(options: Options): Plugin {
)
}

let plugins: PluginItem[] = [["@babel/plugin-proposal-decorators", { decoratorsBeforeExport: true }]]

if (options.plugins) {
plugins = plugins.concat(options.plugins)
}

const ast = parse(code, {
configFile: false,
filename: id,
ast: true,
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
plugins: options.plugins,
plugins,
})

traverse(ast as Node, {
Expand Down
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc4d7d9

Please sign in to comment.