|
1 | | -import {map} from "@softwareventures/array"; |
2 | | -import type {Document} from "yaml"; |
3 | 1 | import type {ProjectSource} from "../project/project.js"; |
4 | 2 | import type {Result} from "../result/result.js"; |
5 | | -import {bindAsyncResultFn, bindFailureFn, failure, mapResultFn} from "../result/result.js"; |
6 | | -import type {ReadYamlFailureReason} from "../project/read-yaml.js"; |
7 | | -import {readProjectYamlAsDocument} from "../project/read-yaml.js"; |
8 | | -import type {WriteYamlFailureReason} from "../project/write-yaml.js"; |
9 | | -import {writeProjectYaml} from "../project/write-yaml.js"; |
| 3 | +import {mapFailureFn} from "../result/result.js"; |
| 4 | +import {yarn} from "./yarn.js"; |
10 | 5 |
|
11 | 6 | export type SetYarnLinkerResult = Result<SetYarnLinkerFailureReason>; |
12 | 7 |
|
13 | 8 | export interface SetYarnLinkerFailureReason { |
14 | 9 | readonly type: "set-yarn-linker-failed"; |
15 | | - readonly reason: ReadYamlFailureReason | WriteYamlFailureReason; |
16 | 10 | } |
17 | 11 |
|
18 | 12 | export async function setYarnLinkerToNodeModules( |
19 | 13 | project: ProjectSource |
20 | 14 | ): Promise<SetYarnLinkerResult> { |
21 | | - return readProjectYamlAsDocument(project, ".yarnrc.yml") |
22 | | - .then( |
23 | | - mapResultFn(document => { |
24 | | - document.set("nodeLinker", "node-modules"); |
25 | | - return document; |
26 | | - }) |
27 | | - ) |
28 | | - .then( |
29 | | - bindAsyncResultFn<ReadYamlFailureReason, WriteYamlFailureReason, Document.Parsed>( |
30 | | - async document => writeProjectYaml(project, ".yarnrc.yml", document) |
31 | | - ) |
32 | | - ) |
33 | | - .then( |
34 | | - bindFailureFn(reasons => |
35 | | - failure( |
36 | | - map( |
37 | | - reasons, |
38 | | - reason => |
39 | | - ({ |
40 | | - type: "set-yarn-linker-failed", |
41 | | - reason |
42 | | - }) as const |
43 | | - ) |
44 | | - ) |
45 | | - ) |
46 | | - ); |
| 15 | + return yarn(project, "config", "set", "nodeLinker", "node-modules").then( |
| 16 | + mapFailureFn(() => ({type: "set-yarn-linker-failed"}) as const) |
| 17 | + ); |
47 | 18 | } |
0 commit comments