|
| 1 | +# package-json-plugin |
| 2 | + |
| 3 | +🕵️ **Code PushUp plugin for evaluating `package.json` configurations** 📦 |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +The plugin crawls the file base depending on your configuration and checks the content `package.json` files. |
| 8 | + |
| 9 | +You can configure the plugin with the following options: |
| 10 | + |
| 11 | +- `directory` - directory to crawl as string |
| 12 | +- `license` - file name pattern as string |
| 13 | +- `type` - size budget as number in bytes |
| 14 | +- `dependencies` - package dependencies as object |
| 15 | +- `devDependencies` - package dependencies as object |
| 16 | +- `optionalDependencies` - package dependencies as object |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file. |
| 21 | + |
| 22 | +2. Copy the [plugin source](../package-json) as is into your project |
| 23 | + |
| 24 | + 1. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.js`). |
| 25 | + |
| 26 | + Pass in the path or the directory to crawl (relative to `process.cwd()`). |
| 27 | + |
| 28 | + ```js |
| 29 | + import packageJsonPlugin from './package-json.plugin'; |
| 30 | + |
| 31 | + export default { |
| 32 | + // ... |
| 33 | + plugins: [ |
| 34 | + // ... |
| 35 | + packageJsonPlugin({ |
| 36 | + directory: 'dist', |
| 37 | + license: 'MIT', |
| 38 | + type: 'module', |
| 39 | + dependencies: { |
| 40 | + package1: '0.0.1', |
| 41 | + }, |
| 42 | + devDependencies: { |
| 43 | + package2: '0.0.1', |
| 44 | + }, |
| 45 | + optionalDependencies: { |
| 46 | + package3: '0.0.1', |
| 47 | + }, |
| 48 | + }), |
| 49 | + ], |
| 50 | + }; |
| 51 | + ``` |
| 52 | + |
| 53 | +3. (Optional) Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups). |
| 54 | + |
| 55 | + Assign weights based on what influence each audit and group should have on the overall category score (assign weight 0 to only include it for extra info, without influencing the category score). |
| 56 | + |
| 57 | +Use the recommendedRefs as quick starting point: |
| 58 | + |
| 59 | +```js |
| 60 | +import packageJsonPlugin, { recommendedRefs } from './package-json.plugin'; |
| 61 | +
|
| 62 | +export default { |
| 63 | + // ... |
| 64 | + categories: [ |
| 65 | + // ... |
| 66 | + { |
| 67 | + slug: 'package-json', |
| 68 | + title: 'Package Json', |
| 69 | + refs: [...recommendedRefs], |
| 70 | + }, |
| 71 | + ], |
| 72 | +}; |
| 73 | +``` |
| 74 | + |
| 75 | +Or set up more fine-grained categories over the exported group references: |
| 76 | + |
| 77 | +```js |
| 78 | +import packageJsonPlugin, { packageJsonDocumentationGroupRef, packageJsonPerformanceGroupRef, packageJsonVersionControlGroupRef } from './package-json.plugin'; |
| 79 | +
|
| 80 | +export default { |
| 81 | + // ... |
| 82 | + categories: [ |
| 83 | + // ... |
| 84 | + { |
| 85 | + slug: 'bug-prevention', |
| 86 | + title: 'Bug prevention', |
| 87 | + refs: [packageJsonVersionControlGroupRef], |
| 88 | + }, |
| 89 | + { |
| 90 | + slug: 'performance', |
| 91 | + title: 'Performance', |
| 92 | + refs: [packageJsonPerformanceGroupRef], |
| 93 | + }, |
| 94 | + { |
| 95 | + slug: 'documentation', |
| 96 | + title: 'Documentation', |
| 97 | + refs: [packageJsonDocumentationGroupRef], |
| 98 | + }, |
| 99 | + ], |
| 100 | +}; |
| 101 | +``` |
| 102 | + |
| 103 | +4. Run the CLI with `npx code-pushup collect` and view or upload report (refer to [CLI docs](../cli/README.md)). |
| 104 | + |
| 105 | +## Audits |
| 106 | + |
| 107 | +Detailed information about the audits can be found in the docs folder of the plugin. |
| 108 | + |
| 109 | +The following audits are present: |
| 110 | + |
| 111 | +**Documentation**: |
| 112 | + |
| 113 | +- [package-json-license](./docs/license.audit.md) |
| 114 | + |
| 115 | +**Performance**: |
| 116 | + |
| 117 | +- [package-json-type](./docs/type.audit.md) |
| 118 | + |
| 119 | +**Bug Prevention**: |
| 120 | + |
| 121 | +- [package-json-dependencies](./docs/dependencies.audit.md) |
| 122 | + |
| 123 | +## Helper |
| 124 | + |
| 125 | +You can use the following exports: |
| 126 | + |
| 127 | +### Constants: |
| 128 | + |
| 129 | +- [`packageSlug`](./src/constants.ts#L5) |
| 130 | +- [`audits`](./src/constants.ts#L6) |
| 131 | + |
| 132 | +### References: |
| 133 | + |
| 134 | +Preconfigured audit and group references are available |
| 135 | + |
| 136 | +The following groups can be referenced are present: |
| 137 | + |
| 138 | +- [`reccomendedRefs`](./src/scoring.ts#L65) |
| 139 | +- [`packageJsonVersionControlGroupRef`](./src/scoring.ts#L20) |
| 140 | +- [`packageJsonPerformanceGroupRef`](./src/scoring.ts#L39) |
| 141 | +- [`packageJsonVersionControlGroupRef`](./src/scoring.ts#L58) |
0 commit comments