1 |
|
2 |
|
3 | import type {AbortSignal} from 'abortcontroller-polyfill/dist/cjs-ponyfill';
|
4 | import type {BundleGroup} from '@parcel/types';
|
5 |
|
6 | import {registerSerializableClass} from './serializer';
|
7 | import AssetGraph from './AssetGraph';
|
8 | import BundleGraph from './BundleGraph';
|
9 | import Graph from './Graph';
|
10 | import ParcelConfig from './ParcelConfig';
|
11 | import {RequestGraph} from './RequestTracker';
|
12 | import Config from './public/Config';
|
13 |
|
14 | import packageJson from '../package.json';
|
15 |
|
16 | export function getBundleGroupId(bundleGroup: BundleGroup): string {
|
17 | return 'bundle_group:' + bundleGroup.entryAssetId;
|
18 | }
|
19 |
|
20 | export function assertSignalNotAborted(signal: ?AbortSignal): void {
|
21 | if (signal && signal.aborted) {
|
22 | throw new BuildAbortError();
|
23 | }
|
24 | }
|
25 |
|
26 | export class BuildAbortError extends Error {
|
27 | name = 'BuildAbortError';
|
28 | }
|
29 |
|
30 | let coreRegistered;
|
31 | export 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 | }
|