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