11import type { E } from '@contentlayer/utils/effect'
2- import { Chunk , OT , pipe , S , T } from '@contentlayer/utils/effect'
2+ import { Array , Chunk , O , OT , pipe , S , T } from '@contentlayer/utils/effect'
33import type { GetContentlayerVersionError } from '@contentlayer/utils/node'
44import { fs } from '@contentlayer/utils/node'
55import * as path from 'node:path'
@@ -48,14 +48,14 @@ export const getConfigWatch = ({
4848 configPath ?: string
4949} ) : S . Stream < OT . HasTracer & HasCwd , never , E . Either < GetConfigError , Config > > => {
5050 const resolveParams = pipe (
51- T . structPar ( { configPath : resolveConfigPath ( { configPath : configPath_ } ) } ) ,
51+ T . structPar ( { configPath : resolveConfigPath ( { configPath : configPath_ } ) , cwd : getCwd } ) ,
5252 T . chainMergeObject ( ( ) => makeTmpDirAndResolveEntryPoint ) ,
5353 T . either ,
5454 )
5555
5656 return pipe (
5757 S . fromEffect ( resolveParams ) ,
58- S . chainMapEitherRight ( ( { configPath, outfilePath } ) =>
58+ S . chainMapEitherRight ( ( { configPath, outfilePath, cwd } ) =>
5959 pipe (
6060 esbuild . makeAndSubscribe ( {
6161 entryPoints : [ configPath ] ,
@@ -70,6 +70,7 @@ export const getConfigWatch = ({
7070 bundle : true ,
7171 logLevel : 'silent' ,
7272 metafile : true ,
73+ absWorkingDir : cwd ,
7374 plugins : [ contentlayerGenPlugin ( ) , makeAllPackagesExternalPlugin ( configPath ) ] ,
7475 } ) ,
7576 S . mapEffectEitherRight ( ( result ) => getConfigFromResult ( { result, configPath } ) ) ,
@@ -133,11 +134,15 @@ const getConfigFromResult = ({
133134
134135 const cwd = yield * $ ( getCwd )
135136
136- const outfilePath = Object . keys ( result . metafile ! . outputs )
137+ // Deriving the exact outfilePath here since it's suffixed with a hash
138+ const outfilePath = pipe (
139+ Object . keys ( result . metafile ! . outputs ) ,
137140 // Will look like `path.join(cacheDir, 'compiled-contentlayer-config-[SOME_HASH].mjs')
138- . filter ( ( _ ) => _ . match ( / c o m p i l e d - c o n t e n t l a y e r - c o n f i g - .+ .m j s $ / ) )
141+ Array . find ( ( _ ) => _ . match ( / c o m p i l e d - c o n t e n t l a y e r - c o n f i g - .+ .m j s $ / ) !== null ) ,
139142 // Needs to be absolute path for ESM import to work
140- . map ( ( _ ) => path . join ( cwd , _ ) ) [ 0 ] !
143+ O . map ( ( _ ) => path . join ( cwd , _ ) ) ,
144+ O . getUnsafe ,
145+ )
141146
142147 const esbuildHash = outfilePath . match ( / c o m p i l e d - c o n t e n t l a y e r - c o n f i g - ( .+ ) .m j s $ / ) ! [ 1 ] !
143148
0 commit comments