@naturalcycles/nodejs-lib 15.107.2 → 15.107.3

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.
@@ -7,7 +7,7 @@ declare class Git2 {
7
7
  commitMessageToTitleMessage(msg: string): string;
8
8
  hasUncommittedChanges(): boolean;
9
9
  /**
10
- * Returns true if there were changes
10
+ * @returns true if there were changes
11
11
  */
12
12
  commitAll(msg: string): boolean;
13
13
  /**
@@ -22,6 +22,14 @@ declare class Git2 {
22
22
  getCurrentBranchName(): string;
23
23
  getCurrentRepoName(): string;
24
24
  getAllBranchesNames(): string[];
25
+ gitRefExists(ref: string): boolean;
26
+ getTrackedFiles(): string[];
27
+ getUntrackedFiles(): string[];
28
+ getTrackedChangedFiles(diffBase: string, diffFilter?: string): string[];
29
+ /**
30
+ * @returns both tracked changed and untracked files
31
+ */
32
+ getAllChangedFiles(diffBase: string): string[];
25
33
  }
26
34
  export declare const git2: Git2;
27
35
  export {};
package/dist/util/git2.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { basename } from 'node:path';
3
+ import { _uniq } from '@naturalcycles/js-lib/array';
3
4
  import { exec2 } from '../exec2/exec2.js';
4
5
  /**
5
6
  * Set of utility functions to work with git.
@@ -26,7 +27,7 @@ class Git2 {
26
27
  }
27
28
  }
28
29
  /**
29
- * Returns true if there were changes
30
+ * @returns true if there were changes
30
31
  */
31
32
  commitAll(msg) {
32
33
  // git commit -a -m "style(lint-all): $GIT_MSG" || true
@@ -120,5 +121,56 @@ class Git2 {
120
121
  .filter(s => !s.includes(' -> '))
121
122
  .map(s => s.split('/')[1]);
122
123
  }
124
+ gitRefExists(ref) {
125
+ try {
126
+ exec2.exec(`git rev-parse --verify --quiet ${ref}`);
127
+ return true;
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ }
133
+ getTrackedFiles() {
134
+ try {
135
+ return exec2
136
+ .exec('git ls-files')
137
+ .split('\n')
138
+ .filter(s => s.trim().length);
139
+ }
140
+ catch {
141
+ return [];
142
+ }
143
+ }
144
+ getUntrackedFiles() {
145
+ try {
146
+ return exec2
147
+ .exec('git ls-files --others --exclude-standard')
148
+ .split('\n')
149
+ .filter(s => s.trim().length);
150
+ }
151
+ catch {
152
+ return [];
153
+ }
154
+ }
155
+ getTrackedChangedFiles(diffBase, diffFilter = 'AMR') {
156
+ try {
157
+ return exec2
158
+ .exec(`git diff --name-only --diff-filter=${diffFilter} ${diffBase}`)
159
+ .split('\n')
160
+ .filter(s => s.trim().length);
161
+ }
162
+ catch {
163
+ return [];
164
+ }
165
+ }
166
+ /**
167
+ * @returns both tracked changed and untracked files
168
+ */
169
+ getAllChangedFiles(diffBase) {
170
+ const tracked = this.getTrackedChangedFiles(diffBase);
171
+ const untracked = this.getUntrackedFiles();
172
+ const changes = [...tracked, ...untracked];
173
+ return _uniq(changes);
174
+ }
123
175
  }
124
176
  export const git2 = new Git2();
@@ -1378,10 +1378,7 @@ function hasNoObjectSchemas(schema) {
1378
1378
  else if (schema.type === 'array') {
1379
1379
  return !schema.items || hasNoObjectSchemas(schema.items);
1380
1380
  }
1381
- else {
1382
- return !!schema.type && ['string', 'number', 'integer', 'boolean', 'null'].includes(schema.type);
1383
- }
1384
- return false;
1381
+ return !!schema.type && ['string', 'number', 'integer', 'boolean', 'null'].includes(schema.type);
1385
1382
  }
1386
1383
  /**
1387
1384
  * Deep copy that preserves functions in customValidations/customConversions.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.107.2",
4
+ "version": "15.107.3",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
@@ -17,7 +17,7 @@
17
17
  "yargs": "^18"
18
18
  },
19
19
  "devDependencies": {
20
- "@typescript/native-preview": "7.0.0-dev.20260415.1",
20
+ "@typescript/native-preview": "beta",
21
21
  "@naturalcycles/dev-lib": "18.4.2"
22
22
  },
23
23
  "exports": {
package/src/util/git2.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { execSync } from 'node:child_process'
2
2
  import { basename } from 'node:path'
3
+ import { _uniq } from '@naturalcycles/js-lib/array'
3
4
  import type { UnixTimestamp } from '@naturalcycles/js-lib/types'
4
5
  import { exec2 } from '../exec2/exec2.js'
5
6
 
@@ -30,7 +31,7 @@ class Git2 {
30
31
  }
31
32
 
32
33
  /**
33
- * Returns true if there were changes
34
+ * @returns true if there were changes
34
35
  */
35
36
  commitAll(msg: string): boolean {
36
37
  // git commit -a -m "style(lint-all): $GIT_MSG" || true
@@ -134,6 +135,59 @@ class Git2 {
134
135
  .filter(s => !s.includes(' -> '))
135
136
  .map(s => s.split('/')[1]!)
136
137
  }
138
+
139
+ gitRefExists(ref: string): boolean {
140
+ try {
141
+ exec2.exec(`git rev-parse --verify --quiet ${ref}`)
142
+ return true
143
+ } catch {
144
+ return false
145
+ }
146
+ }
147
+
148
+ getTrackedFiles(): string[] {
149
+ try {
150
+ return exec2
151
+ .exec('git ls-files')
152
+ .split('\n')
153
+ .filter(s => s.trim().length)
154
+ } catch {
155
+ return []
156
+ }
157
+ }
158
+
159
+ getUntrackedFiles(): string[] {
160
+ try {
161
+ return exec2
162
+ .exec('git ls-files --others --exclude-standard')
163
+ .split('\n')
164
+ .filter(s => s.trim().length)
165
+ } catch {
166
+ return []
167
+ }
168
+ }
169
+
170
+ getTrackedChangedFiles(diffBase: string, diffFilter = 'AMR'): string[] {
171
+ try {
172
+ return exec2
173
+ .exec(`git diff --name-only --diff-filter=${diffFilter} ${diffBase}`)
174
+ .split('\n')
175
+ .filter(s => s.trim().length)
176
+ } catch {
177
+ return []
178
+ }
179
+ }
180
+
181
+ /**
182
+ * @returns both tracked changed and untracked files
183
+ */
184
+ getAllChangedFiles(diffBase: string): string[] {
185
+ const tracked = this.getTrackedChangedFiles(diffBase)
186
+ const untracked = this.getUntrackedFiles()
187
+
188
+ const changes = [...tracked, ...untracked]
189
+ return _uniq(changes)
190
+ }
137
191
  }
138
192
 
139
193
  export const git2 = new Git2()
@@ -1933,11 +1933,9 @@ function hasNoObjectSchemas(schema: JsonSchema): boolean {
1933
1933
  return true
1934
1934
  } else if (schema.type === 'array') {
1935
1935
  return !schema.items || hasNoObjectSchemas(schema.items)
1936
- } else {
1937
- return !!schema.type && ['string', 'number', 'integer', 'boolean', 'null'].includes(schema.type)
1938
1936
  }
1939
1937
 
1940
- return false
1938
+ return !!schema.type && ['string', 'number', 'integer', 'boolean', 'null'].includes(schema.type)
1941
1939
  }
1942
1940
 
1943
1941
  type EnumBaseType = 'string' | 'number' | 'other'