@decohere/core 0.0.1-dev.118 → 0.0.1-dev.119

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.
Files changed (125) hide show
  1. package/commonjs/src/caching/cache-manager.js +3 -3
  2. package/commonjs/src/caching/index.js +1 -1
  3. package/commonjs/src/caching/map-cache.js +39 -0
  4. package/commonjs/src/io/io.js +0 -3
  5. package/es6/src/caching/cache-manager.js +3 -3
  6. package/es6/src/caching/index.js +1 -1
  7. package/es6/src/caching/map-cache.js +35 -0
  8. package/es6/src/caching/memoize.decorator.js +1 -1
  9. package/es6/src/io/io.js +0 -3
  10. package/package.json +6 -40
  11. package/types/src/caching/index.d.ts +1 -1
  12. package/types/src/caching/map-cache.d.ts +23 -0
  13. package/types/src/caching/memoize.decorator.d.ts +1 -1
  14. package/types/src/io/io.d.ts +0 -3
  15. package/commonjs/src/caching/node-cache-memoize.adapter.js +0 -49
  16. package/commonjs/src/cli/action.js +0 -65
  17. package/commonjs/src/cli/command.js +0 -127
  18. package/commonjs/src/cli/index.js +0 -61
  19. package/commonjs/src/cli/module.type.js +0 -18
  20. package/commonjs/src/cli/options.js +0 -115
  21. package/commonjs/src/diagnostics/index.js +0 -22
  22. package/commonjs/src/diagnostics/trace.js +0 -86
  23. package/commonjs/src/interop/docker/docker.js +0 -54
  24. package/commonjs/src/interop/errors/interop.error.js +0 -12
  25. package/commonjs/src/interop/git/git.js +0 -134
  26. package/commonjs/src/interop/git/git.types.js +0 -4
  27. package/commonjs/src/interop/index.js +0 -97
  28. package/commonjs/src/interop/node/index.js +0 -18
  29. package/commonjs/src/interop/node/node.js +0 -45
  30. package/commonjs/src/interop/npm/npm.js +0 -231
  31. package/commonjs/src/interop/npm/npm.types.js +0 -16
  32. package/commonjs/src/interop/pnpm/pnpm.js +0 -34
  33. package/commonjs/src/interop/pnpm/pnpm.types.js +0 -4
  34. package/commonjs/src/interop/shell/shell.argv.js +0 -45
  35. package/commonjs/src/interop/shell/shell.js +0 -105
  36. package/commonjs/src/interop/shell/shell.types.js +0 -4
  37. package/commonjs/src/interop/types/detect-package-manager.js +0 -71
  38. package/commonjs/src/interop/types/package-manager.js +0 -4
  39. package/commonjs/src/interop/yarn/yarn.js +0 -34
  40. package/commonjs/src/interop/yarn/yarn.types.js +0 -4
  41. package/commonjs/src/io/find-directories.js +0 -21
  42. package/commonjs/src/io/find-file.js +0 -45
  43. package/commonjs/src/io/watch.js +0 -261
  44. package/commonjs/src/semver/index.js +0 -18
  45. package/commonjs/src/semver/semver.js +0 -92
  46. package/commonjs/src/testing/flush-promises.js +0 -16
  47. package/commonjs/src/testing/glob-with-memfs.js +0 -22
  48. package/commonjs/src/testing/index.js +0 -22
  49. package/commonjs/src/testing/memfs.js +0 -52
  50. package/commonjs/src/testing/mock-logger.js +0 -36
  51. package/commonjs/src/testing/spy-on-constructor.js +0 -27
  52. package/es6/src/caching/node-cache-memoize.adapter.js +0 -37
  53. package/es6/src/cli/action.js +0 -47
  54. package/es6/src/cli/command.js +0 -106
  55. package/es6/src/cli/index.js +0 -4
  56. package/es6/src/cli/module.type.js +0 -11
  57. package/es6/src/cli/options.js +0 -76
  58. package/es6/src/diagnostics/index.js +0 -1
  59. package/es6/src/diagnostics/trace.js +0 -68
  60. package/es6/src/interop/docker/docker.js +0 -44
  61. package/es6/src/interop/errors/interop.error.js +0 -2
  62. package/es6/src/interop/git/git.js +0 -124
  63. package/es6/src/interop/git/git.types.js +0 -1
  64. package/es6/src/interop/index.js +0 -21
  65. package/es6/src/interop/node/index.js +0 -1
  66. package/es6/src/interop/node/node.js +0 -35
  67. package/es6/src/interop/npm/npm.js +0 -180
  68. package/es6/src/interop/npm/npm.types.js +0 -6
  69. package/es6/src/interop/pnpm/pnpm.js +0 -24
  70. package/es6/src/interop/pnpm/pnpm.types.js +0 -1
  71. package/es6/src/interop/shell/shell.argv.js +0 -35
  72. package/es6/src/interop/shell/shell.js +0 -95
  73. package/es6/src/interop/shell/shell.types.js +0 -1
  74. package/es6/src/interop/types/detect-package-manager.js +0 -50
  75. package/es6/src/interop/types/package-manager.js +0 -1
  76. package/es6/src/interop/yarn/yarn.js +0 -24
  77. package/es6/src/interop/yarn/yarn.types.js +0 -1
  78. package/es6/src/io/find-directories.js +0 -11
  79. package/es6/src/io/find-file.js +0 -27
  80. package/es6/src/io/watch.js +0 -238
  81. package/es6/src/semver/index.js +0 -1
  82. package/es6/src/semver/semver.js +0 -71
  83. package/es6/src/testing/flush-promises.js +0 -6
  84. package/es6/src/testing/glob-with-memfs.js +0 -20
  85. package/es6/src/testing/index.js +0 -5
  86. package/es6/src/testing/memfs.js +0 -25
  87. package/es6/src/testing/mock-logger.js +0 -26
  88. package/es6/src/testing/spy-on-constructor.js +0 -31
  89. package/types/src/caching/node-cache-memoize.adapter.d.ts +0 -22
  90. package/types/src/cli/action.d.ts +0 -36
  91. package/types/src/cli/command.d.ts +0 -34
  92. package/types/src/cli/index.d.ts +0 -7
  93. package/types/src/cli/module.type.d.ts +0 -36
  94. package/types/src/cli/options.d.ts +0 -28
  95. package/types/src/diagnostics/index.d.ts +0 -1
  96. package/types/src/diagnostics/trace.d.ts +0 -10
  97. package/types/src/interop/docker/docker.d.ts +0 -19
  98. package/types/src/interop/errors/interop.error.d.ts +0 -2
  99. package/types/src/interop/git/git.d.ts +0 -16
  100. package/types/src/interop/git/git.types.d.ts +0 -14
  101. package/types/src/interop/index.d.ts +0 -14
  102. package/types/src/interop/node/index.d.ts +0 -1
  103. package/types/src/interop/node/node.d.ts +0 -5
  104. package/types/src/interop/npm/npm.d.ts +0 -29
  105. package/types/src/interop/npm/npm.types.d.ts +0 -24
  106. package/types/src/interop/pnpm/pnpm.d.ts +0 -9
  107. package/types/src/interop/pnpm/pnpm.types.d.ts +0 -3
  108. package/types/src/interop/shell/shell.argv.d.ts +0 -5
  109. package/types/src/interop/shell/shell.d.ts +0 -6
  110. package/types/src/interop/shell/shell.types.d.ts +0 -9
  111. package/types/src/interop/types/detect-package-manager.d.ts +0 -4
  112. package/types/src/interop/types/package-manager.d.ts +0 -10
  113. package/types/src/interop/yarn/yarn.d.ts +0 -9
  114. package/types/src/interop/yarn/yarn.types.d.ts +0 -3
  115. package/types/src/io/find-directories.d.ts +0 -2
  116. package/types/src/io/find-file.d.ts +0 -9
  117. package/types/src/io/watch.d.ts +0 -16
  118. package/types/src/semver/index.d.ts +0 -1
  119. package/types/src/semver/semver.d.ts +0 -18
  120. package/types/src/testing/flush-promises.d.ts +0 -1
  121. package/types/src/testing/glob-with-memfs.d.ts +0 -3
  122. package/types/src/testing/index.d.ts +0 -5
  123. package/types/src/testing/memfs.d.ts +0 -5
  124. package/types/src/testing/mock-logger.d.ts +0 -13
  125. package/types/src/testing/spy-on-constructor.d.ts +0 -21
@@ -16,7 +16,7 @@ _export(exports, {
16
16
  return Caching;
17
17
  }
18
18
  });
19
- const _nodecachememoizeadapter = require("./node-cache-memoize.adapter.js");
19
+ const _mapcache = require("./map-cache.js");
20
20
  const Caches = {
21
21
  default: "DEFAULT",
22
22
  memoize: "MEMOIZE_CACHE"
@@ -40,8 +40,8 @@ const Caches = {
40
40
  */ getCache(name, memoize = false) {
41
41
  const cacheName = name ?? this.defaultCacheName;
42
42
  if (!this.caches.has(cacheName)) {
43
- const cache = _nodecachememoizeadapter.NodeCacheAdapter.create({
44
- enableMemoization: memoize
43
+ const cache = new _mapcache.MapCache({
44
+ memoize
45
45
  });
46
46
  this.caches.set(cacheName, cache);
47
47
  }
@@ -7,7 +7,7 @@ _export_star(require("./cache.js"), exports);
7
7
  _export_star(require("./cache-manager.js"), exports);
8
8
  _export_star(require("./invalidate-cache.decorator.js"), exports);
9
9
  _export_star(require("./memoize.decorator.js"), exports);
10
- _export_star(require("./node-cache-memoize.adapter.js"), exports);
10
+ _export_star(require("./map-cache.js"), exports);
11
11
  function _export_star(from, to) {
12
12
  Object.keys(from).forEach(function(k) {
13
13
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MapCache", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MapCache;
9
+ }
10
+ });
11
+ class MapCache {
12
+ #entries = new Map();
13
+ #memoize;
14
+ constructor(options = {}){
15
+ this.#memoize = options.memoize ?? false;
16
+ }
17
+ get isMemoize() {
18
+ return this.#memoize;
19
+ }
20
+ get(key) {
21
+ const value = this.#entries.get(key);
22
+ if (this.#memoize || value === null || typeof value !== "object") {
23
+ return value;
24
+ }
25
+ return structuredClone(value);
26
+ }
27
+ set(key, value) {
28
+ this.#entries.set(key, value);
29
+ }
30
+ has(key) {
31
+ return this.#entries.has(key);
32
+ }
33
+ del(key) {
34
+ this.#entries.delete(key);
35
+ }
36
+ flushAll() {
37
+ this.#entries.clear();
38
+ }
39
+ }
@@ -6,12 +6,9 @@ _export_star(require("./copy-file.js"), exports);
6
6
  _export_star(require("./delete-file.js"), exports);
7
7
  _export_star(require("./directory-exists.js"), exports);
8
8
  _export_star(require("./file-exists.js"), exports);
9
- _export_star(require("./find-directories.js"), exports);
10
- _export_star(require("./find-file.js"), exports);
11
9
  _export_star(require("./read-file.js"), exports);
12
10
  _export_star(require("./remove-dir.js"), exports);
13
11
  _export_star(require("./url-to-path.js"), exports);
14
- _export_star(require("./watch.js"), exports);
15
12
  _export_star(require("./write-file.js"), exports);
16
13
  function _export_star(from, to) {
17
14
  Object.keys(from).forEach(function(k) {
@@ -1,4 +1,4 @@
1
- import { NodeCacheAdapter } from "./node-cache-memoize.adapter.js";
1
+ import { MapCache } from "./map-cache.js";
2
2
  export const Caches = {
3
3
  default: "DEFAULT",
4
4
  memoize: "MEMOIZE_CACHE"
@@ -22,8 +22,8 @@ export const Caches = {
22
22
  */ getCache(name, memoize = false) {
23
23
  const cacheName = name ?? this.defaultCacheName;
24
24
  if (!this.caches.has(cacheName)) {
25
- const cache = NodeCacheAdapter.create({
26
- enableMemoization: memoize
25
+ const cache = new MapCache({
26
+ memoize
27
27
  });
28
28
  this.caches.set(cacheName, cache);
29
29
  }
@@ -3,4 +3,4 @@ export * from "./cache.js";
3
3
  export * from "./cache-manager.js";
4
4
  export * from "./invalidate-cache.decorator.js";
5
5
  export * from "./memoize.decorator.js";
6
- export * from "./node-cache-memoize.adapter.js";
6
+ export * from "./map-cache.js";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The built-in cache: a plain `Map`, no expiry.
3
+ *
4
+ * By default `get` returns a `structuredClone` of an object, so a caller that changes what it
5
+ * got back can't change the cached value. With `memoize` it returns the stored reference.
6
+ * Scalars, `null` and `undefined` are returned as they are.
7
+ */ export class MapCache {
8
+ #entries = new Map();
9
+ #memoize;
10
+ constructor(options = {}){
11
+ this.#memoize = options.memoize ?? false;
12
+ }
13
+ get isMemoize() {
14
+ return this.#memoize;
15
+ }
16
+ get(key) {
17
+ const value = this.#entries.get(key);
18
+ if (this.#memoize || value === null || typeof value !== "object") {
19
+ return value;
20
+ }
21
+ return structuredClone(value);
22
+ }
23
+ set(key, value) {
24
+ this.#entries.set(key, value);
25
+ }
26
+ has(key) {
27
+ return this.#entries.has(key);
28
+ }
29
+ del(key) {
30
+ this.#entries.delete(key);
31
+ }
32
+ flushAll() {
33
+ this.#entries.clear();
34
+ }
35
+ }
@@ -2,7 +2,7 @@ import { CacheDecorator } from "./cache.decorator.js";
2
2
  import { Caches, Caching } from "./cache-manager.js";
3
3
  /**
4
4
  * Memoize decorator class that extends CacheDecorator with memoization support
5
- * Automatically uses a memoization-capable cache (NodeCache with useClones: false)
5
+ * Automatically uses a memoization-capable cache (a MapCache that hands out references)
6
6
  */ export class MemoizeDecorator extends CacheDecorator {
7
7
  decorator(target, propertyKey, descriptor) {
8
8
  const cache = this.options?.cache ?? Caching.getCache(this.options?.name ?? Caches.memoize, true);
package/es6/src/io/io.js CHANGED
@@ -2,10 +2,7 @@ export * from "./copy-file.js";
2
2
  export * from "./delete-file.js";
3
3
  export * from "./directory-exists.js";
4
4
  export * from "./file-exists.js";
5
- export * from "./find-directories.js";
6
- export * from "./find-file.js";
7
5
  export * from "./read-file.js";
8
6
  export * from "./remove-dir.js";
9
7
  export * from "./url-to-path.js";
10
- export * from "./watch.js";
11
8
  export * from "./write-file.js";
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@decohere/core",
3
- "version": "0.0.1-dev.118",
4
- "description": "Core utility library — collections, caching, IO, CLI primitives, reflection, and composition",
3
+ "version": "0.0.1-dev.119",
4
+ "description": "The runtime base every Decohere package builds on: reflection, composition, configuration types, extensibility, collections, objects, caching on a Map, and basic file IO. No side effects on import.",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "utilities",
8
- "collections",
9
- "caching",
10
- "io",
11
- "cli",
12
8
  "reflection",
9
+ "composition",
10
+ "caching",
13
11
  "decohere"
14
12
  ],
15
13
  "license": "ISC",
@@ -37,11 +35,6 @@
37
35
  "import": "./es6/src/extensibility/index.js",
38
36
  "require": "./commonjs/src/extensibility/index.js"
39
37
  },
40
- "./interop": {
41
- "types": "./types/src/interop/index.d.ts",
42
- "import": "./es6/src/interop/index.js",
43
- "require": "./commonjs/src/interop/index.js"
44
- },
45
38
  "./io": {
46
39
  "types": "./types/src/io/index.d.ts",
47
40
  "import": "./es6/src/io/index.js",
@@ -62,45 +55,18 @@
62
55
  "import": "./es6/src/system/index.js",
63
56
  "require": "./commonjs/src/system/index.js"
64
57
  },
65
- "./semver": {
66
- "types": "./types/src/semver/index.d.ts",
67
- "import": "./es6/src/semver/index.js",
68
- "require": "./commonjs/src/semver/index.js"
69
- },
70
- "./testing": {
71
- "types": "./types/src/testing/index.d.ts",
72
- "import": "./es6/src/testing/index.js",
73
- "require": "./commonjs/src/testing/index.js"
74
- },
75
58
  "./composition": {
76
59
  "types": "./types/src/composition/index.d.ts",
77
60
  "import": "./es6/src/composition/index.js",
78
61
  "require": "./commonjs/src/composition/index.js"
79
- },
80
- "./cli": {
81
- "types": "./types/src/cli/index.d.ts",
82
- "import": "./es6/src/cli/index.js",
83
- "require": "./commonjs/src/cli/index.js"
84
- },
85
- "./diagnostics": {
86
- "types": "./types/src/diagnostics/index.d.ts",
87
- "import": "./es6/src/diagnostics/index.js",
88
- "require": "./commonjs/src/diagnostics/index.js"
89
62
  }
90
63
  },
91
64
  "scripts": {
92
65
  "test": "echo \"Error: no test specified\" && exit 1"
93
66
  },
94
67
  "dependencies": {
95
- "@cacheable/node-cache": "^2.0.1",
96
- "@decohere/scribe": "0.0.1-dev.118",
97
- "commander": "^13.1.0",
98
- "glob": "^13.0.1",
99
- "picomatch": "^4.0.4",
68
+ "@decohere/scribe": "0.0.1-dev.119",
100
69
  "reflect-metadata": "^0.2.2"
101
70
  },
102
- "devDependencies": {
103
- "memfs": "^4.17.0",
104
- "vitest": "^3.2.6"
105
- }
71
+ "devDependencies": {}
106
72
  }
@@ -3,4 +3,4 @@ export * from "./cache.js";
3
3
  export * from "./cache-manager.js";
4
4
  export * from "./invalidate-cache.decorator.js";
5
5
  export * from "./memoize.decorator.js";
6
- export * from "./node-cache-memoize.adapter.js";
6
+ export * from "./map-cache.js";
@@ -0,0 +1,23 @@
1
+ import type { ICache } from "./cache.js";
2
+ type MapCacheOptions = {
3
+ /** Hand out the stored reference instead of a copy (what `@memoize` needs). */
4
+ memoize?: boolean;
5
+ };
6
+ /**
7
+ * The built-in cache: a plain `Map`, no expiry.
8
+ *
9
+ * By default `get` returns a `structuredClone` of an object, so a caller that changes what it
10
+ * got back can't change the cached value. With `memoize` it returns the stored reference.
11
+ * Scalars, `null` and `undefined` are returned as they are.
12
+ */
13
+ export declare class MapCache implements ICache {
14
+ #private;
15
+ constructor(options?: MapCacheOptions);
16
+ get isMemoize(): boolean;
17
+ get(key: string): unknown;
18
+ set(key: string, value: unknown): void;
19
+ has(key: string): boolean;
20
+ del(key: string): void;
21
+ flushAll(): void;
22
+ }
23
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { CacheDecorator } from "./cache.decorator.js";
2
2
  /**
3
3
  * Memoize decorator class that extends CacheDecorator with memoization support
4
- * Automatically uses a memoization-capable cache (NodeCache with useClones: false)
4
+ * Automatically uses a memoization-capable cache (a MapCache that hands out references)
5
5
  */
6
6
  export declare class MemoizeDecorator extends CacheDecorator {
7
7
  decorator(target: object, propertyKey: string, descriptor: PropertyDescriptor): void;
@@ -2,10 +2,7 @@ export * from "./copy-file.js";
2
2
  export * from "./delete-file.js";
3
3
  export * from "./directory-exists.js";
4
4
  export * from "./file-exists.js";
5
- export * from "./find-directories.js";
6
- export * from "./find-file.js";
7
5
  export * from "./read-file.js";
8
6
  export * from "./remove-dir.js";
9
7
  export * from "./url-to-path.js";
10
- export * from "./watch.js";
11
8
  export * from "./write-file.js";
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "NodeCacheAdapter", {
6
- enumerable: true,
7
- get: function() {
8
- return NodeCacheAdapter;
9
- }
10
- });
11
- const _nodecache = /*#__PURE__*/ _interop_require_default(require("@cacheable/node-cache"));
12
- function _interop_require_default(obj) {
13
- return obj && obj.__esModule ? obj : {
14
- default: obj
15
- };
16
- }
17
- class NodeCacheAdapter {
18
- static create(options = {
19
- enableMemoization: false
20
- }) {
21
- const nodeCache = new _nodecache.default({
22
- useClones: !options.enableMemoization
23
- });
24
- return new NodeCacheAdapter(nodeCache);
25
- }
26
- supportsMemoization = true;
27
- cache;
28
- constructor(inst = new _nodecache.default()){
29
- this.cache = inst;
30
- }
31
- get isMemoize() {
32
- return !this.cache.options.useClones;
33
- }
34
- get(key) {
35
- return this.cache.get(key);
36
- }
37
- set(key, value) {
38
- this.cache.set(key, value);
39
- }
40
- has(key) {
41
- return this.cache.has(key);
42
- }
43
- del(key) {
44
- this.cache.del(key);
45
- }
46
- flushAll() {
47
- this.cache.flushAll();
48
- }
49
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get ActionMap () {
13
- return ActionMap;
14
- },
15
- get ActionResponse () {
16
- return ActionResponse;
17
- }
18
- });
19
- const ActionMap = Symbol("ActionMap");
20
- class ActionResponse {
21
- static Success(name, data) {
22
- return new ActionResponse({
23
- name,
24
- data,
25
- succeeded: true
26
- });
27
- }
28
- static Skipped(name) {
29
- return new ActionResponse({
30
- name,
31
- skipped: true
32
- });
33
- }
34
- static Blocking(name) {
35
- return new ActionResponse({
36
- name,
37
- succeeded: true,
38
- blocking: true
39
- });
40
- }
41
- static Error(name, messageOrData, data) {
42
- if (Array.isArray(messageOrData)) {
43
- const message = messageOrData.filter((r)=>!r.succeeded).map((r)=>r.error ?? "Unknown error").join("\n");
44
- return new ActionResponse({
45
- name,
46
- message,
47
- data: messageOrData
48
- });
49
- }
50
- return new ActionResponse({
51
- name,
52
- message: messageOrData,
53
- data
54
- });
55
- }
56
- constructor(data){
57
- Object.assign(this, data);
58
- }
59
- name;
60
- succeeded = false;
61
- skipped = false;
62
- blocking = false;
63
- message;
64
- data;
65
- }
@@ -1,127 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get CommandError () {
13
- return CommandError;
14
- },
15
- get CommandResponse () {
16
- return CommandResponse;
17
- },
18
- get DecohereCommand () {
19
- return DecohereCommand;
20
- }
21
- });
22
- const _commander = require("commander");
23
- const CommandResponse = {
24
- success (_ctx, responses) {
25
- return responses;
26
- },
27
- help () {
28
- return {};
29
- },
30
- fromAction (name, response) {
31
- return {
32
- [name]: response
33
- };
34
- }
35
- };
36
- class CommandError extends Error {
37
- }
38
- class DecohereCommand extends _commander.Command {
39
- get actions() {
40
- return [];
41
- }
42
- constructor(name, handler){
43
- super();
44
- if (typeof name === "string" || typeof name === "function") {
45
- this.name(this.parseCommandName(name));
46
- } else {
47
- this.name(this.parseCommandName(this.constructor));
48
- if (name) {
49
- this.registerSubcommand(name, handler);
50
- }
51
- }
52
- if (handler && !this.commands.length) {
53
- this.action(handler);
54
- }
55
- this.exitOverride();
56
- }
57
- /**
58
- * Whether the command, with these options, runs until it is stopped (`flux serve`,
59
- * `forge build --watch`). The CLI then listens for SIGINT and SIGTERM from the moment it
60
- * starts, so a stop during start-up still shuts down cleanly; other commands keep Node's
61
- * default, where Ctrl+C ends them at once.
62
- */ runsUntilStopped(_options) {
63
- return false;
64
- }
65
- async run(actions, options) {
66
- const responses = await this.runActions(actions, options);
67
- this.throwOnErrors(responses);
68
- return CommandResponse.success(options, responses);
69
- }
70
- registerSubcommand(commands, onAction) {
71
- if (typeof commands === "function") {
72
- const instance = new commands(commands, onAction);
73
- this.addCommand(instance);
74
- if (onAction && !instance.commands.length) {
75
- instance.action(onAction);
76
- }
77
- return;
78
- }
79
- for (const [key, command] of Object.entries(commands)){
80
- const instance = command instanceof DecohereCommand ? command : new command(key, onAction);
81
- this.addCommand(instance);
82
- if (onAction && !instance.commands.length) {
83
- instance.action(onAction);
84
- }
85
- }
86
- }
87
- async runActions(actions, options) {
88
- const selectedActions = this.getSelectedActions(actions);
89
- const responses = {};
90
- for (const [actionKey, action] of selectedActions){
91
- responses[actionKey] = await action.run(options);
92
- }
93
- return responses;
94
- }
95
- getSelectedActions(actions) {
96
- if (!this.actions.length) {
97
- return [];
98
- }
99
- const actionEntries = Object.entries(actions);
100
- return this.actions.map((ActionClass)=>{
101
- const selectedAction = actionEntries.find(([, action])=>action instanceof ActionClass);
102
- if (!selectedAction) {
103
- throw new CommandError(`${this.name()} command missing action instance for ${ActionClass.name}`);
104
- }
105
- return selectedAction;
106
- });
107
- }
108
- throwOnErrors(responses) {
109
- const failures = Object.entries(responses).filter(([, response])=>{
110
- if (!response) {
111
- return false;
112
- }
113
- return !response.succeeded && !response.skipped;
114
- });
115
- if (!failures.length) {
116
- return;
117
- }
118
- throw new CommandError(`${this.name()} command failed. ${failures.map(([actionName, response])=>`${actionName}: ${response?.message ?? "Unknown error"}`).join("\n")}`);
119
- }
120
- parseCommandName(stringLike) {
121
- const command = typeof stringLike === "string" ? stringLike : stringLike.name?.toLowerCase().replace("command", "") ?? "";
122
- if (command === "") {
123
- throw new CommandError(`Could not parse command name from ${stringLike.toString()}`);
124
- }
125
- return command;
126
- }
127
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get ActionMap () {
13
- return _action.ActionMap;
14
- },
15
- get ActionResponse () {
16
- return _action.ActionResponse;
17
- },
18
- get CommandError () {
19
- return _command.CommandError;
20
- },
21
- get CommandResponse () {
22
- return _command.CommandResponse;
23
- },
24
- get ConfigFileOption () {
25
- return _options.ConfigFileOption;
26
- },
27
- get ConfigurationOption () {
28
- return _options.ConfigurationOption;
29
- },
30
- get DecohereCommand () {
31
- return _command.DecohereCommand;
32
- },
33
- get DryRunOption () {
34
- return _options.DryRunOption;
35
- },
36
- get EnvFileIfExistsOption () {
37
- return _options.EnvFileIfExistsOption;
38
- },
39
- get EnvFileOption () {
40
- return _options.EnvFileOption;
41
- },
42
- get LogLevelOption () {
43
- return _options.LogLevelOption;
44
- },
45
- get ModuleManifest () {
46
- return _moduletype.ModuleManifest;
47
- },
48
- get NoBuildOptions () {
49
- return _options.NoBuildOptions;
50
- },
51
- get NoCleanOptions () {
52
- return _options.NoCleanOptions;
53
- },
54
- get ProjectOption () {
55
- return _options.ProjectOption;
56
- }
57
- });
58
- const _action = require("./action.js");
59
- const _command = require("./command.js");
60
- const _moduletype = require("./module.type.js");
61
- const _options = require("./options.js");
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ModuleManifest", {
6
- enumerable: true,
7
- get: function() {
8
- return ModuleManifest;
9
- }
10
- });
11
- class ModuleManifest {
12
- /** Sub-command classes this module contributes. */ commands = {};
13
- /** Action classes this module contributes. */ actions = {};
14
- /** Register infrastructure services into the DI container. */ registerServices(_builder) {}
15
- /** Lazily create a workspace instance. Return null if this module does not use a workspace. */ createWorkspace(_options) {
16
- return Promise.resolve(null);
17
- }
18
- }