Skip to content

Commit ddce56a

Browse files
committed
chore: using new build setup to output both esm and umd builds
1 parent 4be67ac commit ddce56a

9 files changed

Lines changed: 1660 additions & 46 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules
2-
lib
2+
dist
33
npm-debug.log
44
.vscode

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## v2.0.0-beta.1
4+
5+
Migrating to this version might require a few of the users you to channge the way how they were importing the libray.
6+
7+
- **[Breaking Change]** Changed the output dir from `lib` to `build`
8+
- **[Breaking Change]** Added separate esm and umd builds
9+
- **[Breaking Change]** Removed the `options.strategy` option

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Calling the `createStore` function returns an object with the following properti
4343
| Property | Description | Type | Default |
4444
| ------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------- | ------- |
4545
| `timeToClear` | Time in **milliseconds** for which the store will keep an item when the policy is `timeout` or `tlru` | Number | 7200000 |
46-
| `strategy` | **Deprecated - use policy option** | - | - |
4746
| `policy` | A Policy to evict items from the store | `timeout`, `lru`, `mru`, `tlru` | `lru` |
4847
| `lruSize` | Size of the cache store when the policy is `lru` or `tlru` | Number | 500 |
4948
| `mruSize` | Size of the cache store when the policy is `mru` | Number | 500 |
@@ -129,7 +128,7 @@ async function loginUser(userId: string) {
129128
- `npm run test` -- Runs tests, lint and build.
130129
- `npm run lint` -- Runs ESLint.
131130
- `npm run format` -- Reformats all of the `.ts` and `.tsx` files with Prettier.
132-
- `npm run build` -- Regenerates `lib` folder that gets included into NPM module.
131+
- `npm run build` -- Regenerates `dist` folder that gets included into NPM module.
133132

134133
## Todos
135134

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
22
"name": "runtime-memcache",
3-
"version": "1.3.1",
3+
"version": "2.0.0-beta.1",
44
"description": "A no dependency javascript runtime key-value cache store for small chunks of arbitrary data (strings, objects, numbers)",
55
"homepage": "https://github.com/tusharf5/runtime-memcache",
6+
"main": "./dist/umd/index.js",
7+
"module": "./dist/esm/index.js",
8+
"types": "./dist/index.d.ts",
9+
"files": [
10+
"dist/"
11+
],
612
"repository": {
713
"type": "git",
814
"url": "https://github.com/tusharf5/runtime-memcache"
@@ -17,11 +23,11 @@
1723
"dev": "yarn build && yarn test",
1824
"lint": "eslint 'src/**/*.{ts}' 'tests/**/*.{ts}'",
1925
"format": "npx prettier --write '**/*.{ts,js,json}'",
20-
"build": "rm -rf lib && tsc -p . && rm -rf lib/tests && rm -rf lib/src",
26+
"build": "webpack --mode=production",
27+
"prebuild": "rm -rf dist && tsc -p . && rm -rf dist/tests && rm -rf dist/src",
2128
"prepublish": "npm run build && npm run test"
2229
},
2330
"license": "MIT",
24-
"main": "lib/index.js",
2531
"keywords": [
2632
"js cache",
2733
"javascript cache",
@@ -34,13 +40,10 @@
3440
"timeout",
3541
"mru"
3642
],
37-
"typings": "lib/index.d.ts",
38-
"files": [
39-
"lib/"
40-
],
4143
"devDependencies": {
4244
"@types/jest": "^25.2.1",
4345
"@types/node": "^13.11.0",
46+
"babel-loader": "^8.1.0",
4447
"eslint": "^6.8.0",
4548
"eslint-config-airbnb": "^18.0.1",
4649
"eslint-config-prettier": "^6.10.1",
@@ -55,6 +58,8 @@
5558
"prettier": "^2.0.2",
5659
"ts-node": "^8.8.2",
5760
"typescript": "^3.8.3",
58-
"typescript-eslint-parser": "^22.0.0"
61+
"typescript-eslint-parser": "^22.0.0",
62+
"webpack": "^4.43.0",
63+
"webpack-cli": "^3.3.11"
5964
}
6065
}

src/store.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ function createStore<K extends string | number | symbol = string, V = any>(
2020
if (typeof userConfig === 'object') {
2121
userConfigVerf = userConfig;
2222
}
23-
if (userConfigVerf.strategy) {
24-
userConfigVerf.policy = userConfigVerf.policy || userConfigVerf.strategy;
25-
console.warn(
26-
'runtime-memcache:: Use the `policy` config option instead of `strategy`. `strategy` option is deprecated and will be removed in the next major version',
27-
);
28-
}
23+
2924
const config: Required<GlobalConfig> = Object.assign({}, defaultConfig, userConfigVerf);
3025

3126
switch (config.policy) {

tests/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const createStore = require('../lib/index').default;
1+
const createStore = require('../dist/esm/index').default;
22

33
jest.setTimeout(30000);
44

tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"compilerOptions": {
3-
"outDir": "lib/",
3+
"outDir": "./dist/esm/",
44
"sourceMap": true,
55
"module": "commonjs",
66
"moduleResolution": "node",
77
"noEmitOnError": true,
8-
"target": "es5",
8+
"target": "es6",
99
"declaration": true,
1010
"removeComments": false,
1111
"noImplicitAny": true,
1212
"forceConsistentCasingInFileNames": true,
1313
"noUnusedLocals": true,
1414
"pretty": true
15-
}
15+
},
16+
"files": ["./src/index.ts"],
17+
"include": ["./src/**/*.ts"]
1618
}

webpack.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path');
2+
3+
module.exports = (env, argv) => {
4+
return {
5+
entry: {
6+
index: path.resolve(__dirname, './dist/esm/index.js'),
7+
},
8+
output: {
9+
path: path.resolve(__dirname, './dist/umd'), // builds to ./dist/umd/
10+
filename: '[name].js', // index.js
11+
library: 'myLibrary', // aka window.myLibrary
12+
libraryTarget: 'umd', // supports commonjs, amd and web browsers
13+
globalObject: 'this',
14+
libraryExport: 'default',
15+
},
16+
module: {
17+
rules: [{ test: /\.t|js$/, use: 'babel-loader' }],
18+
},
19+
};
20+
};

0 commit comments

Comments
 (0)