@idlebox/common 1.4.0 → 1.4.2

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 (217) hide show
  1. package/lib/cjs/__create_index.generated.cjs +12 -4
  2. package/lib/cjs/__create_index.generated.cjs.map +1 -1
  3. package/lib/cjs/date/timeString.cjs +4 -4
  4. package/lib/cjs/date/timeString.cjs.map +1 -1
  5. package/lib/cjs/error/convertUnknown.cjs +2 -2
  6. package/lib/cjs/error/convertUnknown.cjs.map +1 -1
  7. package/lib/cjs/error/known.cjs +2 -2
  8. package/lib/cjs/error/known.cjs.map +1 -1
  9. package/lib/cjs/error/pretty.cjs +225 -154
  10. package/lib/cjs/error/pretty.cjs.map +1 -1
  11. package/lib/cjs/function/asyncCallbackList.cjs +2 -2
  12. package/lib/cjs/function/asyncCallbackList.cjs.map +1 -1
  13. package/lib/cjs/function/callbackList.cjs +2 -2
  14. package/lib/cjs/function/callbackList.cjs.map +1 -1
  15. package/lib/cjs/function/delayCallbackList.cjs +2 -2
  16. package/lib/cjs/function/delayCallbackList.cjs.map +1 -1
  17. package/lib/cjs/lifecycle/dispose/disposedError.cjs +7 -7
  18. package/lib/cjs/lifecycle/dispose/disposedError.cjs.map +1 -1
  19. package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs +8 -8
  20. package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs.map +1 -1
  21. package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs +9 -9
  22. package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs.map +1 -1
  23. package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs +7 -7
  24. package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs.map +1 -1
  25. package/lib/cjs/lifecycle/event/event.cjs +61 -6
  26. package/lib/cjs/lifecycle/event/event.cjs.map +1 -1
  27. package/lib/cjs/lifecycle/event/memorized.cjs +2 -2
  28. package/lib/cjs/lifecycle/event/memorized.cjs.map +1 -1
  29. package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs +2 -2
  30. package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs.map +1 -1
  31. package/lib/cjs/lifecycle/promise/cancellationToken/source.cjs +8 -8
  32. package/lib/cjs/lifecycle/promise/cancellationToken/source.cjs.map +1 -1
  33. package/lib/cjs/lifecycle/promise/deferredPromise.cjs +2 -2
  34. package/lib/cjs/lifecycle/promise/deferredPromise.cjs.map +1 -1
  35. package/lib/cjs/lifecycle/timeout/timeout.cjs +4 -4
  36. package/lib/cjs/lifecycle/timeout/timeout.cjs.map +1 -1
  37. package/lib/cjs/lifecycle/timeout/timeoutError.cjs +2 -2
  38. package/lib/cjs/lifecycle/timeout/timeoutError.cjs.map +1 -1
  39. package/lib/cjs/log/logger.cjs +6 -6
  40. package/lib/cjs/log/logger.cjs.map +1 -1
  41. package/lib/cjs/misc/package.json.cjs +22 -0
  42. package/lib/cjs/misc/package.json.cjs.map +1 -1
  43. package/lib/cjs/object/definePublicConstant.cjs +9 -3
  44. package/lib/cjs/object/definePublicConstant.cjs.map +1 -1
  45. package/lib/cjs/object/objectSame.cjs +4 -4
  46. package/lib/cjs/object/objectSame.cjs.map +1 -1
  47. package/lib/cjs/path/pathArray.cjs +9 -9
  48. package/lib/cjs/path/pathArray.cjs.map +1 -1
  49. package/lib/cjs/platform/globalSingleton.cjs +5 -5
  50. package/lib/cjs/platform/globalSingleton.cjs.map +1 -1
  51. package/lib/cjs/platform/globalSymbol.cjs +2 -2
  52. package/lib/cjs/platform/globalSymbol.cjs.map +1 -1
  53. package/lib/cjs/promise/promiseCollection.cjs +4 -4
  54. package/lib/cjs/promise/promiseCollection.cjs.map +1 -1
  55. package/lib/cjs/promise/timeoutPromiseCollection.cjs +4 -4
  56. package/lib/cjs/promise/timeoutPromiseCollection.cjs.map +1 -1
  57. package/lib/cjs/reflection/classes/singleton.cjs +2 -2
  58. package/lib/cjs/reflection/classes/singleton.cjs.map +1 -1
  59. package/lib/cjs/reflection/methods/initOnRead.cjs +2 -2
  60. package/lib/cjs/reflection/methods/initOnRead.cjs.map +1 -1
  61. package/lib/cjs/state/StateMachine.cjs +2 -2
  62. package/lib/cjs/state/StateMachine.cjs.map +1 -1
  63. package/lib/cjs/string/concatType.generated.cjs +0 -1
  64. package/lib/cjs/string/concatType.generated.cjs.map +1 -1
  65. package/lib/esm/__create_index.generated.d.ts +9 -0
  66. package/lib/esm/__create_index.generated.d.ts.map +1 -1
  67. package/lib/esm/__create_index.generated.js +4 -0
  68. package/lib/esm/__create_index.generated.js.map +1 -1
  69. package/lib/esm/__virtual_tsconfig.tsbuildinfo +1 -1
  70. package/lib/esm/array/arrayUnique.d.ts.map +1 -1
  71. package/lib/esm/date/timeString.js +1 -1
  72. package/lib/esm/date/timeString.js.map +1 -1
  73. package/lib/esm/error/convertUnknown.js +1 -1
  74. package/lib/esm/error/convertUnknown.js.map +1 -1
  75. package/lib/esm/error/known.js +1 -1
  76. package/lib/esm/error/known.js.map +1 -1
  77. package/lib/esm/error/pretty.d.ts +34 -1
  78. package/lib/esm/error/pretty.d.ts.map +1 -1
  79. package/lib/esm/error/pretty.js +219 -150
  80. package/lib/esm/error/pretty.js.map +1 -1
  81. package/lib/esm/function/asyncCallbackList.js +1 -1
  82. package/lib/esm/function/asyncCallbackList.js.map +1 -1
  83. package/lib/esm/function/callbackList.js +1 -1
  84. package/lib/esm/function/callbackList.js.map +1 -1
  85. package/lib/esm/function/delayCallbackList.js +1 -1
  86. package/lib/esm/function/delayCallbackList.js.map +1 -1
  87. package/lib/esm/lifecycle/dispose/disposableEvent.d.ts +1 -1
  88. package/lib/esm/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
  89. package/lib/esm/lifecycle/dispose/disposedError.js +3 -3
  90. package/lib/esm/lifecycle/dispose/disposedError.js.map +1 -1
  91. package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts +2 -2
  92. package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts.map +1 -1
  93. package/lib/esm/lifecycle/dispose/lifecycle.async.js +3 -3
  94. package/lib/esm/lifecycle/dispose/lifecycle.async.js.map +1 -1
  95. package/lib/esm/lifecycle/dispose/lifecycle.d.ts +1 -1
  96. package/lib/esm/lifecycle/dispose/lifecycle.d.ts.map +1 -1
  97. package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts +2 -2
  98. package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts.map +1 -1
  99. package/lib/esm/lifecycle/dispose/lifecycle.global.js +3 -3
  100. package/lib/esm/lifecycle/dispose/lifecycle.global.js.map +1 -1
  101. package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts +2 -2
  102. package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts.map +1 -1
  103. package/lib/esm/lifecycle/dispose/lifecycle.sync.js +2 -2
  104. package/lib/esm/lifecycle/dispose/lifecycle.sync.js.map +1 -1
  105. package/lib/esm/lifecycle/event/event.d.ts +13 -1
  106. package/lib/esm/lifecycle/event/event.d.ts.map +1 -1
  107. package/lib/esm/lifecycle/event/event.js +61 -6
  108. package/lib/esm/lifecycle/event/event.js.map +1 -1
  109. package/lib/esm/lifecycle/event/memorized.d.ts +2 -2
  110. package/lib/esm/lifecycle/event/memorized.d.ts.map +1 -1
  111. package/lib/esm/lifecycle/event/memorized.js +1 -1
  112. package/lib/esm/lifecycle/event/memorized.js.map +1 -1
  113. package/lib/esm/lifecycle/promise/cancellationToken/driver.browser.d.ts +1 -1
  114. package/lib/esm/lifecycle/promise/cancellationToken/driver.browser.d.ts.map +1 -1
  115. package/lib/esm/lifecycle/promise/cancellationToken/driver.common.d.ts +1 -1
  116. package/lib/esm/lifecycle/promise/cancellationToken/driver.common.d.ts.map +1 -1
  117. package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js +1 -1
  118. package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js.map +1 -1
  119. package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts +3 -3
  120. package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts.map +1 -1
  121. package/lib/esm/lifecycle/promise/cancellationToken/source.js +4 -4
  122. package/lib/esm/lifecycle/promise/cancellationToken/source.js.map +1 -1
  123. package/lib/esm/lifecycle/promise/deferredPromise.js +1 -1
  124. package/lib/esm/lifecycle/promise/deferredPromise.js.map +1 -1
  125. package/lib/esm/lifecycle/timeout/timeout.d.ts +1 -1
  126. package/lib/esm/lifecycle/timeout/timeout.d.ts.map +1 -1
  127. package/lib/esm/lifecycle/timeout/timeout.js +2 -2
  128. package/lib/esm/lifecycle/timeout/timeout.js.map +1 -1
  129. package/lib/esm/lifecycle/timeout/timeoutError.js +1 -1
  130. package/lib/esm/lifecycle/timeout/timeoutError.js.map +1 -1
  131. package/lib/esm/log/logger.js +2 -2
  132. package/lib/esm/log/logger.js.map +1 -1
  133. package/lib/esm/misc/package.json.d.ts +19 -1
  134. package/lib/esm/misc/package.json.d.ts.map +1 -1
  135. package/lib/esm/misc/package.json.js +21 -1
  136. package/lib/esm/misc/package.json.js.map +1 -1
  137. package/lib/esm/object/definePublicConstant.d.ts +1 -0
  138. package/lib/esm/object/definePublicConstant.d.ts.map +1 -1
  139. package/lib/esm/object/definePublicConstant.js +8 -3
  140. package/lib/esm/object/definePublicConstant.js.map +1 -1
  141. package/lib/esm/object/objectSame.js +1 -1
  142. package/lib/esm/object/objectSame.js.map +1 -1
  143. package/lib/esm/path/pathArray.js +3 -3
  144. package/lib/esm/path/pathArray.js.map +1 -1
  145. package/lib/esm/platform/globalSingleton.js +2 -2
  146. package/lib/esm/platform/globalSingleton.js.map +1 -1
  147. package/lib/esm/platform/globalSymbol.js +1 -1
  148. package/lib/esm/platform/globalSymbol.js.map +1 -1
  149. package/lib/esm/promise/promiseCollection.d.ts +2 -2
  150. package/lib/esm/promise/promiseCollection.d.ts.map +1 -1
  151. package/lib/esm/promise/promiseCollection.js +2 -2
  152. package/lib/esm/promise/promiseCollection.js.map +1 -1
  153. package/lib/esm/promise/timeoutPromiseCollection.d.ts +2 -2
  154. package/lib/esm/promise/timeoutPromiseCollection.d.ts.map +1 -1
  155. package/lib/esm/promise/timeoutPromiseCollection.js +2 -2
  156. package/lib/esm/promise/timeoutPromiseCollection.js.map +1 -1
  157. package/lib/esm/reflection/classes/singleton.js +1 -1
  158. package/lib/esm/reflection/classes/singleton.js.map +1 -1
  159. package/lib/esm/reflection/methods/initOnRead.d.ts +1 -1
  160. package/lib/esm/reflection/methods/initOnRead.d.ts.map +1 -1
  161. package/lib/esm/reflection/methods/initOnRead.js +1 -1
  162. package/lib/esm/reflection/methods/initOnRead.js.map +1 -1
  163. package/lib/esm/state/StateMachine.d.ts +1 -1
  164. package/lib/esm/state/StateMachine.d.ts.map +1 -1
  165. package/lib/esm/state/StateMachine.js +1 -1
  166. package/lib/esm/state/StateMachine.js.map +1 -1
  167. package/lib/esm/string/concatType.generated.d.ts.map +1 -1
  168. package/lib/esm/string/concatType.generated.js +0 -1
  169. package/lib/esm/string/concatType.generated.js.map +1 -1
  170. package/lib/esm/typingHelper/deep.partial.d.ts +1 -1
  171. package/lib/esm/typingHelper/deep.partial.d.ts.map +1 -1
  172. package/lib/esm/typingHelper/deep.readonly.d.ts +1 -1
  173. package/lib/esm/typingHelper/deep.readonly.d.ts.map +1 -1
  174. package/lib/esm/typingHelper/deep.required.d.ts +1 -1
  175. package/lib/esm/typingHelper/deep.required.d.ts.map +1 -1
  176. package/lib/esm/typingHelper/deep.writable.d.ts +1 -1
  177. package/lib/esm/typingHelper/deep.writable.d.ts.map +1 -1
  178. package/package.json +2 -2
  179. package/src/date/timeString.ts +1 -1
  180. package/src/error/convertUnknown.ts +1 -1
  181. package/src/error/known.ts +1 -1
  182. package/src/error/pretty.ts +269 -153
  183. package/src/function/asyncCallbackList.ts +1 -1
  184. package/src/function/callbackList.ts +1 -1
  185. package/src/function/delayCallbackList.ts +1 -1
  186. package/src/lifecycle/dispose/disposableEvent.ts +1 -1
  187. package/src/lifecycle/dispose/disposedError.ts +3 -3
  188. package/src/lifecycle/dispose/lifecycle.async.ts +4 -4
  189. package/src/lifecycle/dispose/lifecycle.global.ts +4 -4
  190. package/src/lifecycle/dispose/lifecycle.sync.ts +3 -3
  191. package/src/lifecycle/dispose/lifecycle.ts +1 -1
  192. package/src/lifecycle/event/event.ts +64 -7
  193. package/src/lifecycle/event/memorized.ts +2 -2
  194. package/src/lifecycle/promise/cancellationToken/driver.browser.ts +2 -2
  195. package/src/lifecycle/promise/cancellationToken/driver.common.ts +3 -3
  196. package/src/lifecycle/promise/cancellationToken/source.ts +6 -6
  197. package/src/lifecycle/promise/deferredPromise.ts +1 -1
  198. package/src/lifecycle/timeout/timeout.ts +2 -2
  199. package/src/lifecycle/timeout/timeoutError.ts +1 -1
  200. package/src/log/logger.ts +2 -2
  201. package/src/misc/package.json.ts +45 -1
  202. package/src/object/definePublicConstant.ts +9 -2
  203. package/src/object/objectSame.ts +1 -1
  204. package/src/path/pathArray.ts +3 -3
  205. package/src/platform/globalSingleton.ts +2 -2
  206. package/src/platform/globalSymbol.ts +1 -1
  207. package/src/promise/promiseCollection.ts +2 -2
  208. package/src/promise/timeoutPromiseCollection.ts +2 -2
  209. package/src/reflection/classes/singleton.ts +1 -1
  210. package/src/reflection/methods/initOnRead.ts +1 -1
  211. package/src/state/StateMachine.ts +1 -1
  212. package/src/string/concatType.generated.ts +0 -3
  213. package/src/string/concatType.generator.ts +3 -13
  214. package/src/typingHelper/deep.partial.ts +1 -1
  215. package/src/typingHelper/deep.readonly.ts +1 -1
  216. package/src/typingHelper/deep.required.ts +1 -1
  217. package/src/typingHelper/deep.writable.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { IDisposable } from '../dispose/lifecycle';
1
+ import { IDisposable } from '../dispose/lifecycle.js';
2
2
 
3
3
  export interface EventHandler<T> {
4
4
  (data: T): void;
@@ -8,12 +8,15 @@ export interface EventRegister<T> {
8
8
  (callback: EventHandler<T>): IDisposable;
9
9
  }
10
10
 
11
+ type DeferFn = () => void;
12
+
11
13
  /**
12
14
  * 事件注册对象
13
15
  * @public
14
16
  */
15
17
  export class Emitter<T> implements IDisposable {
16
18
  protected readonly _callbacks: EventHandler<T>[] = [];
19
+ private executing: boolean = false;
17
20
 
18
21
  constructor() {
19
22
  this.handle = this.handle.bind(this);
@@ -31,8 +34,15 @@ export class Emitter<T> implements IDisposable {
31
34
  * @param data 回调数据
32
35
  */
33
36
  public fire(data: T) {
34
- for (const callback of this._callbacks) {
35
- callback(data);
37
+ this.requireNotExecuting();
38
+ this.executing = true;
39
+ try {
40
+ for (const callback of this._callbacks) {
41
+ callback(data);
42
+ }
43
+ } finally {
44
+ this.doDefer();
45
+ this.executing = false;
36
46
  }
37
47
  }
38
48
 
@@ -40,6 +50,8 @@ export class Emitter<T> implements IDisposable {
40
50
  * 与 `fire()`相同,但是忽略任何错误,并且即便出错也继续执行全部callback
41
51
  */
42
52
  public fireNoError(data: T) {
53
+ this.requireNotExecuting();
54
+ this.executing = true;
43
55
  for (const callback of this._callbacks) {
44
56
  try {
45
57
  callback(data);
@@ -47,6 +59,8 @@ export class Emitter<T> implements IDisposable {
47
59
  console.error('Error ignored: ', e);
48
60
  }
49
61
  }
62
+ this.doDefer();
63
+ this.executing = false;
50
64
  }
51
65
 
52
66
  /**
@@ -61,18 +75,55 @@ export class Emitter<T> implements IDisposable {
61
75
  * @param callback 回调函数
62
76
  */
63
77
  handle(callback: EventHandler<T>): IDisposable {
64
- this._callbacks.unshift(callback);
78
+ this.requireNotExecuting();
79
+ let disposed = false;
80
+ this._callbacks.unshift((e) => {
81
+ if (!disposed) callback(e);
82
+ });
83
+ const realDispose = () => {
84
+ const index = this._callbacks.indexOf(callback);
85
+ if (index !== -1) {
86
+ this._callbacks.splice(index, 1);
87
+ }
88
+ };
65
89
  return {
66
90
  dispose: () => {
67
- const index = this._callbacks.indexOf(callback);
68
- if (index !== -1) {
69
- this._callbacks.splice(index, 1);
91
+ disposed = true;
92
+ if (this.executing) {
93
+ this.defer(realDispose);
94
+ } else {
95
+ realDispose();
70
96
  }
71
97
  },
72
98
  };
73
99
  }
74
100
 
101
+ /**
102
+ * 注册一次性回调
103
+ * @param callback 回调函数
104
+ */
105
+ once(callback: EventHandler<T>): IDisposable {
106
+ this.requireNotExecuting();
107
+ const disposable = this.handle((data) => {
108
+ callback(data);
109
+ disposable.dispose();
110
+ });
111
+ return disposable;
112
+ }
113
+
114
+ private defers: DeferFn[] = [];
115
+ public defer(fn: DeferFn) {
116
+ this.defers.push(fn);
117
+ }
118
+ private doDefer() {
119
+ for (const fn of this.defers) {
120
+ fn();
121
+ }
122
+ this.defers.length = 0;
123
+ }
124
+
75
125
  dispose() {
126
+ this.requireNotExecuting();
76
127
  this._callbacks.length = 0;
77
128
  this.fireNoError =
78
129
  this.fire =
@@ -81,4 +132,10 @@ export class Emitter<T> implements IDisposable {
81
132
  throw new Error('Event is disposed');
82
133
  };
83
134
  }
135
+
136
+ private requireNotExecuting() {
137
+ if (this.executing) {
138
+ throw new Error('conflict state, emitter is firing');
139
+ }
140
+ }
84
141
  }
@@ -1,5 +1,5 @@
1
- import { IDisposable } from '../dispose/lifecycle';
2
- import { Emitter, EventHandler } from './event';
1
+ import { IDisposable } from '../dispose/lifecycle.js';
2
+ import { Emitter, EventHandler } from './event.js';
3
3
 
4
4
  /**
5
5
  * 会记住上次fire的内容,并在每个新的handler注册时立即调用一次的Emitter
@@ -1,6 +1,6 @@
1
- import { EventHandler } from '../../event/event';
1
+ import { EventHandler } from '../../event/event.js';
2
2
 
3
- import type { CancellationDriver, __CancellationToken } from './source';
3
+ import type { CancellationDriver, __CancellationToken } from './source.js';
4
4
 
5
5
  declare const AbortController: any; // TODO
6
6
  declare type AbortController = any; // TODO
@@ -1,7 +1,7 @@
1
- import { IDisposable } from '../../dispose/lifecycle';
2
- import { Emitter, EventHandler } from '../../event/event';
1
+ import { IDisposable } from '../../dispose/lifecycle.js';
2
+ import { Emitter, EventHandler } from '../../event/event.js';
3
3
 
4
- import type { CancellationDriver, __CancellationToken } from './source';
4
+ import type { CancellationDriver, __CancellationToken } from './source.js';
5
5
 
6
6
  /** @internal */
7
7
  export class CancellationDriverCommon implements CancellationDriver {
@@ -1,9 +1,9 @@
1
- import { globalObject } from '../../../platform/globalObject';
2
- import { IDisposable } from '../../dispose/lifecycle';
3
- import { DisposableOnce } from '../../dispose/lifecycle.sync';
4
- import { EventHandler } from '../../event/event';
5
- import { CancellationDriverBrowser } from './driver.browser';
6
- import { CancellationDriverCommon } from './driver.common';
1
+ import { globalObject } from '../../../platform/globalObject.js';
2
+ import { IDisposable } from '../../dispose/lifecycle.js';
3
+ import { DisposableOnce } from '../../dispose/lifecycle.sync.js';
4
+ import { EventHandler } from '../../event/event.js';
5
+ import { CancellationDriverBrowser } from './driver.browser.js';
6
+ import { CancellationDriverCommon } from './driver.common.js';
7
7
 
8
8
  /** @public */
9
9
  export interface CancellationToken {
@@ -1,4 +1,4 @@
1
- import { CanceledError } from './cancel';
1
+ import { CanceledError } from './cancel.js';
2
2
 
3
3
  export type ValueCallback<T = any> = (value: T | Promise<T>) => void;
4
4
  export type ProgressCallback<T = any> = (value: T) => void;
@@ -1,5 +1,5 @@
1
- import { TimeoutError } from './timeoutError';
2
- import { DeferredPromise } from '../promise/deferredPromise';
1
+ import { TimeoutError } from './timeoutError.js';
2
+ import { DeferredPromise } from '../promise/deferredPromise.js';
3
3
 
4
4
  /**
5
5
  * @returns promise reject with TimeoutError after specific time
@@ -1,4 +1,4 @@
1
- import { humanDate } from '../../date/timeString';
1
+ import { humanDate } from '../../date/timeString.js';
2
2
 
3
3
  /**
4
4
  * Error when timeout() done
package/src/log/logger.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { nameFunction } from '../function/functionName';
2
- import { isWeb } from '../platform/os';
1
+ import { nameFunction } from '../function/functionName.js';
2
+ import { isWeb } from '../platform/os.js';
3
3
 
4
4
  export enum ColorKind {
5
5
  DISABLE,
@@ -12,6 +12,50 @@ interface IOverridesObject {
12
12
 
13
13
  type IOverrides = Record<string, string | IOverridesObject>;
14
14
 
15
+ export interface IExportCondition {
16
+ node?: string | IExportCondition;
17
+ 'node-addons'?: string | IExportCondition;
18
+ browser?: string | IExportCondition;
19
+ require?: string;
20
+ import?: string;
21
+ types?: string;
22
+ default?: string;
23
+ [platform: string]: undefined | string | IExportCondition;
24
+ }
25
+
26
+ export interface IExportMap {
27
+ [exportPath: string]: string | IExportCondition;
28
+ }
29
+ export interface IFullExportsField {
30
+ [exportPath: string]: IExportCondition;
31
+ }
32
+
33
+ export type IExportsField = string | IExportCondition | IExportMap;
34
+
35
+ function isPathMap(exportsField: IExportCondition | IExportMap): exportsField is IExportMap {
36
+ return Object.keys(exportsField).some((e) => e.startsWith('.'));
37
+ }
38
+ export function parseExportsField(exports: IExportsField): IFullExportsField {
39
+ if (typeof exports === 'string') {
40
+ return { '.': { default: exports } };
41
+ }
42
+ if (!isPathMap(exports)) {
43
+ return { '.': exports };
44
+ }
45
+ let ret: IFullExportsField = {};
46
+ for (const [path, def] of Object.entries(exports)) {
47
+ if (typeof def === 'string') {
48
+ ret[path] = { default: def };
49
+ } else {
50
+ ret[path] = def;
51
+ }
52
+ }
53
+ return ret;
54
+ }
55
+
56
+ // export function resolveImport(exports:IFullExportsField, file:string,platform:string, condition: string){
57
+ // }
58
+
15
59
  export interface IPackageJson {
16
60
  name: string;
17
61
  version: string;
@@ -48,7 +92,7 @@ export interface IPackageJson {
48
92
  private: boolean;
49
93
  publishConfig: Record<string, any>;
50
94
  workspaces: string[];
51
- exports: string | Record<string, string | Record<string, string>>;
95
+ exports: IExportsField;
52
96
  dependencies: Record<string, string>;
53
97
  devDependencies: Record<string, string>;
54
98
  optionalDependencies: Record<string, string>;
@@ -1,6 +1,4 @@
1
1
  export function definePublicConstant(object: any, propertyKey: string | symbol, value: any) {
2
- if (object[propertyKey] === value) return;
3
- delete object[propertyKey];
4
2
  Object.defineProperty(object, propertyKey, {
5
3
  configurable: false,
6
4
  enumerable: true,
@@ -8,3 +6,12 @@ export function definePublicConstant(object: any, propertyKey: string | symbol,
8
6
  value,
9
7
  });
10
8
  }
9
+
10
+ export function definePrivateConstant(object: any, propertyKey: string | symbol, value: any) {
11
+ Object.defineProperty(object, propertyKey, {
12
+ configurable: false,
13
+ enumerable: false,
14
+ writable: false,
15
+ value,
16
+ });
17
+ }
@@ -1,4 +1,4 @@
1
- import { isArraySame } from '../array/arraySame';
1
+ import { isArraySame } from '../array/arraySame.js';
2
2
 
3
3
  /**
4
4
  * Should ensure a and b is none-null before call this
@@ -1,6 +1,6 @@
1
- import { isWindows } from '../platform/os';
2
- import { ucfirst } from '../string/castCase';
3
- import { normalizePath } from './normalizePath';
1
+ import { isWindows } from '../platform/os.js';
2
+ import { ucfirst } from '../string/castCase.js';
3
+ import { normalizePath } from './normalizePath.js';
4
4
 
5
5
  const isAbsolute = /^[a-z]:[/\\]/i;
6
6
 
@@ -1,5 +1,5 @@
1
- import { functionName } from '../function/functionName';
2
- import { ensureGlobalObject } from './globalObject';
1
+ import { functionName } from '../function/functionName.js';
2
+ import { ensureGlobalObject } from './globalObject.js';
3
3
 
4
4
  const singletonRegistry = ensureGlobalObject(`@@idlebox/global-singleton`, () => {
5
5
  return new Map<string | symbol, any>();
@@ -1,4 +1,4 @@
1
- import { ensureGlobalObject } from './globalObject';
1
+ import { ensureGlobalObject } from './globalObject.js';
2
2
 
3
3
  const symbolRegistry = ensureGlobalObject(`@@idlebox/global-symbol`, () => {
4
4
  return {} as Record<string, Record<string, symbol>>;
@@ -1,5 +1,5 @@
1
- import { CanceledError } from '../lifecycle/promise/cancel';
2
- import { DeferredPromise } from '../lifecycle/promise/deferredPromise';
1
+ import { CanceledError } from '../lifecycle/promise/cancel.js';
2
+ import { DeferredPromise } from '../lifecycle/promise/deferredPromise.js';
3
3
 
4
4
  export class PromiseCollection {
5
5
  protected readonly promiseList: Record<string, DeferredPromise<any>> = {};
@@ -1,5 +1,5 @@
1
- import { TimeoutError } from '../lifecycle/timeout/timeoutError';
2
- import { PromiseCollection } from './promiseCollection';
1
+ import { TimeoutError } from '../lifecycle/timeout/timeoutError.js';
2
+ import { PromiseCollection } from './promiseCollection.js';
3
3
 
4
4
  export class TimeoutPromiseCollection extends PromiseCollection {
5
5
  constructor(private readonly defaultTimeoutMs = 50000) {
@@ -1,4 +1,4 @@
1
- import { hookClass } from './hookClass';
1
+ import { hookClass } from './hookClass.js';
2
2
 
3
3
  export const singletonSymbol = Symbol('@gongt/singleton');
4
4
 
@@ -1,4 +1,4 @@
1
- import { InitFunc, initOnRead } from '../../object/initOnRead';
1
+ import { InitFunc, initOnRead } from '../../object/initOnRead.js';
2
2
 
3
3
  /**
4
4
  * Decorater version of `initOnRead`
@@ -1,4 +1,4 @@
1
- import { Emitter } from '../lifecycle/event/event';
1
+ import { Emitter } from '../lifecycle/event/event.js';
2
2
 
3
3
  // type StateType = string | number;
4
4
  // type EventType = string | number;
@@ -7,7 +7,6 @@
7
7
  *
8
8
  */
9
9
 
10
-
11
10
  export function concatStringType
12
11
  <T0 extends string>
13
12
  (t0: T0):
@@ -88,8 +87,6 @@ export function concatStringType
88
87
  <T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string, T15 extends string, T16 extends string, T17 extends string, T18 extends string, T19 extends string>
89
88
  (t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14, t15: T15, t16: T16, t17: T17, t18: T18, t19: T19):
90
89
  `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}${T15}${T16}${T17}${T18}${T19}`;
91
-
92
- /* copy */
93
90
  export function concatStringType(a: string[]): string {
94
91
  return a.join('');
95
92
  }
@@ -1,13 +1,8 @@
1
- import { readFileSync } from 'fs';
2
-
3
- /* copy */
4
1
  export function concatStringType(a: string[]): string {
5
2
  return a.join('');
6
3
  }
7
- /* copy end */
8
4
 
9
- export function generate() {
10
- let content = '';
5
+ export function generate(builder: any) {
11
6
  const typeList = [];
12
7
  const argList = [];
13
8
  const returnList = [];
@@ -19,13 +14,8 @@ export function generate() {
19
14
  const type = typeList.join(', ');
20
15
  const arg = argList.join(', ');
21
16
  const ret = returnList.join('');
22
- content += `export function concatStringType\n\t<${type}>\n\t\t(${arg}):\n\t\`${ret}\`;\n`;
17
+ builder.append(`export function concatStringType\n\t<${type}>\n\t\t(${arg}):\n\t\`${ret}\`;`);
23
18
  }
24
19
 
25
- const full: string = readFileSync(__filename, 'utf-8');
26
- const lines = full.split('\n');
27
- content += '\n';
28
- content += lines.slice(lines.indexOf('/* copy */'), lines.indexOf('/* copy end */')).join('\n');
29
-
30
- return content;
20
+ builder.copyFunctionDeclare('concatStringType');
31
21
  }
@@ -1,4 +1,4 @@
1
- import { Primitive } from './literal';
1
+ import { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepPartial<T> = T extends Primitive
4
4
  ? T
@@ -1,4 +1,4 @@
1
- import { Primitive } from './literal';
1
+ import { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepReadonly<T> = T extends Primitive
4
4
  ? T
@@ -1,4 +1,4 @@
1
- import { Primitive } from './literal';
1
+ import { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepNonNullable<T> = T extends Primitive
4
4
  ? T
@@ -1,4 +1,4 @@
1
- import { Primitive } from './literal';
1
+ import { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepWriteable<T> = T extends Primitive
4
4
  ? T