Skip to content

Commit 6fbdb36

Browse files
committed
improve docs about using plugins
1 parent 6f28d6f commit 6fbdb36

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

docs/docs/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ npx v8r@latest <filename>
2121
Local install:
2222

2323
```bash
24-
npm install -g v8r
25-
v8r <filename>
24+
npm install --save-dev v8r
25+
npx v8r <filename>
2626
```

docs/docs/plugins/using-plugins.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,63 @@ plugins:
1919
```
2020
2121
Plugins are invoked one at a time in the order they are specified in your config file.
22+
23+
In general, there are four ways that users invoke v8r:
24+
25+
- Local install (recommended)
26+
- Global install (`npm install -g v8r`)
27+
- Ad-hoc invocation (`npx v8r@latest`)
28+
- via [MegaLinter](https://megalinter.io/)
29+
30+
Each of these methods has slightly different considerations when working with plugins.
31+
32+
## Local Install
33+
34+
If you are using plugins, this is the recommended way to use v8r. In this case it is straightforward to use both NPM package plugins and local file plugins in your project. Install v8r and any plugins in your project's `package.json`. This allows you to pin your versions, co-ordinate upgrades in the event of any [breaking changes](../semver.md) and use different versions of v8r in different projects if needed.
35+
36+
## Global Install
37+
38+
It is possible to install v8r into the global environment using `npm install -g v8r`. This can be useful if you want to use v8r across lots of projects but this model may not be a good fit if you use plugins. That said, you can also install NPM package plugins into your global environment. For example `npm install -g v8r v8r-plugin-ndjson`.
39+
40+
As a general rule, if you have a project with a config file and local plugins, then you also want a local install of v8r. However, if you want to use local file plugins with a global install, you can run `npm link v8r` in your project dir. This will create a symlink in your project's `node_modules` dir to your global v8r install. That will then allow you to `import ... from "v8r";` in local plugins.
41+
42+
## Ad-hoc Invocation
43+
44+
It is also possible to invoke v8r directly from npm using `npx`. If you invoke v8r ad-hoc with npx, there is no way to use a local file plugin. However, you can install NPM package plugins into the temporary environment. For example:
45+
46+
```bash
47+
npx --package v8r-plugin-ndjson@latest --package v8r@latest -- v8r *.json
48+
```
49+
50+
For local file plugins, you will need an installation of some description.
51+
52+
## MegaLinter
53+
54+
[MegaLinter](https://megalinter.io/) is a separate project, but it is one of the most common ways that users consume v8r. MegaLinter effectively gives you a global install of v8r (with the drawbacks associated with that). However the global packages live in `/node-deps`.
55+
56+
Similar to a standard global install, you can install NPM packages into the global (or "root") environment. For example:
57+
58+
```yaml title=".mega-linter.yml"
59+
ENABLE_LINTERS:
60+
- JSON_V8R
61+
JSON_V8R_CLI_LINT_MODE: project
62+
JSON_V8R_PRE_COMMANDS:
63+
- command: 'npm install v8r-plugin-ndjson'
64+
continue_if_failed: False
65+
cwd: root
66+
```
67+
68+
It is also possible to use local plugins with MegaLinter. The workaround for this is similar to using a global install. In this case, it is necessary to create the symlink we need manually because `npm link` doesn't know to look at the packages installed in `/node-deps`.
69+
70+
```yaml title=".mega-linter.yml"
71+
ENABLE_LINTERS:
72+
- JSON_V8R
73+
JSON_V8R_CLI_LINT_MODE: project
74+
JSON_V8R_PRE_COMMANDS:
75+
- command: 'mkdir -p node_modules'
76+
continue_if_failed: False
77+
cwd: workspace
78+
- command: 'ln -s /node-deps/node_modules/v8r node_modules/v8r'
79+
continue_if_failed: False
80+
cwd: workspace
81+
```

0 commit comments

Comments
 (0)