vitest 0.18.1 → 0.19.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/LICENSE.md +5 -5
- package/dist/browser.d.ts +1850 -0
- package/dist/browser.mjs +20 -0
- package/dist/{chunk-api-setup.9d3f7670.mjs → chunk-api-setup.0cf2c96a.mjs} +23 -6
- package/dist/{chunk-constants.d4406290.mjs → chunk-constants.38b43a44.mjs} +3 -3
- package/dist/{chunk-env-node.bbba78e5.mjs → chunk-defaults.408a0cfe.mjs} +456 -455
- package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
- package/dist/{chunk-integrations-globals.00b6e1ad.mjs → chunk-integrations-globals.803277be.mjs} +6 -5
- package/dist/chunk-node-git.9058b82a.mjs +1139 -0
- package/dist/chunk-runtime-chain.1e1aabb3.mjs +2025 -0
- package/dist/chunk-runtime-error.d82dd2cf.mjs +644 -0
- package/dist/{chunk-runtime-chain.b60d57da.mjs → chunk-runtime-hooks.db398170.mjs} +10 -2013
- package/dist/{chunk-runtime-mocker.1d853e3a.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +3 -3
- package/dist/{chunk-runtime-rpc.9d1f4c48.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
- package/dist/{chunk-utils-global.0a7416cf.mjs → chunk-utils-global.2aa95025.mjs} +11 -6
- package/dist/{chunk-utils-source-map.c03f8bc4.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
- package/dist/{chunk-vite-node-externalize.6956d2d9.mjs → chunk-vite-node-externalize.a2813ad7.mjs} +103 -1173
- package/dist/{chunk-vite-node-utils.8077cd3c.mjs → chunk-vite-node-utils.ad73f2ab.mjs} +13 -2
- package/dist/cli.mjs +8 -10
- package/dist/config.cjs +3 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.mjs +3 -1
- package/dist/entry.mjs +14 -597
- package/dist/index.d.ts +39 -4
- package/dist/index.mjs +8 -5
- package/dist/node.d.ts +28 -2
- package/dist/node.mjs +10 -12
- package/dist/suite.mjs +13 -0
- package/dist/vendor-index.61438b77.mjs +335 -0
- package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
- package/dist/worker.mjs +5 -5
- package/package.json +11 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ViteDevServer, TransformResult, CommonServerOptions } from 'vite';
|
|
1
|
+
import { ViteDevServer, TransformResult, CommonServerOptions, AliasOptions } from 'vite';
|
|
2
2
|
import { Stats } from 'fs';
|
|
3
3
|
import { SpyImpl } from 'tinyspy';
|
|
4
4
|
import { MessagePort } from 'worker_threads';
|
|
5
|
-
|
|
5
|
+
import * as chai from 'chai';
|
|
6
|
+
export { chai };
|
|
7
|
+
export { assert, should } from 'chai';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
@@ -374,15 +376,18 @@ interface WorkerPool {
|
|
|
374
376
|
|
|
375
377
|
declare class StateManager {
|
|
376
378
|
filesMap: Map<string, File>;
|
|
379
|
+
pathsSet: Set<string>;
|
|
377
380
|
idMap: Map<string, Task>;
|
|
378
381
|
taskFileMap: WeakMap<Task, File>;
|
|
379
382
|
errorsSet: Set<unknown>;
|
|
380
383
|
catchError(err: unknown, type: string): void;
|
|
381
384
|
clearErrors(): void;
|
|
382
385
|
getUnhandledErrors(): unknown[];
|
|
386
|
+
getPaths(): string[];
|
|
383
387
|
getFiles(keys?: string[]): File[];
|
|
384
388
|
getFilepaths(): string[];
|
|
385
389
|
getFailedFilepaths(): string[];
|
|
390
|
+
collectPaths(paths?: string[]): void;
|
|
386
391
|
collectFiles(files?: File[]): void;
|
|
387
392
|
clearFiles(paths?: string[]): void;
|
|
388
393
|
updateId(task: Task): void;
|
|
@@ -528,7 +533,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
528
533
|
start: number;
|
|
529
534
|
end: number;
|
|
530
535
|
watchFilters?: string[];
|
|
531
|
-
isTTY:
|
|
536
|
+
isTTY: false;
|
|
532
537
|
ctx: Vitest;
|
|
533
538
|
private _filesInWatchMode;
|
|
534
539
|
private _lastRunTimeout;
|
|
@@ -584,6 +589,10 @@ declare class DotReporter extends BaseReporter {
|
|
|
584
589
|
onUserConsoleLog(log: UserConsoleLog): void;
|
|
585
590
|
}
|
|
586
591
|
|
|
592
|
+
interface Callsite {
|
|
593
|
+
line: number;
|
|
594
|
+
column: number;
|
|
595
|
+
}
|
|
587
596
|
declare class JsonReporter implements Reporter {
|
|
588
597
|
start: number;
|
|
589
598
|
ctx: Vitest;
|
|
@@ -596,6 +605,7 @@ declare class JsonReporter implements Reporter {
|
|
|
596
605
|
* @param report
|
|
597
606
|
*/
|
|
598
607
|
writeReport(report: string): Promise<void>;
|
|
608
|
+
protected getFailureLocation(test: Test): Callsite | undefined;
|
|
599
609
|
}
|
|
600
610
|
|
|
601
611
|
declare class VerboseReporter extends DefaultReporter {
|
|
@@ -970,6 +980,7 @@ interface TestContext {
|
|
|
970
980
|
|
|
971
981
|
interface Reporter {
|
|
972
982
|
onInit?(ctx: Vitest): void;
|
|
983
|
+
onPathsCollected?: (paths?: string[]) => Awaitable<void>;
|
|
973
984
|
onCollected?: (files?: File[]) => Awaitable<void>;
|
|
974
985
|
onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
|
|
975
986
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
|
|
@@ -1180,6 +1191,12 @@ interface InlineConfig {
|
|
|
1180
1191
|
* @default 10000
|
|
1181
1192
|
*/
|
|
1182
1193
|
hookTimeout?: number;
|
|
1194
|
+
/**
|
|
1195
|
+
* Default timeout to wait for close when Vitest shuts down, in milliseconds
|
|
1196
|
+
*
|
|
1197
|
+
* @default 1000
|
|
1198
|
+
*/
|
|
1199
|
+
teardownTimeout?: number;
|
|
1183
1200
|
/**
|
|
1184
1201
|
* Silent mode
|
|
1185
1202
|
*
|
|
@@ -1248,6 +1265,11 @@ interface InlineConfig {
|
|
|
1248
1265
|
* @internal WIP
|
|
1249
1266
|
*/
|
|
1250
1267
|
ui?: boolean;
|
|
1268
|
+
/**
|
|
1269
|
+
* Use in browser environment
|
|
1270
|
+
* @experimental
|
|
1271
|
+
*/
|
|
1272
|
+
browser?: boolean;
|
|
1251
1273
|
/**
|
|
1252
1274
|
* Open UI automatically.
|
|
1253
1275
|
*
|
|
@@ -1359,6 +1381,12 @@ interface InlineConfig {
|
|
|
1359
1381
|
*/
|
|
1360
1382
|
seed?: number;
|
|
1361
1383
|
};
|
|
1384
|
+
/**
|
|
1385
|
+
* Specifies an `Object`, or an `Array` of `Object`,
|
|
1386
|
+
* which defines aliases used to replace values in `import` or `require` statements.
|
|
1387
|
+
* Will be merged with the default aliases inside `resolve.alias`.
|
|
1388
|
+
*/
|
|
1389
|
+
alias?: AliasOptions;
|
|
1362
1390
|
}
|
|
1363
1391
|
interface UserConfig extends InlineConfig {
|
|
1364
1392
|
/**
|
|
@@ -1710,6 +1738,7 @@ interface WorkerRPC {
|
|
|
1710
1738
|
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
|
|
1711
1739
|
onFinished: (files: File[], errors?: unknown[]) => void;
|
|
1712
1740
|
onWorkerExit: (code?: number) => void;
|
|
1741
|
+
onPathsCollected: (paths: string[]) => void;
|
|
1713
1742
|
onUserConsoleLog: (log: UserConsoleLog) => void;
|
|
1714
1743
|
onUnhandledRejection: (err: unknown) => void;
|
|
1715
1744
|
onCollected: (files: File[]) => void;
|
|
@@ -1724,6 +1753,7 @@ interface WorkerGlobalState {
|
|
|
1724
1753
|
current?: Test;
|
|
1725
1754
|
filepath?: string;
|
|
1726
1755
|
moduleCache: ModuleCacheMap;
|
|
1756
|
+
browserHashMap?: Map<string, string>;
|
|
1727
1757
|
mockMap: MockMap;
|
|
1728
1758
|
}
|
|
1729
1759
|
|
|
@@ -1959,7 +1989,12 @@ interface TransformResultWithSource extends TransformResult {
|
|
|
1959
1989
|
source?: string;
|
|
1960
1990
|
}
|
|
1961
1991
|
interface WebSocketHandlers {
|
|
1992
|
+
onWatcherStart: () => Promise<void>;
|
|
1993
|
+
onFinished(files?: File[]): Promise<void>;
|
|
1994
|
+
onCollected(files?: File[]): Promise<void>;
|
|
1995
|
+
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
1962
1996
|
getFiles(): File[];
|
|
1997
|
+
getPaths(): string[];
|
|
1963
1998
|
getConfig(): ResolvedConfig;
|
|
1964
1999
|
getModuleGraph(id: string): Promise<ModuleGraphData>;
|
|
1965
2000
|
getTransformResult(id: string): Promise<TransformResultWithSource | undefined>;
|
|
@@ -1968,7 +2003,7 @@ interface WebSocketHandlers {
|
|
|
1968
2003
|
rerun(files: string[]): Promise<void>;
|
|
1969
2004
|
updateSnapshot(file?: File): Promise<void>;
|
|
1970
2005
|
}
|
|
1971
|
-
interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog'> {
|
|
2006
|
+
interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog' | 'onPathsCollected'> {
|
|
1972
2007
|
}
|
|
1973
2008
|
|
|
1974
2009
|
export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable$1 as Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookCleanupCallback, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyInstance, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, createExpect, describe, globalExpect as expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { c as createExpect, d as describe, b as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.1e1aabb3.mjs';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, h as getRunningMode, f as isFirstRun, j as isWatchMode, e as runOnce, v as vi, g as vitest, w as withCallback } from './chunk-runtime-hooks.db398170.mjs';
|
|
3
|
+
import * as chai from 'chai';
|
|
4
|
+
export { chai };
|
|
5
|
+
export { assert, should } from 'chai';
|
|
3
6
|
import 'util';
|
|
4
|
-
import './chunk-utils-global.
|
|
7
|
+
import './chunk-utils-global.2aa95025.mjs';
|
|
5
8
|
import 'path';
|
|
6
9
|
import 'tty';
|
|
7
10
|
import 'local-pkg';
|
|
8
11
|
import './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
9
|
-
import './chunk-runtime-rpc.
|
|
12
|
+
import './chunk-runtime-rpc.45d8ee19.mjs';
|
|
10
13
|
import 'fs';
|
|
11
|
-
import './chunk-utils-source-map.
|
|
14
|
+
import './chunk-utils-source-map.8b066ce2.mjs';
|
|
12
15
|
import './spy.mjs';
|
|
13
16
|
import 'tinyspy';
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ViteDevServer, TransformResult, CommonServerOptions, UserConfig as UserConfig$1, Plugin as Plugin$1 } from 'vite';
|
|
1
|
+
import { ViteDevServer, TransformResult, AliasOptions, CommonServerOptions, UserConfig as UserConfig$1, Plugin as Plugin$1 } from 'vite';
|
|
2
2
|
import { Stats } from 'fs';
|
|
3
3
|
|
|
4
4
|
interface UpdatePayload {
|
|
@@ -357,7 +357,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
357
357
|
start: number;
|
|
358
358
|
end: number;
|
|
359
359
|
watchFilters?: string[];
|
|
360
|
-
isTTY:
|
|
360
|
+
isTTY: false;
|
|
361
361
|
ctx: Vitest;
|
|
362
362
|
private _filesInWatchMode;
|
|
363
363
|
private _lastRunTimeout;
|
|
@@ -439,6 +439,10 @@ declare class DotReporter extends BaseReporter {
|
|
|
439
439
|
onUserConsoleLog(log: UserConsoleLog): void;
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
+
interface Callsite {
|
|
443
|
+
line: number;
|
|
444
|
+
column: number;
|
|
445
|
+
}
|
|
442
446
|
declare class JsonReporter implements Reporter {
|
|
443
447
|
start: number;
|
|
444
448
|
ctx: Vitest;
|
|
@@ -451,6 +455,7 @@ declare class JsonReporter implements Reporter {
|
|
|
451
455
|
* @param report
|
|
452
456
|
*/
|
|
453
457
|
writeReport(report: string): Promise<void>;
|
|
458
|
+
protected getFailureLocation(test: Test): Callsite | undefined;
|
|
454
459
|
}
|
|
455
460
|
|
|
456
461
|
declare class VerboseReporter extends DefaultReporter {
|
|
@@ -750,6 +755,7 @@ interface TestContext {
|
|
|
750
755
|
|
|
751
756
|
interface Reporter {
|
|
752
757
|
onInit?(ctx: Vitest): void;
|
|
758
|
+
onPathsCollected?: (paths?: string[]) => Awaitable<void>;
|
|
753
759
|
onCollected?: (files?: File[]) => Awaitable<void>;
|
|
754
760
|
onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
|
|
755
761
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
|
|
@@ -959,6 +965,12 @@ interface InlineConfig {
|
|
|
959
965
|
* @default 10000
|
|
960
966
|
*/
|
|
961
967
|
hookTimeout?: number;
|
|
968
|
+
/**
|
|
969
|
+
* Default timeout to wait for close when Vitest shuts down, in milliseconds
|
|
970
|
+
*
|
|
971
|
+
* @default 1000
|
|
972
|
+
*/
|
|
973
|
+
teardownTimeout?: number;
|
|
962
974
|
/**
|
|
963
975
|
* Silent mode
|
|
964
976
|
*
|
|
@@ -1027,6 +1039,11 @@ interface InlineConfig {
|
|
|
1027
1039
|
* @internal WIP
|
|
1028
1040
|
*/
|
|
1029
1041
|
ui?: boolean;
|
|
1042
|
+
/**
|
|
1043
|
+
* Use in browser environment
|
|
1044
|
+
* @experimental
|
|
1045
|
+
*/
|
|
1046
|
+
browser?: boolean;
|
|
1030
1047
|
/**
|
|
1031
1048
|
* Open UI automatically.
|
|
1032
1049
|
*
|
|
@@ -1138,6 +1155,12 @@ interface InlineConfig {
|
|
|
1138
1155
|
*/
|
|
1139
1156
|
seed?: number;
|
|
1140
1157
|
};
|
|
1158
|
+
/**
|
|
1159
|
+
* Specifies an `Object`, or an `Array` of `Object`,
|
|
1160
|
+
* which defines aliases used to replace values in `import` or `require` statements.
|
|
1161
|
+
* Will be merged with the default aliases inside `resolve.alias`.
|
|
1162
|
+
*/
|
|
1163
|
+
alias?: AliasOptions;
|
|
1141
1164
|
}
|
|
1142
1165
|
interface UserConfig extends InlineConfig {
|
|
1143
1166
|
/**
|
|
@@ -1482,15 +1505,18 @@ interface WorkerPool {
|
|
|
1482
1505
|
|
|
1483
1506
|
declare class StateManager {
|
|
1484
1507
|
filesMap: Map<string, File>;
|
|
1508
|
+
pathsSet: Set<string>;
|
|
1485
1509
|
idMap: Map<string, Task>;
|
|
1486
1510
|
taskFileMap: WeakMap<Task, File>;
|
|
1487
1511
|
errorsSet: Set<unknown>;
|
|
1488
1512
|
catchError(err: unknown, type: string): void;
|
|
1489
1513
|
clearErrors(): void;
|
|
1490
1514
|
getUnhandledErrors(): unknown[];
|
|
1515
|
+
getPaths(): string[];
|
|
1491
1516
|
getFiles(keys?: string[]): File[];
|
|
1492
1517
|
getFilepaths(): string[];
|
|
1493
1518
|
getFailedFilepaths(): string[];
|
|
1519
|
+
collectPaths(paths?: string[]): void;
|
|
1494
1520
|
collectFiles(files?: File[]): void;
|
|
1495
1521
|
clearFiles(paths?: string[]): void;
|
|
1496
1522
|
updateId(task: Task): void;
|
package/dist/node.mjs
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.
|
|
2
|
-
export { V as VitestRunner } from './chunk-runtime-mocker.
|
|
3
|
-
import './chunk-
|
|
1
|
+
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.a2813ad7.mjs';
|
|
2
|
+
export { V as VitestRunner } from './chunk-runtime-mocker.dfdfd57b.mjs';
|
|
3
|
+
import './chunk-utils-global.2aa95025.mjs';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'tty';
|
|
4
6
|
import 'local-pkg';
|
|
7
|
+
import './chunk-defaults.408a0cfe.mjs';
|
|
5
8
|
import 'fs';
|
|
6
9
|
import 'module';
|
|
7
10
|
import 'url';
|
|
8
|
-
import './chunk-utils-global.0a7416cf.mjs';
|
|
9
|
-
import 'path';
|
|
10
|
-
import 'tty';
|
|
11
11
|
import 'vite';
|
|
12
12
|
import 'process';
|
|
13
|
-
import './chunk-constants.
|
|
13
|
+
import './chunk-constants.38b43a44.mjs';
|
|
14
14
|
import 'os';
|
|
15
15
|
import 'util';
|
|
16
16
|
import 'stream';
|
|
17
17
|
import 'events';
|
|
18
18
|
import './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
19
|
-
import './chunk-vite-node-utils.
|
|
19
|
+
import './chunk-vite-node-utils.ad73f2ab.mjs';
|
|
20
20
|
import 'vm';
|
|
21
21
|
import 'assert';
|
|
22
22
|
import 'debug';
|
|
23
23
|
import 'worker_threads';
|
|
24
24
|
import 'tinypool';
|
|
25
25
|
import 'perf_hooks';
|
|
26
|
-
import './chunk-utils-source-map.
|
|
26
|
+
import './chunk-utils-source-map.8b066ce2.mjs';
|
|
27
27
|
import 'crypto';
|
|
28
|
-
import '
|
|
29
|
-
import 'child_process';
|
|
30
|
-
import './vendor-index.4bf9c627.mjs';
|
|
28
|
+
import './vendor-index.61438b77.mjs';
|
|
31
29
|
import './chunk-magic-string.efe26975.mjs';
|
|
32
30
|
import 'readline';
|
|
33
31
|
import './vendor-index.de788b6a.mjs';
|
package/dist/suite.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import 'util';
|
|
2
|
+
import './chunk-utils-global.2aa95025.mjs';
|
|
3
|
+
export { e as clearCollectorContext, o as createSuiteHooks, f as defaultSuite, d as describe, g as getCurrentSuite, i as it, s as suite, t as test } from './chunk-runtime-chain.1e1aabb3.mjs';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'tty';
|
|
6
|
+
import 'local-pkg';
|
|
7
|
+
import 'chai';
|
|
8
|
+
import './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
9
|
+
import './chunk-runtime-rpc.45d8ee19.mjs';
|
|
10
|
+
import 'fs';
|
|
11
|
+
import './chunk-utils-source-map.8b066ce2.mjs';
|
|
12
|
+
import './spy.mjs';
|
|
13
|
+
import 'tinyspy';
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
2
|
+
import assert$1 from 'assert';
|
|
3
|
+
import require$$2 from 'events';
|
|
4
|
+
|
|
5
|
+
var onetime$1 = {exports: {}};
|
|
6
|
+
|
|
7
|
+
var mimicFn$2 = {exports: {}};
|
|
8
|
+
|
|
9
|
+
const mimicFn$1 = (to, from) => {
|
|
10
|
+
for (const prop of Reflect.ownKeys(from)) {
|
|
11
|
+
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
mimicFn$2.exports = mimicFn$1;
|
|
18
|
+
// TODO: Remove this for the next major release
|
|
19
|
+
mimicFn$2.exports.default = mimicFn$1;
|
|
20
|
+
|
|
21
|
+
const mimicFn = mimicFn$2.exports;
|
|
22
|
+
|
|
23
|
+
const calledFunctions = new WeakMap();
|
|
24
|
+
|
|
25
|
+
const onetime = (function_, options = {}) => {
|
|
26
|
+
if (typeof function_ !== 'function') {
|
|
27
|
+
throw new TypeError('Expected a function');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let returnValue;
|
|
31
|
+
let callCount = 0;
|
|
32
|
+
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
33
|
+
|
|
34
|
+
const onetime = function (...arguments_) {
|
|
35
|
+
calledFunctions.set(onetime, ++callCount);
|
|
36
|
+
|
|
37
|
+
if (callCount === 1) {
|
|
38
|
+
returnValue = function_.apply(this, arguments_);
|
|
39
|
+
function_ = null;
|
|
40
|
+
} else if (options.throw === true) {
|
|
41
|
+
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return returnValue;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
mimicFn(onetime, function_);
|
|
48
|
+
calledFunctions.set(onetime, callCount);
|
|
49
|
+
|
|
50
|
+
return onetime;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
onetime$1.exports = onetime;
|
|
54
|
+
// TODO: Remove this for the next major release
|
|
55
|
+
onetime$1.exports.default = onetime;
|
|
56
|
+
|
|
57
|
+
onetime$1.exports.callCount = function_ => {
|
|
58
|
+
if (!calledFunctions.has(function_)) {
|
|
59
|
+
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return calledFunctions.get(function_);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var signalExit = {exports: {}};
|
|
66
|
+
|
|
67
|
+
var signals$1 = {exports: {}};
|
|
68
|
+
|
|
69
|
+
var hasRequiredSignals;
|
|
70
|
+
|
|
71
|
+
function requireSignals () {
|
|
72
|
+
if (hasRequiredSignals) return signals$1.exports;
|
|
73
|
+
hasRequiredSignals = 1;
|
|
74
|
+
(function (module) {
|
|
75
|
+
// This is not the set of all possible signals.
|
|
76
|
+
//
|
|
77
|
+
// It IS, however, the set of all signals that trigger
|
|
78
|
+
// an exit on either Linux or BSD systems. Linux is a
|
|
79
|
+
// superset of the signal names supported on BSD, and
|
|
80
|
+
// the unknown signals just fail to register, so we can
|
|
81
|
+
// catch that easily enough.
|
|
82
|
+
//
|
|
83
|
+
// Don't bother with SIGKILL. It's uncatchable, which
|
|
84
|
+
// means that we can't fire any callbacks anyway.
|
|
85
|
+
//
|
|
86
|
+
// If a user does happen to register a handler on a non-
|
|
87
|
+
// fatal signal like SIGWINCH or something, and then
|
|
88
|
+
// exit, it'll end up firing `process.emit('exit')`, so
|
|
89
|
+
// the handler will be fired anyway.
|
|
90
|
+
//
|
|
91
|
+
// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
92
|
+
// artificially, inherently leave the process in a
|
|
93
|
+
// state from which it is not safe to try and enter JS
|
|
94
|
+
// listeners.
|
|
95
|
+
module.exports = [
|
|
96
|
+
'SIGABRT',
|
|
97
|
+
'SIGALRM',
|
|
98
|
+
'SIGHUP',
|
|
99
|
+
'SIGINT',
|
|
100
|
+
'SIGTERM'
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
if (process.platform !== 'win32') {
|
|
104
|
+
module.exports.push(
|
|
105
|
+
'SIGVTALRM',
|
|
106
|
+
'SIGXCPU',
|
|
107
|
+
'SIGXFSZ',
|
|
108
|
+
'SIGUSR2',
|
|
109
|
+
'SIGTRAP',
|
|
110
|
+
'SIGSYS',
|
|
111
|
+
'SIGQUIT',
|
|
112
|
+
'SIGIOT'
|
|
113
|
+
// should detect profiler and enable/disable accordingly.
|
|
114
|
+
// see #21
|
|
115
|
+
// 'SIGPROF'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (process.platform === 'linux') {
|
|
120
|
+
module.exports.push(
|
|
121
|
+
'SIGIO',
|
|
122
|
+
'SIGPOLL',
|
|
123
|
+
'SIGPWR',
|
|
124
|
+
'SIGSTKFLT',
|
|
125
|
+
'SIGUNUSED'
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
} (signals$1));
|
|
129
|
+
return signals$1.exports;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Note: since nyc uses this module to output coverage, any lines
|
|
133
|
+
// that are in the direct sync flow of nyc's outputCoverage are
|
|
134
|
+
// ignored, since we can never get coverage for them.
|
|
135
|
+
// grab a reference to node's real process object right away
|
|
136
|
+
var process$1 = commonjsGlobal.process;
|
|
137
|
+
|
|
138
|
+
const processOk = function (process) {
|
|
139
|
+
return process &&
|
|
140
|
+
typeof process === 'object' &&
|
|
141
|
+
typeof process.removeListener === 'function' &&
|
|
142
|
+
typeof process.emit === 'function' &&
|
|
143
|
+
typeof process.reallyExit === 'function' &&
|
|
144
|
+
typeof process.listeners === 'function' &&
|
|
145
|
+
typeof process.kill === 'function' &&
|
|
146
|
+
typeof process.pid === 'number' &&
|
|
147
|
+
typeof process.on === 'function'
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// some kind of non-node environment, just no-op
|
|
151
|
+
/* istanbul ignore if */
|
|
152
|
+
if (!processOk(process$1)) {
|
|
153
|
+
signalExit.exports = function () {
|
|
154
|
+
return function () {}
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
var assert = assert$1;
|
|
158
|
+
var signals = requireSignals();
|
|
159
|
+
var isWin = /^win/i.test(process$1.platform);
|
|
160
|
+
|
|
161
|
+
var EE = require$$2;
|
|
162
|
+
/* istanbul ignore if */
|
|
163
|
+
if (typeof EE !== 'function') {
|
|
164
|
+
EE = EE.EventEmitter;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var emitter;
|
|
168
|
+
if (process$1.__signal_exit_emitter__) {
|
|
169
|
+
emitter = process$1.__signal_exit_emitter__;
|
|
170
|
+
} else {
|
|
171
|
+
emitter = process$1.__signal_exit_emitter__ = new EE();
|
|
172
|
+
emitter.count = 0;
|
|
173
|
+
emitter.emitted = {};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Because this emitter is a global, we have to check to see if a
|
|
177
|
+
// previous version of this library failed to enable infinite listeners.
|
|
178
|
+
// I know what you're about to say. But literally everything about
|
|
179
|
+
// signal-exit is a compromise with evil. Get used to it.
|
|
180
|
+
if (!emitter.infinite) {
|
|
181
|
+
emitter.setMaxListeners(Infinity);
|
|
182
|
+
emitter.infinite = true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
signalExit.exports = function (cb, opts) {
|
|
186
|
+
/* istanbul ignore if */
|
|
187
|
+
if (!processOk(commonjsGlobal.process)) {
|
|
188
|
+
return function () {}
|
|
189
|
+
}
|
|
190
|
+
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
|
|
191
|
+
|
|
192
|
+
if (loaded === false) {
|
|
193
|
+
load();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
var ev = 'exit';
|
|
197
|
+
if (opts && opts.alwaysLast) {
|
|
198
|
+
ev = 'afterexit';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var remove = function () {
|
|
202
|
+
emitter.removeListener(ev, cb);
|
|
203
|
+
if (emitter.listeners('exit').length === 0 &&
|
|
204
|
+
emitter.listeners('afterexit').length === 0) {
|
|
205
|
+
unload();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
emitter.on(ev, cb);
|
|
209
|
+
|
|
210
|
+
return remove
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
var unload = function unload () {
|
|
214
|
+
if (!loaded || !processOk(commonjsGlobal.process)) {
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
loaded = false;
|
|
218
|
+
|
|
219
|
+
signals.forEach(function (sig) {
|
|
220
|
+
try {
|
|
221
|
+
process$1.removeListener(sig, sigListeners[sig]);
|
|
222
|
+
} catch (er) {}
|
|
223
|
+
});
|
|
224
|
+
process$1.emit = originalProcessEmit;
|
|
225
|
+
process$1.reallyExit = originalProcessReallyExit;
|
|
226
|
+
emitter.count -= 1;
|
|
227
|
+
};
|
|
228
|
+
signalExit.exports.unload = unload;
|
|
229
|
+
|
|
230
|
+
var emit = function emit (event, code, signal) {
|
|
231
|
+
/* istanbul ignore if */
|
|
232
|
+
if (emitter.emitted[event]) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
emitter.emitted[event] = true;
|
|
236
|
+
emitter.emit(event, code, signal);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// { <signal>: <listener fn>, ... }
|
|
240
|
+
var sigListeners = {};
|
|
241
|
+
signals.forEach(function (sig) {
|
|
242
|
+
sigListeners[sig] = function listener () {
|
|
243
|
+
/* istanbul ignore if */
|
|
244
|
+
if (!processOk(commonjsGlobal.process)) {
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
// If there are no other listeners, an exit is coming!
|
|
248
|
+
// Simplest way: remove us and then re-send the signal.
|
|
249
|
+
// We know that this will kill the process, so we can
|
|
250
|
+
// safely emit now.
|
|
251
|
+
var listeners = process$1.listeners(sig);
|
|
252
|
+
if (listeners.length === emitter.count) {
|
|
253
|
+
unload();
|
|
254
|
+
emit('exit', null, sig);
|
|
255
|
+
/* istanbul ignore next */
|
|
256
|
+
emit('afterexit', null, sig);
|
|
257
|
+
/* istanbul ignore next */
|
|
258
|
+
if (isWin && sig === 'SIGHUP') {
|
|
259
|
+
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
260
|
+
// so use a supported signal instead
|
|
261
|
+
sig = 'SIGINT';
|
|
262
|
+
}
|
|
263
|
+
/* istanbul ignore next */
|
|
264
|
+
process$1.kill(process$1.pid, sig);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
signalExit.exports.signals = function () {
|
|
270
|
+
return signals
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
var loaded = false;
|
|
274
|
+
|
|
275
|
+
var load = function load () {
|
|
276
|
+
if (loaded || !processOk(commonjsGlobal.process)) {
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
loaded = true;
|
|
280
|
+
|
|
281
|
+
// This is the number of onSignalExit's that are in play.
|
|
282
|
+
// It's important so that we can count the correct number of
|
|
283
|
+
// listeners on signals, and don't wait for the other one to
|
|
284
|
+
// handle it instead of us.
|
|
285
|
+
emitter.count += 1;
|
|
286
|
+
|
|
287
|
+
signals = signals.filter(function (sig) {
|
|
288
|
+
try {
|
|
289
|
+
process$1.on(sig, sigListeners[sig]);
|
|
290
|
+
return true
|
|
291
|
+
} catch (er) {
|
|
292
|
+
return false
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
process$1.emit = processEmit;
|
|
297
|
+
process$1.reallyExit = processReallyExit;
|
|
298
|
+
};
|
|
299
|
+
signalExit.exports.load = load;
|
|
300
|
+
|
|
301
|
+
var originalProcessReallyExit = process$1.reallyExit;
|
|
302
|
+
var processReallyExit = function processReallyExit (code) {
|
|
303
|
+
/* istanbul ignore if */
|
|
304
|
+
if (!processOk(commonjsGlobal.process)) {
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
process$1.exitCode = code || /* istanbul ignore next */ 0;
|
|
308
|
+
emit('exit', process$1.exitCode, null);
|
|
309
|
+
/* istanbul ignore next */
|
|
310
|
+
emit('afterexit', process$1.exitCode, null);
|
|
311
|
+
/* istanbul ignore next */
|
|
312
|
+
originalProcessReallyExit.call(process$1, process$1.exitCode);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
var originalProcessEmit = process$1.emit;
|
|
316
|
+
var processEmit = function processEmit (ev, arg) {
|
|
317
|
+
if (ev === 'exit' && processOk(commonjsGlobal.process)) {
|
|
318
|
+
/* istanbul ignore else */
|
|
319
|
+
if (arg !== undefined) {
|
|
320
|
+
process$1.exitCode = arg;
|
|
321
|
+
}
|
|
322
|
+
var ret = originalProcessEmit.apply(this, arguments);
|
|
323
|
+
/* istanbul ignore next */
|
|
324
|
+
emit('exit', process$1.exitCode, null);
|
|
325
|
+
/* istanbul ignore next */
|
|
326
|
+
emit('afterexit', process$1.exitCode, null);
|
|
327
|
+
/* istanbul ignore next */
|
|
328
|
+
return ret
|
|
329
|
+
} else {
|
|
330
|
+
return originalProcessEmit.apply(this, arguments)
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { onetime$1 as o, signalExit as s };
|