-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
utils.js
54 lines (45 loc) 路 1.4 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// @flow strict-local
import type {AbortSignal} from 'abortcontroller-polyfill/dist/cjs-ponyfill';
import type {BundleGroup} from '@parcel/types';
import {registerSerializableClass} from './serializer';
import AssetGraph from './AssetGraph';
import BundleGraph from './BundleGraph';
import Graph from './Graph';
import ParcelConfig from './ParcelConfig';
import {RequestGraph} from './RequestTracker';
import Config from './public/Config';
// flowlint-next-line untyped-import:off
import packageJson from '../package.json';
export function getBundleGroupId(bundleGroup: BundleGroup): string {
return 'bundle_group:' + bundleGroup.entryAssetId;
}
export function assertSignalNotAborted(signal: ?AbortSignal): void {
if (signal && signal.aborted) {
throw new BuildAbortError();
}
}
export class BuildAbortError extends Error {
name = 'BuildAbortError';
}
let coreRegistered;
export function registerCoreWithSerializer() {
if (coreRegistered) {
return;
}
const packageVersion: mixed = packageJson.version;
if (typeof packageVersion !== 'string') {
throw new Error('Expected package version to be a string');
}
// $FlowFixMe
for (let [name, ctor] of (Object.entries({
AssetGraph,
Config,
BundleGraph,
Graph,
ParcelConfig,
RequestGraph,
}): Array<[string, Class<*>]>)) {
registerSerializableClass(packageVersion + ':' + name, ctor);
}
coreRegistered = true;
}