mem-fs-editor
Advanced tools
Comparing version 10.0.2 to 11.0.0
@@ -1,2 +0,2 @@ | ||
import type { MemFsEditor, MemFsEditorFile } from '../index.js'; | ||
export default function commitFileAsync<EditorFile extends MemFsEditorFile>(this: MemFsEditor<EditorFile>, file: EditorFile): Promise<void>; | ||
import type { MemFsEditorFile } from '../index.js'; | ||
export default function commitFileAsync<EditorFile extends MemFsEditorFile>(file: EditorFile): Promise<void>; |
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import { clearFileState, isFileStateModified, isFileStateDeleted, setCommittedFile } from '../state.js'; | ||
import { clearFileState, isFileStateModified, isFileStateDeleted, setCommittedFile, isFileNew } from '../state.js'; | ||
async function write(file) { | ||
@@ -37,6 +37,2 @@ if (!file.contents) { | ||
export default async function commitFileAsync(file) { | ||
const existingFile = this.store.get(file.path); | ||
if (!existingFile || existingFile !== file) { | ||
this.store.add(file); | ||
} | ||
if (isFileStateModified(file)) { | ||
@@ -46,3 +42,3 @@ setCommittedFile(file); | ||
} | ||
else if (isFileStateDeleted(file)) { | ||
else if (isFileStateDeleted(file) && !isFileNew(file)) { | ||
setCommittedFile(file); | ||
@@ -49,0 +45,0 @@ await remove(file); |
@@ -1,6 +0,4 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { PipelineSource } from 'stream'; | ||
import { type FileTransform, type PipelineOptions } from 'mem-fs'; | ||
import type { MemFsEditor, MemFsEditorFile } from '../index.js'; | ||
declare function commit<EditorFile extends MemFsEditorFile>(this: MemFsEditor<EditorFile>, stream?: PipelineSource<any>): any; | ||
declare function commit<EditorFile extends MemFsEditorFile>(this: MemFsEditor<EditorFile>, filters?: any[], stream?: PipelineSource<any>): any; | ||
declare function commit<EditorFile extends MemFsEditorFile>(this: MemFsEditor<EditorFile>, options?: PipelineOptions<EditorFile> | FileTransform<EditorFile>, ...transforms: FileTransform<EditorFile>[]): Promise<void>; | ||
export default commit; |
@@ -1,15 +0,11 @@ | ||
import { promisify } from 'util'; | ||
import { pipeline as _pipeline } from 'stream'; | ||
const pipeline = promisify(_pipeline); | ||
import { createPendingFilesPassthrough, createCommitTransform } from '../transform.js'; | ||
import { isFileTransform } from 'mem-fs'; | ||
import { createCommitTransform } from '../transform.js'; | ||
import { isFilePending } from '../state.js'; | ||
function commit(filters, stream) { | ||
if (!Array.isArray(filters)) { | ||
stream = filters; | ||
filters = []; | ||
async function commit(options, ...transforms) { | ||
if (isFileTransform(options)) { | ||
transforms = [options, ...transforms]; | ||
options = undefined; | ||
} | ||
stream = stream ?? this.store.stream({ filter: (file) => isFilePending(file) }); | ||
filters = filters ?? []; | ||
return pipeline(stream, createPendingFilesPassthrough(), ...filters, createCommitTransform(this)); | ||
await this.store.pipeline({ filter: isFilePending, ...options }, ...transforms, createCommitTransform()); | ||
} | ||
export default commit; |
/// <reference types="node" resolution-mode="require"/> | ||
import type { Store } from 'mem-fs'; | ||
import type Vinyl from 'vinyl'; | ||
export type { PipelineOptions, FileTransform } from 'mem-fs'; | ||
import read from './actions/read.js'; | ||
@@ -19,3 +20,2 @@ import readJSON from './actions/read-json.js'; | ||
import commit from './actions/commit.js'; | ||
import commitFileAsync from './actions/commit-file-async.js'; | ||
import dump from './actions/dump.js'; | ||
@@ -62,5 +62,4 @@ export type { AppendOptions } from './actions/append.js'; | ||
commit: typeof commit<EditorFile>; | ||
commitFileAsync: typeof commitFileAsync<EditorFile>; | ||
dump: typeof dump<EditorFile>; | ||
} | ||
export declare function create(store: any): MemFsEditor<VinylMemFsEditorFile>; |
@@ -16,4 +16,4 @@ import read from './actions/read.js'; | ||
import commit from './actions/commit.js'; | ||
import commitFileAsync from './actions/commit-file-async.js'; | ||
import dump from './actions/dump.js'; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
export class MemFsEditor { | ||
@@ -43,3 +43,2 @@ store; | ||
MemFsEditor.prototype.commit = commit; | ||
MemFsEditor.prototype.commitFileAsync = commitFileAsync; | ||
MemFsEditor.prototype.dump = dump; | ||
@@ -46,0 +45,0 @@ export function create(store) { |
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { Transform, TransformCallback } from 'stream'; | ||
import type { MemFsEditor, MemFsEditorFile } from './index.js'; | ||
export declare function createTransform<EditorFile extends MemFsEditorFile = MemFsEditorFile>(transform: (file: EditorFile, encoding: BufferEncoding, cb: TransformCallback) => void): Transform; | ||
export declare const createPendingFilesPassthrough: () => Transform; | ||
export declare const createCommitTransform: <EditorFile extends MemFsEditorFile = MemFsEditorFile>(memFsEditor: MemFsEditor<EditorFile>) => Transform; | ||
import { Duplex } from 'stream'; | ||
import type { MemFsEditorFile } from './index.js'; | ||
export declare const createCommitTransform: <EditorFile extends MemFsEditorFile = MemFsEditorFile>() => Duplex; |
@@ -1,20 +0,8 @@ | ||
import { Transform } from 'stream'; | ||
import { isFilePending } from './state.js'; | ||
export function createTransform(transform) { | ||
return new Transform({ | ||
objectMode: true, | ||
transform(...args) { | ||
transform.apply(this, args); | ||
}, | ||
}); | ||
} | ||
export const createPendingFilesPassthrough = () => createTransform((file, _enc, cb) => { | ||
// Don't process deleted file who haven't been commited yet. | ||
cb(undefined, isFilePending(file) ? file : undefined); | ||
import { Duplex } from 'stream'; | ||
import commitFileAsync from './actions/commit-file-async.js'; | ||
export const createCommitTransform = () => Duplex.from(async function* (generator) { | ||
for await (const file of generator) { | ||
await commitFileAsync(file); | ||
yield file; | ||
} | ||
}); | ||
export const createCommitTransform = (memFsEditor) => createTransform((file, _enc, cb) => { | ||
memFsEditor | ||
.commitFileAsync(file) | ||
.then(() => cb()) | ||
.catch((error) => cb(error)); | ||
}); |
{ | ||
"name": "mem-fs-editor", | ||
"version": "10.0.2", | ||
"version": "11.0.0", | ||
"description": "File edition helpers working on top of mem-fs", | ||
@@ -36,32 +36,38 @@ "type": "module", | ||
"dependencies": { | ||
"@types/ejs": "^3.1.2", | ||
"binaryextensions": "^4.16.0", | ||
"@types/ejs": "^3.1.3", | ||
"@types/node": "^18.18.5", | ||
"binaryextensions": "^4.18.0", | ||
"commondir": "^1.0.1", | ||
"deep-extend": "^0.6.0", | ||
"ejs": "^3.1.9", | ||
"globby": "^13.1.4", | ||
"globby": "^13.2.2", | ||
"isbinaryfile": "^5.0.0", | ||
"mem-fs": "^3.0.0", | ||
"minimatch": "^9.0.0", | ||
"minimatch": "^9.0.3", | ||
"multimatch": "^6.0.0", | ||
"normalize-path": "^3.0.0", | ||
"textextensions": "^5.13.0", | ||
"textextensions": "^5.16.0", | ||
"vinyl": "^3.0.0" | ||
}, | ||
"peerDependencies": { | ||
"mem-fs": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^3.0.3", | ||
"@typescript-eslint/eslint-plugin": "^6.7.5", | ||
"@typescript-eslint/parser": "^6.7.5", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"coveralls": "^3.1.1", | ||
"escape-regexp": "0.0.1", | ||
"eslint": "^8.5.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint": "^8.51.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-config-xo": "^0.43.1", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"mem-fs": "^3.0.0", | ||
"prettier": "^2.5.1", | ||
"sinon": "^15.0.1", | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.30.1" | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"prettier": "^3.0.3", | ||
"prettier-plugin-packagejson": "^2.4.6", | ||
"sinon": "^16.1.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
"engines": { | ||
"node": ">=16.13.0" | ||
"node": ">=18.0.0" | ||
} | ||
} |
@@ -107,3 +107,3 @@ # mem-fs-editor | ||
You can also optionally pass a `copyOptions` object (see [copy() documentation for more details](#copyfrom-to-options)). | ||
You can also optionally pass a `copyOptions` object (see [copy() documentation for more details](#copyfrom-to-options-context-templateoptions-)). | ||
@@ -143,10 +143,13 @@ Templates syntax looks like this: | ||
### `#commit([filters,] [stream,] callback)` | ||
### `#commit([options,] [...transforms])` | ||
Persist every changes made to files in the mem-fs store to disk. | ||
Pass stored files through a pipeline and persist every changes made to files in the mem-fs store to disk. | ||
If provided, `filters` is an array of TransformStream to be applied on a stream of vinyl files (like gulp plugins). | ||
If provided, `stream` is a stream of vinyl files. | ||
If provided, `options` is the pipeline options. | ||
By default only modified files are passed through the pipeline. | ||
Pass a custom filter `options.filter` to customize files passed through the pipeline. | ||
If provided, `...transforms` is a vararg of TransformStream to be applied on a stream of vinyl files (like gulp plugins). | ||
`commitTransform` is appended to `transforms` and persists modified files to disk, non modified files are passed through. | ||
`callback` is called once the files are updated on disk. | ||
returns promise that is resolved once the pipeline is finished. | ||
@@ -153,0 +156,0 @@ ### `#dump([cwd,] [filter])` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44422
46
822
160
14
14
+ Added@types/node@^18.18.5
+ Addedmem-fs@4.1.1(transitive)
- Removedmem-fs@^3.0.0
- Removedmem-fs@3.0.0(transitive)
Updated@types/ejs@^3.1.3
Updatedbinaryextensions@^4.18.0
Updatedglobby@^13.2.2
Updatedminimatch@^9.0.3
Updatedtextextensions@^5.16.0