New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

glob-cache

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-cache - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

# [0.2.0](https://github.com/tunnckoCore/opensource/compare/glob-cache@0.1.4...glob-cache@0.2.0) (2020-01-21)
### Bug Fixes
* update broken docs generation ([e6c743f](https://github.com/tunnckoCore/opensource/commit/e6c743ff89745dcc9d70c3b9628048d1e3047381))
### Features
* **glob-cache:** support node 10; plus more docs ([25b1987](https://github.com/tunnckoCore/opensource/commit/25b1987f132b425c7506dd95bd2cb7df923bbaa7))
## [0.1.4](https://github.com/tunnckoCore/opensource/compare/glob-cache@0.1.3...glob-cache@0.1.4) (2020-01-19)

@@ -8,0 +24,0 @@

11

package.json
{
"name": "glob-cache",
"version": "0.1.4",
"description": "Caching layer (using `cacache`) for any file globbing solution (`glob`, `fast-glob`, `tiny-glob`). Makes you Instant Fast™ and allows you to hook into very specific & important part of the process",
"version": "0.2.0",
"description": "Caching layer (using `cacache`) for any file globbing solution (`glob`, `fast-glob`, `tiny-glob` and `globby`). Makes you Instant Fast™ and allows you to hook into very specific & important part of the process",
"repository": {

@@ -14,3 +14,3 @@ "type": "git",

"engines": {
"node": ">=12.13"
"node": ">=10.18"
},

@@ -87,3 +87,6 @@ "dependencies": {

},
"gitHead": "26c89a642d91e714b8a462405595a22f08f9e6ae"
"devDependencies": {
"rimraf": "^3.0.0"
},
"gitHead": "e34faa45ba57a5d678c507c1da6fe65a7fc54f7c"
}

@@ -10,3 +10,3 @@ <p align="center">

> Caching layer (using `cacache`) for any file globbing solution (`glob`, `fast-glob`, `tiny-glob`). Makes you Instant Fast™ and allows you to hook into very specific & important part of the process
> Caching layer (using `cacache`) for any file globbing solution (`glob`, `fast-glob`, `tiny-glob` and `globby`). Makes you Instant Fast™ and allows you to hook into very specific & important part of the process

@@ -81,3 +81,3 @@ Please consider following this project's author, [Charlike Mike Reagent](https://github.com/tunnckoCore), and :star: the project to show your :heart: and support.

This project requires [**Node.js**](https://nodejs.org) **>=12.13** _(see [Support & Release Policy](https://github.com/tunnckoCoreLabs/support-release-policy))_. Install it using
This project requires [**Node.js**](https://nodejs.org) **>=10.18** _(see [Support & Release Policy](https://github.com/tunnckoCoreLabs/support-release-policy))_. Install it using
[**yarn**](https://yarnpkg.com) or [**npm**](https://npmjs.com).<br>

@@ -96,3 +96,3 @@ _We highly recommend to use Yarn when you think to contribute to this project._

### [globCache](./src/index.js#L46)
### [globCache](./src/index.js#L48)

@@ -115,3 +115,3 @@ Match files and folders using glob patterns. Returns a resolved Promise containing

- `options.hook` **{Function}** - a hook function passed with [Context](#context-and-how-it-works)
- `options.glob` **{Function}** - a globbing library like [glob][], [fast-glob][], [tiny-glob][], defaults to `fast-glob`
- `options.glob` **{Function}** - a globbing library like [glob][], [globby][], [fast-glob][], [tiny-glob][], defaults to `fast-glob`
- `options.globOptions` **{object}** - options passed to the `options.glob` library

@@ -198,2 +198,30 @@ - `options.cacheLocation` **{string}** - a filepath location of the cache, defaults to `./.cache/glob-cache`

And when you run it for the second time, the `cacheFile` won't be `null` anymore, like so
```
{
file: {
path: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/src/index.js',
contents: <Buffer 2f 2a 20 65 73 6c 69 6e 74 2d 64 69 73 61 62 6c 65 20 6e 6f 2d 70 61 72 61 6d 2d 72 65 61 73 73 69 67 6e 20 2a 2f 0a 0a 27 75 73 65 20 73 74 72 69 63 ... 5268 more bytes>,
size: 5318,
integrity: 'sha512-946V9t8jWq6oGdAVnrl206b077+Ejl0VFn/MK1axZdsFyvzGrT+MfzH2aVQOUPMcp8jm5tZvES7A1XXEsRvZ9w=='
},
cacheFile: {
key: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/src/index.js',
integrity: 'sha512-946V9t8jWq6oGdAVnrl206b077+Ejl0VFn/MK1axZdsFyvzGrT+MfzH2aVQOUPMcp8jm5tZvES7A1XXEsRvZ9w==',
path: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/test/fixture-cache/content-v2/sha512/78/84/a154130fdefee002a708cee1ae570db54b1a278fed9b7a3847c73b2545bd48947c2cd192d365f9d87653f098f80d98b4ee37923ba467dbc314acf0f42e39',
size: 5318,
time: 1579561781331,
metadata: undefined
},
cacheLocation: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/test/fixture-cache',
cacache: { /* cacache instance */ },
valid: true,
missing: false
}
```
As you can see above, both the `file.integrity` and `cacheFile.integrity` are the same, also the `size`,
so the both files are equal (and so `valid: true`), and if you didn't put `always: true`, in this case the `hook` won't be called.
One more thing to clarify. When there is no cache, e.g. the state is "missing",

@@ -204,2 +232,54 @@ and if you look over the code you'll see that the `valid` is

In case you use the `options.always: true` option, you may need to have similar check in your `options.hook`:
```js
const JestWorker = require('jest-worker');
let worker = null;
(async () => {
await globCache({
async hook(ctx) {
if (ctx.valid === false || (ctx.valid && ctx.missing)) {
// If we are here, it's either the first run, or
// only when there's a difference between the actual file and the cache file.
// So we can, for example, call our worker/runner or whatever here.
worker =
worker ||
new JestWorker(require.resolve('./my-awesome-worker-or-runner.js'), {
numWorkers: 7,
forkOptions: { stdio: 'inherit' },
});
await worker.default(ctx);
await worker.end();
}
},
});
})();
```
Above you're looking on a basic solution similar to what's done in Jest with the difference
that Jest can detect changes only if it's a Git project. At least the `--onlyChanged`
works that way (with Git requirement) - which isn't a big problem of course since mostly
every project is using Git, but anyway.
The point is, that you can do whatever you want in custom conditions based on your preferences and needs.
In above example you may wonder why we are instatiating JestWorker inside the `if` statement.
That's because if you instantiate it before the call of `globCache` (where is the `let worker` assignment)
then you have no way to end the worker in any meaningful and easy way.
Similar implementation you can see in the [`hela-eslint-workers`](https://github.com/tunnckoCore/opensource/tree/hela-eslint-workers/%40hela/eslint/src) branch
where using `glob-cache` we are trying to speed up ESLint a bit,
by putting `eslint.executeOnFiles` or `eslint.executeOnText` inside a worker.
The thing is that it doesn't help much, because ESLint is just slow - for the same reason
even the `jest-runner-eslint` doesn't help much with performance. The complexity in ESLint
is O(n) - the more configs and plugins you have in your config, the more slow it will run even on a
single file - it's inevitable and a huge problem. I'm not saying all that just to hate.
It's just because of the synchornous design of ESLint and the way it works. A big pain point is
not only that it exposes & uses only sync methods, but also the architecture of resolving huge amount
of configs and plugins. That may change if [RFC#9](https://github.com/eslint/rfcs/pull/9)
is accepted, for which I have big hopes. Even if it's accepted it will take few major releases.
**[back to top](#readme)**

@@ -289,3 +369,3 @@

[last-commit-url]: https://github.com/tunnckoCore/opensource/commits/master
[nodejs-img]: https://badgen.net/badge/node/>=12.13/green?cache=300
[nodejs-img]: https://badgen.net/badge/node/>=10.18/green?cache=300
[downloads-weekly-img]: https://badgen.net/npm/dw/glob-cache?icon=npm&cache=300

@@ -334,2 +414,3 @@ [downloads-monthly-img]: https://badgen.net/npm/dm/glob-cache?icon=npm&cache=300

[glob]: https://github.com/isaacs/node-glob
[globby]: https://github.com/sindresorhus/globby
[tiny-glob]: https://github.com/terkelg/tiny-glob

@@ -6,2 +6,3 @@ /* eslint-disable no-param-reassign */

const fs = require('fs');
const util = require('util');
const crypto = require('crypto');

@@ -12,2 +13,3 @@ const cacache = require('cacache');

const readFile = util.promisify(fs.readFile);
const defaultOptions = {

@@ -42,3 +44,3 @@ include: [],

* @param {Function} options.hook - a hook function passed with [Context](#context-and-how-it-works)
* @param {Function} options.glob - a globbing library like [glob][], [fast-glob][], [tiny-glob][], defaults to `fast-glob`
* @param {Function} options.glob - a globbing library like [glob][], [globby][], [fast-glob][], [tiny-glob][], defaults to `fast-glob`
* @param {object} options.globOptions - options passed to the `options.glob` library

@@ -70,3 +72,3 @@ * @param {string} options.cacheLocation - a filepath location of the cache, defaults to `./.cache/glob-cache`

}
file.contents = await fs.promises.readFile(file.path);
file.contents = await readFile(file.path);
return file;

@@ -144,3 +146,3 @@ }),

}
const contents = await fs.promises.readFile(fp);
const contents = await readFile(fp);
const integrity = integrityFromContents(contents);

@@ -147,0 +149,0 @@ const hash = await cacache.get.hasContent(cacheLoc, integrity);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc