Skip to content
Open
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/@contentlayer/core/src/dynamic-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const dynamicBuild = ({ config, verbose }: { config: Config; verbose: boo

const cache = yield* $(
pipe(
config.source.fetchData({ schemaDef, verbose, skipCachePersistence: true }),
config.source.fetchData({ schemaDef, verbose, skipCachePersistence: true, watch: false }),
S.runHead,
T.map(O.getUnsafe),
T.chain((_) => T.fromEither(() => _)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const generateDotpkgStream = ({
S.fromEffect(resolveParams),
S.chainMapEitherRight(({ schemaDef, targetPath }) =>
pipe(
config.source.fetchData({ schemaDef, verbose }),
config.source.fetchData({ schemaDef, verbose, watch: isDev }),
S.mapEffectEitherRight((cache) =>
pipe(
writeFilesForCache({ config, schemaDef, targetPath, cache, generationOptions, writtenFilesCache, isDev }),
Expand Down
1 change: 1 addition & 0 deletions packages/@contentlayer/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export type FetchData = (_: {
schemaDef: SchemaDef
verbose: boolean
skipCachePersistence?: boolean
watch?: boolean
}) => S.Stream<
OT.HasTracer & HasClock & HasCwd & HasConsole & fs.HasFs,
never,
Expand Down
31 changes: 19 additions & 12 deletions packages/@contentlayer/source-files/src/fetchData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const fetchData = ({
contentDirExclude,
skipCachePersistence = false,
verbose,
watch = true,
}: {
coreSchemaDef: core.SchemaDef
documentTypeDefs: LocalSchema.DocumentTypeDef[]
Expand All @@ -38,6 +39,12 @@ export const fetchData = ({
*/
skipCachePersistence?: boolean
verbose: boolean
/**
* Whether file system changes should be watched for incremental updates.
* Disable this for one-off builds to avoid hanging on environments without
* file watcher support (e.g. sandboxed CI agents).
*/
watch?: boolean
}): S.Stream<
OT.HasTracer & HasCwd & HasConsole & fs.HasFs,
never,
Expand All @@ -48,18 +55,18 @@ export const fetchData = ({

const initEvent: CustomUpdateEventInit = { _tag: 'init' }

const watchPaths = contentDirInclude.length > 0 ? contentDirInclude : ['.']

const fileUpdatesStream = pipe(
FSWatch.makeAndSubscribe(watchPaths, {
cwd: contentDirPath,
ignoreInitial: true,
ignored: contentDirExclude as unknown as string[], // NOTE type cast needed because of readonly array
// Unfortunately needed in order to avoid race conditions
awaitWriteFinish: { stabilityThreshold: 50, pollInterval: 10 },
}),
S.mapEitherRight(chokidarAllEventToCustomUpdateEvent),
)
const fileUpdatesStream = watch
? pipe(
FSWatch.makeAndSubscribe(contentDirInclude.length > 0 ? contentDirInclude : ['.'], {
cwd: contentDirPath,
ignoreInitial: true,
ignored: contentDirExclude as unknown as string[], // NOTE type cast needed because of readonly array
// Unfortunately needed in order to avoid race conditions
awaitWriteFinish: { stabilityThreshold: 50, pollInterval: 10 },
}),
S.mapEitherRight(chokidarAllEventToCustomUpdateEvent),
)
: S.fromIterable<E.Either<FSWatch.FileWatcherError, CustomUpdateEvent>>([])

const resolveParams = pipe(
skipCachePersistence
Expand Down
3 changes: 2 additions & 1 deletion packages/@contentlayer/source-files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const makeSource: core.MakeSourcePlugin<Args> = (args) => async (sourceKe
makeCoreSchema({ documentTypeDefs, options, esbuildHash }),
T.mapError((error) => new SourceProvideSchemaError({ error })),
),
fetchData: ({ schemaDef, verbose, skipCachePersistence }) =>
fetchData: ({ schemaDef, verbose, skipCachePersistence, watch }) =>
pipe(
S.fromEffect(core.getCwd),
S.chain((cwd) => {
Expand All @@ -127,6 +127,7 @@ export const makeSource: core.MakeSourcePlugin<Args> = (args) => async (sourceKe
contentDirInclude,
verbose,
skipCachePersistence,
watch,
})
}),
),
Expand Down