Skip to content

Commit 9e2a612

Browse files
authored
👷 Adds CI/CD processes (#1)
* 👷 Adds CI/CD system * 🚨 Adds eslint * 🔥 Remove unused code * 👷 Caches modules * 📝 Adds Readme
1 parent 7ee3b73 commit 9e2a612

16 files changed

+2834
-470
lines changed

.eslintrc.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
8+
"parser": "@typescript-eslint/parser",
9+
"parserOptions": {
10+
"ecmaVersion": "latest",
11+
"sourceType": "module"
12+
},
13+
"plugins": ["@typescript-eslint"],
14+
"rules": {
15+
"no-warning-comments": "warn",
16+
"require-await": "error",
17+
"no-unused-vars": "off",
18+
"@typescript-eslint/no-unused-vars": [
19+
"error",
20+
{
21+
"argsIgnorePattern": "^_",
22+
"varsIgnorePattern": "^_"
23+
}
24+
]
25+
},
26+
"overrides": [
27+
{
28+
"files": ["*.test.*", "*.spec.*"],
29+
"rules": {
30+
"@typescript-eslint/no-explicit-any": "off"
31+
}
32+
}
33+
]
34+
}

.github/workflows/npmdeploy.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Publish to NPM
2+
on:
3+
push:
4+
paths:
5+
- 'package.json'
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
jobs:
10+
Check-Versions:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
outdated: ${{ steps.version_check.outputs.outdated }}
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: 18
22+
always-auth: true
23+
- name: Compares Versions
24+
id: version_check
25+
run: |
26+
node ./scripts/predeploy.js
27+
echo "outdated=$(node ./scripts/predeploy.js)" >> $GITHUB_OUTPUT
28+
29+
Build-Publish:
30+
needs: Check-Versions
31+
if: ${{needs.Check-Versions.outputs.outdated}}
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Is Outdated
35+
run: echo ${{needs.Check-Versions.outputs.outdated}}
36+
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
40+
- name: Setup Node
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: 18
44+
always-auth: true
45+
46+
- name: Install pnpm
47+
uses: pnpm/[email protected]
48+
id: pnpm-install
49+
with:
50+
version: latest
51+
run_install: false
52+
53+
- name: Get pnpm store directory
54+
id: pnpm-cache
55+
run: |
56+
pnpm store path
57+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
58+
59+
- uses: actions/cache@v3
60+
name: Setup pnpm cache
61+
with:
62+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
63+
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
64+
restore-keys: |
65+
${{ runner.os }}-pnpm-
66+
67+
- name: Install Dependencies
68+
run: pnpm i
69+
70+
- name: Build package
71+
run: pnpm run build
72+
73+
- name: SetupAuth
74+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
75+
76+
- name: Publish package on NPM 📦
77+
run: pnpm publish
78+
env:
79+
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test-pr.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Perform Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
jobs:
8+
Test-PR:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Install Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
17+
- uses: pnpm/[email protected]
18+
name: Install pnpm
19+
id: pnpm-install
20+
with:
21+
version: latest
22+
run_install: false
23+
24+
- name: Get pnpm store directory
25+
id: pnpm-cache
26+
run: |
27+
pnpm store path
28+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
29+
30+
- uses: actions/cache@v3
31+
name: Setup pnpm cache
32+
with:
33+
path: |
34+
${{ steps.pnpm-cache.outputs.STORE_PATH }}
35+
node_modules
36+
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-pnpm-
39+
40+
- name: Install Dependencies
41+
run: pnpm i
42+
43+
- name: Lint
44+
run: pnpm run lint:check
45+
46+
- name: Test
47+
run: pnpm run test --run
48+
49+
- name: Build Package
50+
run: pnpm run build

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
test.ts
3+
dist
4+
coverage

.husky/pre-commit

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
pnpm exec lint-staged
5+
pnpm run test --run
6+
bun run build || pnpm run build
7+
bun run size || pnpm run size
8+
git add size.json

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# A simple Weak Reference Least Recently Used Cache
2+
3+
[<img src="https://img.shields.io/npm/v/@ekwoka/weak-lru-cache?label=%20&style=for-the-badge&logo=pnpm&logoColor=white">](https://www.npmjs.com/package/@ekwoka/weak-lru-cache)
4+
<img src="https://img.shields.io/npm/types/@ekwoka/weak-lru-cache?label=%20&logo=typescript&logoColor=white&style=for-the-badge">
5+
<img src="https://img.shields.io/npm/dt/@ekwoka/weak-lru-cache?style=for-the-badge&logo=npm&logoColor=white" >
6+
[<img src="https://img.shields.io/bundlephobia/minzip/@ekwoka/weak-lru-cache?style=for-the-badge&logo=esbuild&logoColor=white">](https://bundlephobia.com/package/@ekwoka/weak-lru-cache)
7+
<img src="https://img.shields.io/badge/coverage-99%25-success?style=for-the-badge&logo=vitest&logoColor=white" alt="99% test coverage">
8+
9+
This cache allows for items to be stored and maintained while in use, but also allowing for unused items to be garbage collected after they have been sufficiently pushed out by more recently used items.

package.json

+57-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,72 @@
11
{
22
"name": "@ekwoka/weak-lru-cache",
3-
"version": "0.0.1",
4-
"private": true,
5-
"description": "",
6-
"main": "index.js",
3+
"version": "0.0.0",
4+
"description": "A simple weak referenced Least Recently Used cache",
5+
"author": {
6+
"name": "Eric Kwoka",
7+
"email": "[email protected]",
8+
"url": "https://thekwoka.net/"
9+
},
10+
"repository": "github:ekwoka/weak-lru-cache",
11+
"license": "ISC",
12+
"keywords": [
13+
"weakmap",
14+
"weakref",
15+
"cache",
16+
"lru",
17+
"least recently used"
18+
],
19+
"type": "module",
20+
"sideEffects": false,
21+
"main": "dist/index.js",
22+
"module": "dist/index.mjs",
23+
"types": "dist/index.d.ts",
24+
"exports": {
25+
".": {
26+
"import": "./dist/index.mjs",
27+
"require": "./dist/index.js"
28+
},
29+
"./package.json": "./package.json"
30+
},
31+
"files": [
32+
"dist"
33+
],
734
"scripts": {
35+
"build": "vite build",
36+
"coverage": "vitest run --coverage",
37+
"lint": "eslint --fix ./src; prettier --write ./src --loglevel error",
38+
"lint:check": "eslint --max-warnings 10 ./src && prettier --check ./src",
39+
"prepare": "husky install",
40+
"size": "node scripts/esbuild.js",
841
"test": "vitest"
942
},
10-
"keywords": [],
11-
"author": "Eric Kwoka",
12-
"license": "ISC",
1343
"devDependencies": {
44+
"@typescript-eslint/eslint-plugin": "^5.50.0",
45+
"@typescript-eslint/parser": "^5.50.0",
46+
"@vitest/coverage-c8": "^0.28.4",
47+
"esbuild": "^0.17.5",
1448
"eslint": "^8.33.0",
49+
"gzip-size": "^7.0.0",
1550
"husky": "^8.0.3",
1651
"lint-staged": "^13.1.0",
1752
"prettier": "^2.8.3",
53+
"pretty-bytes": "^6.1.0",
1854
"typescript": "^4.9.5",
1955
"vite": "^4.1.1",
56+
"vite-plugin-dts": "^1.7.2",
2057
"vitest": "^0.28.4"
58+
},
59+
"prettier": {
60+
"singleQuote": true,
61+
"bracketSameLine": true
62+
},
63+
"lint-staged": {
64+
"*.{js,ts,mjs}": [
65+
"eslint --fix",
66+
"prettier --write"
67+
],
68+
"*.{json,md,mdx,html,css,scss,less,graphql,yml,yaml}": [
69+
"prettier --write"
70+
]
2171
}
2272
}

0 commit comments

Comments
 (0)