@cobol-ts/files 0.0.13 → 0.0.16

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 (2) hide show
  1. package/README.md +18 -32
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,38 +1,24 @@
1
- # `@cobol-ts/files`
1
+ # @cobol-ts/files
2
2
 
3
- Small Node.js filesystem utilities. This package is **not** the `@cobol-ts/errors` monad, a COBOL parser, or the streaming byte-backed cursor; its previous README was an accidental copy of the errors package documentation.
3
+ Provide a small text-file port plus a Node adapter, and upward directory discovery for `.cobolts` configuration.
4
4
 
5
- ## Exported API
5
+ The `TextFiles` interface separates filesystem I/O from catalogue and generator logic.
6
6
 
7
- ```ts
8
- import {findDirectoryUp} from '@cobol-ts/files';
7
+ ## Example
9
8
 
10
- const fixtures = await findDirectoryUp('fixtures');
9
+ ```typescript
10
+ import {findDirectoryUp, nodeTextFiles} from '@cobol-ts/files'
11
+
12
+ const configDirectory = await findDirectoryUp('.cobolts', process.cwd())
13
+ const source = await nodeTextFiles.read(`${configDirectory}/files.yaml`)
11
14
  ```
12
15
 
13
- `findDirectoryUp(dirName: string): Promise<string>` searches for a **directory with exactly that name** among the children of the current working directory, then its parent, then successive ancestors. It returns the first matching absolute path. It calls `fs.stat()` and checks `isDirectory()`, so an ordinary file of the same name is not a match.
14
-
15
- When the filesystem root is reached without a match, it rejects with `Directory "<name>" not found`. The implementation currently ignores errors from the individual `stat()` attempts, not only `ENOENT`, so permissions and other filesystem errors can present as "not found". It uses `process.cwd()` and Node's `node:fs/promises` and `node:path`; it is not browser-compatible.
16
-
17
- This utility does **not** search recursively through arbitrary descendants, accept an absolute search root, create directories or load files. It is unrelated to the cursor's `fillFileBuffer` abstraction.
18
-
19
- ## Source
20
-
21
- - `src/files.ts`: `findDirectoryUp()` implementation.
22
- - `index.ts`: package entrypoint, re-exporting the utility.
23
-
24
- ## Text-file port
25
-
26
- `TextFiles` is the small I/O boundary for configuration and TypeScript source generation. It can be replaced by an in-memory implementation in tests:
27
-
28
- ```ts
29
- export interface TextFiles {
30
- read(filename: string): Promise<string>
31
- write(filename: string, text: readonly string[]): Promise<void>
32
- exists(filename: string): Promise<boolean>
33
- }
34
- ```
35
-
36
- `nodeTextFiles` is the standard Node implementation. It reads UTF-8, writes each string as a line with `\n` separators and a final newline for a nonempty array, creates missing parent directories, and checks whether a file path exists. Exceptions from Node I/O are propagated for callers to convert into their own `ErrorsOr` context.
37
-
38
- Top-level convenience functions `readTextFile(filename)` and `writeTextFile(filename, lines)` delegate to `nodeTextFiles`. The existing `findDirectoryUp()` API remains unchanged.
16
+ `TextFiles` is a small read/write port used by configuration and generators. `findDirectoryUp` walks parents looking for a directory; it throws when no match exists.
17
+
18
+ ## Source and tests
19
+
20
+ **Public entry points:** [files.ts](./src/files.ts), [text.files.ts](./src/text.files.ts).
21
+
22
+ **Tests:** [files.spec.ts](src/files.spec.ts), [text.files.spec.ts](src/text.files.spec.ts)
23
+
24
+ **Related:** [@cobol-ts/file-catalogue](../../config/file-catalogue/README.md) · [@cobol-ts/codegen](../../codegen/codegen/README.md).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cobol-ts/files",
3
3
  "description": "file utilities for the @cobol-ts project",
4
- "version": "0.0.13",
4
+ "version": "0.0.16",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "browserslist": {
@@ -17,7 +17,7 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@cobol-ts/records": "0.0.13"
20
+ "@cobol-ts/records": "0.0.16"
21
21
  },
22
22
  "devDependencies": {
23
23
  "typescript": "^5.2.2",