@jchip/error 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,7 @@
1
1
  # @jchip/error <sup>[![Version Badge][npm-version-svg]][package-url]</sup> <!-- omit in toc -->
2
2
 
3
- [![dependency status][deps-svg]][deps-url]
4
- [![dev dependency status][dev-deps-svg]][dev-deps-url]
5
3
  [![License][license-image]][license-url]
6
4
  [![build][build-image]][build-url]
7
- [![coverage][coverage-image]][coverage-url]
8
5
 
9
6
  [![Downloads][downloads-image]][downloads-url]
10
7
 
@@ -152,16 +149,10 @@ AggregateError: require failed
152
149
  [aggregateerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError
153
150
  [license-image]: https://img.shields.io/npm/l/@jchip/error.svg
154
151
  [license-url]: LICENSE
155
- [build-image]: https://github.com/jchip/error/actions/workflows/node.js.yml/badge.svg
156
- [build-url]: https://github.com/jchip/error/actions/workflows/node.js.yml
157
- [coverage-image]: https://coveralls.io/repos/github/jchip/error/badge.svg?branch=main
158
- [coverage-url]: https://coveralls.io/github/jchip/error?branch=main
152
+ [build-image]: https://github.com/jchip/fynjs/actions/workflows/ci.yml/badge.svg
153
+ [build-url]: https://github.com/jchip/fynjs/actions/workflows/ci.yml
159
154
  [downloads-image]: https://img.shields.io/npm/dm/@jchip/error.svg
160
155
  [downloads-url]: https://npm-stat.com/charts.html?package=%40jchip%2Ferror
161
- [deps-svg]: https://david-dm.org/jchip/error.svg
162
- [deps-url]: https://david-dm.org/jchip/error
163
- [dev-deps-svg]: https://david-dm.org/jchip/error/dev-status.svg
164
- [dev-deps-url]: https://david-dm.org/jchip/error#info=devDependencies
165
156
  [npm-badge-png]: https://nodei.co/npm/@jchip/error.png?downloads=true&stars=true
166
157
  [package-url]: https://npmjs.com/package/@jchip/error
167
158
  [npm-version-svg]: https://versionbadg.es/jchip/error.svg
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** options for cleanErrorStack */
2
- declare type CleanErrorStackOptions = {
2
+ type CleanErrorStackOptions = {
3
3
  /** string to replace part of the stack trace paths */
4
4
  replacePath?: false | string;
5
5
  /** list of string or RegExp to match stack trace paths to ignore */
package/dist/index.js CHANGED
@@ -1,11 +1,4 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AggregateError = exports.aggregateErrorStack = exports.aggregateStack = exports.cleanErrorStack = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- /* eslint-disable @typescript-eslint/ban-ts-comment */
1
+ import Path from "path";
9
2
  const defaultPathFilter = [
10
3
  new RegExp(`/node_modules.*/(pirates/|isomorphic-loader/lib/extend-require)`),
11
4
  ];
@@ -16,7 +9,7 @@ const defaultPathFilter = [
16
9
  * @param options - clean error stack options
17
10
  * @returns cleaned up stack trace
18
11
  */
19
- function cleanErrorStack(error, { replacePath = `${process.cwd()}/`, ignorePathFilter = [] } = {}) {
12
+ export function cleanErrorStack(error, { replacePath = `${process.cwd()}/`, ignorePathFilter = [] } = {}) {
20
13
  const stack = error && (error.stack || error.message);
21
14
  if (!stack) {
22
15
  return String(stack);
@@ -32,7 +25,7 @@ function cleanErrorStack(error, { replacePath = `${process.cwd()}/`, ignorePathF
32
25
  // skip any stack tracing line not in these formats:
33
26
  // - " at Blah (/foo/bar:##:##)" format
34
27
  // - "scheme://path" (ie: webpack://path)
35
- if (!match || (!match[3].match(/[^:]+:\/\//) && !path_1.default.isAbsolute(match[3]))) {
28
+ if (!match || (!match[3].match(/[^:]+:\/\//) && !Path.isAbsolute(match[3]))) {
36
29
  return false;
37
30
  }
38
31
  const path = match[3].replace(/\\/g, "/");
@@ -48,7 +41,6 @@ function cleanErrorStack(error, { replacePath = `${process.cwd()}/`, ignorePathF
48
41
  .join("\n");
49
42
  return result;
50
43
  }
51
- exports.cleanErrorStack = cleanErrorStack;
52
44
  /**
53
45
  * Build stack of aggregate errors
54
46
  *
@@ -56,7 +48,7 @@ exports.cleanErrorStack = cleanErrorStack;
56
48
  * @param errors - aggregated errors
57
49
  * @returns aggregate stack
58
50
  */
59
- function aggregateStack(stack, errors) {
51
+ export function aggregateStack(stack, errors) {
60
52
  return [stack]
61
53
  .concat(errors &&
62
54
  errors.map &&
@@ -66,23 +58,20 @@ function aggregateStack(stack, errors) {
66
58
  }))
67
59
  .join("\n");
68
60
  }
69
- exports.aggregateStack = aggregateStack;
70
61
  /**
71
62
  * build the aggregate stack of an AggregateError
72
63
  *
73
64
  * @param error aggregate error
74
65
  * @returns aggregate stack
75
66
  */
76
- /* eslint-disable-next-line no-use-before-define */
77
- function aggregateErrorStack(error) {
67
+ export function aggregateErrorStack(error) {
78
68
  return aggregateStack(error.__stack || error.message || String(error), error.errors);
79
69
  }
80
- exports.aggregateErrorStack = aggregateErrorStack;
81
70
  /**
82
71
  * AggregateError
83
72
  * - https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-aggregate-error-objects
84
73
  */
85
- class AggregateError extends Error {
74
+ export class AggregateError extends Error {
86
75
  constructor(errors, msg) {
87
76
  if (!errors || !(errors[Symbol.iterator] instanceof Function)) {
88
77
  throw new TypeError(`input errors must be iterable but it's ${typeof errors}`);
@@ -113,5 +102,3 @@ class AggregateError extends Error {
113
102
  });
114
103
  }
115
104
  }
116
- exports.AggregateError = AggregateError;
117
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,20 +1,28 @@
1
1
  {
2
2
  "name": "@jchip/error",
3
- "version": "1.0.3",
3
+ "version": "2.0.0",
4
4
  "description": "utilities and polyfill for node.js errors",
5
- "homepage": "https://jchip.github.io/error",
6
- "main": "dist/index.js",
5
+ "homepage": "https://github.com/jchip/fynjs/tree/main/packages/error",
6
+ "type": "module",
7
+ "types": "./dist/index.d.ts",
8
+ "main": "./dist/index.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "engines": {
17
+ "node": ">=22.12.0"
18
+ },
7
19
  "scripts": {
8
- "build": "tsc",
9
- "test": "xrun xarc/test-only",
10
- "lint": "xrun xarc/lint",
11
- "coverage": "xrun xarc/test-cov",
12
- "coveralls": "cat coverage/lcov.info | coveralls",
13
- "check": "xrun --serial xarc/check coveralls",
14
- "publish-util-pre": "publish-util-prepublishonly",
15
- "prepublishOnly": "xrun --serial [[build, docs], xarc/check, publish-util-pre]",
16
- "postpack": "publish-util-postpack",
17
- "docs": "xrun xarc/docs"
20
+ "build": "rm -rf dist && tsc -p tsconfig.json",
21
+ "test": "vitest run",
22
+ "ci:check": "tsc --noEmit -p tsconfig.json && npm test",
23
+ "coverage": "vitest run --coverage",
24
+ "prepublishOnly": "xrun build",
25
+ "postpack": "publish-util-postpack"
18
26
  },
19
27
  "keywords": [
20
28
  "errors",
@@ -32,18 +40,19 @@
32
40
  "license": "Apache-2.0",
33
41
  "dependencies": {},
34
42
  "files": [
35
- "dist",
36
- "src"
43
+ "dist"
37
44
  ],
38
45
  "publishConfig": {
39
46
  "access": "public",
40
47
  "registry": "https://registry.npmjs.com/"
41
48
  },
49
+ "bugs": {
50
+ "url": "https://github.com/jchip/fynjs/issues"
51
+ },
42
52
  "repository": {
43
53
  "type": "git",
44
- "url": "https://github.com/jchip/error"
54
+ "url": "git+https://github.com/jchip/fynjs.git",
55
+ "directory": "packages/error"
45
56
  },
46
- "engines": {
47
- "node": ">= 10"
48
- }
57
+ "sideEffects": false
49
58
  }
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
1
- # v1.0.3
2
-
3
- # v1.0.2
4
-
5
- # v1.0.1
6
-
7
- # v1.0.0 - 2021/08/20
8
-
9
- first release
10
-
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/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AAK,CAAC,MAAM,CAAC,CAAC;AACvF,CAAC;AAFD,kDAEC;AAED;;;GAGG;AACH,MAAa,cAAe,SAAQ,KAAK;IASvC,YAAY,MAAc,EAAE,GAAY;QACtC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,QAAQ,CAAC,EAAE;YAC7D,MAAM,IAAI,SAAS,CAAC,0CAA0C,OAAO,MAAM,EAAE,CAAC,CAAC;SAChF;QACD,KAAK,CAAC,GAAG,CAAC,CAAC;QAEX,oFAAoF;QACpF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;QAEjE,IAAI,QAAgB,CAAC;QAErB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;YAC5B,mCAAmC;YACnC,MAAM,EAAE;gBACN,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE,KAAK;gBACjB,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;aACzB;YACD,sBAAsB;YACtB,OAAO,EAAE;gBACP,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB;YACD,uBAAuB;YACvB,KAAK,EAAE;gBACL,GAAG;oBACD,OAAO,QAAQ,IAAI,CAAC,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC5D,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAzCD,wCAyCC"}
package/src/index.ts DELETED
@@ -1,140 +0,0 @@
1
- import Path from "path";
2
-
3
- /* eslint-disable @typescript-eslint/ban-ts-comment */
4
-
5
- const defaultPathFilter = [
6
- new RegExp(`/node_modules.*/(pirates/|isomorphic-loader/lib/extend-require)`),
7
- ] as (string | RegExp)[];
8
-
9
- /** options for cleanErrorStack */
10
- type CleanErrorStackOptions = {
11
- /** string to replace part of the stack trace paths */
12
- replacePath?: false | string;
13
- /** list of string or RegExp to match stack trace paths to ignore */
14
- ignorePathFilter?: (string | RegExp)[];
15
- };
16
-
17
- /**
18
- * Return the stack text of an error with internal modules removed
19
- *
20
- * @param error - error
21
- * @param options - clean error stack options
22
- * @returns cleaned up stack trace
23
- */
24
- export function cleanErrorStack(
25
- error: Error,
26
- { replacePath = `${process.cwd()}/`, ignorePathFilter = [] }: CleanErrorStackOptions = {}
27
- ): string {
28
- const stack = error && (error.stack || error.message);
29
- if (!stack) {
30
- return String(stack);
31
- }
32
-
33
- const result = stack
34
- .split("\n")
35
- .map((line) => {
36
- // keep all non stack tracing lines
37
- if (!line.match(/ {4,}at/)) {
38
- return line;
39
- }
40
- const match = line.match(/( {4,}at)([^\(]+\()([^\)]+\))(.*)/);
41
- // skip any stack tracing line not in these formats:
42
- // - " at Blah (/foo/bar:##:##)" format
43
- // - "scheme://path" (ie: webpack://path)
44
- if (!match || (!match[3].match(/[^:]+:\/\//) && !Path.isAbsolute(match[3]))) {
45
- return false;
46
- }
47
- const path = match[3].replace(/\\/g, "/");
48
- if (
49
- defaultPathFilter
50
- .concat(ignorePathFilter)
51
- .find((s) => s && (s instanceof RegExp ? path.match(s) : path.includes(s)))
52
- ) {
53
- return false;
54
- }
55
- const path2 = replacePath && replacePath.length > 1 ? path.replace(replacePath, "") : path;
56
- return `${match[1]}${match[2]}${path2}${match[4]}`;
57
- })
58
- .filter((x) => x)
59
- .join("\n");
60
-
61
- return result;
62
- }
63
-
64
- /**
65
- * Build stack of aggregate errors
66
- *
67
- * @param stack - top error
68
- * @param errors - aggregated errors
69
- * @returns aggregate stack
70
- */
71
- export function aggregateStack(stack: string, errors: any[]): string {
72
- return [stack]
73
- .concat(
74
- errors &&
75
- errors.map &&
76
- errors.map((e) => {
77
- const s = e && (e.stack || e.message);
78
- return (s || String(e)).replace(/^/gm, " ");
79
- })
80
- )
81
- .join("\n");
82
- }
83
-
84
- /**
85
- * build the aggregate stack of an AggregateError
86
- *
87
- * @param error aggregate error
88
- * @returns aggregate stack
89
- */
90
- /* eslint-disable-next-line no-use-before-define */
91
- export function aggregateErrorStack(error: AggregateError): string {
92
- return aggregateStack(error.__stack || error.message || String(error), error.errors);
93
- }
94
-
95
- /**
96
- * AggregateError
97
- * - https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-aggregate-error-objects
98
- */
99
- export class AggregateError extends Error {
100
- /** "AggregateError" */
101
- readonly name: string;
102
- /** errors collected */
103
- errors: any[];
104
- /** aggregate stack */
105
- stack: string;
106
- /** original error stack before generating an aggregate one */
107
- __stack: string;
108
- constructor(errors?: any[], msg?: string) {
109
- if (!errors || !(errors[Symbol.iterator] instanceof Function)) {
110
- throw new TypeError(`input errors must be iterable but it's ${typeof errors}`);
111
- }
112
- super(msg);
113
-
114
- // Using defineProperty to replicate behavior of Object.keys(new Error()) returns []
115
- Object.defineProperty(this, "name", { value: "AggregateError" });
116
-
117
- let aggStack: string;
118
-
119
- Object.defineProperties(this, {
120
- // specify errors according to spec
121
- errors: {
122
- configurable: true,
123
- enumerable: false,
124
- writable: true,
125
- value: [].concat(errors),
126
- },
127
- // save original stack
128
- __stack: {
129
- enumerable: false,
130
- value: this.stack,
131
- },
132
- // make aggregate stack
133
- stack: {
134
- get() {
135
- return aggStack || (aggStack = aggregateErrorStack(this));
136
- },
137
- },
138
- });
139
- }
140
- }