Compare commits

...

6 Commits

Author SHA1 Message Date
github-actions[bot]
f9014c15a6 Version Packages 2022-03-07 18:42:20 +01:00
Thomas Allmer
7e277cd88f feat(plugins-manager): support a wrapPlugin property for adding 2022-03-07 18:35:41 +01:00
Thomas Allmer
bc6106381c chore: lock file maintainance 2022-03-06 21:05:23 +01:00
dependabot[bot]
00bf3882f6 chore(deps-dev): bump node-fetch from 2.6.1 to 2.6.7
Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.1 to 2.6.7.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Commits](https://github.com/node-fetch/node-fetch/compare/v2.6.1...v2.6.7)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-06 20:51:33 +01:00
dependabot[bot]
543e297c5b chore(deps): bump pathval from 1.1.0 to 1.1.1
Bumps [pathval](https://github.com/chaijs/pathval) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/chaijs/pathval/releases)
- [Changelog](https://github.com/chaijs/pathval/blob/master/CHANGELOG.md)
- [Commits](https://github.com/chaijs/pathval/compare/v1.1.0...v1.1.1)

---
updated-dependencies:
- dependency-name: pathval
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-06 20:50:48 +01:00
dependabot[bot]
70b0ce8e1c chore(deps): bump simple-get from 3.1.0 to 3.1.1
Bumps [simple-get](https://github.com/feross/simple-get) from 3.1.0 to 3.1.1.
- [Release notes](https://github.com/feross/simple-get/releases)
- [Commits](https://github.com/feross/simple-get/compare/v3.1.0...v3.1.1)

---
updated-dependencies:
- dependency-name: simple-get
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-06 20:50:31 +01:00
7 changed files with 272 additions and 514 deletions

View File

@@ -112,16 +112,13 @@ addPlugin(MyClass, { otherProp: 'new name' }); // ts error
Many plugin systems require you to either execute a plugin function like in `rollup`.
<!-- prettier-ignore-start -->
```js
import json from '@rollup/plugin-json';
/** @type {import('rocket/cli').RocketCliConfig} */
export default ({
export default /** @type {import('rocket/cli').RocketCliConfig} */ ({
plugins: [json({ preferConst: true })],
});
```
<!-- prettier-ignore-end -->
or add it in a special way like in `eleventy`
@@ -254,6 +251,18 @@ addPlugin(myPlugin, { myFlag: true }); // ts ok
addPlugin(myPlugin, { notExisting: true }); // ts error
```
Note: There is a "hidden" feature in addPlugin that if you attach a `wrapPlugin` property to the returning function it will call `wrapPlugin` on the plugin before adding it.
```js
// example auto wrap rollup plugins for @web/dev-server
import { fromRollup } from '@web/dev-server-rollup';
const userSetupFunctions = [addPlugin(json)].map(mod => {
mod.wrapPlugin = fromRollup;
return mod;
});
```
## Adjusting Plugin Options
Adjusting options means to either

View File

@@ -47,7 +47,7 @@
"update-package-configs": "node scripts/update-package-configs.mjs && yarn format"
},
"devDependencies": {
"@changesets/cli": "^2.12.0",
"@changesets/cli": "^2.20.0",
"@custom-elements-manifest/analyzer": "^0.4.12",
"@open-wc/testing": "^3.0.0-next.1",
"@rollup/plugin-commonjs": "^17.0.0",
@@ -75,7 +75,7 @@
"husky": "^4.3.7",
"lint-staged": "^10.5.3",
"mocha": "^8.2.1",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.7",
"npm-run-all": "^4.1.5",
"onchange": "^7.1.0",
"prettier": "^2.2.1",
@@ -84,8 +84,6 @@
"puppeteer": "^9.0.0",
"remark-emoji": "^2.1.0",
"rimraf": "^3.0.2",
"rocket-preset-code-tabs": "^0.2.6",
"rocket-preset-custom-elements-manifest": "^0.1.7",
"rollup": "^2.36.1",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^9.2.3",

View File

@@ -1,5 +1,11 @@
# plugins-manager
## 0.3.1
### Patch Changes
- 7e277cd: Add a "hidden" feature in addPlugin that if you attach a `wrapPlugin` property to the returning function it will call `wrapPlugin` on the plugin before adding it.
## 0.3.0
### Minor Changes

View File

@@ -1,6 +1,6 @@
{
"name": "plugins-manager",
"version": "0.3.0",
"version": "0.3.1",
"publishConfig": {
"access": "public"
},

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
* @template {import('../types/main').Plugin} T
* @param {T} plugin
@@ -12,6 +13,10 @@ export function addPlugin(plugin, options = {}, { how = 'after', location = 'bot
if (plugins === undefined) {
plugins = [];
}
// @ts-ignore
const usePlugin = addPluginFn.wrapPlugin ? addPluginFn.wrapPlugin(plugin) : plugin;
// only add if name is not already in the meta plugin list
if (plugins.findIndex(pluginObj => pluginObj.plugin === plugin) === -1) {
let index = -1;
@@ -40,7 +45,7 @@ export function addPlugin(plugin, options = {}, { how = 'after', location = 'bot
}
plugins.splice(index, 0, {
plugin,
plugin: usePlugin,
options,
});
}

View File

@@ -109,4 +109,18 @@ describe('addPlugin', () => {
});
expect(config.plugins).to.deep.equal(['-- newFirst last Plugin --']);
});
it('[advanced] can add a `wrapPlugin` property to the function itself which will call it on the plugin on init', async () => {
function myWrapper(plugin) {
return () => 'wrapped' + plugin();
}
const config = applyPlugins({
setupPlugins: [addPlugin(insertPlugin)].map(mod => {
mod.wrapPlugin = myWrapper;
return mod;
}),
});
expect(config.plugins).to.deep.equal(['wrapped-- first last Plugin --']);
});
});

734
yarn.lock

File diff suppressed because it is too large Load Diff