Skip to content

Commit

Permalink
docs: Provide example of reading package.json for plugins meta (#18530)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
nzakas and fasttime committed Jun 3, 2024
1 parent c6de7bb commit 38c159e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docs/src/extend/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,27 @@ export default plugin;
module.exports = plugin;
```

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`.
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:

```js
import fs from "fs";

const pkg = JSON.parse(fs.readFileSync(new URL("./package.json", import.meta.url), "utf8"));

const plugin = {

// preferred location of name and version
meta: {
name: pkg.name,
version: pkg.version
},
rules: {
// add rules here
}
};

export default plugin;
```
::: tip
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:
Expand Down

0 comments on commit 38c159e

Please sign in to comment.