Skip to content

Commit

Permalink
Merge branch 'fix/202003_npm_update_dependencies' of https://github.c…
Browse files Browse the repository at this point in the history
…om/yumetodo/flat-cache into yumetodo-fix/202003_npm_update_dependencies
  • Loading branch information
royriojas committed Nov 8, 2020
2 parents ef48276 + a5c482c commit f3235a6
Show file tree
Hide file tree
Showing 9 changed files with 2,393 additions and 6,333 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,29 @@
{
"extends": [
"eslint:recommended",
"plugin:mocha/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"env": {
"node": true,
"es6": true,
"mocha": true
},
"plugins": [
"mocha"
],
"rules": {
"prettier/prettier": [
"error", {
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 120,
"arrowParens": "avoid"
}
]
}
}
79 changes: 71 additions & 8 deletions .gitignore
@@ -1,32 +1,95 @@
### https://raw.github.com/github/gitignore/c1b7904af6689bd01646f008b0561d4f19a0e972/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
# Dependency directories
node_modules/
jspm_packages/

# Users Environment Variables
.lock-wscript
# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Users Environment Variables
test/fixtures/
.cache
.cache2

122 changes: 61 additions & 61 deletions cache.js
@@ -1,7 +1,7 @@
var path = require( 'path' );
var fs = require( 'fs' );
var utils = require( './utils' );
var del = require( './del' );
var path = require('path');
var fs = require('fs');
var utils = require('./utils');
var del = require('./del');
var writeJSON = utils.writeJSON;

var cache = {
Expand All @@ -14,15 +14,15 @@ var cache = {
* @param docId {String} the id of the cache, would also be used as the name of the file cache
* @param [cacheDir] {String} directory for the cache entry
*/
load: function ( docId, cacheDir ) {
load: function (docId, cacheDir) {
var me = this;

me._visited = { };
me._persisted = { };
me._pathToFile = cacheDir ? path.resolve( cacheDir, docId ) : path.resolve( __dirname, './.cache/', docId );
me._visited = {};
me._persisted = {};
me._pathToFile = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, './.cache/', docId);

if ( fs.existsSync( me._pathToFile ) ) {
me._persisted = utils.tryParse( me._pathToFile, { } );
if (fs.existsSync(me._pathToFile)) {
me._persisted = utils.tryParse(me._pathToFile, {});
}
},

Expand All @@ -31,12 +31,12 @@ var cache = {
* @method loadFile
* @param {String} pathToFile the path to the file containing the info for the cache
*/
loadFile: function ( pathToFile ) {
loadFile: function (pathToFile) {
var me = this;
var dir = path.dirname( pathToFile );
var fName = path.basename( pathToFile );
var dir = path.dirname(pathToFile);
var fName = path.basename(pathToFile);

me.load( fName, dir );
me.load(fName, dir);
},

/**
Expand All @@ -49,36 +49,36 @@ var cache = {
},

keys: function () {
return Object.keys( this._persisted );
return Object.keys(this._persisted);
},
/**
* sets a key to a given value
* @method setKey
* @param key {string} the key to set
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
*/
setKey: function ( key, value ) {
this._visited[ key ] = true;
this._persisted[ key ] = value;
setKey: function (key, value) {
this._visited[key] = true;
this._persisted[key] = value;
},
/**
* remove a given key from the cache
* @method removeKey
* @param key {String} the key to remove from the object
*/
removeKey: function ( key ) {
delete this._visited[ key ]; // esfmt-ignore-line
delete this._persisted[ key ]; // esfmt-ignore-line
removeKey: function (key) {
delete this._visited[key]; // esfmt-ignore-line
delete this._persisted[key]; // esfmt-ignore-line
},
/**
* Return the value of the provided key
* @method getKey
* @param key {String} the name of the key to retrieve
* @returns {*} the value from the key
*/
getKey: function ( key ) {
this._visited[ key ] = true;
return this._persisted[ key ];
getKey: function (key) {
this._visited[key] = true;
return this._persisted[key];
},

/**
Expand All @@ -89,20 +89,20 @@ var cache = {
*/
_prune: function () {
var me = this;
var obj = { };
var obj = {};

var keys = Object.keys( me._visited );
var keys = Object.keys(me._visited);

// no keys visited for either get or set value
if ( keys.length === 0 ) {
if (keys.length === 0) {
return;
}

keys.forEach( function ( key ) {
obj[ key ] = me._persisted[ key ];
} );
keys.forEach(function (key) {
obj[key] = me._persisted[key];
});

me._visited = { };
me._visited = {};
me._persisted = obj;
},

Expand All @@ -112,11 +112,11 @@ var cache = {
* @param [noPrune=false] {Boolean} whether to remove from cache the non visited files
* @method save
*/
save: function ( noPrune ) {
save: function (noPrune) {
var me = this;

(!noPrune) && me._prune();
writeJSON( me._pathToFile, me._persisted );
!noPrune && me._prune();
writeJSON(me._pathToFile, me._persisted);
},

/**
Expand All @@ -125,19 +125,19 @@ var cache = {
* @return {Boolean} true or false if the file was successfully deleted
*/
removeCacheFile: function () {
return del( this._pathToFile );
return del(this._pathToFile);
},
/**
* Destroy the file cache and cache content.
* @method destroy
*/
destroy: function () {
var me = this;
me._visited = { };
me._persisted = { };
me._visited = {};
me._persisted = {};

me.removeCacheFile();
}
},
};

module.exports = {
Expand All @@ -149,28 +149,28 @@ module.exports = {
* @param [cacheDir] {String} directory for the cache entry
* @returns {cache} cache instance
*/
load: function ( docId, cacheDir ) {
return this.create( docId, cacheDir );
load: function (docId, cacheDir) {
return this.create(docId, cacheDir);
},

/**
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
* cache storage.
*
* @method create
* @param docId {String} the id of the cache, would also be used as the name of the file cache
* @param [cacheDir] {String} directory for the cache entry
* @returns {cache} cache instance
*/
create: function ( docId, cacheDir ) {
var obj = Object.create( cache );
obj.load( docId, cacheDir );
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
* cache storage.
*
* @method create
* @param docId {String} the id of the cache, would also be used as the name of the file cache
* @param [cacheDir] {String} directory for the cache entry
* @returns {cache} cache instance
*/
create: function (docId, cacheDir) {
var obj = Object.create(cache);
obj.load(docId, cacheDir);
return obj;
},

createFromFile: function ( filePath ) {
var obj = Object.create( cache );
obj.loadFile( filePath );
createFromFile: function (filePath) {
var obj = Object.create(cache);
obj.loadFile(filePath);
return obj;
},
/**
Expand All @@ -181,17 +181,17 @@ module.exports = {
* @param cacheDir {String} the directory where the cache file was written
* @returns {Boolean} true if the cache folder was deleted. False otherwise
*/
clearCacheById: function ( docId, cacheDir ) {
var filePath = cacheDir ? path.resolve( cacheDir, docId ) : path.resolve( __dirname, './.cache/', docId );
return del( filePath );
clearCacheById: function (docId, cacheDir) {
var filePath = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, './.cache/', docId);
return del(filePath);
},
/**
* Remove all cache stored in the cache directory
* @method clearAll
* @returns {Boolean} true if the cache folder was deleted. False otherwise
*/
clearAll: function ( cacheDir ) {
var filePath = cacheDir ? path.resolve( cacheDir ) : path.resolve( __dirname, './.cache/' );
return del( filePath );
}
clearAll: function (cacheDir) {
var filePath = cacheDir ? path.resolve(cacheDir) : path.resolve(__dirname, './.cache/');
return del(filePath);
},
};
14 changes: 7 additions & 7 deletions del.js
@@ -1,12 +1,12 @@
var rimraf = require( 'rimraf' ).sync;
var fs = require( 'fs' );
var rimraf = require('rimraf').sync;
var fs = require('fs');

module.exports = function del( file ) {
if ( fs.existsSync( file ) ) {
module.exports = function del(file) {
if (fs.existsSync(file)) {
//if rimraf doesn't throw then the file has been deleted or didn't exist
rimraf( file, {
glob: false
} );
rimraf(file, {
glob: false,
});
return true;
}
return false;
Expand Down

0 comments on commit f3235a6

Please sign in to comment.