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.3.1 to 0.3.2

11

CHANGELOG.md

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

## [0.3.2](https://github.com/tunnckoCore/opensource/compare/glob-cache@0.3.1...glob-cache@0.3.2) (2020-02-03)
### Bug Fixes
* mass update (docks,configs) + rename workspaces ([61ccee3](https://github.com/tunnckoCore/opensource/commit/61ccee33ca1cce122de9c7d6522a7a2913f65828))
## [0.3.1](https://github.com/tunnckoCore/opensource/compare/glob-cache@0.3.0...glob-cache@0.3.1) (2020-01-24)

@@ -8,0 +19,0 @@

6

package.json
{
"name": "glob-cache",
"version": "0.3.1",
"version": "0.3.2",
"licenseStart": 2020,

@@ -13,3 +13,3 @@ "license": "(Parity-7.0.0 AND Prosperity-3.0.0) OR Patron-1.0.0",

"url": "https://github.com/tunnckoCore/opensource.git",
"directory": "packages/glob-cache"
"directory": "@packages/glob-cache"
},

@@ -93,3 +93,3 @@ "main": "src/index.js",

},
"gitHead": "ad49973baa1ebd832396c69017c32d9fa5d9b5b2"
"gitHead": "53ea9daed9e587e9f61d03f59cbbcad9e5ea1d17"
}

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

> 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
> 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
Please consider following this project's author, [Charlike Mike Reagent](https://github.com/tunnckoCore), and :star: the project to show your :heart: and support.
Please consider following this project's author,
[Charlike Mike Reagent](https://github.com/tunnckoCore), and :star: the project
to show your :heart: and support.

@@ -26,5 +30,6 @@ <div id="readme"></div>

If you have any _how-to_ kind of questions, please read the [Contributing Guide][contributing-url] and [Code of Conduct][code_of_conduct-url] documents.
For bugs reports and feature requests, [please create an issue][open-issue-url] or ping
[@tunnckoCore](https://twitter.com/tunnckoCore) at Twitter.
If you have any _how-to_ kind of questions, please read the [Contributing
Guide][contributing-url] and [Code of Conduct][code_of_conduct-url] documents.
For bugs reports and feature requests, [please create an issue][open-issue-url]
or ping [@tunnckoCore](https://twitter.com/tunnckoCore) at Twitter.

@@ -38,3 +43,5 @@ [![Conventional Commits][ccommits-img]][ccommits-url]

Project is [semantically](https://semver.org) versioned & automatically released from [GitHub Actions](https://github.com/features/actions) with [Lerna](https://github.com/lerna/lerna).
Project is [semantically](https://semver.org) versioned & automatically released
from [GitHub Actions](https://github.com/features/actions) with
[Lerna](https://github.com/lerna/lerna).

@@ -64,24 +71,25 @@ [![Become a Patron][patreon-img]][patreon-url]

<!-- highlights -->
## Table of Contents
- [Install](#install)
- [API](#api)
- [globCache](#globcache)
- [Context and how it works](#context-and-how-it-works)
- [Signature](#signature)
- [Params](#params)
- [Examples](#examples)
- [Contributing](#contributing)
- [Guides and Community](#guides-and-community)
- [Support the project](#support-the-project)
- [OPEN Open Source](#open-open-source)
- [Wonderful Contributors](#wonderful-contributors)
- [Contributors](#contributors)
- [License](#license)
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
_(TOC generated by [verb](https://github.com/verbose/verb) using
[markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
## Install
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>
_We highly recommend to use Yarn when you think to contribute to this project._
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> _We highly recommend to use Yarn when you
think to contribute to this project._

@@ -94,4 +102,2 @@ ```bash

## API
_Generated using [jest-runner-docs](https://ghub.now.sh/jest-runner-docs)._

@@ -101,8 +107,11 @@

Match files and folders using glob patterns. Returns a resolved Promise containing
a `{ results, cacache }` object - where `results` is an array of [Context](#context-and-how-it-works) objects
and `cacache` is the [cacache][] package.
Match files and folders using glob patterns. Returns a resolved Promise
containing a `{ results, cacache }` object - where `results` is an array of
[Context](#context-and-how-it-works) objects and `cacache` is the [cacache][]
package.
**Signature**
<span id="globcache-signature"></span>
#### Signature
```ts

@@ -113,15 +122,24 @@ function(options)

<span id="globcache-params"></span>
**Params**
- `options.include` **{Array&lt;string&gt;}** - string or array of string glob patterns
#### Params
- `options.include` **{Array&lt;string&gt;}** - string or array of string glob
patterns
- `options.exclude` **{string}** - ignore patterns
- `options.always` **{boolean}** - a boolean that makes `options.hook` to always be called
- `options.hook` **{Function}** - a hook function passed with [Context](#context-and-how-it-works)
- `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
- `options.cacheLocation` **{string}** - a filepath location of the cache, defaults to `./.cache/glob-cache`
- `options.always` **{boolean}** - a boolean that makes `options.hook` to always
be called
- `options.hook` **{Function}** - a hook function passed with
[Context](#context-and-how-it-works)
- `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
- `options.cacheLocation` **{string}** - a filepath location of the cache,
defaults to `./.cache/glob-cache`
- `returns` **{Promise}**
**Example**
<span id="globcache-examples"></span>
#### Examples
```js

@@ -138,151 +156,2 @@ const tinyGlob = require('tiny-glob');

## Context and how it works
Each context contains a `{ file, cacheFile, cacheLocation, cacache }` and more properties.
The `file` one represents the fresh file loaded from the system, the `cacheFile` represents the
file from the cache. Both has `path`, `size` and `integrity` properties, plus more.
The `cacheFile` can be `null` if it's the first hit (not found in cache),
in such case the `ctx.missing` will be `true` and on next runs this will be `false`.
Important to note is that `cacheFile` don't have a `contents` property, but has `path`
which points to the place of the cache file on the disk.
The interesting one is the `ctx.valid`. This one is the reason for the whole existance
of this module. If both the "source" file and cache file are the same,
e.g. same size and integrity (which means the contents/shasum are equal),
then `ctx.valid: true`, otherwise this will be `false`. Simply said, when you change your file(s)
matched by a the given glob pattern(s), then it will be `valid: false` and the `options.hook` will
be called.
There is also one more key point, and it's in the `options`. We have `options.hook` and
`options.always`. By default we only call the `options.hook` when `valid: false` which is
important and intentional, because most of the time you only want to do or run something
when there are actual changes in the files, right? But there are also a cases when you want
more control, that's why we have `options.always` option which bypass the previous validation
and so the `options.hook` will always be called and so you can decide what to do or
make more additional checks - for example, listen the `mtime` - or track the dependencies
of the file. Tracking dependencies is something that some test runner may benefit.
Because all that, we also expose `cacache` to that `options.hook`,
so you can update or clean the cache - it's up to you.
Example `results` array with context (which is also passed to `options.hook`):
```
[
{
file: {
path: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/test/index.js',
contents: <Buffer 27 75 73 65 20 73 74 72 69 63 74 27 3b 0a 0a 63 6f 6e 73 74 20 70 61 74 68 20 3d 20 72 65 71 75 69 72 65 28 27 70 61 74 68 27 29 3b 0a 63 6f 6e 73 74 ... 350 more bytes>,
size: 400,
integrity: 'sha512-p5daDYwu9vhNNjT9vfRrWHXIwwlPxeqeub4gs3qMZ88J//ONUH7Je2Muu9o+MxjA1Fv3xwbgkBdjcHgdj7ar4A=='
},
cacheFile: null,
cacheLocation: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/test/fixture-cache',
cacache: { /* cacache instance */ },
valid: true,
missing: true
},
{
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: null,
cacheLocation: '/home/charlike/github/tunnckoCore/opensource/packages/glob-cache/test/fixture-cache',
cacache: { /* cacache instance */ },
valid: true,
missing: true
}
]
```
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",
and if you look over the code you'll see that the `valid` is
hard-coded/forced to be `true`. You may expect the hook to be called in the first run
but it will not. For that behavior you should use the `always: true`.
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)**

@@ -294,45 +163,51 @@

Please read the [Contributing Guide][contributing-url] and [Code of Conduct][code_of_conduct-url] documents for advices.
Please read the [Contributing Guide][contributing-url] and [Code of
Conduct][code_of_conduct-url] documents for advices.
For bug reports and feature requests, please join our [community][community-url] forum and open a thread there with prefixing the title of the thread with the name of the project if there's no separate channel for it.
For bug reports and feature requests, please join our [community][community-url]
forum and open a thread there with prefixing the title of the thread with the
name of the project if there's no separate channel for it.
Consider reading the [Support and Release Policy](https://github.com/tunnckoCoreLabs/support-release-policy) guide if you are interested in what are the supported Node.js versions and how we proceed. In short, we support latest two even-numbered Node.js release lines.
Consider reading the
[Support and Release Policy](https://github.com/tunnckoCoreLabs/support-release-policy)
guide if you are interested in what are the supported Node.js versions and how
we proceed. In short, we support latest two even-numbered Node.js release lines.
### Support the project
[Become a Partner or Sponsor?][patreon-url] :dollar: Check the **Partner**, **Sponsor** or **Omega-level** tiers! :tada: You can get your company logo, link & name on this file. It's also rendered on package page in [npmjs.com][npmv-url] and [yarnpkg.com](https://yarnpkg.com/en/package/glob-cache) sites too! :rocket:
[Become a Partner or Sponsor?][kofi-url] :dollar: Check the **OpenSource**
Commision (tier). :tada: You can get your company logo, link & name on this
file. It's also rendered on package's page in [npmjs.com][npmv-url] and
[yarnpkg.com](https://yarnpkg.com/en/package/glob-cache) sites too! :rocket:
Not financial support? Okey! [Pull requests](https://github.com/tunnckoCoreLabs/contributing#opening-a-pull-request), stars and all kind of [contributions](https://opensource.guide/how-to-contribute/#what-it-means-to-contribute) are always
welcome. :sparkles:
Not financial support? Okey!
[Pull requests](https://github.com/tunnckoCoreLabs/contributing#opening-a-pull-request),
stars and all kind of
[contributions](https://opensource.guide/how-to-contribute/#what-it-means-to-contribute)
are always welcome. :sparkles:
<!--
### OPEN Open Source
## Contributors
This project is following [OPEN Open Source](http://openopensource.org) model
This project follows the
[all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind are welcome!
> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is built on collective efforts and it's not strongly guarded by its founders.
Thanks goes to these wonderful people
([emoji key](https://allcontributors.org/docs/en/emoji-key)), consider showing
your [support](#support-the-project) to them:
There are a few basic ground-rules for its contributors
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://tunnckoCore.com"><img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="100px;" alt=""/><br /><sub><b>Charlike Mike Reagent</b></sub></a><br /><a href="#infra-tunnckoCore" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=tunnckoCore" title="Code">💻</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=tunnckoCore" title="Documentation">📖</a> <a href="#ideas-tunnckoCore" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-tunnckoCore" title="Maintenance">🚧</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=tunnckoCore" title="Tests">⚠️</a></td>
</tr>
</table>
1. Any **significant modifications** must be subject to a pull request to get feedback from other contributors.
2. [Pull requests](https://github.com/tunnckoCoreLabs/contributing#opening-a-pull-request) to get feedback are _encouraged_ for any other trivial contributions, but are not required.
3. Contributors should attempt to adhere to the prevailing code-style and development workflow.
-->
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
### Wonderful Contributors
Thanks to the hard work of these wonderful people this project is alive! It follows the
[all-contributors](https://github.com/kentcdodds/all-contributors) specification.
Don't hesitate to add yourself to that list if you have made any contribution! ;) [See how,
here](https://github.com/jfmengels/all-contributors-cli#usage).
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="120px;"/><br /><sub><b>Charlike Mike Reagent</b></sub>](https://tunnckocore.com)<br />[💻](https://github.com/tunnckoCore/opensource/commits?author=tunnckoCore "Code") [📖](https://github.com/tunnckoCore/opensource/commits?author=tunnckoCore "Documentation") [💬](#question-tunnckoCore "Answering Questions") [👀](#review-tunnckoCore "Reviewed Pull Requests") [🔍](#fundingFinding-tunnckoCore "Funding Finding") |
| :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
Consider showing your [support](#support-the-project) to them. :sparkling_heart:
**[back to top](#readme)**

@@ -342,5 +217,11 @@

Copyright (c) 2020-present, [Charlike Mike Reagent](https://tunnckocore.com) `<opensource@tunnckocore.com>` & [contributors](#wonderful-contributors).<br>
Released under the [(Parity-7.0.0 AND Prosperity-3.0.0) OR Patron-1.0.0 License][license-url].
Copyright (c) 2020-present, [Charlike Mike Reagent](https://tunnckocore.com)
`<opensource@tunnckocore.com>` & [contributors](#wonderful-contributors).<br>
Released under the [(Parity-7.0.0 AND Prosperity-3.0.0) OR Patron-1.0.0
License][license-url].
<!-- badges -->
<!-- prettier-ignore-start -->
[contributing-url]: https://github.com/tunnckoCore/opensource/blob/master/CONTRIBUTING.md

@@ -353,4 +234,6 @@ [code_of_conduct-url]: https://github.com/tunnckoCore/opensource/blob/master/CODE_OF_CONDUCT.md

[npmv-img]: https://badgen.net/npm/v/glob-cache?icon=npm&cache=300
[license-url]: https://github.com/tunnckoCore/opensource/blob/master/packages/glob-cache/LICENSE
[license-img]: https://badgen.net/npm/license/glob-cache?cache=300
[libera-manifesto-url]: https://liberamanifesto.com

@@ -362,21 +245,32 @@ [libera-manifesto-img]: https://badgen.net/badge/libera/manifesto/grey

[codecoverage-img]: https://badgen.net/badge/coverage/100%25/green?icon=codecov&cache=300
[codecoverage-url]: https://codecov.io/gh/tunnckoCore/opensource
[codestyle-url]: https://github.com/airbnb/javascript
[codestyle-img]: https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb&cache=300
[linuxbuild-url]: https://github.com/tunnckocore/opensource/actions
[linuxbuild-img]: https://badgen.net/github/checks/tunnckoCore/opensource/master?cache=300&label=build&icon=github
[ccommits-url]: https://conventionalcommits.org/
[ccommits-img]: https://badgen.net/badge/conventional%20commits/v1.0.0/green?cache=300
[standard-release-url]: https://github.com/standard-release/standard-release
[standard-release-img]: https://badgen.net/badge/semantically/released/05c5ff?cache=300
[community-img]: https://badgen.net/badge/join/community/7b16ff?cache=300
[community-url]: https://github.com/tunnckocorehq/community
[last-commit-img]: https://badgen.net/github/last-commit/tunnckoCore/opensource/master?cache=300
[last-commit-url]: https://github.com/tunnckoCore/opensource/commits/master
[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
[downloads-monthly-img]: https://badgen.net/npm/dm/glob-cache?icon=npm&cache=300
[downloads-total-img]: https://badgen.net/npm/dt/glob-cache?icon=npm&cache=300
[renovateapp-url]: https://renovatebot.com
[renovateapp-img]: https://badgen.net/badge/renovate/enabled/green?cache=300
[prs-welcome-img]: https://badgen.net/badge/PRs/welcome/green?cache=300

@@ -417,2 +311,5 @@ [prs-welcome-url]: http://makeapullrequest.com

[tunnckocore_newsletter]: https://badgen.net/https/liam-badge-daknys6gadky.runkit.sh/com/newsletter/tunnckocore?label&color=5199FF&icon=https://svgshare.com/i/Dt6.svg
<!-- prettier-ignore-end -->
[cacache]: https://github.com/npm/cacache

@@ -419,0 +316,0 @@ [fast-glob]: https://github.com/mrmlnc/fast-glob

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