@doist/cli-core 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
+ ## [0.2.0](https://github.com/Doist/cli-core/compare/v0.1.0...v0.2.0) (2026-05-06)
2
+
3
+ ### Features
4
+
5
+ * bake cli-core codes into CliError, add CliErrorCode aggregator ([#4](https://github.com/Doist/cli-core/issues/4)) ([8c0d959](https://github.com/Doist/cli-core/commit/8c0d95987db3b35b1715cd72eb603cbb99420211))
6
+
1
7
  ## [0.1.0](https://github.com/Doist/cli-core/compare/v0.0.1...v0.1.0) (2026-05-06)
2
8
 
3
9
  ### Features
4
10
 
5
- * add CliError + config file I/O helpers ([#1](https://github.com/Doist/cli-core/issues/1)) ([8daf2d1](https://github.com/Doist/cli-core/commit/8daf2d1f67f44f91713ffc2192b681704fa86d88))
6
- * add terminal detection + JSON/NDJSON formatters ([#2](https://github.com/Doist/cli-core/issues/2)) ([f2bfde8](https://github.com/Doist/cli-core/commit/f2bfde8ff3a2a41eb402acc49223980c5d4be393))
11
+ - add CliError + config file I/O helpers ([#1](https://github.com/Doist/cli-core/issues/1)) ([8daf2d1](https://github.com/Doist/cli-core/commit/8daf2d1f67f44f91713ffc2192b681704fa86d88))
12
+ - add terminal detection + JSON/NDJSON formatters ([#2](https://github.com/Doist/cli-core/issues/2)) ([f2bfde8](https://github.com/Doist/cli-core/commit/f2bfde8ff3a2a41eb402acc49223980c5d4be393))
package/dist/config.d.ts CHANGED
@@ -30,6 +30,31 @@ export type ReadConfigStrictResult = {
30
30
  state: 'present';
31
31
  config: Record<string, unknown>;
32
32
  };
33
+ /**
34
+ * Canonical CliError codes for the broken states of `readConfigStrict`. The
35
+ * `satisfies` clause guarantees every failure state has a corresponding code.
36
+ *
37
+ * Exported as both a runtime map (so a future `readConfigOrThrow` helper — and
38
+ * consumers writing their own state-to-throw translation — can look codes up
39
+ * instead of hand-writing strings) and as the `ConfigErrorCode` type alias.
40
+ */
41
+ export declare const BROKEN_CONFIG_STATE_TO_CODE: {
42
+ readonly 'read-failed': "CONFIG_READ_FAILED";
43
+ readonly 'invalid-json': "CONFIG_INVALID_JSON";
44
+ readonly 'invalid-shape': "CONFIG_INVALID_SHAPE";
45
+ };
46
+ /**
47
+ * Canonical CliError codes emitted when `readConfigStrict` reports a broken
48
+ * config file. Derived from `BROKEN_CONFIG_STATE_TO_CODE` so the type and the
49
+ * runtime map can never drift.
50
+ *
51
+ * cli-core does not throw these itself (the library returns a discriminated
52
+ * result so consumers control formatting), but every consumer that does the
53
+ * states-to-throw translation ends up using the same three codes. Including
54
+ * this in each CLI's `ErrorCode` union is also unnecessary now that
55
+ * `CliError`'s constructor accepts the cli-core canonical codes directly.
56
+ */
57
+ export type ConfigErrorCode = (typeof BROKEN_CONFIG_STATE_TO_CODE)[keyof typeof BROKEN_CONFIG_STATE_TO_CODE];
33
58
  /**
34
59
  * Read and parse a JSON config file strictly, distinguishing missing files
35
60
  * from broken ones. The library returns a discriminated result instead of
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAGpF;AAED,MAAM,MAAM,sBAAsB,GAC5B;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GACpB;IAAE,KAAK,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GACtC;IAAE,KAAK,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GACvC;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,MAAM,E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E,GACvC;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;CAAE,GACtF;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAA;AAU3D;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B;;;;CAIc,CAAA;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GACvB,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA;AAElF;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBpF;AAED,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC9C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,kBAAuB,GACjC,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC/C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,OAAO,GAAE,kBAAuB,GACjC,OAAO,CAAC,IAAI,CAAC,CAoBf"}
package/dist/config.js CHANGED
@@ -25,6 +25,19 @@ export async function readConfig(path) {
25
25
  const result = await readConfigStrict(path);
26
26
  return result.state === 'present' ? result.config : {};
27
27
  }
28
+ /**
29
+ * Canonical CliError codes for the broken states of `readConfigStrict`. The
30
+ * `satisfies` clause guarantees every failure state has a corresponding code.
31
+ *
32
+ * Exported as both a runtime map (so a future `readConfigOrThrow` helper — and
33
+ * consumers writing their own state-to-throw translation — can look codes up
34
+ * instead of hand-writing strings) and as the `ConfigErrorCode` type alias.
35
+ */
36
+ export const BROKEN_CONFIG_STATE_TO_CODE = {
37
+ 'read-failed': 'CONFIG_READ_FAILED',
38
+ 'invalid-json': 'CONFIG_INVALID_JSON',
39
+ 'invalid-shape': 'CONFIG_INVALID_SHAPE',
40
+ };
28
41
  /**
29
42
  * Read and parse a JSON config file strictly, distinguishing missing files
30
43
  * from broken ones. The library returns a discriminated result instead of
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;IACtE,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;AAC7C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAmB,IAAY;IAC3D,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,OAAO,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAE,MAAM,CAAC,MAAqB,CAAC,CAAC,CAAC,EAAE,CAAA;AAC1E,CAAC;AASD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY;IAC/C,IAAI,OAAe,CAAA;IACnB,IAAI,CAAC;QACD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C,GAAG,OAAO,KAAK,CAAA;IACtB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAA;IACjE,OAAO,MAAM,CAAA;AACjB,CAAC"}
package/dist/errors.d.ts CHANGED
@@ -1,12 +1,28 @@
1
+ import type { ConfigErrorCode } from './config.js';
1
2
  export type ErrorType = 'error' | 'info';
2
3
  export interface CliErrorOptions {
3
4
  hints?: string[];
4
5
  type?: ErrorType;
5
6
  }
6
7
  /**
7
- * Generic CLI error carrying a structured code, optional hints, and a severity type.
8
+ * Aggregator of every error code that cli-core itself defines. Baked into the
9
+ * `CliError` constructor so consumers don't have to redeclare these strings in
10
+ * their own `ErrorCode` union — they're always accepted.
8
11
  *
9
- * Pass a string-literal union as `TCode` to constrain codes per CLI:
12
+ * Grows as future modules add their own well-known codes:
13
+ *
14
+ * ```ts
15
+ * export type CliErrorCode = ConfigErrorCode | SpinnerErrorCode | …
16
+ * ```
17
+ */
18
+ export type CliErrorCode = ConfigErrorCode;
19
+ /**
20
+ * Generic CLI error carrying a structured code, optional hints, and a severity
21
+ * type.
22
+ *
23
+ * `code` accepts either the consumer's `TCode` union or any code defined by
24
+ * cli-core itself (`CliErrorCode`). Pass a string-literal union as `TCode` to
25
+ * constrain codes per CLI; the cli-core codes are always allowed alongside.
10
26
  *
11
27
  * ```ts
12
28
  * import { CliError } from '@doist/cli-core'
@@ -14,14 +30,16 @@ export interface CliErrorOptions {
14
30
  * throw new CliError<Code>('AUTH_FAILED', 'Token rejected', {
15
31
  * hints: ['Run td auth login'],
16
32
  * })
33
+ * // CONFIG_INVALID_JSON also accepted without listing it in `Code`:
34
+ * throw new CliError<Code>('CONFIG_INVALID_JSON', 'Bad JSON')
17
35
  * ```
18
36
  *
19
37
  * The `(string & {})` trick preserves intellisense while accepting dynamic codes.
20
38
  */
21
39
  export declare class CliError<TCode extends string = string> extends Error {
22
- readonly code: TCode;
40
+ readonly code: TCode | CliErrorCode;
23
41
  readonly hints?: string[];
24
42
  readonly type: ErrorType;
25
- constructor(code: TCode, message: string, options?: CliErrorOptions);
43
+ constructor(code: TCode | CliErrorCode, message: string, options?: CliErrorOptions);
26
44
  }
27
45
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAA;AAExC,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,CAAC,EAAE,SAAS,CAAA;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,QAAQ,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;aAK1C,IAAI,EAAE,KAAK;IAJ/B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;gBAGJ,IAAI,EAAE,KAAK,EAC3B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,eAAoB;CAOpC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAA;AAExC,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,CAAC,EAAE,SAAS,CAAA;CACnB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,CAAA;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAQ,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;IAC9D,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,YAAY,CAAA;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;gBAEZ,IAAI,EAAE,KAAK,GAAG,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAOzF"}
package/dist/errors.js CHANGED
@@ -1,7 +1,10 @@
1
1
  /**
2
- * Generic CLI error carrying a structured code, optional hints, and a severity type.
2
+ * Generic CLI error carrying a structured code, optional hints, and a severity
3
+ * type.
3
4
  *
4
- * Pass a string-literal union as `TCode` to constrain codes per CLI:
5
+ * `code` accepts either the consumer's `TCode` union or any code defined by
6
+ * cli-core itself (`CliErrorCode`). Pass a string-literal union as `TCode` to
7
+ * constrain codes per CLI; the cli-core codes are always allowed alongside.
5
8
  *
6
9
  * ```ts
7
10
  * import { CliError } from '@doist/cli-core'
@@ -9,6 +12,8 @@
9
12
  * throw new CliError<Code>('AUTH_FAILED', 'Token rejected', {
10
13
  * hints: ['Run td auth login'],
11
14
  * })
15
+ * // CONFIG_INVALID_JSON also accepted without listing it in `Code`:
16
+ * throw new CliError<Code>('CONFIG_INVALID_JSON', 'Bad JSON')
12
17
  * ```
13
18
  *
14
19
  * The `(string & {})` trick preserves intellisense while accepting dynamic codes.
@@ -19,8 +24,8 @@ export class CliError extends Error {
19
24
  type;
20
25
  constructor(code, message, options = {}) {
21
26
  super(message);
22
- this.code = code;
23
27
  this.name = 'CliError';
28
+ this.code = code;
24
29
  this.hints = options.hints;
25
30
  this.type = options.type ?? 'error';
26
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,QAAwC,SAAQ,KAAK;IAK1C;IAJX,KAAK,CAAW;IAChB,IAAI,CAAW;IAExB,YACoB,IAAW,EAC3B,OAAe,EACf,UAA2B,EAAE;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAA;QAJE,SAAI,GAAJ,IAAI,CAAO;QAK3B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAA;IACvC,CAAC;CACJ"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,QAAwC,SAAQ,KAAK;IACrD,IAAI,CAAsB;IAC1B,KAAK,CAAW;IAChB,IAAI,CAAW;IAExB,YAAY,IAA0B,EAAE,OAAe,EAAE,UAA2B,EAAE;QAClF,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAA;IACvC,CAAC;CACJ"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { getConfigPath, readConfig, readConfigStrict, updateConfig, writeConfig } from './config.js';
2
- export type { ReadConfigStrictResult, WriteConfigOptions } from './config.js';
1
+ export { BROKEN_CONFIG_STATE_TO_CODE, getConfigPath, readConfig, readConfigStrict, updateConfig, writeConfig, } from './config.js';
2
+ export type { ConfigErrorCode, ReadConfigStrictResult, WriteConfigOptions } from './config.js';
3
3
  export { CliError } from './errors.js';
4
- export type { CliErrorOptions, ErrorType } from './errors.js';
4
+ export type { CliErrorCode, CliErrorOptions, ErrorType } from './errors.js';
5
5
  export { formatJson, formatNdjson } from './json.js';
6
6
  export { isCI, isStderrTTY, isStdinTTY, isStdoutTTY } from './terminal.js';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACpG,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,2BAA2B,EAC3B,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,GACd,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { getConfigPath, readConfig, readConfigStrict, updateConfig, writeConfig } from './config.js';
1
+ export { BROKEN_CONFIG_STATE_TO_CODE, getConfigPath, readConfig, readConfigStrict, updateConfig, writeConfig, } from './config.js';
2
2
  export { CliError } from './errors.js';
3
3
  export { formatJson, formatNdjson } from './json.js';
4
4
  export { isCI, isStderrTTY, isStdinTTY, isStdoutTTY } from './terminal.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEpG,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,2BAA2B,EAC3B,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,GACd,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/cli-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Shared core utilities for Doist CLI projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",