11/**
22 * @since 1.0.0
33 */
4- import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem"
54import * as NodePath from "@effect/platform-node/NodePath"
6- import * as FileSystem from "@effect/platform/FileSystem"
75import * as Path from "@effect/platform/Path"
86import * as Arr from "effect/Array"
97import * as Effect from "effect/Effect"
@@ -12,10 +10,8 @@ import * as Layer from "effect/Layer"
1210import * as Option from "effect/Option"
1311import * as Stream from "effect/Stream"
1412import * as SubscriptionRef from "effect/SubscriptionRef"
15- import * as Module from "node:module"
16- import * as VM from "node:vm"
1713import * as Config from "./Config.ts"
18- import { ContentlayerError } from "./ContentlayerError.ts "
14+ import { ContentlayerError } from "./ContentlayerError.js "
1915import type { EsbuildSuccess } from "./Esbuild.ts"
2016import { Esbuild } from "./Esbuild.ts"
2117
@@ -61,7 +57,6 @@ export class ConfigBuilder extends Effect.Tag("@effect/contentlayer/ConfigBuilde
6157> ( ) {
6258 static Live = Layer . scoped ( this , make ) . pipe (
6359 Layer . provide ( Esbuild . Live ) ,
64- Layer . provide ( NodeFileSystem . layer ) ,
6560 Layer . provide ( NodePath . layer )
6661 )
6762}
@@ -74,7 +69,7 @@ const build = (
7469) : Effect . Effect <
7570 Option . Option < BuiltConfig > ,
7671 ContentlayerError ,
77- FileSystem . FileSystem | Path . Path
72+ Path . Path
7873> =>
7974 Effect . gen ( function * ( ) {
8075 const path = yield * Path . Path
@@ -100,24 +95,11 @@ export const fromPath = Effect.fnUntraced(function*(
10095 entrypoint : string ,
10196 hash : string
10297) {
103- const fs = yield * FileSystem . FileSystem
10498 const path = yield * Path . Path
105-
106- const content = yield * Effect . orDie ( fs . readFileString ( outPath ) )
10799 const resolvedPath = path . resolve ( outPath )
108100
109- const context = VM . createContext ( {
110- ...globalThis ,
111- process,
112- __filename : resolvedPath ,
113- __dirname : path . dirname ( resolvedPath )
114- } )
115- context . require = Module . createRequire ( entrypoint )
116- context . module = { exports : { } }
117- context . exports = context . module . exports
118-
119- yield * Effect . try ( {
120- try : ( ) => VM . runInContext ( content , context ) ,
101+ const content = yield * Effect . tryPromise ( {
102+ try : ( ) => import ( new URL ( `file://${ resolvedPath } ` ) as any ) ,
121103 catch : ( cause ) =>
122104 new ContentlayerError ( {
123105 module : "ConfigBuilder" ,
@@ -127,7 +109,7 @@ export const fromPath = Effect.fnUntraced(function*(
127109 } )
128110 } )
129111
130- return configAsOption ( context . module . exports . default ) . pipe (
112+ return configAsOption ( content . default ) . pipe (
131113 Option . map ( ( config ) : BuiltConfig => ( {
132114 hash,
133115 config,
0 commit comments