Skip to content

Commit

Permalink
fix(migrate): workaround issue with p-map and ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Jan 23, 2024
1 parent 4daf297 commit bb26198
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/@sanity/migrate/src/destinations/commitMutations.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {pMapIterable} from 'p-map'
import {MultipleMutationResult} from '@sanity/client'
import {fetchAsyncIterator, FetchOptions} from '../fetch-utils/fetchStream'
import {parseJSON} from '../it-utils/json'
import {decodeText} from '../it-utils/decodeText'
import {concatStr} from '../it-utils/concatStr'
import {lastValueFrom} from '../it-utils/lastValueFrom'

export function commitMutations(
export async function commitMutations(
fetchOptions: AsyncIterableIterator<FetchOptions>,
options: {concurrency: number},
) {
// todo: convert to top level import when we can
const {pMapIterable} = await import('p-map')

return pMapIterable(
fetchOptions,
async (opts): Promise<MultipleMutationResult> =>
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/migrate/src/runner/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function* run(config: MigrationRunnerOptions, migration: Migration)

const batches = batchMutations(toSanityMutations(mutations), MUTATION_ENDPOINT_MAX_BODY_SIZE)

const commits = commitMutations(toFetchOptionsIterable(config.api, batches), {concurrency})
const commits = await commitMutations(toFetchOptionsIterable(config.api, batches), {concurrency})

for await (const result of commits) {
yield formatMutationResponse(result)
Expand Down

0 comments on commit bb26198

Please sign in to comment.