@w5s/dev 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ import { exec, execSync } from './exec.js';
2
+
3
+ export type YarnVersionKind = 'berry' | 'classic';
4
+
5
+ export interface YarnVersionOptions {
6
+ /**
7
+ * Option target state
8
+ */
9
+ readonly state: 'present' | 'absent';
10
+
11
+ /**
12
+ * Version mapping function
13
+ *
14
+ * @param content
15
+ */
16
+ readonly update?: (() => YarnVersionKind | undefined) | undefined;
17
+ }
18
+
19
+ /**
20
+ * Synchronous version of {@link yarnVersion}
21
+ *
22
+ * @example
23
+ * yarnVersionSync({
24
+ * state: 'present',
25
+ * update: () => 'berry', // or 'classic'
26
+ * })
27
+ */
28
+ export function yarnVersionSync(options: YarnVersionOptions) {
29
+ const { state, update } = options;
30
+ if (state === 'present') {
31
+ execSync('yarn', ['set', 'version', `${update == null ? 'berry' : update()}`]);
32
+ } else {
33
+ // TODO: remove yarn.lock
34
+ throw new Error('Not implemented');
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Set/Unset yarn configuration value
40
+ *
41
+ * @example
42
+ * await yarnVersion({
43
+ * state: 'present',
44
+ * update: () => 'berry', // or 'classic'
45
+ * })
46
+ */
47
+ export async function yarnVersion(options: YarnVersionOptions): Promise<void> {
48
+ const { state, update } = options;
49
+ if (state === 'present') {
50
+ await exec('yarn', ['set', 'version', `${update == null ? 'berry' : update()}`]);
51
+ } else {
52
+ // TODO: remove yarn.lock
53
+ throw new Error('Not implemented');
54
+ }
55
+ }
File without changes