Skip to content

Commit 766b4df

Browse files
Modernize: TypeScript, Jest, ESLint, GitHub Actions, verify-publish
- Migrate to TypeScript (src/index.ts, src/lib.ts) - Replace JSHint/Mocha with ESLint flat config and Jest - Add GitHub Actions CI (Node 20, 22, 24) - Add verify-publish smoke test - Herror as ES class, require new Herror() - Bump to 1.0.0, Node >=20 - Full MIT license in README (2017-present) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent fef889f commit 766b4df

29 files changed

Lines changed: 5557 additions & 421 deletions

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
node-version: ['20', '22', '24']
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Lint
30+
run: npm run lint
31+
32+
- name: Build
33+
run: npm run dist
34+
35+
- name: Test
36+
run: npm test

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
node_modules
2+
dist
3+
coverage
4+
*.tgz
5+
test/verify-publish/node_modules
6+
test/verify-publish/package-lock.json

.jshintrc

Lines changed: 0 additions & 19 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 58 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,90 @@
1-
# herro! [![NPM version][badge-npm]][link-npm][![npm downloads][badge-donwloads]][link-npm]
2-
3-
[![Build][badge-build]][link-build]
4-
5-
What if stack traces looked like this?
6-
7-
```sh
8-
Error: something broke
9-
at Context.<anonymous> (./test/Herror.js:9:17)
10-
at callFn (mocha@2.2.5/lib/runnable.js:266:21)
11-
at Test.Runnable.run (mocha@2.2.5/lib/runnable.js:259:7)
12-
at Runner.runTest (mocha@2.2.5/lib/runner.js:390:10)
13-
at mocha@2.2.5/lib/runner.js:473:12
14-
at next (mocha@2.2.5/lib/runner.js:315:14)
15-
at mocha@2.2.5/lib/runner.js:325:7
16-
at next (mocha@2.2.5/lib/runner.js:260:23)
17-
at Immediate._onImmediate (mocha@2.2.5/lib/runner.js:292:5)
18-
at processImmediate [as _immediateCallback] (timers.js:369:17)
1+
# herro
2+
3+
[![npm version](https://img.shields.io/npm/v/herro.svg)](https://www.npmjs.com/package/herro)
4+
[![npm downloads](https://img.shields.io/npm/dm/herro.svg)](https://www.npmjs.com/package/herro)
5+
[![CI](https://github.com/stringparser/herro/actions/workflows/ci.yml/badge.svg)](https://github.com/stringparser/herro/actions/workflows/ci.yml)
6+
7+
Humanized stack traces for the `Error` class: show `<module>@<version>` instead of `node_modules/<module>`, and add a footer with cwd, node version, and ISO date.
8+
9+
**Example:**
10+
11+
```
12+
Herror: something broke
13+
at Context.<anonymous> (./test/Herror.test.ts:9:17)
14+
at callFn (jest@29.7.0/lib/runnable.js:266:21)
15+
at Test.Runnable.run (jest@29.7.0/lib/runner.js:259:7)
16+
...
1917
--
20-
cwd /Users/stringparser/code/herro
21-
node-v1.5.0 2015-06-14T16:09:05.544Z
18+
cwd /Users/you/code/your-app
19+
node-v20.10.0 2025-02-07T12:00:00.000Z
2220
```
23-
Changes paths that have
24-
- The current working directory with `.`
25-
- `node_modules/<module>` with `<module>@<version>`
2621

27-
Adds a footer with
28-
- The current working directory
29-
- An ISO date and node version from were `error` was thrown
22+
- Replaces **cwd** with `.` and **`node_modules/<module>`** with **`<module>@<version>`**
23+
- Appends **cwd**, **node version**, and **ISO date** to the stack
3024

31-
## api
32-
```js
33-
var herro = require('herro');
34-
```
25+
---
3526

36-
The `module.exports` two functions
37-
- `herro.Herror`
38-
- `herro.global`
27+
## Install
3928

40-
### Herror
41-
```js
42-
function Herror(String message)
29+
```bash
30+
npm install herro
4331
```
44-
`Error` class with paths on its stack trace as `<module>@<version>`
45-
instead of `node_modules/<module>`. Inherits from the `Error` class.
4632

47-
_arguments_
48-
- `message` type string message for the error
33+
**Requires Node.js ≥20.**
4934

50-
_returns_
51-
- a new `error` instance
35+
---
5236

53-
#### usage
54-
```js
55-
var Herror = require('herro').Herror;
37+
## API
5638

57-
if('something broke'){
58-
throw new Herror('oh, no, you did not!');
59-
}
60-
```
39+
Built in TypeScript; types are included.
6140

62-
### global
63-
```js
64-
function global([Boolean flag])
65-
```
41+
### `Herror`
6642

67-
If `flag` is truthy or `undefined`, it will make all stack traces
68-
have `<module>@<version>` instead of `node_modules/<module>`. If `flag` is falsy it will revert stacktraces to their default format.
43+
Error subclass whose instances get humanized stack traces. Use with `new` only.
6944

70-
#### usage
71-
```js
72-
var herro = require('herro');
45+
```ts
46+
import { Herror } from 'herro';
7347

74-
herro.global(); // make it global
75-
herro.global(false); // go back to the normal stack format
48+
throw new Herror('something broke');
7649
```
7750

78-
## install
51+
### `global(flag?)`
7952

80-
With [npm](https://www.npmjs.com)
53+
When `flag` is truthy or omitted, all stack traces (including plain `Error`) use the humanized format. When `flag` is `false`, restores the default format.
8154

82-
```
83-
npm install herro
55+
```ts
56+
import { global } from 'herro';
57+
58+
global(); // enable humanized stacks globally
59+
global(false); // revert to default format
8460
```
8561

86-
## test
62+
### Utilities
8763

88-
```
89-
herro (master) ✔ npm test
90-
91-
herro
92-
Herror
93-
✓ should format stack traces
94-
✓ should have an ISO date string
95-
✓ should have the current node version
96-
✓ should have the current working directory
97-
npmize
98-
✓ CWD/node_modules/module/file.js into module@version
99-
✓ CWD/node_modules/m1/node_modules/m2/file.js into m1@version/m2@version2
100-
global
101-
✓ global(truthy || undefined) npmizes stacks
102-
✓ global(falsy) brings back default format
103-
104-
105-
8 passing (21ms)
106-
```
64+
- **`npmize(stack: string): string`** – transform a stack string to `<module>@<version>` paths
65+
- **`formatStack(stack: string): string`** – npmize and append cwd / node version / date footer
66+
67+
---
68+
69+
## Scripts
10770

108-
## license
71+
| Command | Description |
72+
|-------------------|----------------------------|
73+
| `npm run dist` | Build TypeScript to `dist/` |
74+
| `npm run lint` | Run ESLint |
75+
| `npm test` | Run Jest + verify-publish |
76+
| `npm run clean` | Remove verify-publish artifacts and `*.tgz` |
77+
78+
---
79+
80+
## License
10981

11082
The MIT License (MIT)
11183

112-
Copyright (c) 2014-present Javier Carrillo
84+
Copyright (c) 2017-present Javier Carrillo
11385

11486
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11587

11688
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11789

11890
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
119-
120-
<!-- links, etc -->
121-
122-
[link-npm]: http://www.npmjs.org/package/herro
123-
[link-build]: https://travis-ci.org/stringparser/herro/builds
124-
125-
[badge-npm]: http://img.shields.io/npm/v/herro.svg?style=flat-square
126-
[badge-build]: http://img.shields.io/travis/stringparser/herro/master.svg?style=flat-square
127-
[badge-donwloads]: http://img.shields.io/npm/dm/herro.svg?style=flat-square

eslint.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const js = require('@eslint/js');
2+
const globals = require('globals');
3+
const tseslint = require('typescript-eslint');
4+
5+
module.exports = tseslint.config(
6+
js.configs.recommended,
7+
...tseslint.configs.recommended,
8+
{
9+
languageOptions: {
10+
globals: {
11+
...globals.node,
12+
},
13+
parserOptions: {
14+
ecmaVersion: 2020,
15+
sourceType: 'module',
16+
},
17+
},
18+
rules: {
19+
'@typescript-eslint/no-require-imports': 'off',
20+
},
21+
}
22+
);

example.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

jest.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
roots: ['<rootDir>/test'],
6+
testMatch: ['**/*.test.ts'],
7+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
8+
moduleFileExtensions: ['ts', 'js', 'json'],
9+
verbose: true,
10+
transform: {
11+
'^.+\\.ts$': [
12+
'ts-jest',
13+
{
14+
tsconfig: {
15+
types: ['jest', 'node'],
16+
},
17+
},
18+
],
19+
},
20+
};

0 commit comments

Comments
 (0)