Skip to content

Commit

Permalink
fix: replace Duplex with Transform (#282)
Browse files Browse the repository at this point in the history
* fix: replace Duplex with Transform

* chore: apply prettier
  • Loading branch information
mshima authored Dec 12, 2024
1 parent e7c4113 commit 091b597
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
7 changes: 1 addition & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": [
"xo",
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"extends": ["xo", "prettier", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"env": {
"node": true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const store = createMemFs();
const fs = createEditor(store);

fs.write('somefile.js', 'var a = 1;');
await fs.commit()
await fs.commit();
```

### `#read(filepath, [options])`
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@
"name": "mem-fs-editor",
"version": "11.1.3",
"description": "File edition helpers working on top of mem-fs",
"type": "module",
"scripts": {
"build": "tsc",
"fix": "eslint . --fix",
"prepare": "npm run build",
"pretest": "eslint .",
"test": "vitest --run"
},
"repository": "SBoudrias/mem-fs-editor",
"author": "Simon Boudrias",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"author": "Simon Boudrias",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand All @@ -29,9 +20,18 @@
"default": "./dist/transform.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"fix": "eslint . --fix",
"prepare": "npm run build",
"pretest": "eslint .",
"test": "vitest --run"
},
"dependencies": {
"@types/ejs": "^3.1.4",
"@types/node": ">=18",
Expand All @@ -47,12 +47,6 @@
"textextensions": "^6.11.0",
"vinyl": "^3.0.0"
},
"peerDependencies": {
"mem-fs": "^4.0.0"
},
"acceptDependencies": {
"isbinaryfile": "^5.0.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
Expand All @@ -69,7 +63,13 @@
"typescript": "^5.2.2",
"vitest": "^2.0.5"
},
"peerDependencies": {
"mem-fs": "^4.0.0"
},
"engines": {
"node": ">=18.0.0"
},
"acceptDependencies": {
"isbinaryfile": "^5.0.3"
}
}
2 changes: 1 addition & 1 deletion src/actions/commit-file-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function write(file: MemFsEditorFile) {
const dir = path.dirname(file.path);
try {
if (!(await fs.stat(dir)).isDirectory()) {
throw new Error(`${file.path} is not a directory`);
throw new Error(`${dir} is not a directory`);
}
} catch (error) {
if ((error as any).code === 'ENOENT') {
Expand Down
17 changes: 10 additions & 7 deletions src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Duplex } from 'stream';
import { Transform } from 'stream';
import commitFileAsync from './actions/commit-file-async.js';
import type { MemFsEditorFile } from './index.js';

export const createCommitTransform = <EditorFile extends MemFsEditorFile = MemFsEditorFile>() =>
Duplex.from(async function* (generator: AsyncGenerator<EditorFile>) {
for await (const file of generator) {
await commitFileAsync(file);
yield file;
}
export const createCommitTransform = () =>
new Transform({
objectMode: true,
transform(file: MemFsEditorFile, _encoding, callback) {
commitFileAsync(file).then(
() => callback(null, file),
(error) => callback(error),
);
},
});

0 comments on commit 091b597

Please sign in to comment.