Comparing version 2.3.0 to 3.0.0
@@ -1,18 +0,29 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { EventEmitter } from 'events'; | ||
import File = require('vinyl'); | ||
import File from 'vinyl'; | ||
import { PassThrough } from 'stream'; | ||
export declare type StreamOptions = { | ||
filter?: (file: File) => boolean; | ||
export type StreamOptions<StoreFile extends { | ||
path: string; | ||
} = File> = { | ||
filter?: (file: StoreFile) => boolean; | ||
}; | ||
export declare class Store extends EventEmitter { | ||
export declare class Store<StoreFile extends { | ||
path: string; | ||
} = File> extends EventEmitter { | ||
loadFile: (filepath: string) => StoreFile; | ||
private store; | ||
constructor(options?: { | ||
loadFile?: (filepath: string) => StoreFile; | ||
}); | ||
private load; | ||
get(filepath: string): File; | ||
get(filepath: string): StoreFile; | ||
existsInMemory(filepath: string): boolean; | ||
add(file: File): this; | ||
each(onEach: (file: File, index: number) => void): this; | ||
all(): File[]; | ||
stream({ filter }?: StreamOptions): PassThrough; | ||
add(file: StoreFile): this; | ||
each(onEach: (file: StoreFile) => void): this; | ||
all(): StoreFile[]; | ||
stream({ filter }?: StreamOptions<StoreFile>): PassThrough; | ||
} | ||
export declare function create(): Store; | ||
export declare function create<StoreFile extends { | ||
path: string; | ||
} = File>(): Store<StoreFile>; |
@@ -1,89 +0,65 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.create = exports.Store = void 0; | ||
var events_1 = require("events"); | ||
var path = require("path"); | ||
var vinylFile = require("vinyl-file"); | ||
var File = require("vinyl"); | ||
var stream_1 = require("stream"); | ||
function createFile(filepath) { | ||
return new File({ | ||
cwd: process.cwd(), | ||
base: process.cwd(), | ||
path: filepath, | ||
contents: null, | ||
}); | ||
import { EventEmitter } from 'events'; | ||
import path from 'path'; | ||
import { vinylFileSync } from 'vinyl-file'; | ||
import File from 'vinyl'; | ||
import { PassThrough } from 'stream'; | ||
function loadFile(filepath) { | ||
try { | ||
return vinylFileSync(filepath); | ||
} | ||
catch (err) { | ||
return new File({ | ||
cwd: process.cwd(), | ||
base: process.cwd(), | ||
path: filepath, | ||
contents: null, | ||
}); | ||
} | ||
} | ||
var Store = /** @class */ (function (_super) { | ||
__extends(Store, _super); | ||
function Store() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.store = {}; | ||
return _this; | ||
export class Store extends EventEmitter { | ||
loadFile; | ||
store = new Map(); | ||
constructor(options) { | ||
super(); | ||
this.loadFile = | ||
options?.loadFile ?? loadFile; | ||
} | ||
Store.prototype.load = function (filepath) { | ||
var file; | ||
try { | ||
file = vinylFile.readSync(filepath); | ||
} | ||
catch (err) { | ||
file = createFile(filepath); | ||
} | ||
this.store[filepath] = file; | ||
load(filepath) { | ||
const file = this.loadFile(filepath); | ||
this.store.set(filepath, file); | ||
return file; | ||
}; | ||
Store.prototype.get = function (filepath) { | ||
} | ||
get(filepath) { | ||
filepath = path.resolve(filepath); | ||
return this.store[filepath] || this.load(filepath); | ||
}; | ||
Store.prototype.existsInMemory = function (filepath) { | ||
return this.store.get(filepath) || this.load(filepath); | ||
} | ||
existsInMemory(filepath) { | ||
filepath = path.resolve(filepath); | ||
return !!this.store[filepath]; | ||
}; | ||
Store.prototype.add = function (file) { | ||
this.store[file.path] = file; | ||
return this.store.has(filepath); | ||
} | ||
add(file) { | ||
this.store.set(file.path, file); | ||
this.emit('change', file.path); | ||
return this; | ||
}; | ||
Store.prototype.each = function (onEach) { | ||
var _this = this; | ||
Object.keys(this.store).forEach(function (key, index) { | ||
onEach(_this.store[key], index); | ||
} | ||
each(onEach) { | ||
this.store.forEach((file) => { | ||
onEach(file); | ||
}); | ||
return this; | ||
}; | ||
Store.prototype.all = function () { | ||
return Object.values(this.store); | ||
}; | ||
Store.prototype.stream = function (_a) { | ||
var _this = this; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.filter, filter = _c === void 0 ? function () { return true; } : _c; | ||
var stream = new stream_1.PassThrough({ objectMode: true, autoDestroy: true }); | ||
setImmediate(function () { | ||
_this.each(function (file) { return filter(file) && stream.write(file); }); | ||
} | ||
all() { | ||
return Array.from(this.store.values()); | ||
} | ||
stream({ filter = () => true } = {}) { | ||
const stream = new PassThrough({ objectMode: true, autoDestroy: true }); | ||
setImmediate(() => { | ||
this.each((file) => filter(file) && stream.write(file)); | ||
stream.end(); | ||
}); | ||
return stream; | ||
}; | ||
return Store; | ||
}(events_1.EventEmitter)); | ||
exports.Store = Store; | ||
function create() { | ||
} | ||
} | ||
export function create() { | ||
return new Store(); | ||
} | ||
exports.create = create; |
{ | ||
"name": "mem-fs", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "Simple in-memory vinyl file store", | ||
"type": "module", | ||
"scripts": { | ||
"test": "eslint . && tsc && mocha && tsc -b ./type-test/tsconfig.build.json", | ||
"prepare": "tsc" | ||
"test": "vitest --run --no-threads", | ||
"prepare": "tsc", | ||
"pretest": "eslint ." | ||
}, | ||
@@ -19,20 +21,21 @@ "repository": "SBoudrias/mem-fs", | ||
"dependencies": { | ||
"@types/node": "^15.6.2", | ||
"@types/vinyl": "^2.0.4", | ||
"vinyl": "^2.0.1", | ||
"vinyl-file": "^3.0.0" | ||
"@types/node": "^18.15.11", | ||
"@types/vinyl": "^2.0.7", | ||
"vinyl": "^3.0.0", | ||
"vinyl-file": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/vinyl-file": "^3.0.0", | ||
"eslint": "^8.6.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-config-xo": "^0.39.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"mocha": "^8.3.2", | ||
"prettier": "^2.5.1", | ||
"typescript": "^4.2.4" | ||
"@typescript-eslint/eslint-plugin": "^5.58.0", | ||
"@typescript-eslint/parser": "^5.58.0", | ||
"eslint": "^8.38.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-config-xo": "^0.43.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"prettier": "^2.8.7", | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.30.1" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=16.13.0" | ||
} | ||
} |
@@ -1,10 +0,7 @@ | ||
mem-fs | ||
============= | ||
# mem-fs | ||
Simple in-memory vinyl file store. | ||
## Usage | ||
Usage | ||
------------- | ||
### Loading a file | ||
@@ -15,4 +12,5 @@ | ||
```js | ||
var store = require('mem-fs').create(); | ||
import { create } from 'mem-fs' | ||
const store = create(); | ||
store.get('/test/file.txt'); | ||
@@ -30,12 +28,13 @@ ``` | ||
```js | ||
var File = require('vinyl'); | ||
var store = require('mem-fs').create(); | ||
import File from 'vinyl'; | ||
import { create } from 'mem-fs'; | ||
var coffeeFile = new File({ | ||
const coffeeFile = new File({ | ||
cwd: '/', | ||
base: '/test/', | ||
path: '/test/file.coffee', | ||
contents: new Buffer('test = 123') | ||
contents: new Buffer('test = 123'), | ||
}); | ||
const store = create(); | ||
store.add(coffeeFile); | ||
@@ -42,0 +41,0 @@ ``` |
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
Yes
5075
9
94
56
+ Added@types/node@18.19.64(transitive)
+ Addedbare-events@2.5.0(transitive)
+ Addedfast-fifo@1.3.2(transitive)
+ Addedfirst-chunk-stream@5.0.0(transitive)
+ Addedqueue-tick@1.0.1(transitive)
+ Addedreplace-ext@2.0.0(transitive)
+ Addedstreamx@2.20.2(transitive)
+ Addedstrip-bom-buf@3.0.1(transitive)
+ Addedstrip-bom-stream@5.0.0(transitive)
+ Addedteex@1.0.1(transitive)
+ Addedtext-decoder@1.2.1(transitive)
+ Addedundici-types@5.26.5(transitive)
+ Addedvinyl@3.0.0(transitive)
+ Addedvinyl-file@5.0.0(transitive)
- Removed@types/node@15.14.9(transitive)
- Removedclone-buffer@1.0.0(transitive)
- Removedcloneable-readable@1.1.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedfirst-chunk-stream@2.0.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreplace-ext@1.0.1(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-bom-buf@1.0.0(transitive)
- Removedstrip-bom-stream@2.0.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvinyl@2.2.1(transitive)
- Removedvinyl-file@3.0.0(transitive)
Updated@types/node@^18.15.11
Updated@types/vinyl@^2.0.7
Updatedvinyl@^3.0.0
Updatedvinyl-file@^5.0.0