@cobol-ts/files 0.0.0-stage → 0.0.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.
- package/README.md +37 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/package.json +58 -3
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@cobol-ts/files`
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Exported API
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {findDirectoryUp} from '@cobol-ts/files';
|
|
9
|
+
|
|
10
|
+
const fixtures = await findDirectoryUp('fixtures');
|
|
11
|
+
```
|
|
12
|
+
|
|
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.
|
|
2
23
|
|
|
3
|
-
|
|
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.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/files"), exports);
|
|
18
|
+
__exportStar(require("./src/text.files"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/files",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "file utilities for the @cobol-ts project",
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"types": "dist/index",
|
|
7
|
+
"browserslist": {
|
|
8
|
+
"development": [
|
|
9
|
+
"last 1 chrome version",
|
|
10
|
+
"last 1 firefox version",
|
|
11
|
+
"last 1 safari version"
|
|
12
|
+
],
|
|
13
|
+
"production": [
|
|
14
|
+
">0.2%",
|
|
15
|
+
"not dead",
|
|
16
|
+
"not op_mini all"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@cobol-ts/records": "0.0.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.2.2",
|
|
24
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
25
|
+
"@types/jest": "^29.0.0",
|
|
26
|
+
"@types/node": "^14.0.0",
|
|
27
|
+
"jest": "^29.0.0",
|
|
28
|
+
"ts-jest": "^29.0.0"
|
|
29
|
+
},
|
|
30
|
+
"eslintConfig": {
|
|
31
|
+
"extends": [
|
|
32
|
+
"react-app",
|
|
33
|
+
"react-app/jest"
|
|
34
|
+
],
|
|
35
|
+
"overrides": [
|
|
36
|
+
{
|
|
37
|
+
"files": [
|
|
38
|
+
"**/*.stories.*"
|
|
39
|
+
],
|
|
40
|
+
"rules": {
|
|
41
|
+
"import/no-anonymous-default-export": "off"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist/index.js",
|
|
48
|
+
"dist/index.d.ts",
|
|
49
|
+
"dist/src/",
|
|
50
|
+
"build/"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"indexing"
|
|
54
|
+
],
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"repository": "git@github.com:intellimaintain/intellimaintain.git",
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "jest --config jest.config.json --env node",
|
|
59
|
+
"test:watch": "npm run test -- --watch"
|
|
60
|
+
}
|
|
6
61
|
}
|