Skip to content

Commit b3a45b2

Browse files
New esm/cjs structure (#129)
1 parent 640afb1 commit b3a45b2

31 files changed

+119
-1236
lines changed

‎.gitignore

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

‎CHANGELOG.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
This only documents breaking changes. For other changes, see the commit log.
2+
3+
# v6
4+
5+
- `dist` no longer committed.
6+
- Files have moved around.
7+
- CommonJS files now have a `.cjs` extension.
8+
- Sourcemaps no longer included.
9+
- iife build switched to a UMD build.
10+
11+
# v5
12+
13+
The changes between 3.x and 5.x related to custom stores.
14+
15+
Old way:
16+
17+
```js
18+
// This no longer works in 4.x
19+
import { Store, set } from 'idb-keyval';
20+
21+
const customStore = new Store('custom-db-name', 'custom-store-name');
22+
set('foo', 'bar', customStore);
23+
```
24+
25+
New way:
26+
27+
```js
28+
import { createStore, set } from 'idb-keyval';
29+
30+
const customStore = createStore('custom-db-name', 'custom-store-name');
31+
set('foo', 'bar', customStore);
32+
```
33+
34+
For more details, see [custom stores](./custom-stores.md).
35+
36+
# v4
37+
38+
4.x was abandoned due to a Safari bug.
39+
40+
# v3
41+
42+
2.x exported an object with methods:
43+
44+
```js
45+
// This no longer works in 3.x
46+
import idbKeyval from 'idb-keyval';
47+
48+
idbKeyval.set('foo', 'bar');
49+
```
50+
51+
Whereas in 3.x you import the methods directly:
52+
53+
```js
54+
import { set } from 'idb-keyval';
55+
56+
set('foo', 'bar');
57+
```
58+
59+
This is better for minification, and allows tree shaking.

‎README.md

+12-58
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,24 @@ import { get, set } from 'idb-keyval/dist/esm-compat';
3636

3737
### All bundles
3838

39-
- `dist/cjs/index.js` CommonJS module.
40-
- `dist/cjs-compat/index.js` CommonJS module, transpiled for older browsers.
41-
- `dist/esm/index.js` EcmaScript module.
42-
- `dist/esm-compat/index.js` EcmaScript module, transpiled for older browsers.
43-
- `dist/iife/index-min.js` Minified plain JS, which creates an `idbKeyval` global containing all methods.
44-
- `dist/iife-compat/index-min.js` As above, but transpiled for older browsers.
39+
A well-behaved bundler should automatically pick the ES module or the CJS module depending on what it supports, but if you need to force it either way:
40+
41+
- `idb-keyval/dist/index.js` EcmaScript module.
42+
- `idb-keyval/dist/index.cjs` CommonJS module.
43+
44+
Legacy builds:
45+
46+
- `idb-keyval/dist/compat.js` EcmaScript module, transpiled for older browsers.
47+
- `idb-keyval/dist/compat.cjs` CommonJS module, transpiled for older browsers.
48+
- `idb-keyval/dist/umd.cjs` UMD module, also transpiled for older browsers.
4549

4650
These built versions are also available on jsDelivr, e.g.:
4751

4852
```html
49-
<script src="https://cdn.jsdelivr.net/npm/idb-keyval@5/dist/iife/index-min.js"></script>
53+
<script src="https://cdn.jsdelivr.net/npm/idb-keyval@6/dist/umd.cjs"></script>
5054
<!-- Or in modern browsers: -->
5155
<script type="module">
52-
import { get, set } from 'https://cdn.jsdelivr.net/npm/idb-keyval@5/+esm';
56+
import { get, set } from 'https://cdn.jsdelivr.net/npm/idb-keyval@6/+esm';
5357
</script>
5458
```
5559

@@ -232,53 +236,3 @@ values().then((values) => console.log(values));
232236
### Custom stores:
233237

234238
By default, the methods above use an IndexedDB database named `keyval-store` and an object store named `keyval`. If you want to use something different, see [custom stores](./custom-stores.md).
235-
236-
## Updating
237-
238-
### Updating from 3.x
239-
240-
The changes between 3.x and 5.x related to custom stores.
241-
242-
(4.x was abandoned due to a Safari bug)
243-
244-
Old way:
245-
246-
```js
247-
// This no longer works in 4.x
248-
import { Store, set } from 'idb-keyval';
249-
250-
const customStore = new Store('custom-db-name', 'custom-store-name');
251-
set('foo', 'bar', customStore);
252-
```
253-
254-
New way:
255-
256-
```js
257-
import { createStore, set } from 'idb-keyval';
258-
259-
const customStore = createStore('custom-db-name', 'custom-store-name');
260-
set('foo', 'bar', customStore);
261-
```
262-
263-
For more details, see [custom stores](./custom-stores.md).
264-
265-
### Updating from 2.x
266-
267-
2.x exported an object with methods:
268-
269-
```js
270-
// This no longer works in 3.x
271-
import idbKeyval from 'idb-keyval';
272-
273-
idbKeyval.set('foo', 'bar');
274-
```
275-
276-
Whereas in 3.x you import the methods directly:
277-
278-
```js
279-
import { set } from 'idb-keyval';
280-
281-
set('foo', 'bar');
282-
```
283-
284-
This is better for minification, and allows tree shaking.

‎dist/cjs-compat/index.d.ts

-73
This file was deleted.

‎dist/cjs-compat/index.d.ts.map

-1
This file was deleted.

0 commit comments

Comments
 (0)