Unified · Split
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | import { createHash } from "node:crypto"; |
| 2 | −import { createRequire } from "node:module"; | |
| 3 | −import { basename, dirname, extname, join, relative, resolve, sep } from "node:path"; | |
| 4 | −import { pathToFileURL } from "node:url"; | |
| 2 | +import { dirname, extname, join, relative, resolve, sep } from "node:path"; | |
| 3 | +import { fileURLToPath, pathToFileURL } from "node:url"; | |
| 5 | 4 | import { FileSystem } from "@effect/platform"; |
| 6 | 5 | import { |
| 7 | 6 | createToolCatalogFromTools, |
| @@ -331,29 +330,44 @@ const transpileSourceFile = (input: { · 323 unmodified lines | ||
| 331 | 330 | return rewriteRelativeImportSpecifiers(transpiled.outputText); |
| 332 | 331 | }); |
| 333 | 332 | |
| 334 | −const resolveExecutorNodeModulesDirectory = (): string | null => { | |
| 335 | − const require = createRequire(import.meta.url); | |
| 336 | − let current = dirname(require.resolve("typescript")); | |
| 333 | +const resolveExecutorNodeModulesDirectory = (): Effect.Effect< | |
| 334 | + string | null, | |
| 335 | + LocalFileSystemError, | |
| 336 | + FileSystem.FileSystem | |
| 337 | +> => | |
| 338 | + Effect.gen(function* () { | |
| 339 | + const fs = yield* FileSystem.FileSystem; | |
| 340 | + let current = dirname(fileURLToPath(import.meta.url)); | |
| 337 | 341 | |
| 338 | − while (true) { | |
| 339 | − if (basename(current) === "node_modules") { | |
| 340 | − return current; | |
| 341 | − } | |
| 342 | + while (true) { | |
| 343 | + const candidate = join(current, "node_modules"); | |
| 344 | + const exists = yield* fs | |
| 345 | + .exists(candidate) | |
| 346 | + .pipe( | |
| 347 | + Effect.mapError( | |
| 348 | + mapFileSystemError( | |
| 349 | + candidate, | |
| 350 | + "check executor node_modules directory", | |
| 351 | + ), | |
| 352 | + ), | |
| 353 | + ); | |
| 354 | + if (exists) { | |
| 355 | + return candidate; | |
| 356 | + } | |
| 342 | 357 | |
| 343 | − const parent = dirname(current); | |
| 344 | − if (parent === current) { | |
| 345 | − return null; | |
| 358 | + const parent = dirname(current); | |
| 359 | + if (parent === current) { | |
| 360 | + return null; | |
| 361 | + } | |
| 362 | + current = parent; | |
| 346 | 363 | } |
| 347 | − current = parent; | |
| 348 | − } | |
| 349 | −}; | |
| 350 | − | |
| 351 | −const EXECUTOR_NODE_MODULES_DIRECTORY = resolveExecutorNodeModulesDirectory(); | |
| 364 | + }); | |
| 352 | 365 | |
| 353 | 366 | const ensureArtifactNodeModulesLink = (artifactRoot: string) => |
| 354 | 367 | Effect.gen(function* () { |
| 355 | 368 | const fs = yield* FileSystem.FileSystem; |
| 356 | 369 | const linkPath = join(artifactRoot, "node_modules"); |
| 370 | + const executorNodeModulesDirectory = yield* resolveExecutorNodeModulesDirectory(); | |
| 357 | 371 | const exists = yield* fs |
| 358 | 372 | .exists(linkPath) |
| 359 | 373 | .pipe( |
| @@ -365,12 +379,12 @@ const ensureArtifactNodeModulesLink = (artifactRoot: string) => · 5 unmodified lines | ||
| 365 | 379 | return; |
| 366 | 380 | } |
| 367 | 381 | |
| 368 | − if (EXECUTOR_NODE_MODULES_DIRECTORY === null) { | |
| 382 | + if (executorNodeModulesDirectory === null) { | |
| 369 | 383 | return; |
| 370 | 384 | } |
| 371 | 385 | |
| 372 | 386 | yield* fs |
| 373 | − .symlink(EXECUTOR_NODE_MODULES_DIRECTORY, linkPath) | |
| 387 | + .symlink(executorNodeModulesDirectory, linkPath) | |
| 374 | 388 | .pipe( |
| 375 | 389 | Effect.mapError( |
| 376 | 390 | mapFileSystemError(linkPath, "create local tool node_modules link"), |