├── blah ├── .npmrc ├── .gitattributes ├── .prettierignore ├── .huskyrc.js ├── .prettierrc.js ├── types ├── cache-manager-fs │ └── index.d.ts └── .eslintrc ├── tsconfig.json ├── .gitignore ├── CHANGELOG.md ├── .github ├── dependabot.yml ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── validate.yml ├── other ├── USERS.md ├── manual-releases.md └── MAINTAINING.md ├── src ├── __tests__ │ └── index.ts └── index.ts ├── LICENSE ├── .all-contributorsrc ├── package.json ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md └── README.md /blah: -------------------------------------------------------------------------------- 1 | thing -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | dist 4 | -------------------------------------------------------------------------------- /.huskyrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require('kcd-scripts/husky') 2 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require('kcd-scripts/prettier') 2 | -------------------------------------------------------------------------------- /types/cache-manager-fs/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'cache-manager-fs' 2 | -------------------------------------------------------------------------------- /types/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "project": "tsconfig.json" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/kcd-scripts/shared-tsconfig.json", 3 | "compilerOptions": { 4 | "typeRoots": ["./node_modules/@types", "./types"] 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | dist 4 | .DS_Store 5 | 6 | # these cause more harm than good 7 | # when working with contributors 8 | package-lock.json 9 | yarn.lock 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | The changelog is automatically updated using 4 | [semantic-release](https://github.com/semantic-release/semantic-release). You 5 | can see it on the [releases page](../../releases). 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: daily 7 | 8 | - package-ecosystem: npm 9 | directory: / 10 | schedule: 11 | interval: daily 12 | -------------------------------------------------------------------------------- /other/USERS.md: -------------------------------------------------------------------------------- 1 | # Users 2 | 3 | If you or your company uses this project, add your name to this list! Eventually 4 | we may have a website to showcase these (wanna build it!?) 5 | 6 | > No users have been added yet! 7 | 8 | 13 | -------------------------------------------------------------------------------- /src/__tests__/index.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs-extra' 2 | 3 | import Cache from '../' 4 | 5 | let cache: Cache | null = null 6 | 7 | afterEach(() => { 8 | if (cache) fs.removeSync(cache.directory) 9 | }) 10 | 11 | test('caches values', async () => { 12 | const key = 'MY_KEY' 13 | const value = 'MY_VALUE' 14 | cache = new Cache() 15 | expect(await cache.get(key)).toBe(null) 16 | await cache.set(key, value) 17 | expect(await cache.get(key)).toBe(value) 18 | 19 | // removing the cache directory causes errors 20 | fs.removeSync(cache.directory) 21 | expect(await cache.get(key)).toBe(undefined) 22 | 23 | // removing the cache directory causes errors 24 | // but we recover from those kinds of errors 25 | fs.removeSync(cache.directory) 26 | expect(await cache.set(key, value)).toBe(value) 27 | }) 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 13 | 14 | - `@remark-embedder/cache` version: 15 | - `node` version: 16 | - `npm` version: 17 | 18 | Relevant code or config 19 | 20 | ```js 21 | 22 | ``` 23 | 24 | What you did: 25 | 26 | What happened: 27 | 28 | 29 | 30 | Reproduction repository: 31 | 32 | 36 | 37 | Problem description: 38 | 39 | Suggested solution: 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2020 Kent C. Dodds 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "cache", 3 | "projectOwner": "remark-embedder", 4 | "imageSize": 100, 5 | "commit": false, 6 | "contributorsPerLine": 7, 7 | "repoHost": "https://github.com", 8 | "repoType": "github", 9 | "skipCi": false, 10 | "files": [ 11 | "README.md" 12 | ], 13 | "contributors": [ 14 | { 15 | "login": "kentcdodds", 16 | "name": "Kent C. Dodds", 17 | "avatar_url": "https://avatars.githubusercontent.com/u/1500684?v=3", 18 | "profile": "https://kentcdodds.com", 19 | "contributions": [ 20 | "code", 21 | "doc", 22 | "infra", 23 | "test" 24 | ] 25 | }, 26 | { 27 | "login": "MichaelDeBoey", 28 | "name": "Michaël De Boey", 29 | "avatar_url": "https://avatars3.githubusercontent.com/u/6643991?v=4", 30 | "profile": "https://michaeldeboey.be", 31 | "contributions": [ 32 | "doc", 33 | "code", 34 | "maintenance" 35 | ] 36 | }, 37 | { 38 | "login": "andreashouben", 39 | "name": "Andreas Houben", 40 | "avatar_url": "https://avatars3.githubusercontent.com/u/3708288?v=4", 41 | "profile": "https://github.com/andreashouben", 42 | "contributions": [ 43 | "doc" 44 | ] 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | **What**: 20 | 21 | 22 | 23 | **Why**: 24 | 25 | 26 | 27 | **How**: 28 | 29 | 30 | 31 | **Checklist**: 32 | 33 | 34 | 35 | 36 | - [ ] Documentation 37 | - [ ] Tests 38 | - [ ] Ready to be merged 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /other/manual-releases.md: -------------------------------------------------------------------------------- 1 | # manual-releases 2 | 3 | This project has an automated release set up. So things are only released when 4 | there are useful changes in the code that justify a release. But sometimes 5 | things get messed up one way or another and we need to trigger the release 6 | ourselves. When this happens, simply bump the number below and commit that with 7 | the following commit message based on your needs: 8 | 9 | **Major** 10 | 11 | ``` 12 | fix(release): manually release a major version 13 | 14 | There was an issue with a major release, so this manual-releases.md 15 | change is to release a new major version. 16 | 17 | Reference: # 18 | 19 | BREAKING CHANGE: 20 | ``` 21 | 22 | **Minor** 23 | 24 | ``` 25 | feat(release): manually release a minor version 26 | 27 | There was an issue with a minor release, so this manual-releases.md 28 | change is to release a new minor version. 29 | 30 | Reference: # 31 | ``` 32 | 33 | **Patch** 34 | 35 | ``` 36 | fix(release): manually release a patch version 37 | 38 | There was an issue with a patch release, so this manual-releases.md 39 | change is to release a new patch version. 40 | 41 | Reference: # 42 | ``` 43 | 44 | The number of times we've had to do a manual release is: 0 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@remark-embedder/cache", 3 | "version": "0.0.0-semantically-released", 4 | "publishConfig": { 5 | "access": "public" 6 | }, 7 | "description": "A cache for @remark-embedder/core", 8 | "main": "dist/index.js", 9 | "types": "dist/index.d.ts", 10 | "keywords": [], 11 | "author": "Kent C. Dodds (https://kentcdodds.com)", 12 | "license": "MIT", 13 | "engines": { 14 | "node": ">=12", 15 | "npm": ">=6" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/remark-embedder/cache" 20 | }, 21 | "bugs": { 22 | "url": "https://github.com/remark-embedder/cache/issues" 23 | }, 24 | "homepage": "https://github.com/remark-embedder/cache#readme", 25 | "files": [ 26 | "dist" 27 | ], 28 | "scripts": { 29 | "build": "kcd-scripts build", 30 | "lint": "kcd-scripts lint", 31 | "setup": "npm install && npm run validate -s", 32 | "test": "kcd-scripts test", 33 | "test:update": "npm test -- --updateSnapshot --coverage", 34 | "typecheck": "kcd-scripts typecheck", 35 | "validate": "kcd-scripts validate" 36 | }, 37 | "dependencies": { 38 | "@babel/runtime": "^7.18.9", 39 | "@types/cache-manager": "^4.0.1", 40 | "@types/fs-extra": "^9.0.13", 41 | "cache-manager": "^4.1.0", 42 | "cache-manager-fs": "^1.0.9", 43 | "fs-extra": "^10.1.0" 44 | }, 45 | "devDependencies": { 46 | "@types/jest": "^28.1.6", 47 | "kcd-scripts": "^12.2.0", 48 | "typescript": "^4.7.4" 49 | }, 50 | "eslintConfig": { 51 | "extends": "./node_modules/kcd-scripts/eslint.js" 52 | }, 53 | "eslintIgnore": [ 54 | "node_modules", 55 | "coverage", 56 | "dist" 57 | ] 58 | } 59 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for being willing to contribute! 4 | 5 | **Working on your first Pull Request?** You can learn how from this _free_ 6 | series [How to Contribute to an Open Source Project on GitHub][egghead] 7 | 8 | ## Project setup 9 | 10 | 1. Fork and clone the repo 11 | 2. Run `npm run setup -s` to install dependencies and run validation 12 | 3. Create a branch for your PR with `git checkout -b pr/your-branch-name` 13 | 14 | > Tip: Keep your `main` branch pointing at the original repository and make pull 15 | > requests from branches on your fork. To do this, run: 16 | > 17 | > ``` 18 | > git remote add upstream https://github.com/remark-embedder/cache 19 | > git fetch upstream 20 | > git branch --set-upstream-to=upstream/main main 21 | > ``` 22 | > 23 | > This will add the original repository as a "remote" called "upstream," Then 24 | > fetch the git information from that remote, then set your local `main` branch 25 | > to use the upstream main branch whenever you run `git pull`. Then you can make 26 | > all of your pull request branches based on this `main` branch. Whenever you 27 | > want to update your version of `main`, do a regular `git pull`. 28 | 29 | ## Committing and Pushing changes 30 | 31 | Please make sure to run the tests before you commit your changes. You can run 32 | `npm run test:update` which will update any snapshots that need updating. Make 33 | sure to include those changes (if they exist) in your commit. 34 | 35 | ## Help needed 36 | 37 | Please checkout the [the open issues][issues] 38 | 39 | Also, please watch the repo and respond to questions/bug reports/feature 40 | requests! Thanks! 41 | 42 | 43 | [egghead]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github 44 | [issues]: https://github.com/remark-embedder/cache/issues 45 | 46 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | 3 | import cacheManager, {type Cache as CMCache, type Store} from 'cache-manager' 4 | import fsStore from 'cache-manager-fs' 5 | import fs from 'fs-extra' 6 | 7 | const TTL = Number.MAX_SAFE_INTEGER 8 | 9 | class Cache { 10 | cache: CMCache 11 | directory: string 12 | 13 | constructor( 14 | directory = path.join( 15 | process.cwd(), 16 | 'node_modules/.cache/@remark-embedder/cache', 17 | ), 18 | ) { 19 | this.directory = directory 20 | this.ensureCacheDirExists() 21 | this.cache = cacheManager.caching({ 22 | store: fsStore as Store, 23 | ttl: TTL, 24 | options: { 25 | ttl: TTL, 26 | path: this.directory, 27 | }, 28 | }) 29 | } 30 | 31 | ensureCacheDirExists() { 32 | fs.ensureDirSync(this.directory) 33 | } 34 | 35 | get(key: string): Promise { 36 | return new Promise(resolve => { 37 | this.cache.get( 38 | key, 39 | ( 40 | error: NodeJS.ErrnoException | undefined, 41 | result: string | undefined, 42 | ) => { 43 | if (error?.code === 'ENOENT') { 44 | this.ensureCacheDirExists() 45 | } 46 | 47 | resolve(error ? undefined : result) 48 | }, 49 | ) 50 | }) 51 | } 52 | 53 | set(key: string, value: string): Promise { 54 | return new Promise(resolve => { 55 | this.cache.set( 56 | key, 57 | value, 58 | {ttl: TTL}, 59 | (err: NodeJS.ErrnoException | undefined) => { 60 | if (err?.code === 'ENOENT') { 61 | this.ensureCacheDirExists() 62 | resolve(this.set(key, value)) 63 | } else { 64 | // istanbul ignore next because I'm not sure how to reproduce this situation 65 | resolve(err ? undefined : value) 66 | } 67 | }, 68 | ) 69 | }) 70 | } 71 | } 72 | 73 | export default Cache 74 | -------------------------------------------------------------------------------- /.github/workflows/validate.yml: -------------------------------------------------------------------------------- 1 | name: validate 2 | on: 3 | push: 4 | branches: 5 | - '+([0-9])?(.{+([0-9]),x}).x' 6 | - 'main' 7 | - 'next' 8 | - 'next-major' 9 | - 'beta' 10 | - 'alpha' 11 | - '!all-contributors/**' 12 | pull_request: {} 13 | jobs: 14 | main: 15 | # ignore all-contributors PRs 16 | if: ${{ !contains(github.head_ref, 'all-contributors') }} 17 | strategy: 18 | matrix: 19 | node: [lts/-1, lts/*, latest] 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: 🛑 Cancel Previous Runs 23 | uses: styfle/cancel-workflow-action@0.11.0 24 | 25 | - name: ⬇️ Checkout repo 26 | uses: actions/checkout@v5 27 | 28 | - name: ⎔ Setup node 29 | uses: actions/setup-node@v6 30 | with: 31 | node-version: ${{ matrix.node }} 32 | 33 | - name: 📥 Download deps 34 | uses: bahmutov/npm-install@v1 35 | with: 36 | useLockFile: false 37 | 38 | - name: ▶️ Run validate script 39 | run: npm run validate 40 | 41 | - name: ⬆️ Upload coverage report 42 | uses: codecov/codecov-action@v3 43 | 44 | release: 45 | needs: main 46 | runs-on: ubuntu-latest 47 | permissions: 48 | contents: write # to be able to publish a GitHub release 49 | id-token: write # to enable use of OIDC for npm provenance 50 | issues: write # to be able to comment on released issues 51 | pull-requests: write # to be able to comment on released pull requests 52 | if: 53 | ${{ github.repository == 'remark-embedder/cache' && 54 | contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha', 55 | github.ref) && github.event_name == 'push' }} 56 | steps: 57 | - name: 🛑 Cancel Previous Runs 58 | uses: styfle/cancel-workflow-action@0.11.0 59 | 60 | - name: ⬇️ Checkout repo 61 | uses: actions/checkout@v5 62 | 63 | - name: ⎔ Setup node 64 | uses: actions/setup-node@v6 65 | with: 66 | node-version: lts/* 67 | 68 | - name: 📥 Download deps 69 | uses: bahmutov/npm-install@v1 70 | with: 71 | useLockFile: false 72 | 73 | - name: 🏗 Run build script 74 | run: npm run build 75 | 76 | - name: 🚀 Release 77 | uses: cycjimmy/semantic-release-action@v5 78 | with: 79 | semantic_version: 25 80 | branches: | 81 | [ 82 | '+([0-9])?(.{+([0-9]),x}).x', 83 | 'main', 84 | 'next', 85 | 'next-major', 86 | {name: 'beta', prerelease: true}, 87 | {name: 'alpha', prerelease: true} 88 | ] 89 | env: 90 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 91 | -------------------------------------------------------------------------------- /other/MAINTAINING.md: -------------------------------------------------------------------------------- 1 | # Maintaining 2 | 3 | 4 | 5 | 6 | **Table of Contents** 7 | 8 | - [Code of Conduct](#code-of-conduct) 9 | - [Issues](#issues) 10 | - [Pull Requests](#pull-requests) 11 | - [Release](#release) 12 | - [Thanks!](#thanks) 13 | 14 | 15 | 16 | This is documentation for maintainers of this project. 17 | 18 | ## Code of Conduct 19 | 20 | Please review, understand, and be an example of it. Violations of the code of 21 | conduct are taken seriously, even (especially) for maintainers. 22 | 23 | ## Issues 24 | 25 | We want to support and build the community. We do that best by helping people 26 | learn to solve their own problems. We have an issue template and hopefully most 27 | folks follow it. If it's not clear what the issue is, invite them to create a 28 | minimal reproduction of what they're trying to accomplish or the bug they think 29 | they've found. 30 | 31 | Once it's determined that a code change is necessary, point people to 32 | [makeapullrequest.com](https://makeapullrequest.com) and invite them to make a 33 | pull request. If they're the one who needs the feature, they're the one who can 34 | build it. If they need some hand holding and you have time to lend a hand, 35 | please do so. It's an investment into another human being, and an investment 36 | into a potential maintainer. 37 | 38 | Remember that this is open source, so the code is not yours, it's ours. If 39 | someone needs a change in the codebase, you don't have to make it happen 40 | yourself. Commit as much time to the project as you want/need to. Nobody can ask 41 | any more of you than that. 42 | 43 | ## Pull Requests 44 | 45 | As a maintainer, you're fine to make your branches on the main repo or on your 46 | own fork. Either way is fine. 47 | 48 | When we receive a pull request, a GitHub Action is kicked off automatically (see 49 | the `.github/workflows/validate.yml` for what runs in the Action). We avoid 50 | merging anything that breaks the GitHub Action. 51 | 52 | Please review PRs and focus on the code rather than the individual. You never 53 | know when this is someone's first ever PR and we want their experience to be as 54 | positive as possible, so be uplifting and constructive. 55 | 56 | When you merge the pull request, 99% of the time you should use the 57 | [Squash and merge](https://help.github.com/articles/merging-a-pull-request/) 58 | feature. This keeps our git history clean, but more importantly, this allows us 59 | to make any necessary changes to the commit message so we release what we want 60 | to release. See the next section on Releases for more about that. 61 | 62 | ## Release 63 | 64 | Our releases are automatic. They happen whenever code lands into `main`. A 65 | GitHub Action gets kicked off and if it's successful, a tool called 66 | [`semantic-release`](https://github.com/semantic-release/semantic-release) is 67 | used to automatically publish a new release to npm as well as a changelog to 68 | GitHub. It is only able to determine the version and whether a release is 69 | necessary by the git commit messages. With this in mind, **please brush up on 70 | [the commit message convention][commit] which drives our releases.** 71 | 72 | > One important note about this: Please make sure that commit messages do NOT 73 | > contain the words "BREAKING CHANGE" in them unless we want to push a major 74 | > version. I've been burned by this more than once where someone will include 75 | > "BREAKING CHANGE: None" and it will end up releasing a new major version. Not 76 | > a huge deal honestly, but kind of annoying... 77 | 78 | ## Thanks! 79 | 80 | Thank you so much for helping to maintain this project! 81 | 82 | 83 | [commit]: https://github.com/conventional-changelog-archived-repos/conventional-changelog-angular/blob/ed32559941719a130bb0327f886d6a32a8cbc2ba/convention.md 84 | 85 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | - Demonstrating empathy and kindness toward other people 21 | - Being respectful of differing opinions, viewpoints, and experiences 22 | - Giving and gracefully accepting constructive feedback 23 | - Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | - Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | - The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | - Trolling, insulting or derogatory comments, and personal or political attacks 33 | - Public or private harassment 34 | - Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | - Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | me+coc@kentcdodds.com. All complaints will be reviewed and investigated promptly 64 | and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series of 86 | actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or permanent 93 | ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within the 113 | community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by 122 | [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

@remark-embedder/cache

3 | 4 |

A cache for @remark-embedder/core

5 |
6 | 7 | --- 8 | 9 | 10 | [![Build Status][build-badge]][build] 11 | [![Code Coverage][coverage-badge]][coverage] 12 | [![version][version-badge]][package] 13 | [![downloads][downloads-badge]][npmtrends] 14 | [![MIT License][license-badge]][license] 15 | [![All Contributors][all-contributors-badge]](#contributors-) 16 | [![PRs Welcome][prs-badge]][prs] 17 | [![Code of Conduct][coc-badge]][coc] 18 | 19 | 20 | ## The problem 21 | 22 | You're using [`@remark-embedder/core`][@remark-embedder/core] and you want to 23 | cache the results of your transformers long-term so you don't have to make 24 | network requests for HTML every time. 25 | 26 | ## This solution 27 | 28 | This is a cache implementation specifically for 29 | [`@remark-embedder/core`][@remark-embedder/core] that saves the results of 30 | `getHTML` for a transformer to disk (in `node_modules/.cache` by default). 31 | 32 | ## Table of Contents 33 | 34 | 35 | 36 | 37 | - [Installation](#installation) 38 | - [Usage](#usage) 39 | - [Inspiration](#inspiration) 40 | - [Other Solutions](#other-solutions) 41 | - [Issues](#issues) 42 | - [🐛 Bugs](#-bugs) 43 | - [💡 Feature Requests](#-feature-requests) 44 | - [Contributors ✨](#contributors-) 45 | - [LICENSE](#license) 46 | 47 | 48 | 49 | ## Installation 50 | 51 | This module is distributed via [npm][npm] which is bundled with [node][node] and 52 | should be installed as one of your project's `dependencies`: 53 | 54 | ```shell 55 | npm install @remark-embedder/cache 56 | ``` 57 | 58 | ## Usage 59 | 60 | ```ts 61 | import Cache from '@remark-embedder/cache' 62 | 63 | const cache = new Cache() 64 | 65 | async function go() { 66 | const result = await remark() 67 | .use(remarkEmbedder, { 68 | cache, 69 | transformers: [ 70 | // transformers 71 | ], 72 | }) 73 | .use(html) 74 | .process(someMarkdown) 75 | } 76 | 77 | go().then(go).then(go).then(go) 78 | 79 | // your transformers will only be called once even though we call process 4 times. 80 | ``` 81 | 82 | The default directory is pretty reasonable: 83 | `path.join(process.cwd(), 'node_modules/.cache/@remark-embedder/cache')`, but if 84 | you want to change it, that's the first argument of the `Cache` constructor: 85 | `new Cache(directory)`. 86 | 87 | ## Inspiration 88 | 89 | - [Gatsby's built-in plugin cache][gatsby-plugin-cache-source] 90 | 91 | ## Other Solutions 92 | 93 | I'm not aware of any, if you are please [make a pull request][prs] and add it 94 | here! 95 | 96 | ## Issues 97 | 98 | _Looking to contribute? Look for the [Good First Issue][good-first-issue] 99 | label._ 100 | 101 | ### 🐛 Bugs 102 | 103 | Please file an issue for bugs, missing documentation, or unexpected behavior. 104 | 105 | [**See Bugs**][bugs] 106 | 107 | ### 💡 Feature Requests 108 | 109 | Please file an issue to suggest new features. Vote on feature requests by adding 110 | a 👍. This helps maintainers prioritize what to work on. 111 | 112 | [**See Feature Requests**][requests] 113 | 114 | ## Contributors ✨ 115 | 116 | Thanks goes to these people ([emoji key][emojis]): 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |

Kent C. Dodds

💻 📖 🚇 ⚠️

Michaël De Boey

📖 💻 🚧

Andreas Houben

📖
128 | 129 | 130 | 131 | 132 | 133 | 134 | This project follows the [all-contributors][all-contributors] specification. 135 | Contributions of any kind welcome! 136 | 137 | ## LICENSE 138 | 139 | MIT 140 | 141 | 142 | [npm]: https://www.npmjs.com 143 | [node]: https://nodejs.org 144 | [build-badge]: https://img.shields.io/github/workflow/status/remark-embedder/cache/validate?logo=github&style=flat-square 145 | [build]: https://github.com/remark-embedder/cache/actions?query=workflow%3Avalidate 146 | [coverage-badge]: https://img.shields.io/codecov/c/github/remark-embedder/cache.svg?style=flat-square 147 | [coverage]: https://codecov.io/github/remark-embedder/cache 148 | [version-badge]: https://img.shields.io/npm/v/@remark-embedder/cache.svg?style=flat-square 149 | [package]: https://www.npmjs.com/package/@remark-embedder/cache 150 | [downloads-badge]: https://img.shields.io/npm/dm/@remark-embedder/cache.svg?style=flat-square 151 | [npmtrends]: https://www.npmtrends.com/@remark-embedder/cache 152 | [license-badge]: https://img.shields.io/npm/l/@remark-embedder/cache.svg?style=flat-square 153 | [license]: https://github.com/remark-embedder/cache/blob/main/LICENSE 154 | [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square 155 | [prs]: https://makeapullrequest.com 156 | [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square 157 | [coc]: https://github.com/remark-embedder/cache/blob/main/CODE_OF_CONDUCT.md 158 | [emojis]: https://github.com/all-contributors/all-contributors#emoji-key 159 | [all-contributors]: https://github.com/all-contributors/all-contributors 160 | [all-contributors-badge]: https://img.shields.io/github/all-contributors/remark-embedder/cache?color=orange&style=flat-square 161 | [bugs]: https://github.com/remark-embedder/cache/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug 162 | [requests]: https://github.com/remark-embedder/cache/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement 163 | [good-first-issue]: https://github.com/remark-embedder/cache/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement+label%3A%22good+first+issue%22 164 | 165 | [@remark-embedder/core]: https://github.com/remark-embedder/core 166 | [gatsby-plugin-cache-source]: https://github.com/gatsbyjs/gatsby/blob/0a06a795c434312150f30048567b0e2cd797027e/packages/gatsby/src/utils/cache.ts 167 | 168 | --------------------------------------------------------------------------------