Skip to content

Commit fe523cf

Browse files
authored
Merge pull request #811 from finos/hotfix/sample-module
fix: ERR_MODULE_NOT_FOUND when sample plugins ran
2 parents 727aa84 + 0e90765 commit fe523cf

File tree

6 files changed

+67
-69
lines changed

6 files changed

+67
-69
lines changed

packages/git-proxy-notify-hello/package.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

plugins/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# GitProxy plugins & samples
2+
GitProxy supports extensibility in the form of plugins. These plugins are specified via [configuration](https://git-proxy.finos.org/docs/category/configuration) as NPM packages or JavaScript code on disk. For each plugin configured, GitProxy will attempt to load each package or file as a standard [Node module](https://nodejs.org/api/modules.html). Plugin authors will create instances of the extension classes exposed by GitProxy and use these objects to implement custom functionality.
3+
4+
For detailed documentation, please refer to the [GitProxy development resources on the project's site](https://git-proxy.finos.org/docs/development/plugins)
5+
6+
## Included plugins
7+
These plugins are maintained by the core GitProxy team. As a future roadmap item, organizations can choose to omit
8+
certain features of GitProxy by simply removing the dependency from a deployed version of the application.
9+
10+
- `git-proxy-plugin-samples`: "hello world" examples of the GitProxy plugin system
11+
12+
## Contributing
13+
14+
Please refer to the [CONTRIBUTING.md](https://git-proxy.finos.org/docs/development/contributing) file for information on how to contribute to the GitProxy project.

plugins/git-proxy-plugin-samples/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55

66
// Peer dependencies; its expected that these deps exist on Node module path if you've installed @finos/git-proxy
7-
import { PullActionPlugin } from "@finos/git-proxy/src/plugin";
8-
import { Step } from "@finos/git-proxy/src/proxy/actions";
7+
import { PullActionPlugin } from "@finos/git-proxy/src/plugin.js";
8+
import { Step } from "@finos/git-proxy/src/proxy/actions/index.js";
99

1010
class RunOnPullPlugin extends PullActionPlugin {
1111
constructor() {

plugins/git-proxy-plugin-samples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@finos/git-proxy-plugin-samples",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A set of sample (dummy) plugins for GitProxy to demonstrate how plugins are authored.",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1"

website/docs/development/plugins.mdx

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@ The below instructions are using the [`@finos/git-proxy-plugin-samples`](https:/
3232
1. Install both `@finos/git-proxy` and the `@finos/git-proxy-plugin-samples` package to the local `node_modules/` directory using the following command:
3333

3434
```bash
35-
$ npm install -g @finos/git-proxy@latest @finos/git-proxy-plugin-samples@0.1.0
35+
$ npm install -g @finos/git-proxy @finos/git-proxy-plugin-samples
3636
```
3737

3838
Alternatively, you can create local packages from source and install those instead.
3939
```bash
4040
$ git clone https://github.com/finos/git-proxy
4141
$ cd git-proxy
4242
$ npm pack
43-
$ npm install -g ./finos-git-proxy-1.3.5.tgz
4443
$ (cd plugins/git-proxy-plugin-samples && npm pack)
45-
$ npm install -g plugins/git-proxy-plugin-samples/finos-git-proxy-plugin-samples-0.1.0.tgz
44+
$ npm install -g \
45+
./finos-git-proxy-1.7.0.tgz \
46+
./plugins/git-proxy-plugin-samples/finos-git-proxy-plugin-samples-0.1.1.tgz
4647
```
4748

4849
2. Create or edit an existing `proxy.config.json` file to configure the plugin(s) to load. You must include the full import path that would typically be used in a `import {}` (ESM) or `require()` (CJS) statement:
@@ -85,7 +86,7 @@ $ cat package.json
8586
"name": "foo-plugin",
8687
...
8788
"dependencies": {
88-
"@finos/git-proxy": "^1.3.5"
89+
"@finos/git-proxy": "^1.7.0"
8990
}
9091
}
9192
# Alternatively, add git-proxy that is cloned locally as a file-based dependency
@@ -122,29 +123,42 @@ Loaded plugin: FooPlugin
122123

123124
## Developing new plugins
124125

125-
To develop a new plugin, you must add `@finos/git-proxy` as a [peer dependency](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies). The main app (also known as the "host application") exports the following extension points:
126+
To develop a new plugin, you must add `@finos/git-proxy` as a [peer dependency](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies). The plugin & proxy classes can then be imported from `@finos/git-proxy` via the following extension points:
126127

127-
- `@finos/git-proxy/src/plugin/PushActionPlugin`: execute as an action in the proxy chain during a `git push`
128-
- `@finos/git-proxy/src/plugin/PullActionPlugin`: execute as an action in the proxy chain during a `git fetch`
129-
- `@finos/git-proxy/src/proxy/actions/Step` and `@finos/git-proxy/src/proxy/actions/Action`: internal classes which act as carriers for `git` state during proxying. Plugins should modify the passed in `action` for affecting any global state of the git operation and add its own custom `Step` object to capture the plugin's own internal state (logs, errored/blocked status, etc.)
128+
```js
129+
import { PushActionPlugin } from '@finos/git-proxy/src/plugin.js'
130+
```
131+
- Use this class to execute as an action in the proxy chain during a `git push`
132+
133+
134+
```js
135+
import { PullActionPlugin } from '@finos/git-proxy/src/plugin.js'
136+
```
137+
- Use this class to execute as an action in the proxy chain during a `git fetch`
138+
139+
140+
```js
141+
import { Step, Action } from '@finos/git-proxy/src/proxy/actions/index.js'
142+
```
143+
- These are internal classes which act as carriers for `git` state during proxying. Plugins should modify the passed in `Action` for affecting any global state of the git operation and add its own custom `Step` object to capture the plugin's own internal state (logs, errored/blocked status, etc).
130144

131-
GitProxy will load your plugin only if it extends one of the two plugin classes above. It is also important that your package has [`exports`](https://nodejs.org/api/packages.html#exports) defined for the plugin loader to properly load your module(s).
145+
GitProxy will load your plugin only if it extends one of the two plugin classes above.
132146

133147
Please see the [sample plugin package included in the repo](https://github.com/finos/git-proxy/tree/main/plugins/git-proxy-plugin-samples) for details on how to structure your plugin package.
134148

135149
If your plugin relies on custom state, it is recommended to create subclasses in the following manner:
136150

137151
```javascript
138-
import { PushActionPlugin } from "@finos/git-proxy/src/plugin";
152+
import { PushActionPlugin } from "@finos/git-proxy/src/plugin.js";
139153

140154
class FooPlugin extends PushActionPlugin {
141155
constructor() {
142156
super(); // don't pass any function to the parent class - let the parent's this.exec function be undefined
143-
this.displayName = 'FooPlugin';
157+
this.someProperty = 'Hello from the FooPlugin';
144158
// overwrite the parent's exec function which is executed as part of GitProxy's action chain.
145159
// use an arrow function if you require access to the instances's state (properties, methods, etc.)
146160
this.exec = async (req, action) => {
147-
console.log(this.displayName);
161+
console.log(this.someProperty);
148162
this.utilMethod();
149163
// do something
150164
return action;
@@ -157,40 +171,20 @@ class FooPlugin extends PushActionPlugin {
157171
}
158172
```
159173

160-
### Example
174+
### Instructions for creating a new plugin package
161175

176+
1. Create a new directory for your plugin package and initialize a new npm package:
162177
```bash
163178
$ npm init
164179
# ...
165-
$ npm install --save-peer @finos/git-proxy@latest
180+
$ npm install --save-peer @finos/git-proxy
166181
```
167182

168-
`package.json`
169-
170-
```json
171-
{
172-
"name": "bar",
173-
"version": "1.0.0",
174-
"main": "index.js",
175-
"scripts": {
176-
"test": "echo \"Error: no test specified\" && exit 1"
177-
},
178-
"author": "",
179-
"license": "ISC",
180-
"description": "",
181-
"exports": {
182-
".": "./bar.js"
183-
},
184-
"peerDependencies": {
185-
"@finos/git-proxy": "^1.3.5"
186-
}
187-
}
188-
```
183+
2. Create a new JavaScript file for your plugin. The file should export an instance of `PushActionPlugin` or `PullActionPlugin`:
189184

190-
`bar.js`
191185
```javascript
192-
import { PushActionPlugin } from "@finos/git-proxy/src/plugin";
193-
import { Step } from "@finos/git-proxy/src/proxy/actions";
186+
import { PushActionPlugin } from "@finos/git-proxy/src/plugin.js";
187+
import { Step } from "@finos/git-proxy/src/proxy/actions/index.js";
194188

195189
//Note: Only use a default export if you do not rely on any state. Otherwise, create a sub-class of [Push/Pull]ActionPlugin
196190
export default new PushActionPlugin(function(req, action) {
@@ -206,3 +200,21 @@ export default new PushActionPlugin(function(req, action) {
206200
return action; // always return the action - even in the case of errors
207201
});
208202
```
203+
204+
3. In your GitProxy installation, install your plugin package & update the `proxy.config.json` file to include the path to your plugin module(s):
205+
206+
```bash
207+
$ npm install @finos/git-proxy /path/to/your/plugin/package
208+
$ cat proxy.config.json
209+
{
210+
"plugins": [
211+
"/path/to/your/plugin/package/index.js"
212+
]
213+
}
214+
$ git-proxy
215+
Service Listening on 8080
216+
HTTP Proxy Listening on 8000
217+
HTTPS Proxy Listening on 8443
218+
Found 1 plugin modules
219+
Loaded plugin: PushActionPlugin
220+
```

0 commit comments

Comments
 (0)