({
tracingServiceName,
verbose,
useInMemoryFs = false,
customCwd,
}: {
tracingServiceName: string
verbose: boolean
useInMemoryFs?: boolean
customCwd?: AbsolutePosixFilePath
})
| 11 | |
| 12 | export const runMain = |
| 13 | <TResult>({ |
| 14 | tracingServiceName, |
| 15 | verbose, |
| 16 | useInMemoryFs = false, |
| 17 | customCwd, |
| 18 | }: { |
| 19 | tracingServiceName: string |
| 20 | verbose: boolean |
| 21 | useInMemoryFs?: boolean |
| 22 | customCwd?: AbsolutePosixFilePath |
| 23 | }) => |
| 24 | (eff: T.Effect<OT.HasTracer & HasClock & HasCwd & HasConsole & fs.HasFs, unknown, TResult>) => |
| 25 | pipe( |
| 26 | T.gen(function* ($) { |
| 27 | if (process.platform === 'win32') { |
| 28 | yield* $(T.log('Warning: Contentlayer might not work as expected on Windows')) |
| 29 | } |
| 30 | |
| 31 | const provideCwd_ = customCwd ? provideCwdCustom(customCwd) : provideCwd |
| 32 | |
| 33 | const result = yield* $(pipe(eff, provideTracing(tracingServiceName, 'based-on-env'), provideCwd_, T.result)) |
| 34 | |
| 35 | if (result._tag === 'Failure') { |
| 36 | const failOrCause = Cause.failureOrCause(result.cause) |
| 37 | const errorWasManaged = failOrCause._tag === 'Left' |
| 38 | |
| 39 | if (!errorWasManaged) { |
| 40 | yield* $( |
| 41 | T.log(`\ |
| 42 | This error shouldn't have happened. Please consider opening a GitHub issue with the stack trace below here: |
| 43 | https://github.com/contentlayerdev/contentlayer/issues`), |
| 44 | ) |
| 45 | } |
| 46 | |
| 47 | // If failure was a managed error and no `--verbose` flag was provided, print the error message |
| 48 | if (errorWasManaged && !verbose) { |
| 49 | if (!core.isSourceFetchDataError(failOrCause.left) || !failOrCause.left.alreadyHandled) { |
| 50 | yield* $(T.log(failOrCause.left)) |
| 51 | } |
| 52 | } |
| 53 | // otherwise for unmanaged errors or with `--verbose` flag provided, print the entire stack trace |
| 54 | else { |
| 55 | yield* $(T.log(pretty(result.cause))) |
| 56 | |
| 57 | const contentlayerVersion = yield* $(getContentlayerVersion()['|>'](T.provide(DummyTracing))) |
| 58 | |
| 59 | yield* $( |
| 60 | T.log(` |
| 61 | OS: ${process.platform} ${os.release()} (arch: ${process.arch}) |
| 62 | Process: ${process.argv.join(' ')} |
| 63 | Node version: ${process.version} |
| 64 | Contentlayer version: ${contentlayerVersion} |
| 65 | `), |
| 66 | ) |
| 67 | } |
| 68 | |
| 69 | yield* $(T.succeedWith(() => process.exit(1))) |
| 70 | return undefined as never |
no test coverage detected
searching dependent graphs…