Skip to content

Commit 38c159e

Browse files
nzakasfasttime
andauthored
docs: Provide example of reading package.json for plugins meta (#18530)
* docs: Provide example of reading package.json for plugins meta fixes #18462 * Update docs/src/extend/plugins.md Co-authored-by: Francesco Trotta <github@fasttime.org> --------- Co-authored-by: Francesco Trotta <github@fasttime.org>
1 parent c6de7bb commit 38c159e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/src/extend/plugins.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,27 @@ export default plugin;
6262
module.exports = plugin;
6363
```
6464

65-
The `meta.name` property should match the npm package name for your plugin and the `meta.version` property should match the npm package version for your plugin. The easiest way to accomplish this is by reading this information from your `package.json`.
65+
The `meta.name` property should match the npm package name for your plugin and the `meta.version` property should match the npm package version for your plugin. The easiest way to accomplish this is by reading this information from your `package.json`, as in this example:
66+
67+
```js
68+
import fs from "fs";
69+
70+
const pkg = JSON.parse(fs.readFileSync(new URL("./package.json", import.meta.url), "utf8"));
71+
72+
const plugin = {
73+
74+
// preferred location of name and version
75+
meta: {
76+
name: pkg.name,
77+
version: pkg.version
78+
},
79+
rules: {
80+
// add rules here
81+
}
82+
};
83+
84+
export default plugin;
85+
```
6686
6787
::: tip
6888
While there are no restrictions on plugin names, it helps others to find your plugin on [npm](https://npmjs.com) when you follow these naming conventions:

0 commit comments

Comments
 (0)