From c5d200d99b4b68c47fe17a6ddf37717c4e01be39 Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Wed, 13 Nov 2024 16:24:41 +0000 Subject: [PATCH] refactor: remove exports from package.json and adjust imports Exports makes it hard to access other paths in the project Until we arrive on stable interfaces to access other parts of git-proxy removing exports would be helpful. Import paths have been adjusted slightly for plugins and the docs for plugins due to the exports aliases being a bit different. --- package.json | 5 ----- plugins/git-proxy-plugin-samples/example.cjs | 6 +++--- plugins/git-proxy-plugin-samples/index.js | 4 ++-- test/fixtures/test-package/default-export.js | 2 +- test/fixtures/test-package/multiple-export.js | 4 ++-- test/fixtures/test-package/package.json | 2 +- test/fixtures/test-package/subclass.js | 2 +- website/docs/development/plugins.mdx | 12 ++++++------ 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 065827d1..85baaed4 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,6 @@ "git-proxy": "./index.js", "git-proxy-all": "concurrently 'npm run server' 'npm run client'" }, - "exports": { - "./plugin": "./src/plugin.js", - "./proxy/actions": "./src/proxy/actions/index.js", - "./src/config/env": "./src/config/env.js" - }, "workspaces": [ "./packages/git-proxy-cli" ], diff --git a/plugins/git-proxy-plugin-samples/example.cjs b/plugins/git-proxy-plugin-samples/example.cjs index 42e6ea1b..581984ca 100644 --- a/plugins/git-proxy-plugin-samples/example.cjs +++ b/plugins/git-proxy-plugin-samples/example.cjs @@ -4,8 +4,8 @@ */ // Peer dependencies; its expected that these deps exist on Node module path if you've installed @finos/git-proxy -const { PushActionPlugin } = require('@finos/git-proxy/plugin'); -const { Step } = require('@finos/git-proxy/proxy/actions'); +const { PushActionPlugin } = require('@finos/git-proxy/src/plugin'); +const { Step } = require('@finos/git-proxy/src/proxy/actions'); 'use strict'; /** @@ -42,4 +42,4 @@ module.exports = { // Sub-classing is fine too if you require more control over the plugin logRequest: new LogRequestPlugin(), someOtherValue: 'foo', // This key will be ignored by the plugin loader -}; \ No newline at end of file +}; diff --git a/plugins/git-proxy-plugin-samples/index.js b/plugins/git-proxy-plugin-samples/index.js index 8aadb364..190799c8 100644 --- a/plugins/git-proxy-plugin-samples/index.js +++ b/plugins/git-proxy-plugin-samples/index.js @@ -4,8 +4,8 @@ */ // Peer dependencies; its expected that these deps exist on Node module path if you've installed @finos/git-proxy -import { PullActionPlugin } from "@finos/git-proxy/plugin"; -import { Step } from "@finos/git-proxy/proxy/actions"; +import { PullActionPlugin } from "@finos/git-proxy/src/plugin"; +import { Step } from "@finos/git-proxy/src/proxy/actions"; class RunOnPullPlugin extends PullActionPlugin { constructor() { diff --git a/test/fixtures/test-package/default-export.js b/test/fixtures/test-package/default-export.js index 7f3fbdc9..688c6906 100644 --- a/test/fixtures/test-package/default-export.js +++ b/test/fixtures/test-package/default-export.js @@ -1,4 +1,4 @@ -const { PushActionPlugin } = require('@osp0/finos-git-proxy/plugin'); +const { PushActionPlugin } = require('@finos/git-proxy/src/plugin'); // test default export module.exports = new PushActionPlugin(async (req, action) => { diff --git a/test/fixtures/test-package/multiple-export.js b/test/fixtures/test-package/multiple-export.js index 3963c025..eeb65caa 100644 --- a/test/fixtures/test-package/multiple-export.js +++ b/test/fixtures/test-package/multiple-export.js @@ -1,4 +1,4 @@ -const { PushActionPlugin, PullActionPlugin } = require('@osp0/finos-git-proxy/plugin'); +const { PushActionPlugin, PullActionPlugin } = require('@finos/git-proxy/src/plugin'); module.exports = { @@ -10,4 +10,4 @@ module.exports = { console.log('PullActionPlugin: ', action); return action; }), -} \ No newline at end of file +} diff --git a/test/fixtures/test-package/package.json b/test/fixtures/test-package/package.json index 1e122332..94b1d50b 100644 --- a/test/fixtures/test-package/package.json +++ b/test/fixtures/test-package/package.json @@ -2,6 +2,6 @@ "name": "test-package", "version": "0.0.0", "dependencies": { - "@osp0/finos-git-proxy": "file:../../.." + "@finos/git-proxy": "file:../../.." } } diff --git a/test/fixtures/test-package/subclass.js b/test/fixtures/test-package/subclass.js index ff98b9a2..8e789098 100644 --- a/test/fixtures/test-package/subclass.js +++ b/test/fixtures/test-package/subclass.js @@ -1,4 +1,4 @@ -const { PushActionPlugin } = require('@osp0/finos-git-proxy/plugin'); +const { PushActionPlugin } = require('@finos/git-proxy/src/plugin'); class DummyPlugin extends PushActionPlugin { constructor(exec) { diff --git a/website/docs/development/plugins.mdx b/website/docs/development/plugins.mdx index fa2610c4..2f24d0bb 100644 --- a/website/docs/development/plugins.mdx +++ b/website/docs/development/plugins.mdx @@ -124,9 +124,9 @@ Loaded plugin: FooPlugin 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: -- `@finos/git-proxy/plugin/PushActionPlugin`: execute as an action in the proxy chain during a `git push` -- `@finos/git-proxy/plugin/PullActionPlugin`: execute as an action in the proxy chain during a `git fetch` -- `@finos/git-proxy/proxy/actions/Step` and `@finos/git-proxy/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.) +- `@finos/git-proxy/src/plugin/PushActionPlugin`: execute as an action in the proxy chain during a `git push` +- `@finos/git-proxy/src/plugin/PullActionPlugin`: execute as an action in the proxy chain during a `git fetch` +- `@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.) 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). @@ -135,7 +135,7 @@ Please see the [sample plugin package included in the repo](https://github.com/f If your plugin relies on custom state, it is recommended to create subclasses in the following manner: ```javascript -import { PushActionPlugin } from "@finos/git-proxy/plugin"; +import { PushActionPlugin } from "@finos/git-proxy/src/plugin"; class FooPlugin extends PushActionPlugin { constructor() { @@ -189,8 +189,8 @@ $ npm install --save-peer @finos/git-proxy@latest `bar.js` ```javascript -import { PushActionPlugin } from "@finos/git-proxy/plugin"; -import { Step } from "@finos/git-proxy/proxy/actions"; +import { PushActionPlugin } from "@finos/git-proxy/src/plugin"; +import { Step } from "@finos/git-proxy/src/proxy/actions"; //Note: Only use a default export if you do not rely on any state. Otherwise, create a sub-class of [Push/Pull]ActionPlugin export default new PushActionPlugin(function(req, action) {