From ed432c5c6757f85bdb95d1c2b1dcc022657b2edc Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 16 Dec 2024 16:07:45 +0000 Subject: [PATCH] fix: remove circular lint --- .../src/build/utils/getFileContent.ts | 28 +------------------ packages/myst-cli/src/process/site.ts | 27 +++++++++++++++++- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/myst-cli/src/build/utils/getFileContent.ts b/packages/myst-cli/src/build/utils/getFileContent.ts index 6d68966e2..bba9cb306 100644 --- a/packages/myst-cli/src/build/utils/getFileContent.ts +++ b/packages/myst-cli/src/build/utils/getFileContent.ts @@ -7,7 +7,7 @@ import { loadFile, selectFile } from '../../process/file.js'; import { loadReferences } from '../../process/loadReferences.js'; import type { TransformFn } from '../../process/mdast.js'; import { transformMdast } from '../../process/mdast.js'; -import { loadProject, selectPageReferenceStates } from '../../process/site.js'; +import { loadProject, selectPageReferenceStates, makeBarrier } from '../../process/site.js'; import { buildIndexTransform, MultiPageReferenceResolver } from 'myst-transforms'; import type { ISession } from '../../session/types.js'; import { selectors } from '../../store/index.js'; @@ -16,32 +16,6 @@ import { castSession } from '../../session/cache.js'; import { VFile } from 'vfile'; import { logMessagesFromVFile } from '../../utils/logging.js'; -/** - * A barrier synchronization primitive that blocks until a fixed number clients are waiting - * - * @param nClients - number of clients that must wait before unblocking - */ -export function makeBarrier(nClients: number): { - promise: Promise; - wait: () => Promise; -} { - const ctx: { resolve?: () => void | undefined } = {}; - const promise = new Promise((resolve) => { - ctx.resolve = resolve; - }); - - let nWaiting = nClients; - const wait = async () => { - nWaiting--; - if (!nWaiting) { - ctx.resolve!(); - } - await promise; - return nWaiting; - }; - return { promise, wait }; -} - export async function getFileContent( session: ISession, files: string[], diff --git a/packages/myst-cli/src/process/site.ts b/packages/myst-cli/src/process/site.ts index dc41c1242..3bfc7c6b3 100644 --- a/packages/myst-cli/src/process/site.ts +++ b/packages/myst-cli/src/process/site.ts @@ -24,7 +24,6 @@ import { resolvePageExports, } from '../build/site/manifest.js'; import { writeRemoteDOIBibtex } from '../build/utils/bibtex.js'; -import { makeBarrier } from '../build/utils/getFileContent.js'; import { MYST_DOI_BIB_FILE } from '../cli/options.js'; import { filterPages, loadProjectFromDisk } from '../project/load.js'; import { DEFAULT_INDEX_FILENAMES } from '../project/fromTOC.js'; @@ -392,6 +391,32 @@ export async function writeFile( session.log.debug(toc(`Wrote "${file}" in %s`)); } +/** + * A barrier synchronization primitive that blocks until a fixed number clients are waiting + * + * @param nClients - number of clients that must wait before unblocking + */ +export function makeBarrier(nClients: number): { + promise: Promise; + wait: () => Promise; +} { + const ctx: { resolve?: () => void | undefined } = {}; + const promise = new Promise((resolve) => { + ctx.resolve = resolve; + }); + + let nWaiting = nClients; + const wait = async () => { + nWaiting--; + if (!nWaiting) { + ctx.resolve!(); + } + await promise; + return nWaiting; + }; + return { promise, wait }; +} + export async function fastProcessFile( session: ISession, {