@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.
- package/lib/cjs/__create_index.generated.cjs +12 -4
- package/lib/cjs/__create_index.generated.cjs.map +1 -1
- package/lib/cjs/date/timeString.cjs +4 -4
- package/lib/cjs/date/timeString.cjs.map +1 -1
- package/lib/cjs/error/convertUnknown.cjs +2 -2
- package/lib/cjs/error/convertUnknown.cjs.map +1 -1
- package/lib/cjs/error/known.cjs +2 -2
- package/lib/cjs/error/known.cjs.map +1 -1
- package/lib/cjs/error/pretty.cjs +225 -154
- package/lib/cjs/error/pretty.cjs.map +1 -1
- package/lib/cjs/function/asyncCallbackList.cjs +2 -2
- package/lib/cjs/function/asyncCallbackList.cjs.map +1 -1
- package/lib/cjs/function/callbackList.cjs +2 -2
- package/lib/cjs/function/callbackList.cjs.map +1 -1
- package/lib/cjs/function/delayCallbackList.cjs +2 -2
- package/lib/cjs/function/delayCallbackList.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/disposedError.cjs +7 -7
- package/lib/cjs/lifecycle/dispose/disposedError.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs +8 -8
- package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs +9 -9
- package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs +7 -7
- package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs.map +1 -1
- package/lib/cjs/lifecycle/event/event.cjs +61 -6
- package/lib/cjs/lifecycle/event/event.cjs.map +1 -1
- package/lib/cjs/lifecycle/event/memorized.cjs +2 -2
- package/lib/cjs/lifecycle/event/memorized.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs +2 -2
- package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/cancellationToken/source.cjs +8 -8
- package/lib/cjs/lifecycle/promise/cancellationToken/source.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/deferredPromise.cjs +2 -2
- package/lib/cjs/lifecycle/promise/deferredPromise.cjs.map +1 -1
- package/lib/cjs/lifecycle/timeout/timeout.cjs +4 -4
- package/lib/cjs/lifecycle/timeout/timeout.cjs.map +1 -1
- package/lib/cjs/lifecycle/timeout/timeoutError.cjs +2 -2
- package/lib/cjs/lifecycle/timeout/timeoutError.cjs.map +1 -1
- package/lib/cjs/log/logger.cjs +6 -6
- package/lib/cjs/log/logger.cjs.map +1 -1
- package/lib/cjs/misc/package.json.cjs +22 -0
- package/lib/cjs/misc/package.json.cjs.map +1 -1
- package/lib/cjs/object/definePublicConstant.cjs +9 -3
- package/lib/cjs/object/definePublicConstant.cjs.map +1 -1
- package/lib/cjs/object/objectSame.cjs +4 -4
- package/lib/cjs/object/objectSame.cjs.map +1 -1
- package/lib/cjs/path/pathArray.cjs +9 -9
- package/lib/cjs/path/pathArray.cjs.map +1 -1
- package/lib/cjs/platform/globalSingleton.cjs +5 -5
- package/lib/cjs/platform/globalSingleton.cjs.map +1 -1
- package/lib/cjs/platform/globalSymbol.cjs +2 -2
- package/lib/cjs/platform/globalSymbol.cjs.map +1 -1
- package/lib/cjs/promise/promiseCollection.cjs +4 -4
- package/lib/cjs/promise/promiseCollection.cjs.map +1 -1
- package/lib/cjs/promise/timeoutPromiseCollection.cjs +4 -4
- package/lib/cjs/promise/timeoutPromiseCollection.cjs.map +1 -1
- package/lib/cjs/reflection/classes/singleton.cjs +2 -2
- package/lib/cjs/reflection/classes/singleton.cjs.map +1 -1
- package/lib/cjs/reflection/methods/initOnRead.cjs +2 -2
- package/lib/cjs/reflection/methods/initOnRead.cjs.map +1 -1
- package/lib/cjs/state/StateMachine.cjs +2 -2
- package/lib/cjs/state/StateMachine.cjs.map +1 -1
- package/lib/cjs/string/concatType.generated.cjs +0 -1
- package/lib/cjs/string/concatType.generated.cjs.map +1 -1
- package/lib/esm/__create_index.generated.d.ts +9 -0
- package/lib/esm/__create_index.generated.d.ts.map +1 -1
- package/lib/esm/__create_index.generated.js +4 -0
- package/lib/esm/__create_index.generated.js.map +1 -1
- package/lib/esm/__virtual_tsconfig.tsbuildinfo +1 -1
- package/lib/esm/array/arrayUnique.d.ts.map +1 -1
- package/lib/esm/date/timeString.js +1 -1
- package/lib/esm/date/timeString.js.map +1 -1
- package/lib/esm/error/convertUnknown.js +1 -1
- package/lib/esm/error/convertUnknown.js.map +1 -1
- package/lib/esm/error/known.js +1 -1
- package/lib/esm/error/known.js.map +1 -1
- package/lib/esm/error/pretty.d.ts +34 -1
- package/lib/esm/error/pretty.d.ts.map +1 -1
- package/lib/esm/error/pretty.js +219 -150
- package/lib/esm/error/pretty.js.map +1 -1
- package/lib/esm/function/asyncCallbackList.js +1 -1
- package/lib/esm/function/asyncCallbackList.js.map +1 -1
- package/lib/esm/function/callbackList.js +1 -1
- package/lib/esm/function/callbackList.js.map +1 -1
- package/lib/esm/function/delayCallbackList.js +1 -1
- package/lib/esm/function/delayCallbackList.js.map +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/disposedError.js +3 -3
- package/lib/esm/lifecycle/dispose/disposedError.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.async.js +3 -3
- package/lib/esm/lifecycle/dispose/lifecycle.async.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.js +3 -3
- package/lib/esm/lifecycle/dispose/lifecycle.global.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.js +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.sync.js.map +1 -1
- package/lib/esm/lifecycle/event/event.d.ts +13 -1
- package/lib/esm/lifecycle/event/event.d.ts.map +1 -1
- package/lib/esm/lifecycle/event/event.js +61 -6
- package/lib/esm/lifecycle/event/event.js.map +1 -1
- package/lib/esm/lifecycle/event/memorized.d.ts +2 -2
- package/lib/esm/lifecycle/event/memorized.d.ts.map +1 -1
- package/lib/esm/lifecycle/event/memorized.js +1 -1
- package/lib/esm/lifecycle/event/memorized.js.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.browser.d.ts +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.browser.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.d.ts +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts +3 -3
- package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/source.js +4 -4
- package/lib/esm/lifecycle/promise/cancellationToken/source.js.map +1 -1
- package/lib/esm/lifecycle/promise/deferredPromise.js +1 -1
- package/lib/esm/lifecycle/promise/deferredPromise.js.map +1 -1
- package/lib/esm/lifecycle/timeout/timeout.d.ts +1 -1
- package/lib/esm/lifecycle/timeout/timeout.d.ts.map +1 -1
- package/lib/esm/lifecycle/timeout/timeout.js +2 -2
- package/lib/esm/lifecycle/timeout/timeout.js.map +1 -1
- package/lib/esm/lifecycle/timeout/timeoutError.js +1 -1
- package/lib/esm/lifecycle/timeout/timeoutError.js.map +1 -1
- package/lib/esm/log/logger.js +2 -2
- package/lib/esm/log/logger.js.map +1 -1
- package/lib/esm/misc/package.json.d.ts +19 -1
- package/lib/esm/misc/package.json.d.ts.map +1 -1
- package/lib/esm/misc/package.json.js +21 -1
- package/lib/esm/misc/package.json.js.map +1 -1
- package/lib/esm/object/definePublicConstant.d.ts +1 -0
- package/lib/esm/object/definePublicConstant.d.ts.map +1 -1
- package/lib/esm/object/definePublicConstant.js +8 -3
- package/lib/esm/object/definePublicConstant.js.map +1 -1
- package/lib/esm/object/objectSame.js +1 -1
- package/lib/esm/object/objectSame.js.map +1 -1
- package/lib/esm/path/pathArray.js +3 -3
- package/lib/esm/path/pathArray.js.map +1 -1
- package/lib/esm/platform/globalSingleton.js +2 -2
- package/lib/esm/platform/globalSingleton.js.map +1 -1
- package/lib/esm/platform/globalSymbol.js +1 -1
- package/lib/esm/platform/globalSymbol.js.map +1 -1
- package/lib/esm/promise/promiseCollection.d.ts +2 -2
- package/lib/esm/promise/promiseCollection.d.ts.map +1 -1
- package/lib/esm/promise/promiseCollection.js +2 -2
- package/lib/esm/promise/promiseCollection.js.map +1 -1
- package/lib/esm/promise/timeoutPromiseCollection.d.ts +2 -2
- package/lib/esm/promise/timeoutPromiseCollection.d.ts.map +1 -1
- package/lib/esm/promise/timeoutPromiseCollection.js +2 -2
- package/lib/esm/promise/timeoutPromiseCollection.js.map +1 -1
- package/lib/esm/reflection/classes/singleton.js +1 -1
- package/lib/esm/reflection/classes/singleton.js.map +1 -1
- package/lib/esm/reflection/methods/initOnRead.d.ts +1 -1
- package/lib/esm/reflection/methods/initOnRead.d.ts.map +1 -1
- package/lib/esm/reflection/methods/initOnRead.js +1 -1
- package/lib/esm/reflection/methods/initOnRead.js.map +1 -1
- package/lib/esm/state/StateMachine.d.ts +1 -1
- package/lib/esm/state/StateMachine.d.ts.map +1 -1
- package/lib/esm/state/StateMachine.js +1 -1
- package/lib/esm/state/StateMachine.js.map +1 -1
- package/lib/esm/string/concatType.generated.d.ts.map +1 -1
- package/lib/esm/string/concatType.generated.js +0 -1
- package/lib/esm/string/concatType.generated.js.map +1 -1
- package/lib/esm/typingHelper/deep.partial.d.ts +1 -1
- package/lib/esm/typingHelper/deep.partial.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.readonly.d.ts +1 -1
- package/lib/esm/typingHelper/deep.readonly.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.required.d.ts +1 -1
- package/lib/esm/typingHelper/deep.required.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.writable.d.ts +1 -1
- package/lib/esm/typingHelper/deep.writable.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/date/timeString.ts +1 -1
- package/src/error/convertUnknown.ts +1 -1
- package/src/error/known.ts +1 -1
- package/src/error/pretty.ts +269 -153
- package/src/function/asyncCallbackList.ts +1 -1
- package/src/function/callbackList.ts +1 -1
- package/src/function/delayCallbackList.ts +1 -1
- package/src/lifecycle/dispose/disposableEvent.ts +1 -1
- package/src/lifecycle/dispose/disposedError.ts +3 -3
- package/src/lifecycle/dispose/lifecycle.async.ts +4 -4
- package/src/lifecycle/dispose/lifecycle.global.ts +4 -4
- package/src/lifecycle/dispose/lifecycle.sync.ts +3 -3
- package/src/lifecycle/dispose/lifecycle.ts +1 -1
- package/src/lifecycle/event/event.ts +64 -7
- package/src/lifecycle/event/memorized.ts +2 -2
- package/src/lifecycle/promise/cancellationToken/driver.browser.ts +2 -2
- package/src/lifecycle/promise/cancellationToken/driver.common.ts +3 -3
- package/src/lifecycle/promise/cancellationToken/source.ts +6 -6
- package/src/lifecycle/promise/deferredPromise.ts +1 -1
- package/src/lifecycle/timeout/timeout.ts +2 -2
- package/src/lifecycle/timeout/timeoutError.ts +1 -1
- package/src/log/logger.ts +2 -2
- package/src/misc/package.json.ts +45 -1
- package/src/object/definePublicConstant.ts +9 -2
- package/src/object/objectSame.ts +1 -1
- package/src/path/pathArray.ts +3 -3
- package/src/platform/globalSingleton.ts +2 -2
- package/src/platform/globalSymbol.ts +1 -1
- package/src/promise/promiseCollection.ts +2 -2
- package/src/promise/timeoutPromiseCollection.ts +2 -2
- package/src/reflection/classes/singleton.ts +1 -1
- package/src/reflection/methods/initOnRead.ts +1 -1
- package/src/state/StateMachine.ts +1 -1
- package/src/string/concatType.generated.ts +0 -3
- package/src/string/concatType.generator.ts +3 -13
- package/src/typingHelper/deep.partial.ts +1 -1
- package/src/typingHelper/deep.readonly.ts +1 -1
- package/src/typingHelper/deep.required.ts +1 -1
- 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
|
-
|
|
35
|
-
|
|
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.
|
|
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
|
-
|
|
68
|
-
if (
|
|
69
|
-
this.
|
|
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,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
|
package/src/log/logger.ts
CHANGED
package/src/misc/package.json.ts
CHANGED
|
@@ -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:
|
|
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
|
+
}
|
package/src/object/objectSame.ts
CHANGED
package/src/path/pathArray.ts
CHANGED
|
@@ -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,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) {
|
|
@@ -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
|
-
|
|
17
|
+
builder.append(`export function concatStringType\n\t<${type}>\n\t\t(${arg}):\n\t\`${ret}\`;`);
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
|
|
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
|
}
|