Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move registerCoreWithSerializer to its own file #9396

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/core/src/Parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ReporterRunner from './ReporterRunner';
import dumpGraphToGraphViz from './dumpGraphToGraphViz';
import resolveOptions from './resolveOptions';
import {ValueEmitter} from '@parcel/events';
import {registerCoreWithSerializer} from './utils';
import {registerCoreWithSerializer} from './registerCoreWithSerializer';
import {AbortController} from 'abortcontroller-polyfill/dist/cjs-ponyfill';
import {PromiseQueue} from '@parcel/utils';
import ParcelConfig from './ParcelConfig';
Expand Down
34 changes: 34 additions & 0 deletions packages/core/core/src/registerCoreWithSerializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @flow
import {Graph} from '@parcel/graph';
import {registerSerializableClass} from './serializer';
import AssetGraph from './AssetGraph';
import BundleGraph from './BundleGraph';
import ParcelConfig from './ParcelConfig';
import {RequestGraph} from './RequestTracker';
import Config from './public/Config';
import packageJson from '../package.json';

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[incompatible-cast]
for (let [name, ctor] of (Object.entries({
AssetGraph,
Config,
BundleGraph,
Graph,
ParcelConfig,
RequestGraph,
// $FlowFixMe[unclear-type]
}): Array<[string, Class<any>]>)) {
registerSerializableClass(packageVersion + ':' + name, ctor);
}
coreRegistered = true;
}
37 changes: 0 additions & 37 deletions packages/core/core/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ import type {PackageManager} from '@parcel/package-manager';

import invariant from 'assert';
import baseX from 'base-x';
import {Graph} from '@parcel/graph';
import {hashObject} from '@parcel/utils';

import {registerSerializableClass} from './serializer';
import AssetGraph from './AssetGraph';
import BundleGraph from './BundleGraph';
import ParcelConfig from './ParcelConfig';
import {RequestGraph} from './RequestTracker';
import Config from './public/Config';
import {fromProjectPath, toProjectPath} from './projectPath';
// flowlint-next-line untyped-import:off
import packageJson from '../package.json';

const base62 = baseX(
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
Expand All @@ -48,33 +38,6 @@ export class BuildAbortError extends Error {
name: string = '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[incompatible-cast]
for (let [name, ctor] of (Object.entries({
AssetGraph,
Config,
BundleGraph,
Graph,
ParcelConfig,
RequestGraph,
// $FlowFixMe[unclear-type]
}): Array<[string, Class<any>]>)) {
registerSerializableClass(packageVersion + ':' + name, ctor);
}

coreRegistered = true;
}

export function getPublicId(
id: string,
alreadyExists: string => boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {reportWorker, report} from './ReporterRunner';
import PackagerRunner, {type PackageRequestResult} from './PackagerRunner';
import Validation, {type ValidationOpts} from './Validation';
import ParcelConfig from './ParcelConfig';
import {registerCoreWithSerializer} from './utils';
import {registerCoreWithSerializer} from './registerCoreWithSerializer';
import {clearBuildCaches} from './buildCache';
import {init as initSourcemaps} from '@parcel/source-map';
import {init as initRust} from '@parcel/rust';
Expand Down
Loading