Skip to content

Commit

Permalink
Update dependencies (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Jul 19, 2022
1 parent e306b45 commit 3b6f61e
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 51 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
run: npm install
- name: XO
run: npx xo

Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
run: npm install
- name: build
run: npm run build --if-present
- name: AVA
Expand All @@ -28,17 +28,17 @@ jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
run: npm install
- name: build
run: npm run build

Types:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
run: npm install
- run: npm run build
- run: npx tsd
50 changes: 39 additions & 11 deletions .github/workflows/esm-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ env:

# FILE GENERATED WITH: npx ghat fregante/ghatemplates/esm-lint
# SOURCE: https://github.com/fregante/ghatemplates
# OPTIONS: {"exclude":["jobs.Node","jobs.Rollup"]}

name: ESM
on:
Expand All @@ -19,19 +18,19 @@ jobs:
Pack:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: npm install
- run: npm run build --if-present
- run: npm pack --dry-run
- run: npm pack --silent 2>/dev/null | xargs -n1 tar -xzf
- uses: actions/upload-artifact@v2
- run: npm pack | tail -1 | xargs -n1 tar -xzf
- uses: actions/upload-artifact@v3
with:
path: package
Webpack:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
- run: npm install ./artifact
- run: echo "${{ env.IMPORT_TEXT }} '${{ env.NPM_MODULE_NAME }}'" > index.js
- run: webpack --entry ./index.js
Expand All @@ -40,27 +39,56 @@ jobs:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
- run: npm install ./artifact
- run: echo "${{ env.IMPORT_TEXT }} '${{ env.NPM_MODULE_NAME }}'" > index.js
- run: npx parcel@2 build index.js
- run: cat dist/index.js
Snowpack:
Rollup:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
- run: npm install ./artifact rollup@2 @rollup/plugin-node-resolve
- run: echo "${{ env.IMPORT_TEXT }} '${{ env.NPM_MODULE_NAME }}'" > index.js
- run: npx rollup -p node-resolve index.js
Vite:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v3
- run: npm install ./artifact
- run: >-
echo '<script type="module">${{ env.IMPORT_TEXT }} "${{
env.NPM_MODULE_NAME }}"</script>' > index.html
- run: npx vite build
- run: cat dist/assets/*
esbuild:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v3
- run: echo '{}' > package.json
- run: echo "${{ env.IMPORT_TEXT }} '${{ env.NPM_MODULE_NAME }}'" > index.js
- run: npm install ./artifact
- run: npx snowpack@2 build
- run: cat build/web_modules/$NPM_MODULE_NAME.js
- run: npx esbuild --bundle index.js
TypeScript:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
- run: npm install ./artifact
- run: echo "${{ env.IMPORT_TEXT }} '${{ env.NPM_MODULE_NAME }}'" > index.ts
- run: tsc index.ts
- run: cat index.js
Node:
runs-on: ubuntu-latest
needs: Pack
steps:
- uses: actions/download-artifact@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
- run: echo "${{ env.IMPORT_TEXT }} '${{ env.NPM_MODULE_NAME }}'" > index.mjs
- run: npm install ./artifact
- run: node index.mjs
13 changes: 9 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import microMemoize from 'micro-memoize';
import {isBackgroundPage} from 'webext-detect-page';
import {isBackgroundPage, isExtensionContext} from 'webext-detect-page';
import toMilliseconds, {TimeDescriptor} from '@sindresorhus/to-milliseconds';
import chromeP from 'webext-polyfill-kinda';

const cacheDefault = {days: 30};

function timeInTheFuture(time: TimeDescriptor): number {
return Date.now() + toMilliseconds(time);
}
Expand Down Expand Up @@ -50,13 +52,14 @@ async function _get<ScopedValue extends Value>(
async function get<ScopedValue extends Value>(
key: string,
): Promise<ScopedValue | undefined> {
return (await _get<ScopedValue>(key, true))?.data;
const cacheItem = await _get<ScopedValue>(key, true);
return cacheItem?.data;
}

async function set<ScopedValue extends Value>(
key: string,
value: ScopedValue,
maxAge: TimeDescriptor = {days: 30},
maxAge: TimeDescriptor = cacheDefault,
): Promise<ScopedValue> {
if (arguments.length < 2) {
throw new TypeError('Expected a value as the second argument');
Expand Down Expand Up @@ -168,7 +171,9 @@ const cache = {

function init(): void {
// Make it available globally for ease of use
(window as any).webextStorageCache = cache;
if (isExtensionContext()) {
(globalThis as any).webextStorageCache = cache;
}

// Automatically clear cache every day
if (!isBackgroundPage()) {
Expand Down
36 changes: 16 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,29 @@
"browser",
"webextensions"
],
"rules": {
"@typescript-eslint/return-await": 0,
"import/extensions": 0,
"import/no-unassigned-import": 0,
"import/no-useless-path-segments": 0,
"no-promise-executor-return": 0,
"unicorn/import-index": 0,
"unicorn/no-object-as-default-parameter": 0
}
"rules": {}
},
"ava": {
"require": [
"./test/_setup.js"
]
},
"dependencies": {
"@sindresorhus/to-milliseconds": "^2.0.0",
"micro-memoize": "^4.0.9",
"webext-detect-page": "^3.1.0",
"webext-polyfill-kinda": "^0.9.0"
"micro-memoize": "^4.0.10",
"webext-detect-page": "^4.0.1",
"webext-polyfill-kinda": "^0.10.0"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@sindresorhus/tsconfig": "^2.0.0",
"@types/chrome": "0.0.163",
"@types/firefox-webext-browser": "^94.0.0",
"@types/chrome": "0.0.193",
"@types/firefox-webext-browser": "^94.0.1",
"@types/sinon-chrome": "^2.2.11",
"ava": "^3.15.0",
"sinon": "^12.0.1",
"ava": "^4.3.1",
"sinon": "^14.0.0",
"sinon-chrome": "^3.0.1",
"tsd": "^0.18.0",
"typescript": "^4.4.4",
"xo": "^0.46.4"
"tsd": "^0.22.0",
"typescript": "^4.7.4",
"xo": "^0.50.0"
}
}
5 changes: 0 additions & 5 deletions test/_fixtures.js

This file was deleted.

5 changes: 5 additions & 0 deletions test/_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import chrome from 'sinon-chrome';

globalThis.location = new URL('chrome://1234/_generated_background_page.html');
globalThis.chrome = chrome;
globalThis.window = {};
9 changes: 6 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import test from 'ava';
import sinon from 'sinon';
import './_fixtures.js';
import toMilliseconds from '@sindresorhus/to-milliseconds';
import cache from '../index.js';

Expand Down Expand Up @@ -171,7 +170,9 @@ test.serial('function() with fresh cache and staleWhileRevalidate', async t => {
t.is(spy.callCount, 0);
t.is(chrome.storage.local.set.callCount, 0);

await new Promise(resolve => setTimeout(resolve, 100));
await new Promise(resolve => {
setTimeout(resolve, 100);
});

// Cache is still fresh, it should never be revalidated
t.is(spy.callCount, 0);
Expand All @@ -195,7 +196,9 @@ test.serial('function() with stale cache and staleWhileRevalidate', async t => {

t.is(spy.callCount, 0, 'It shouldn’t be called yet');

await new Promise(resolve => setTimeout(resolve, 100));
await new Promise(resolve => {
setTimeout(resolve, 100);
});

t.is(spy.callCount, 1, 'It should be revalidated');
t.is(chrome.storage.local.set.callCount, 1);
Expand Down

0 comments on commit 3b6f61e

Please sign in to comment.