Skip to content

Commit

Permalink
build(prettier): integrate prettier with eslint
Browse files Browse the repository at this point in the history
add husky pre-commit hook to ensure any changed files have prettier formatting applied automatically
prior to commit

fix #10
  • Loading branch information
Ed Clement authored and Splaktar committed Jan 27, 2022
1 parent 30507ba commit f180175
Show file tree
Hide file tree
Showing 14 changed files with 1,758 additions and 3,983 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage/
lib/
node_modules/
commitlint.config.js
jest.config.js
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": ["@verdaccio"],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"rules": {
"no-case-declarations": 0,
"@typescript-eslint/ban-ts-ignore": 0,
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx pretty-quick --staged
npm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/
lib/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120
}
20 changes: 8 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,27 @@ All notable changes to this project will be documented in this file. See [standa

## 1.0.0 (2021-12-23)


### ⚠ BREAKING CHANGES

* **configuration:** configuration option `enabled` changed to `metricsEnabled`
- **configuration:** configuration option `enabled` changed to `metricsEnabled`

### Features

* **metrics:** implement ability to collect default prometheus metrics ([001e8f8](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/001e8f804c74e81cbc25e099b956ca2d0de65be6)), closes [#4](https://github.com/xlts-dev/verdaccio-prometheus-middleware/issues/4)
* **metrics:** Initial implementation of package install/download metrics capturing and metrics endpoint ([11e8ac6](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/11e8ac6fc89c44531a5753d5b672276174972524))

- **metrics:** implement ability to collect default prometheus metrics ([001e8f8](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/001e8f804c74e81cbc25e099b956ca2d0de65be6)), closes [#4](https://github.com/xlts-dev/verdaccio-prometheus-middleware/issues/4)
- **metrics:** Initial implementation of package install/download metrics capturing and metrics endpoint ([11e8ac6](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/11e8ac6fc89c44531a5753d5b672276174972524))

### Bug Fixes

* **configuration:** configuration option `enabled` changed to `metricsEnabled` ([dbd0afe](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/dbd0afeb4e009dd217e006555c8ab87a0bc6f4a9))
* **metrics:** fix issue where package download counters were not fully accurate ([97eb944](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/97eb944f86dfc4c9a1c5ada3460986e92c0e8d01)), closes [#7](https://github.com/xlts-dev/verdaccio-prometheus-middleware/issues/7)
* **metrics:** Only collect metrics for download of tarball files. Metrics were previously collected for any GET request that looked like it was for a package.json or tarball install but this was less reliable as there were was no way to guarantee the request coming in was for an actual package.json (e.g. browser requests for favicon.ico). Also, Verdaccio would only hand off requests that generate a 401/403 to the middelware for non-tarball requests so metrics could be misleading. ([67caa0f](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/67caa0f2e733966af9ece23ab649879378bd28e4))
- **configuration:** configuration option `enabled` changed to `metricsEnabled` ([dbd0afe](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/dbd0afeb4e009dd217e006555c8ab87a0bc6f4a9))
- **metrics:** fix issue where package download counters were not fully accurate ([97eb944](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/97eb944f86dfc4c9a1c5ada3460986e92c0e8d01)), closes [#7](https://github.com/xlts-dev/verdaccio-prometheus-middleware/issues/7)
- **metrics:** Only collect metrics for download of tarball files. Metrics were previously collected for any GET request that looked like it was for a package.json or tarball install but this was less reliable as there were was no way to guarantee the request coming in was for an actual package.json (e.g. browser requests for favicon.ico). Also, Verdaccio would only hand off requests that generate a 401/403 to the middelware for non-tarball requests so metrics could be misleading. ([67caa0f](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/67caa0f2e733966af9ece23ab649879378bd28e4))

# 0.1.0 (2021-12-23)


### Bug Fixes

* **metrics:** Only collect metrics for download of tarball files. Metrics were previously collected for any GET request that looked like it was for a package.json or tarball install but this was less reliable as there were was no way to guarantee the request coming in was for an actual package.json (e.g. browser requests for favicon.ico). Also, Verdaccio would only hand off requests that generate a 401/403 to the middelware for non-tarball requests so metrics could be misleading. ([67caa0f](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/67caa0f2e733966af9ece23ab649879378bd28e4))

- **metrics:** Only collect metrics for download of tarball files. Metrics were previously collected for any GET request that looked like it was for a package.json or tarball install but this was less reliable as there were was no way to guarantee the request coming in was for an actual package.json (e.g. browser requests for favicon.ico). Also, Verdaccio would only hand off requests that generate a 401/403 to the middelware for non-tarball requests so metrics could be misleading. ([67caa0f](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/67caa0f2e733966af9ece23ab649879378bd28e4))

### Features

* **metrics:** Initial implementation of package install/download metrics capturing and metrics endpoint ([11e8ac6](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/11e8ac6fc89c44531a5753d5b672276174972524))
- **metrics:** Initial implementation of package install/download metrics capturing and metrics endpoint ([11e8ac6](https://github.com/xlts-dev/verdaccio-prometheus-middleware/commit/11e8ac6fc89c44531a5753d5b672276174972524))
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
# verdaccio-prometheus-middleware

Metrics middleware plugin for Verdaccio. Collects metrics specifically for package tarball install/download requests and
exposes them at a configurable metrics endpoint (defaults to `/-/metrics`). The metrics are produced in the standard
[prometheus metrics text format](https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-example).

A [counter](https://prometheus.io/docs/concepts/metric_types/#counter) metric is used to track the number of package
tarball installs/downloads. The following [labels](https://prometheus.io/docs/practices/naming/#labels) are applied to
_every_ request:

- `username` - The Verdaccio username of the user attempting to install/download a package. If the request is
unauthenticated then the value `UNKNOWN` is used.
- `userAgentName` - The name of the user agent the client used to make the request. It is derived from the `user-agent`
header on the request. If no `user-agent` header is provided it defaults to `UNKNOWN`.
- `statusCode` - The status code of the response from Verdaccio.

Optionally, an additional `packageGroup` label can be applied *if* a `packageGroups` option is added to the plugin
Optionally, an additional `packageGroup` label can be applied _if_ a `packageGroups` option is added to the plugin
configuration.

## Installation

Because of how Verdaccio loads plugins, you will need to install this package using an `npm` alias in your `package.json`:

```json
"dependencies": {
"verdaccio-metrics": "npm:@xlts.dev/verdaccio-prometheus-middleware"
}
```

## Configuration

Complete configuration example:

```yaml
middlewares:
metrics:
Expand All @@ -48,22 +54,25 @@ middlewares:
```
## Package Groups
The `packageGroups` configuration option accepts an object map whose keys are expected to be a regular expression string
and the value the name of the package group that should be used for the `packageGroup` metric label. If no
`packageGroups` are defined, a `packageGroup` [label](https://prometheus.io/docs/practices/naming/#labels) will NOT be
applied to the [counter](https://prometheus.io/docs/concepts/metric_types/#counter) metric.

The regular expression key is evaluated against the request path in the following manner:

```javascript
// scoped packages generally have the `/` url encoded to `%2f`
new RegExp(packageGroupRegex).test(decodeURIComponent(request.path))
new RegExp(packageGroupRegex).test(decodeURIComponent(request.path));
```

The order of the keys/values in the object map matters. The regular expressions are evaluated from first to last in the
order they are listed under the `packageGroups` configuration option and the first matching regex will have the
corresponding package grouping value applied when the install/download counter metric is collected.

Given the following example configuration:

```yaml
# Verdaccio config file
middlewares:
Expand All @@ -76,10 +85,11 @@ middlewares:
'@.*': scoped
'.*': other
```
... the following packages would resolve to the `packageGroup` as listed in the table:

| Package Name | Package Group |
|-----------------------------------|---------------|
| --------------------------------- | ------------- |
| `@babel/core` | babel |
| `@babel/parser` | babel |
| `@babel/plugin-transform-runtime` | babel-plugin |
Expand All @@ -90,8 +100,8 @@ middlewares:
| `react` | other |
| `apollo-server-express` | other |


## Contributing

This project enforces the [Angular commit message format](https://github.com/angular/angular/blob/13.1.1/CONTRIBUTING.md#-commit-message-format).

A [husky](https://typicode.github.io/husky/#/) `prepare-commit-msg` hook is used in conjunction with
Expand All @@ -103,13 +113,17 @@ is linted using [commitlint](https://commitlint.js.org/#/) and a [husky](https:/
is followed.

## Pull Requests

Prior to opening a pull request, please ensure that you run the command:

```bash
npm run release
```

This will automatically increment the version number in the `package.json` based on the types of commits contained in
the pull request and update the `CHANGELOG.md` appropriately. If a specific version type needs to be forced, the same
command can be executed with an argument passed:

```bash
# force incrementing to a new major version
npm run release -- -r major
Expand Down
Loading

0 comments on commit f180175

Please sign in to comment.