Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added scripts to serve plugins locally for dev #140

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,38 @@ cd plugins/plugin
npm start # starts just the current directory plugin in watch mode
```

This will rebuild the plugin(s) any time the source changes. However, you still need to restart the deephaven-core server each time a change is made for the change to be picked up.
This will rebuild the plugin(s) any time the source changes. If you are mapping the folder directly via DHC start options, you will need to restart the deephaven-core server each time a change is made for the change to be picked up.

##### Serve Plugins

Vite supports a proxy configuration that can be used to point local DHC or DHE to another url when loading plugins. This has the benefit of not requiring a server restart when developing plugins. If you would like to use this option, you can run:

```shell
npm run serve
```

This will serve the `plugins` directory at `http://localhost:5173`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the port in the readme match the default in the config?

const DEFAULT_PORT = 4100;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll fix in another PR


The vite proxy can be configured in DHC with something like:

```typescript
proxy['/js-plugins'] = {
target: 'http://localhost:4100',
changeOrigin: true,
rewrite: path => path.replace(/^\/js-plugins/, ''),
};
```

The proxy can be configured in DHE for DeephavenCommunity worker with:

```typescript
proxy['/iriside/worker-kind/DeephavenCommunity/plugins'] = {
target: 'http://localhost:4100',
changeOrigin: true,
rewrite: path =>
path.replace(/^\/iriside\/worker-kind\/DeephavenCommunity\/plugins/, ''),
};
```

#### Running deephaven-core

Expand Down
169 changes: 167 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"scripts": {
"start": "lerna run start --stream",
"build": "lerna run build --stream",
"serve": "run-p start serve:plugins",
"serve:plugins": "vite",
"test": "jest --watch --changedSince origin/main",
"test:unit": "jest --config jest.config.unit.cjs",
"test:lint": "jest --config jest.config.lint.cjs",
Expand All @@ -23,8 +25,8 @@
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.2.5",
"@types/shortid": "^0.0.29",
"@types/prop-types": "^15.7.10",
"@types/shortid": "^0.0.29",
"eslint": "^8.37.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.6.2",
Expand All @@ -37,7 +39,8 @@
"lerna": "^6.6.1",
"npm-run-all": "^4.1.5",
"nx": "15.9.2",
"prettier": "^2.8.7"
"prettier": "^2.8.7",
"vite": "~4.1.4"
},
"prettier": "@deephaven/prettier-config"
}
18 changes: 18 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig, loadEnv } from 'vite';

const DEFAULT_PORT = 4100;

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const port = Number(env.PORT || process.env.PORT || DEFAULT_PORT);

// This config doesn't build anything, it just serves the files from the
// plugins directory
return {
publicDir: 'plugins',
server: {
port,
},
};
});