( dir: string, fs: Fs, )
| 27 | * re-throws any other error (e.g. malformed package.json, missing export). |
| 28 | */ |
| 29 | export async function runnerPathInDir( |
| 30 | dir: string, |
| 31 | fs: Fs, |
| 32 | ): Promise<string | undefined> { |
| 33 | const pkgPath = path.join( |
| 34 | dir, |
| 35 | "node_modules", |
| 36 | "@qawolf", |
| 37 | "flows", |
| 38 | "package.json", |
| 39 | ); |
| 40 | try { |
| 41 | const pkg = JSON.parse(await fs.readFile(pkgPath)) as { |
| 42 | exports?: Record<string, { import?: string } | string>; |
| 43 | }; |
| 44 | const entry = pkg.exports?.["./_runner"]; |
| 45 | const importPath = |
| 46 | typeof entry === "object" && entry !== null ? entry.import : undefined; |
| 47 | if (typeof importPath !== "string") { |
| 48 | throw new Error( |
| 49 | `@qawolf/flows at ${pkgPath} does not export "./_runner" with an "import" condition`, |
| 50 | ); |
| 51 | } |
| 52 | return path.resolve(path.dirname(pkgPath), importPath); |
| 53 | } catch (err) { |
| 54 | if (!isNoEntError(err)) throw err; |
| 55 | return undefined; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | async function findFlowsRunnerPath(flowPath: string, fs: Fs): Promise<string> { |
| 60 | let dir = path.dirname(flowPath); |
no test coverage detected