UNPKG

1.36 kBJavaScriptView Raw
1// @flow strict-local
2
3import type {AbortSignal} from 'abortcontroller-polyfill/dist/cjs-ponyfill';
4import type {BundleGroup} from '@parcel/types';
5
6import {registerSerializableClass} from './serializer';
7import AssetGraph from './AssetGraph';
8import BundleGraph from './BundleGraph';
9import Graph from './Graph';
10import ParcelConfig from './ParcelConfig';
11import {RequestGraph} from './RequestTracker';
12import Config from './public/Config';
13// $FlowFixMe this is untyped
14import packageJson from '../package.json';
15
16export function getBundleGroupId(bundleGroup: BundleGroup): string {
17 return 'bundle_group:' + bundleGroup.entryAssetId;
18}
19
20export function assertSignalNotAborted(signal: ?AbortSignal): void {
21 if (signal && signal.aborted) {
22 throw new BuildAbortError();
23 }
24}
25
26export class BuildAbortError extends Error {
27 name = 'BuildAbortError';
28}
29
30let coreRegistered;
31export function registerCoreWithSerializer() {
32 if (coreRegistered) {
33 return;
34 }
35
36 const packageVersion: mixed = packageJson.version;
37 if (typeof packageVersion !== 'string') {
38 throw new Error('Expected package version to be a string');
39 }
40
41 for (let ctor of [
42 AssetGraph,
43 Config,
44 BundleGraph,
45 Graph,
46 ParcelConfig,
47 RequestGraph,
48 ]) {
49 registerSerializableClass(packageVersion + ':' + ctor.name, ctor);
50 }
51
52 coreRegistered = true;
53}