Skip to content

Commit 7f7b919

Browse files
Modernize bundle (#3)
* feat: modernize browser/node support BREAKING CHANGE: Only support evergreen browsers and LTS Node * docs: add bundlephobia badge, docs TOC * ci: remove Node 10 from GitHub workflow
1 parent 5b26a8d commit 7f7b919

File tree

8 files changed

+40
-73
lines changed

8 files changed

+40
-73
lines changed

.browserslistrc

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
Chrome 49
2-
Edge 12
3-
Firefox 18
4-
Opera 36
5-
Safari 10
1+
last 3 Chrome versions
2+
last 3 Firefox versions
3+
last 3 Edge versions
4+
last 2 Safari versions
5+
last 2 iOS versions
6+
last 3 ChromeAndroid versions
7+
maintained Node versions

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [10, 12, 14, 16]
15+
node-version: [12, 14, 16]
1616

1717
steps:
1818
- uses: actions/checkout@v2

README.md

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# recursive-proxy-mock
22

3-
[![npm](https://badgen.net/npm/v/recursive-proxy-mock)](https://www.npmjs.com/package/recursive-proxy-mock) [![license MIT](https://badgen.net/npm/license/recursive-proxy-mock)](https://github.com/CreativeTechGuy/recursive-proxy-mock/blob/main/LICENSE) [![npm type definitions](https://badgen.net/npm/types/recursive-proxy-mock)](https://www.npmjs.com/package/recursive-proxy-mock) [![npm](https://badgen.net/npm/dm/recursive-proxy-mock)](https://www.npmjs.com/package/recursive-proxy-mock) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
3+
[![npm](https://badgen.net/npm/v/recursive-proxy-mock)](https://www.npmjs.com/package/recursive-proxy-mock) [![license MIT](https://badgen.net/npm/license/recursive-proxy-mock)](https://github.com/CreativeTechGuy/recursive-proxy-mock/blob/main/LICENSE) [![npm type definitions](https://badgen.net/npm/types/recursive-proxy-mock)](https://www.npmjs.com/package/recursive-proxy-mock) [![bundlephobia](https://badgen.net/bundlephobia/minzip/recursive-proxy-mock)](https://bundlephobia.com/package/recursive-proxy-mock) [![npm](https://badgen.net/npm/dm/recursive-proxy-mock)](https://www.npmjs.com/package/recursive-proxy-mock) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
44

55
> Create a proxy which can mock any object, function, class, etc. with infinite depth and combinations.
66
@@ -20,8 +20,8 @@
2020
- [`hasPathBeenVisited(proxy, path) => boolean`](#haspathbeenvisitedproxy-path--boolean)
2121
- [`hasPathBeenCalledWith(proxy, path, args) => boolean`](#haspathbeencalledwithproxy-path-args--boolean)
2222
- [`getVisitedPathData(proxy, path) => ProxyData[] | null`](#getvisitedpathdataproxy-path--proxydata--null)
23-
- [`replayMock(proxy, target)`](#replaymockproxy-target)
2423
- [ProxyData](#proxydata)
24+
- [`replayProxy(proxy, target)`](#replayproxyproxy-target)
2525
- [`listAllProxyOperations(proxy) => ProxyData[]`](#listallproxyoperationsproxy--proxydata)
2626
- [ProxyPath](#proxypath)
2727
- [Caveats](#caveats)
@@ -226,15 +226,6 @@ Function to get details about every time a path was visited. Useful in conjuncti
226226

227227
- `proxy` - the root proxy object that was returned from `recursiveProxyMock`
228228
- `path` - see the [ProxyPath section](#proxypath) for more details.
229-
230-
### `replayMock(proxy, target)`
231-
232-
Replay every operation performed on a proxy mock object onto a target object. This can effectively let you time travel to queue up any actions and replay them as many times as you would like. Every property accessor, every function call, etc will be replayed onto the target.
233-
234-
- `proxy` - the root proxy object that was returned from `recursiveProxyMock`
235-
236-
- `target` - any object/function/class etc which will be operated on in the same way that the `proxy` object was.
237-
238229
- Returns: Array of `ProxyData` objects, one for each time the path was visited on the proxy object. `null` if it was never visited.
239230

240231
#### ProxyData
@@ -254,6 +245,13 @@ A `ProxyData` object contains any relevant details about the operation. For exam
254245
- All other handlers:
255246
- No useful additional information is available
256247

248+
### `replayProxy(proxy, target)`
249+
250+
Replay every operation performed on a proxy mock object onto a target object. This can effectively let you time travel to queue up any actions and replay them as many times as you would like. Every property accessor, every function call, etc will be replayed onto the target.
251+
252+
- `proxy` - the root proxy object that was returned from `recursiveProxyMock`
253+
- `target` - any object/function/class etc which will be operated on in the same way that the `proxy` object was.
254+
257255
### `listAllProxyOperations(proxy) => ProxyData[]`
258256

259257
A debug function which lists the raw "proxy stack" of every operation that was performed on the mock. This is an array of [ProxyData](#proxydata) objects which have metadata that is used to power all of the other functions. For example, every object has a `parent` property which contains a number. This number will be the same as some other object's `self` property. Using those two values you can construct a tree containing every path that was accessed on the object.
@@ -332,7 +330,7 @@ expect(hasPathBeenVisited(res, ["redirect", ProxySymbol.APPLY])).toStrictEqual(t
332330

333331
## Browser/Node Support
334332

335-
Out of the box we support all browsers that support the [Proxy object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#browser_compatibility) and any current LTS version of Node. Unfortunately Proxy cannot be polyfilled for older versions so this is the best browser support we can do.
333+
Out of the box we support all modern browsers and any currently maintained version of Node. Unfortunately Proxy cannot be polyfilled, so supporting a browser like Internet Explorer is completely out of the question.
336334

337335
## Performance & Size
338336

babel.config.js

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
1-
const packageJSON = require("./package.json");
2-
3-
const transformRuntimeVersion = packageJSON.devDependencies["@babel/plugin-transform-runtime"];
4-
51
module.exports = (api) => {
62
const isTest = api.env("test");
73
const config = {
8-
plugins: [
9-
[
10-
"@babel/transform-runtime",
11-
{
12-
corejs: 3,
13-
version: transformRuntimeVersion,
14-
},
15-
],
16-
],
17-
presets: [],
18-
};
19-
if (isTest) {
20-
config.presets.push(
4+
plugins: [],
5+
presets: [
216
[
227
"@babel/env",
238
{
249
bugfixes: true,
2510
useBuiltIns: "usage",
2611
corejs: 3,
2712
shippedProposals: true,
13+
...(isTest
14+
? {
15+
targets: {
16+
node: "current",
17+
},
18+
}
19+
: {}),
2820
},
2921
],
30-
[
31-
"@babel/typescript",
32-
{
33-
allowDeclareFields: true,
34-
onlyRemoveTypeImports: true,
35-
},
36-
]
37-
);
38-
} else {
22+
],
23+
};
24+
if (isTest) {
3925
config.presets.push([
40-
"@babel/env",
26+
"@babel/typescript",
4127
{
42-
bugfixes: true,
43-
useBuiltIns: false,
44-
shippedProposals: true,
28+
allowDeclareFields: true,
29+
onlyRemoveTypeImports: true,
4530
},
4631
]);
4732
}

cspell.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": "0.1",
3-
"words": ["commitlint", "corejs", "eqeqeq", "iife", "lcov", "ttypescript", "webgl"],
3+
"words": ["bundlephobia", "commitlint", "corejs", "eqeqeq", "iife", "lcov", "ttypescript", "webgl"],
44
"ignoreRegExpList": ["\\(#.*\\)"],
55
"ignorePaths": ["/coverage", "/dist", "package-lock.json", "package.json"]
66
}

package-lock.json

+2-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"url": "https://github.com/CreativeTechGuy/recursive-proxy-mock.git"
3232
},
3333
"engines": {
34-
"node": ">=10"
34+
"node": ">=12"
3535
},
3636
"scripts": {
3737
"release": "npm run lint && npm run format:check && npm run spellcheck && npm run test && npm run build",
@@ -85,8 +85,5 @@
8585
"ttypescript": "^1.5.12",
8686
"typescript": "^4.4.0-beta",
8787
"typescript-transform-paths": "^3.3.0"
88-
},
89-
"dependencies": {
90-
"@babel/runtime-corejs3": "^7.15.3"
9188
}
9289
}

rollup.config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,28 @@ const typescriptPluginConfig = {
2020

2121
export default [
2222
{
23-
input: "src/index.ts",
23+
input: "./src/index.ts",
2424
output: {
2525
file: "./dist/cjs/index.js",
2626
format: "cjs",
2727
sourcemap: true,
2828
},
29-
external: [/@babel\/runtime/],
3029
plugins: [
3130
typescript(typescriptPluginConfig),
32-
babel({ babelHelpers: "runtime", extensions: [".js", ".ts"], exclude: /node_modules/ }),
31+
babel({ babelHelpers: "bundled", extensions: [".js", ".ts"] }),
3332
nodeResolve(),
3433
commonjs(),
3534
bundleSize(),
3635
],
3736
},
3837
{
39-
input: "src/index.ts",
38+
input: "./src/index.ts",
4039
output: {
4140
dir: "./dist/esm",
4241
format: "esm",
4342
sourcemap: true,
4443
preserveModules: true,
4544
},
46-
external: [/@babel\/runtime/],
4745
plugins: [
4846
typescript({
4947
...typescriptPluginConfig,

0 commit comments

Comments
 (0)