Skip to content

Commit

Permalink
Modernize bundle (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CreativeTechGuy authored Aug 15, 2021
1 parent 5b26a8d commit 7f7b919
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 73 deletions.
12 changes: 7 additions & 5 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Chrome 49
Edge 12
Firefox 18
Opera 36
Safari 10
last 3 Chrome versions
last 3 Firefox versions
last 3 Edge versions
last 2 Safari versions
last 2 iOS versions
last 3 ChromeAndroid versions
maintained Node versions
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [10, 12, 14, 16]
node-version: [12, 14, 16]

steps:
- uses: actions/checkout@v2
Expand Down
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# recursive-proxy-mock

[![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)
[![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)

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

- `proxy` - the root proxy object that was returned from `recursiveProxyMock`
- `path` - see the [ProxyPath section](#proxypath) for more details.

### `replayMock(proxy, target)`

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.

- `proxy` - the root proxy object that was returned from `recursiveProxyMock`

- `target` - any object/function/class etc which will be operated on in the same way that the `proxy` object was.

- Returns: Array of `ProxyData` objects, one for each time the path was visited on the proxy object. `null` if it was never visited.

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

### `replayProxy(proxy, target)`

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.

- `proxy` - the root proxy object that was returned from `recursiveProxyMock`
- `target` - any object/function/class etc which will be operated on in the same way that the `proxy` object was.

### `listAllProxyOperations(proxy) => ProxyData[]`

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.
Expand Down Expand Up @@ -332,7 +330,7 @@ expect(hasPathBeenVisited(res, ["redirect", ProxySymbol.APPLY])).toStrictEqual(t

## Browser/Node Support

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.
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.

## Performance & Size

Expand Down
45 changes: 15 additions & 30 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
const packageJSON = require("./package.json");

const transformRuntimeVersion = packageJSON.devDependencies["@babel/plugin-transform-runtime"];

module.exports = (api) => {
const isTest = api.env("test");
const config = {
plugins: [
[
"@babel/transform-runtime",
{
corejs: 3,
version: transformRuntimeVersion,
},
],
],
presets: [],
};
if (isTest) {
config.presets.push(
plugins: [],
presets: [
[
"@babel/env",
{
bugfixes: true,
useBuiltIns: "usage",
corejs: 3,
shippedProposals: true,
...(isTest
? {
targets: {
node: "current",
},
}
: {}),
},
],
[
"@babel/typescript",
{
allowDeclareFields: true,
onlyRemoveTypeImports: true,
},
]
);
} else {
],
};
if (isTest) {
config.presets.push([
"@babel/env",
"@babel/typescript",
{
bugfixes: true,
useBuiltIns: false,
shippedProposals: true,
allowDeclareFields: true,
onlyRemoveTypeImports: true,
},
]);
}
Expand Down
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0.1",
"words": ["commitlint", "corejs", "eqeqeq", "iife", "lcov", "ttypescript", "webgl"],
"words": ["bundlephobia", "commitlint", "corejs", "eqeqeq", "iife", "lcov", "ttypescript", "webgl"],
"ignoreRegExpList": ["\\(#.*\\)"],
"ignorePaths": ["/coverage", "/dist", "package-lock.json", "package.json"]
}
17 changes: 2 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"url": "https://github.com/CreativeTechGuy/recursive-proxy-mock.git"
},
"engines": {
"node": ">=10"
"node": ">=12"
},
"scripts": {
"release": "npm run lint && npm run format:check && npm run spellcheck && npm run test && npm run build",
Expand Down Expand Up @@ -85,8 +85,5 @@
"ttypescript": "^1.5.12",
"typescript": "^4.4.0-beta",
"typescript-transform-paths": "^3.3.0"
},
"dependencies": {
"@babel/runtime-corejs3": "^7.15.3"
}
}
8 changes: 3 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,28 @@ const typescriptPluginConfig = {

export default [
{
input: "src/index.ts",
input: "./src/index.ts",
output: {
file: "./dist/cjs/index.js",
format: "cjs",
sourcemap: true,
},
external: [/@babel\/runtime/],
plugins: [
typescript(typescriptPluginConfig),
babel({ babelHelpers: "runtime", extensions: [".js", ".ts"], exclude: /node_modules/ }),
babel({ babelHelpers: "bundled", extensions: [".js", ".ts"] }),
nodeResolve(),
commonjs(),
bundleSize(),
],
},
{
input: "src/index.ts",
input: "./src/index.ts",
output: {
dir: "./dist/esm",
format: "esm",
sourcemap: true,
preserveModules: true,
},
external: [/@babel\/runtime/],
plugins: [
typescript({
...typescriptPluginConfig,
Expand Down

0 comments on commit 7f7b919

Please sign in to comment.