Skip to content

Commit

Permalink
Remove circular dependency from core
Browse files Browse the repository at this point in the history
  • Loading branch information
MonicaOlejniczak committed Oct 21, 2024
1 parent 963983d commit 96bae9c
Show file tree
Hide file tree
Showing 49 changed files with 127 additions and 85 deletions.
18 changes: 18 additions & 0 deletions packages/core/build-cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@atlaspack/build-cache",
"description": "Serialize and deserialize data structures to a build cache",
"version": "2.12.0",
"license": "(MIT OR Apache-2.0)",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/atlassian-labs/atlaspack.git"
},
"main": "lib/index.js",
"source": "src/index.js",
"engines": {
"node": ">= 16.0.0"
}
}
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/core/build-cache/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @flow

export * from './buildCache';
export * from './serializer';
export * from './serializerCore';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// @flow

import assert from 'assert';
import sinon from 'sinon';

import {
serialize,
deserialize,
registerSerializableClass,
unregisterSerializableClass,
} from '../src/serializer';
import assert from 'assert';
import sinon from 'sinon';

describe('serializer', () => {
it('should serialize a basic object', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/core/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
"check-ts": "tsc --noEmit index.d.ts"
},
"dependencies": {
"@atlaspack/build-cache": "2.12.0",
"@atlaspack/fs": "2.12.0",
"@atlaspack/logger": "2.12.0",
"@atlaspack/rust": "2.12.0",
"@atlaspack/utils": "2.12.0",
"lmdb": "2.8.5"
},
"peerDependencies": {
"@atlaspack/core": "^2.12.0"
},
"devDependencies": {
"idb": "^5.0.8"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/core/cache/src/FSCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import type {Cache} from './types';
import stream from 'stream';
import path from 'path';
import {promisify} from 'util';

import logger from '@atlaspack/logger';
import {
serialize,
deserialize,
registerSerializableClass,
} from '@atlaspack/core';
serialize,
} from '@atlaspack/build-cache';

// flowlint-next-line untyped-import:off
import packageJson from '../package.json';

import {WRITE_LIMIT_CHUNK} from './constants';

const pipeline: (Readable, Writable) => Promise<void> = promisify(
Expand Down
10 changes: 6 additions & 4 deletions packages/core/cache/src/IDBCache.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
import type {Cache} from './types';

import {Readable} from 'stream';

import {
serialize,
deserialize,
registerSerializableClass,
} from '@atlaspack/core';
serialize,
} from '@atlaspack/build-cache';
import {bufferStream} from '@atlaspack/utils';
// $FlowFixMe[untyped-import]
import packageJson from '../package.json';
// $FlowFixMe[untyped-import]
import {openDB} from 'idb';

// $FlowFixMe[untyped-import]
import packageJson from '../package.json';

const STORE_NAME = 'cache';

export class IDBCache implements Cache {
Expand Down
10 changes: 6 additions & 4 deletions packages/core/cache/src/LMDBCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import type {Readable, Writable} from 'stream';
import stream from 'stream';
import path from 'path';
import {promisify} from 'util';

import {
serialize,
deserialize,
registerSerializableClass,
} from '@atlaspack/core';
serialize,
} from '@atlaspack/build-cache';
import {NodeFS} from '@atlaspack/fs';
// flowlint-next-line untyped-import:off
import packageJson from '../package.json';
// $FlowFixMe
import lmdb from 'lmdb';

// $FlowFixMe
import packageJson from '../package.json';

import {FSCache} from './FSCache';

const pipeline: (Readable, Writable) => Promise<void> = promisify(
Expand Down
12 changes: 7 additions & 5 deletions packages/core/cache/src/LMDBLiteCache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// @flow strict-local

import {
deserialize,
registerSerializableClass,
serialize,
} from '@atlaspack/build-cache';
import {Lmdb} from '@atlaspack/rust';
import type {FilePath} from '@atlaspack/types';
import type {Cache} from './types';
Expand All @@ -8,12 +13,9 @@ import type {Readable, Writable} from 'stream';
import stream from 'stream';
import path from 'path';
import {promisify} from 'util';
import {
serialize,
deserialize,
registerSerializableClass,
} from '@atlaspack/core';

import {NodeFS} from '@atlaspack/fs';

// $FlowFixMe
import packageJson from '../package.json';

Expand Down
8 changes: 5 additions & 3 deletions packages/core/cache/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
export type {Cache} from './types';
export * from './LMDBCache';
export * from './LMDBLiteCache';

export * from './FSCache';
export * from './IDBCache';
export * from './LMDBCache';
export * from './LMDBLiteCache';

export type {Cache} from './types';
3 changes: 2 additions & 1 deletion packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@mischnic/json-sourcemap": "^0.1.0",
"@atlaspack/build-cache": "2.12.0",
"@atlaspack/cache": "2.12.0",
"@atlaspack/diagnostic": "2.12.0",
"@atlaspack/events": "2.12.0",
Expand All @@ -32,10 +33,10 @@
"@atlaspack/plugin": "2.12.0",
"@atlaspack/profiler": "2.12.0",
"@atlaspack/rust": "2.12.0",
"@parcel/source-map": "^2.1.1",
"@atlaspack/types": "2.12.0",
"@atlaspack/utils": "2.12.0",
"@atlaspack/workers": "2.12.0",
"@parcel/source-map": "^2.1.1",
"base-x": "^3.0.8",
"browserslist": "^4.6.6",
"clone": "^2.1.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/core/src/CommittedAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import type {AST, Blob} from '@atlaspack/types';
import type {Asset, Dependency, AtlaspackOptions} from './types';

import {Readable} from 'stream';

import {deserializeRaw} from '@atlaspack/build-cache';
import SourceMap from '@parcel/source-map';
import {bufferStream, blobToStream, streamFromPromise} from '@atlaspack/utils';

import {generateFromAST} from './assetUtils';
import {deserializeRaw} from './serializer';

export default class CommittedAsset {
key: ?string;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/PackagerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {ConfigRequest} from './requests/ConfigRequest';
import type {DevDepSpecifier} from './requests/DevDepRequest';

import invariant from 'assert';
import {createBuildCache} from '@atlaspack/build-cache';
import {blobToStream, TapStream} from '@atlaspack/utils';
import {PluginLogger} from '@atlaspack/logger';
import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
Expand Down Expand Up @@ -57,7 +58,6 @@ import {
createDevDependency,
getWorkerDevDepRequests,
} from './requests/DevDepRequest';
import {createBuildCache} from './buildCache';
import {getInvalidationId, getInvalidationHash} from './assetUtils';
import {optionsProxy} from './utils';
import {invalidateDevDeps} from './requests/DevDepRequest';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/RequestTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import invariant, {AssertionError} from 'assert';
import path from 'path';

import {deserialize, serialize} from '@atlaspack/build-cache';
import type {Cache} from '@atlaspack/cache';
import {getFeatureFlag} from '@atlaspack/feature-flags';
import {ContentGraph} from '@atlaspack/graph';
Expand Down Expand Up @@ -60,7 +61,6 @@ import type {AtlaspackConfigRequestResult} from './requests/AtlaspackConfigReque
import type {AtlaspackBuildRequestResult} from './requests/AtlaspackBuildRequest';
import type {EntryRequestResult} from './requests/EntryRequest';
import type {BundleGraphResult} from './requests/BundleGraphRequest';
import {deserialize, serialize} from './serializer';
import type {
AssetRequestResult,
AtlaspackOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/UncommittedAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {Asset, Dependency, AtlaspackOptions, Invalidations} from './types';
import invariant from 'assert';
import {Readable} from 'stream';
import SourceMap from '@parcel/source-map';
import {serializeRaw} from '@atlaspack/build-cache';
import {
blobToStream,
bufferStream,
Expand All @@ -23,7 +24,6 @@ import {
SOURCEMAP_RE,
} from '@atlaspack/utils';
import {hashString, hashBuffer, Hash} from '@atlaspack/rust';
import {serializeRaw} from './serializer';
import {createDependency, mergeDependencies} from './Dependency';
import {mergeEnvironments} from './Environment';
import {ATLASPACK_VERSION} from './constants';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/assetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
} from './types';

import {Readable} from 'stream';
import {createBuildCache} from '@atlaspack/build-cache';
import {PluginLogger} from '@atlaspack/logger';
import nullthrows from 'nullthrows';
import CommittedAsset from './CommittedAsset';
Expand All @@ -30,7 +31,6 @@ import {Asset as PublicAsset} from './public/Asset';
import PluginOptions from './public/PluginOptions';
import {blobToStream, hashFile} from '@atlaspack/utils';
import {hashFromOption, toInternalSourceLocation} from './utils';
import {createBuildCache} from './buildCache';
import {
type ProjectPath,
fromProjectPath,
Expand Down
10 changes: 0 additions & 10 deletions packages/core/core/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
// @flow

// Needs to be exported first because of circular imports
export {
registerSerializableClass,
unregisterSerializableClass,
prepareForSerialization,
restoreDeserializedObject,
serialize,
deserialize,
} from './serializer';

export {
default,
default as Atlaspack,
Expand Down
11 changes: 7 additions & 4 deletions packages/core/core/src/registerCoreWithSerializer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// @flow

import {registerSerializableClass} from '@atlaspack/build-cache';
import {Graph} from '@atlaspack/graph';
import {registerSerializableClass} from './serializer';

import packageJson from '../package.json';

import AtlaspackConfig from './AtlaspackConfig';
import AssetGraph from './AssetGraph';
import BundleGraph from './BundleGraph';
import AtlaspackConfig from './AtlaspackConfig';
import {RequestGraph} from './RequestTracker';
import Config from './public/Config';
import packageJson from '../package.json';
import {RequestGraph} from './RequestTracker';

let coreRegistered;
export function registerCoreWithSerializer() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/requests/AtlaspackConfigRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
ProcessedAtlaspackConfig,
} from '../types';

import {createBuildCache} from '@atlaspack/build-cache';
import {
isDirectoryInside,
hashObject,
Expand All @@ -36,7 +37,6 @@ import invariant from 'assert';
import AtlaspackConfigSchema from '../AtlaspackConfig.schema';
import {optionsProxy} from '../utils';
import AtlaspackConfig from '../AtlaspackConfig';
import {createBuildCache} from '../buildCache';
import {toProjectPath} from '../projectPath';
import {requestTypes} from '../RequestTracker';

Expand Down
3 changes: 1 addition & 2 deletions packages/core/core/src/requests/ConfigRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {LoadedPlugin} from '../AtlaspackConfig';
import type {RequestResult, RunAPI} from '../RequestTracker';
import type {ProjectPath} from '../projectPath';

import {serializeRaw} from '../serializer';
import {createBuildCache, serializeRaw} from '@atlaspack/build-cache';
import {PluginLogger} from '@atlaspack/logger';
import PluginOptions from '../public/PluginOptions';
import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
Expand All @@ -29,7 +29,6 @@ import {hashString, Hash} from '@atlaspack/rust';
import {PluginTracer} from '@atlaspack/profiler';
import {requestTypes} from '../RequestTracker';
import {fromProjectPath, fromProjectPathRelative} from '../projectPath';
import {createBuildCache} from '../buildCache';

export type PluginWithLoadConfig = {
loadConfig?: ({|
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/requests/DevDepRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type {
import type {RequestResult, RunAPI} from '../RequestTracker';
import type {ProjectPath} from '../projectPath';

import {createBuildCache} from '@atlaspack/build-cache';
import nullthrows from 'nullthrows';
import {getInvalidationHash} from '../assetUtils';
import {createBuildCache} from '../buildCache';
import {invalidateOnFileCreateToInternal} from '../utils';
import {
fromProjectPath,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/requests/PathRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
} from '../types';
import type {ConfigAndCachePath} from './AtlaspackConfigRequest';

import {createBuildCache} from '@atlaspack/build-cache';
import ThrowableDiagnostic, {
convertSourceLocationToHighlight,
errorToDiagnostic,
Expand All @@ -40,7 +41,6 @@ import {
toProjectPathUnsafe,
} from '../projectPath';
import {Priority} from '../types';
import {createBuildCache} from '../buildCache';
import type {LoadedPlugin} from '../AtlaspackConfig';
import {createConfig} from '../InternalConfig';
import {loadPluginConfig, runConfigRequest} from './ConfigRequest';
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 @@ -22,7 +22,7 @@ import PackagerRunner, {type RunPackagerRunnerResult} from './PackagerRunner';
import Validation, {type ValidationOpts} from './Validation';
import AtlaspackConfig from './AtlaspackConfig';
import {registerCoreWithSerializer} from './registerCoreWithSerializer';
import {clearBuildCaches} from './buildCache';
import {clearBuildCaches} from '@atlaspack/build-cache';
import {init as initSourcemaps} from '@parcel/source-map';
import {init as initRust} from '@atlaspack/rust';
import WorkerFarm from '@atlaspack/workers';
Expand Down
Loading

0 comments on commit 96bae9c

Please sign in to comment.