diff --git a/packages/core/cache/src/FSCache.js b/packages/core/cache/src/FSCache.js index 48577ae803c4..cc4b85e33e61 100644 --- a/packages/core/cache/src/FSCache.js +++ b/packages/core/cache/src/FSCache.js @@ -102,7 +102,7 @@ export class FSCache implements Cache { return Buffer.concat(await Promise.all(buffers)); } - async setLargeBlob(key: string, contents: Buffer): Promise { + async setLargeBlob(key: string, contents: Buffer | string): Promise { const chunks = Math.ceil(contents.length / WRITE_LIMIT_CHUNK); const writePromises: Promise[] = []; @@ -110,7 +110,12 @@ export class FSCache implements Cache { writePromises.push( this.fs.writeFile( this.#getFilePath(key, i), - contents.subarray(i * WRITE_LIMIT_CHUNK, (i + 1) * WRITE_LIMIT_CHUNK), + typeof contents === 'string' + ? contents.slice(i * WRITE_LIMIT_CHUNK, (i + 1) * WRITE_LIMIT_CHUNK) + : contents.subarray( + i * WRITE_LIMIT_CHUNK, + (i + 1) * WRITE_LIMIT_CHUNK, + ), ), ); } diff --git a/packages/core/cache/src/IDBCache.browser.js b/packages/core/cache/src/IDBCache.browser.js index 6de017c5906b..15fbf65adbba 100644 --- a/packages/core/cache/src/IDBCache.browser.js +++ b/packages/core/cache/src/IDBCache.browser.js @@ -114,7 +114,7 @@ export class IDBCache implements Cache { return this.getBlob(key); } - setLargeBlob(key: string, contents: Buffer): Promise { + setLargeBlob(key: string, contents: Buffer | string): Promise { return this.setBlob(key, contents); } diff --git a/packages/core/cache/src/LMDBCache.js b/packages/core/cache/src/LMDBCache.js index bfe6428dae9a..01cf6f743518 100644 --- a/packages/core/cache/src/LMDBCache.js +++ b/packages/core/cache/src/LMDBCache.js @@ -111,7 +111,7 @@ export class LMDBCache implements Cache { return Buffer.concat(await Promise.all(buffers)); } - async setLargeBlob(key: string, contents: Buffer): Promise { + async setLargeBlob(key: string, contents: Buffer | string): Promise { const chunks = Math.ceil(contents.length / WRITE_LIMIT_CHUNK); const writePromises: Promise[] = []; @@ -119,7 +119,12 @@ export class LMDBCache implements Cache { writePromises.push( this.fs.writeFile( this.#getFilePath(key, i), - contents.subarray(i * WRITE_LIMIT_CHUNK, (i + 1) * WRITE_LIMIT_CHUNK), + typeof contents === 'string' + ? contents.slice(i * WRITE_LIMIT_CHUNK, (i + 1) * WRITE_LIMIT_CHUNK) + : contents.subarray( + i * WRITE_LIMIT_CHUNK, + (i + 1) * WRITE_LIMIT_CHUNK, + ), ), ); } diff --git a/packages/core/cache/src/types.js b/packages/core/cache/src/types.js index 55063964bbdb..163b3d57644b 100644 --- a/packages/core/cache/src/types.js +++ b/packages/core/cache/src/types.js @@ -12,7 +12,7 @@ export interface Cache { setBlob(key: string, contents: Buffer | string): Promise; hasLargeBlob(key: string): Promise; getLargeBlob(key: string): Promise; - setLargeBlob(key: string, contents: Buffer): Promise; + setLargeBlob(key: string, contents: Buffer | string): Promise; getBuffer(key: string): Promise; /** * In a multi-threaded environment, where there are potentially multiple Cache diff --git a/packages/dev/bundle-stats-cli/src/cli.js b/packages/dev/bundle-stats-cli/src/cli.js index c4deed1549c4..fd60930f27b4 100644 --- a/packages/dev/bundle-stats-cli/src/cli.js +++ b/packages/dev/bundle-stats-cli/src/cli.js @@ -18,9 +18,9 @@ import {getBundleStats} from '@parcel/reporter-bundle-stats/src/BundleStatsRepor import {PackagedBundle as PackagedBundleClass} from '@parcel/core/src/public/Bundle'; import type {commander$Command} from 'commander'; -function run({cacheDir, outDir}) { +async function run({cacheDir, outDir}) { // 1. load bundle graph and info via parcel~query - let {bundleGraph, bundleInfo} = loadGraphs(cacheDir); + let {bundleGraph, bundleInfo} = await loadGraphs(cacheDir); if (bundleGraph == null) { console.error('Bundle Graph could not be found'); diff --git a/packages/dev/query/src/index.js b/packages/dev/query/src/index.js index 756301366397..1746fd010dbe 100644 --- a/packages/dev/query/src/index.js +++ b/packages/dev/query/src/index.js @@ -94,7 +94,7 @@ export async function loadGraphs(cacheDir: string): Promise<{| ); if (bundleGraphRequestNode != null) { bundleGraph = BundleGraph.deserialize( - (await loadLargeBlobRequestRequestSync(cache, bundleGraphRequestNode)) + (await loadLargeBlobRequestRequest(cache, bundleGraphRequestNode)) .bundleGraph.value, ); @@ -103,8 +103,8 @@ export async function loadGraphs(cacheDir: string): Promise<{| ).find(n => n.type === 'request' && n.value.type === 'asset_graph_request'); if (assetGraphRequest != null) { assetGraph = AssetGraph.deserialize( - (await loadLargeBlobRequestRequestSync(cache, assetGraphRequest)) - .assetGraph.value, + (await loadLargeBlobRequestRequest(cache, assetGraphRequest)).assetGraph + .value, ); } } @@ -124,7 +124,7 @@ export async function loadGraphs(cacheDir: string): Promise<{| return {assetGraph, bundleGraph, requestTracker, bundleInfo}; } -async function loadLargeBlobRequestRequestSync(cache, node) { +async function loadLargeBlobRequestRequest(cache, node) { invariant(node.type === 'request'); return v8.deserialize( await cache.getLargeBlob(nullthrows(node.value.resultCacheKey)),