initial commit
This commit is contained in:
59
node_modules/fs-memo/CHANGELOG.md
generated
vendored
Normal file
59
node_modules/fs-memo/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
## [1.2.0](https://github.com/nuxt-contrib/fs-memo/compare/v1.1.0...v1.2.0) (2020-11-16)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* options.file ([813a517](https://github.com/nuxt-contrib/fs-memo/commit/813a517fa0f32b111b4d1e8453f1065a4ea23f2b))
|
||||
|
||||
## [1.1.0](https://github.com/nuxt-contrib/fs-memo/compare/v1.0.1...v1.1.0) (2020-11-16)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* write to node_modules/.cache/fs-memo/default.json ([4697250](https://github.com/nuxt-contrib/fs-memo/commit/46972506d0a655c1f2e96c3998fc8bc477abea27))
|
||||
|
||||
### [1.0.1](https://github.com/nuxt-contrib/fs-memo/compare/v1.0.0...v1.0.1) (2020-06-16)
|
||||
|
||||
## [1.0.0](https://github.com/nuxt-contrib/fs-memo/compare/v0.0.6...v1.0.0) (2020-06-16)
|
||||
|
||||
### [0.0.6](https://github.com/nuxt-contrib/fs-memo/compare/v0.0.5...v0.0.6) (2020-06-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix options type and destructure ([af16d46](https://github.com/nuxt-contrib/fs-memo/commit/af16d460a15b24027e9ab07a4fe14da2dfca74ef))
|
||||
* **pkg:** add missing files field ([c27fb23](https://github.com/nuxt-contrib/fs-memo/commit/c27fb2398f0b086b047e09211abf9a970e058312))
|
||||
|
||||
### [0.0.5](https://github.com/nuxt-contrib/fs-memo/compare/v0.0.4...v0.0.5) (2020-05-31)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **types:** set memo type to any ([7397658](https://github.com/nuxt-contrib/fs-memo/commit/7397658e1a9a24c0c58e26b766e02af1062f792f))
|
||||
|
||||
### [0.0.4](https://github.com/nuxt-contrib/fs-memo/compare/v0.0.3...v0.0.4) (2020-05-31)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* always validate memo file ([224ba35](https://github.com/nuxt-contrib/fs-memo/commit/224ba3559f60ae8d7ed1d249d7c7a6326519b663))
|
||||
|
||||
### [0.0.3](https://github.com/nuxt-contrib/fs-memo/compare/v0.0.2...v0.0.3) (2020-05-31)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* pid check ([f5f6706](https://github.com/nuxt-contrib/fs-memo/commit/f5f67068c8dc731c2c39b42bb6b8cb0dc18cf286))
|
||||
|
||||
### [0.0.2](https://github.com/nuxt-contrib/fs-memo/compare/v0.0.1...v0.0.2) (2020-05-31)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* default name ([5835f70](https://github.com/nuxt-contrib/fs-memo/commit/5835f70e6ad018f2d856725cad1bb149dc74a502))
|
||||
|
||||
### 0.0.1 (2020-05-31)
|
||||
21
node_modules/fs-memo/LICENSE
generated
vendored
Normal file
21
node_modules/fs-memo/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
64
node_modules/fs-memo/README.md
generated
vendored
Normal file
64
node_modules/fs-memo/README.md
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
# fs-memo
|
||||
|
||||
> Easy persisted memo object for Node.js
|
||||
|
||||
[](https://npmjs.com/package/fs-memo)
|
||||
[](https://npmjs.com/package/fs-memo)
|
||||
|
||||
## Usage
|
||||
|
||||
Install package:
|
||||
|
||||
```bash
|
||||
yarn add fs-memo
|
||||
# or
|
||||
or npm install fs-memo
|
||||
```
|
||||
|
||||
```js
|
||||
const { getMemo, setMemo } = require('fs-memo')
|
||||
// or
|
||||
import { getMemo, setMemo } from 'fs-memo'
|
||||
```
|
||||
|
||||
|
||||
### `getMemo(options)`
|
||||
|
||||
```ts
|
||||
getMemo(options: MemoOptions): Promise<any>
|
||||
```
|
||||
|
||||
Load latest memo from file-system and combine with local state from CJS cache.
|
||||
|
||||
FS loading silently bails if:
|
||||
- The process that made memo is still alive with different pid
|
||||
- Any fs error happens (like permission denied)
|
||||
|
||||
### `setMemo(options)`
|
||||
|
||||
```ts
|
||||
setMemo(memo: object, options: MemoOptions): Promise<void>
|
||||
```
|
||||
|
||||
Update local state from CJS cache and persist memo object to file-system.
|
||||
|
||||
FS persistence silently bails if any error happens.
|
||||
|
||||
## Options
|
||||
|
||||
### `dir`
|
||||
|
||||
Specify directory where memo file should be stored. Default dir is `node_modules/.cache/fs-memo`
|
||||
|
||||
### `name`
|
||||
|
||||
Name of memo file. Default name is `default` (`.json` is appended to file name)
|
||||
|
||||
### `file`
|
||||
|
||||
Optionally provide full path to file (discards `dir` and `name` options)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
9
node_modules/fs-memo/dist/index.d.ts
generated
vendored
Normal file
9
node_modules/fs-memo/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface MemoOptions {
|
||||
dir: string;
|
||||
name: string;
|
||||
file: string;
|
||||
}
|
||||
declare function getMemo(config: Partial<MemoOptions>): Promise<any>;
|
||||
declare function setMemo(memo: object, config: Partial<MemoOptions>): Promise<void>;
|
||||
|
||||
export { getMemo, setMemo };
|
||||
56
node_modules/fs-memo/dist/index.js
generated
vendored
Normal file
56
node_modules/fs-memo/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const _memo = {
|
||||
_pid: process.pid
|
||||
};
|
||||
async function getMemo(config) {
|
||||
const options = getOptions(config);
|
||||
try {
|
||||
const memo = JSON.parse(await fs.promises.readFile(options.file, "utf-8")) || {};
|
||||
if (!memo._pid) {
|
||||
throw new Error("Memo lacks _pid");
|
||||
}
|
||||
if (memo._pid === _memo._pid || !isAlive(memo.pid)) {
|
||||
Object.assign(_memo, memo);
|
||||
_memo._pid = process.pid;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
return _memo;
|
||||
}
|
||||
async function setMemo(memo, config) {
|
||||
const options = getOptions(config);
|
||||
Object.assign(_memo, memo);
|
||||
_memo._pid = process.pid;
|
||||
try {
|
||||
await fs.promises.mkdir(options.dir);
|
||||
} catch (e) {
|
||||
}
|
||||
try {
|
||||
await fs.promises.writeFile(options.file, JSON.stringify(_memo), "utf-8");
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
function getOptions(config) {
|
||||
const options = {...config};
|
||||
options.name = options.name || "default";
|
||||
options.dir = options.dir || path.resolve(process.cwd(), "node_modules/.cache/fs-memo");
|
||||
options.file = options.file || path.resolve(options.dir, options.name + ".json");
|
||||
return options;
|
||||
}
|
||||
function isAlive(pid) {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return e.code === "EPERM";
|
||||
}
|
||||
}
|
||||
|
||||
exports.getMemo = getMemo;
|
||||
exports.setMemo = setMemo;
|
||||
25
node_modules/fs-memo/package.json
generated
vendored
Normal file
25
node_modules/fs-memo/package.json
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "fs-memo",
|
||||
"version": "1.2.0",
|
||||
"description": "easy persisted memo object",
|
||||
"repository": "nuxt-contrib/fs-memo",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "siroc build",
|
||||
"lint": "eslint --ext ts .",
|
||||
"release": "yarn build && standard-version && npm publish && git push --follow-tags"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nuxtjs/eslint-config-typescript": "latest",
|
||||
"@types/node": "latest",
|
||||
"eslint": "latest",
|
||||
"siroc": "^0.4.0",
|
||||
"standard-version": "latest",
|
||||
"typescript": "latest"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user