flatten-tool 1.2.0 → 1.2.2

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.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/index.ts +11 -19
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -111,6 +111,12 @@ This project uses Bun for runtime, TypeScript for type safety, and follows the g
111
111
 
112
112
  ## Changelog
113
113
 
114
+ ### v1.2.2
115
+ - Added `setMaxListeners(0)` on WriteStream in Markdown merging to silence listener warnings when processing many files.
116
+
117
+ ### v1.2.1
118
+ - Fixed memory leak warnings in Markdown merging by refactoring to use `pipeline` and `finished` from `node:stream/promises`.
119
+
114
120
  ### v1.2.0
115
121
  - Implemented streaming for Markdown merging to improve memory efficiency for large files/directories.
116
122
  - Updated documentation and coding guidelines.
package/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { copyFile, rename, rm, stat, mkdir, readdir, rmdir, readFile, writeFile } from 'node:fs/promises';
3
3
  import { join, relative, sep, resolve, extname } from 'node:path';
4
4
  import { createReadStream, createWriteStream } from 'node:fs';
5
+ import { pipeline, finished } from 'node:stream/promises';
5
6
  import yargs from 'yargs';
6
7
  import { hideBin } from 'yargs/helpers';
7
8
  import { globby } from 'globby';
@@ -68,6 +69,7 @@ export async function flattenDirectory(
68
69
  }
69
70
 
70
71
  const writeStream = createWriteStream(absTarget);
72
+ writeStream.setMaxListeners(0);
71
73
 
72
74
  for (const srcPath of files) {
73
75
  const relPath = relative(absSource, srcPath).replace(/\\/g, '/');
@@ -75,32 +77,22 @@ export async function flattenDirectory(
75
77
  const isMd = ['md', 'markdown'].includes(ext.toLowerCase());
76
78
  const ticks = isMd ? '````' : '```';
77
79
 
78
- // Header + opening fence
80
+ // Write header synchronously
79
81
  writeStream.write(`# ${relPath}\n\n${ticks}${ext}\n`);
80
82
 
81
- // Stream file content as UTF-8 text (matches previous readFile(..., 'utf8') behavior)
83
+ // Stream file content (preserve original UTF-8 text behavior)
82
84
  const readStream = createReadStream(srcPath, { encoding: 'utf8' });
83
85
 
84
- await new Promise<void>((resolve, reject) => {
85
- readStream.pipe(writeStream, { end: false });
86
+ // Pipe with { end: false } so writeStream stays open for next files
87
+ await pipeline(readStream, writeStream, { end: false });
86
88
 
87
- readStream.on('end', () => {
88
- // Closing fence + trailing newlines
89
- writeStream.write(`\n${ticks}\n\n`);
90
- resolve();
91
- });
92
-
93
- readStream.on('error', reject);
94
- writeStream.on('error', reject);
95
- });
89
+ // Write closing fence
90
+ writeStream.write(`\n${ticks}\n\n`);
96
91
  }
97
92
 
98
- // Finalise the output file
99
- await new Promise<void>((resolve, reject) => {
100
- writeStream.end();
101
- writeStream.on('close', resolve);
102
- writeStream.on('error', reject);
103
- });
93
+ // Close the output file and wait for it to finish
94
+ writeStream.end();
95
+ await finished(writeStream);
104
96
 
105
97
  if (move) {
106
98
  for (const srcPath of files) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatten-tool",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "CLI tool to flatten directory structures: merge files into a single Markdown file (default) or copy/move to a flat directory with escaped filenames. Respects .gitignore, supports move/overwrite, and more.",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -27,12 +27,12 @@
27
27
  "license": "MIT",
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/yourusername/flatten-tool.git"
30
+ "url": "git+https://github.com/MBanucu/flatten-tool.git"
31
31
  },
32
32
  "bugs": {
33
- "url": "https://github.com/yourusername/flatten-tool/issues"
33
+ "url": "https://github.com/MBanucu/flatten-tool/issues"
34
34
  },
35
- "homepage": "https://github.com/yourusername/flatten-tool#readme",
35
+ "homepage": "https://github.com/MBanucu/flatten-tool#readme",
36
36
  "files": [
37
37
  "index.ts",
38
38
  "README.md",
@@ -43,12 +43,12 @@
43
43
  "@types/yargs": "^17.0.35"
44
44
  },
45
45
  "peerDependencies": {
46
- "typescript": "^5"
46
+ "typescript": "^5.9.3"
47
47
  },
48
48
  "dependencies": {
49
49
  "globby": "^16.1.0",
50
50
  "ignore": "^7.0.5",
51
- "minimatch": "^10.1.1",
51
+ "minimatch": "^10.1.2",
52
52
  "yargs": "^18.0.0"
53
53
  }
54
54
  }