Skip to content

Commit

Permalink
docs: simplified npm link for dev debugging (apache#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud authored and zhaoyongjie committed Nov 24, 2021
1 parent 7e7d114 commit 43d7d60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,66 +1,25 @@
## Debugging Superset plugins in Superset app
# Debug Superset plugins in Superset app

### Activating plugins for local development
## Activate plugins for local development

1. Enable `npm link` for the package.
1. First, make sure you have run `yarn` and `yarn build` in `superset-ui` or your own plugin repo.
2. Go to [sueprset-frontend](https://github.com/apache/incubator-superset/tree/master/superset-frontend),
use `npm link` to create a symlink of the plugin source code in `node_modules`:

```sh
cd superset-ui
cd packages/superset-ui-chart
npm link
```
```sh
cd incubator-superset/superset-frontend
# npm link ~/path/to/your/plugin
npm link ../../superset-ui/plugins/plugin-chart-word-cloud
```

2. Link the local package to `incubator-superset`.
3. Start developing with webpack dev server:

```sh
cd incubator-superset/superset-frontend
npm link @superset-ui/chart \# use package name in package.json, not directory name
```
```sh
npm run dev-server
```

3. After npm link complete, update the import statements in Superset.
The dev server will automatically build from the source code under `path/to/your-plugin/src` and watch the changes.

Instead of
## Deactivate plugins

```js
import { xxx } from '@superset-ui/plugin-chart-horizon';
```

which will point to the transpiled code.

do refer to `src`

```js
import { xxx } from '@superset-ui/plugin-chart-horizon/src';
```

4. After that you can run `dev-server` as usual.

```sh
npm run dev-server
```

Now when you change the code in `@superset-ui`, it will update the app immediately similar to code
inside `incubator-superset`.

### Deactivating plugins for local development

1. Change the `import` statements back.

2. Unlink the package from `incubator-superset`.

```sh
cd incubator-superset/superset-frontend
npm unlink @superset-ui/chart
```

Note: Quite often, `npm link` mess up your `node_modules` and the `unlink` command above does not
work correctly, making webpack build fails or other unexpected behaviors. If that happens, just
delete your `node_modules` and `npm install` from scratch.

3. Clean up global link.

```sh
cd superset-ui
cd packages/superset-ui-chart
npm unlink
```
To deactivate a plugin, simply run `npm install` in `incubator-superset/superset-frontend` again.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,4 @@ yarn build
yarn storybook
```

### Tips

When developing, if you would like to see live changes in Storybook.

Instead of

```js
import { xxx } from '@superset-ui/plugin-chart-horizon';
```

which will point to the transpiled code.

Do refer to `src`

```js
import { xxx } from '@superset-ui/plugin-chart-horizon/src';
```

Then after you are satisfied with all the changes, `yarn build` the entire project and remove `/src`
from the `import` statement and check Storybook again. This rarely happens, but the minification
sometimes can cause issue and you may see different results ranging from crashing to different
behavior.
The Storybook will [automatically build from the source code](https://github.com/apache-superset/superset-ui/blob/master/packages/superset-ui-demo/.storybook/main.js#L49-L58) when package names start with `@superset-ui/`.

0 comments on commit 43d7d60

Please sign in to comment.