1- import { ArtifactsDir } from '@contentlayer/core'
1+ import { ArtifactsDir , getCwd } from '@contentlayer/core'
22import { OT , pipe , T } from '@contentlayer/utils/effect'
33import { fs } from '@contentlayer/utils/node'
44import * as path from 'path'
@@ -11,13 +11,12 @@ export class PostInstallCommand extends BaseCommand {
1111 executeSafe = pipe (
1212 T . gen ( function * ( $ ) {
1313 // `process.env.INIT_CWD` is set by `yarn` or `npm` during installation
14- const cwd = process . env . INIT_CWD ?? process . cwd ( )
1514 const artifactsDirPath = yield * $ ( ArtifactsDir . mkdir )
1615
1716 yield * $ ( T . forEachPar_ ( [ 'data' , 'types' ] , ( moduleName ) => makeModuleStub ( { artifactsDirPath, moduleName } ) ) )
1817
19- yield * $ ( createSymlinkForDotpkg ( { artifactsDirPath, cwd } ) )
20- yield * $ ( addToplevelDotpkgToGitignore ( cwd ) )
18+ yield * $ ( createSymlinkForDotpkg ( { artifactsDirPath } ) )
19+ yield * $ ( addToplevelDotpkgToGitignore ( ) )
2120 } ) ,
2221 OT . withSpan ( '@contentlayer/cli/commands/PostInstallCommand:executeSafe' , { attributes : { cwd : process . cwd ( ) } } ) ,
2322 )
@@ -45,8 +44,9 @@ const moduleStubFile = `\
4544export {}
4645`
4746
48- const createSymlinkForDotpkg = ( { artifactsDirPath, cwd } : { artifactsDirPath : string ; cwd : string } ) =>
47+ const createSymlinkForDotpkg = ( { artifactsDirPath } : { artifactsDirPath : string } ) =>
4948 T . gen ( function * ( $ ) {
49+ const cwd = yield * $ ( getCwd )
5050 const symlinkPath = path . join ( cwd , '.contentlayer' )
5151 // NOTE dir-symlinks are interpreted as dirs by the OS
5252 const symlinkExists = yield * $ ( fs . fileOrDirExists ( symlinkPath ) )
@@ -55,8 +55,9 @@ const createSymlinkForDotpkg = ({ artifactsDirPath, cwd }: { artifactsDirPath: s
5555 }
5656 } )
5757
58- const addToplevelDotpkgToGitignore = ( cwd : string ) =>
58+ const addToplevelDotpkgToGitignore = ( ) =>
5959 T . gen ( function * ( $ ) {
60+ const cwd = yield * $ ( getCwd )
6061 const gitignoreFilePath = path . join ( cwd , '.gitignore' )
6162 const gitignoreExists = yield * $ ( fs . fileOrDirExists ( gitignoreFilePath ) )
6263 if ( gitignoreExists ) {
0 commit comments