|
1 |
| -import * as path from 'path'; |
2 |
| -import * as fs from 'fs-extra'; |
3 | 1 | import { execSync } from 'child_process';
|
| 2 | +import * as path from 'path'; |
| 3 | + |
4 | 4 | import { ChangelogJson } from 'beachball';
|
| 5 | +import * as fs from 'fs-extra'; |
5 | 6 | import { rollup as lernaAliases } from 'lerna-alias';
|
| 7 | + |
6 | 8 | import { IChangelogEntry } from './types';
|
7 | 9 |
|
8 | 10 | const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
|
@@ -49,28 +51,48 @@ export function getTagToChangelogMap(maxAgeDays?: number): Map<string, IChangelo
|
49 | 51 | * @returns List of tags
|
50 | 52 | */
|
51 | 53 | export function getTags(maxAgeDays?: number): string[] {
|
| 54 | + const ONE_MEGABYTE = 1024 * 1000; |
| 55 | + const TEN_MEGABYTES = ONE_MEGABYTE * 10; |
52 | 56 | console.log(`Getting tags${maxAgeDays ? ` up to ${maxAgeDays} days old` : ''}...`);
|
53 | 57 |
|
54 |
| - const cmd = 'git for-each-ref --sort=-creatordate --format="%(refname:short) -- %(creatordate)" refs/tags'; |
| 58 | + try { |
| 59 | + const cmd = 'git for-each-ref --sort=-creatordate --format="%(refname:short) -- %(creatordate)" refs/tags'; |
| 60 | + const gitForEachRefBuffer = execSync(cmd, { |
| 61 | + // execSync buffer is by default 1MB (node 16). Our git refs tog is much bigger than that, thus setting for 10MB |
| 62 | + maxBuffer: TEN_MEGABYTES, |
| 63 | + }); |
| 64 | + const currentBufferSize = (gitForEachRefBuffer.byteLength / ONE_MEGABYTE).toFixed(2); |
55 | 65 |
|
56 |
| - let tagsAndDates = execSync(cmd, { cwd: process.cwd() }) |
57 |
| - .toString() |
58 |
| - .split(/\r?\n/g) |
59 |
| - .map(tag => tag.split(' -- ')) |
60 |
| - .filter(arr => arr.length === 2); |
| 66 | + console.warn(` |
| 67 | + 📣 NOTE: "git for-each-ref" current buffer size is ${currentBufferSize}MB. |
| 68 | + If this will be more than maxBuffer ${TEN_MEGABYTES}MB this command will fail and you'll have to increase maxBuffer! |
| 69 | + `); |
61 | 70 |
|
62 |
| - if (maxAgeDays) { |
63 |
| - const endIndex = tagsAndDates.findIndex(([, date]) => !_isNewEnough(date, maxAgeDays)); |
64 |
| - if (endIndex !== -1) { |
65 |
| - tagsAndDates = tagsAndDates.slice(0, endIndex); |
| 71 | + let tagsAndDates = gitForEachRefBuffer |
| 72 | + .toString() |
| 73 | + .split(/\r?\n/g) |
| 74 | + .map(tag => tag.split(' -- ')) |
| 75 | + .filter(arr => arr.length === 2); |
| 76 | + |
| 77 | + if (maxAgeDays) { |
| 78 | + const endIndex = tagsAndDates.findIndex(([, date]) => !_isNewEnough(date, maxAgeDays)); |
| 79 | + if (endIndex !== -1) { |
| 80 | + tagsAndDates = tagsAndDates.slice(0, endIndex); |
| 81 | + } |
66 | 82 | }
|
67 |
| - } |
68 | 83 |
|
69 |
| - const tags = tagsAndDates.map(([tag]) => tag); |
| 84 | + const tags = tagsAndDates.map(([tag]) => tag); |
70 | 85 |
|
71 |
| - console.log(`Found ${tags.length} tag(s).\n`); |
| 86 | + console.log(`Found ${tags.length} tag(s).\n`); |
72 | 87 |
|
73 |
| - return tags; |
| 88 | + return tags; |
| 89 | + } catch (err) { |
| 90 | + if (err.code === 'ENOBUFS') { |
| 91 | + throw new Error(`maxBuffer ${TEN_MEGABYTES}MB was reached. Increase its size in the codebase`); |
| 92 | + } |
| 93 | + |
| 94 | + throw err; |
| 95 | + } |
74 | 96 | }
|
75 | 97 |
|
76 | 98 | /**
|
|
0 commit comments