{"_id":"@dkamyshov/hot-persist","_rev":"9-067053547964637387a3424865b5d0f1","time":{"created":"2023-01-29T18:52:32.302Z","1.0.0":"2023-01-28T17:49:35.173Z","modified":"2024-03-02T11:27:56.468Z","1.0.1":"2023-01-29T18:52:32.519Z","1.1.0":"2024-03-02T11:26:44.181Z","1.1.1":"2024-03-02T11:27:55.814Z"},"name":"@dkamyshov/hot-persist","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.1":{"name":"@dkamyshov/hot-persist","version":"1.0.1","description":"The persistence API for HMR in webpack 4/5, vite 2/3/4, parcel 2.","keywords":["hot-reload","hmr","webpack","vite","parcel","persist","persistence"],"repository":{"type":"git","url":"git+https://github.com/dkamyshov/hot-persist.git"},"license":"MIT","main":"./lib/cjs/persist.js","module":"./lib/esm/persist.js","types":"./lib/esm/persist.d.ts","engines":{"node":">=0.12.0"},"scripts":{"lint:prettier":"prettier -c \"**/*\"","lint:eslint":"eslint -c .eslintrc.js --ext .js,.ts . --color","prettier:fix":"prettier --write \"**/*\"","typecheck":"tsc","test":"KEY_TOKEN=test_key_token jest","test:integration":"bash scripts/run-integration-tests.sh","build:esm":"BABEL_ENV=esm babel src --out-dir lib/esm --extensions .ts,.js","build:cjs":"BABEL_ENV=cjs babel src --out-dir lib/cjs --extensions .ts,.js","build:types":"tsc -p tsconfig.build.json","build":"export KEY_TOKEN=$(node ./scripts/generate-random-id.js) && yarn build:esm && yarn build:cjs && yarn build:types","clean":"rm -rf lib","prepare":"yarn clean && yarn test && yarn build"},"devDependencies":{"@babel/cli":"^7.20.7","@babel/core":"^7.20.12","@babel/plugin-proposal-nullish-coalescing-operator":"^7.18.6","@babel/plugin-proposal-optional-chaining":"^7.20.7","@babel/plugin-transform-modules-commonjs":"^7.20.11","@babel/preset-typescript":"^7.18.6","@types/jest":"^29.4.0","@typescript-eslint/eslint-plugin":"^5.49.0","@typescript-eslint/parser":"^5.49.0","babel-plugin-transform-define":"^2.1.0","eslint":"^8.32.0","jest":"^29.4.0","prettier":"^2.8.3","typescript":"^4.9.4"},"peerDependencies":{"@types/node":"*","@types/webpack-env":"*","@types/parcel-env":"*","webpack":">=4","vite":">=2","parcel":">=2"},"peerDependenciesMeta":{"@types/node":{"optional":true},"@types/webpack-env":{"optional":true},"@types/parcel-env":{"optional":true},"webpack":{"optional":true},"vite":{"optional":true},"parcel":{"optional":true}},"gitHead":"65b13095705616028b7860fd320ffe2aedd57df5","bugs":{"url":"https://github.com/dkamyshov/hot-persist/issues"},"homepage":"https://github.com/dkamyshov/hot-persist#readme","_id":"@dkamyshov/hot-persist@1.0.1","_nodeVersion":"16.18.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-XaEU4xx61TBvuYeLlDgq5iVhkHXPDxQB8p9shXTUfvzL+Bqm/N6aneJotkLCDfmwY/nenJYO1Y2ftqTIIEm3ww==","shasum":"3e99cc89be1742beed186a6397d03cc98acd2ac7","tarball":"https://registry.npmjs.org/@dkamyshov/hot-persist/-/hot-persist-1.0.1.tgz","fileCount":33,"unpackedSize":40260,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBrFVHeKVqC1n/8IZWyhowXxRcKhpcM+/5tjjNcz7y6+AiEApsAzJt51MhczjdZdMdX/Utxd+sRF8iQBKjDQiuv9JFk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj1sBwACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq6pQ/+OSaDIWifLMmme9KVxeuS4Cm9OqCHran0gzQfSQ8pNYZ4/kvC\r\nM1k/ATsxYIcPO0tQNtwyCfa/xAq7VelQTkbtURyd111z0u2q0RUcTQWmNRFZ\r\nUHtAjgfXbgVm7OBY70iWSPQdSL+Co0Z1VPAXUaa0FDsUphCPdYf6/FaJu1g7\r\nVCYSjgYU1Ur4j8Ofx2GiVqPjwuhc3fENxOdqCsMjfIvydmmsUEHCP9KJCzrl\r\nSN3Rarf7CulpenllH/7JWRwrHgnjcw8f148F4G33qByZbEiFB9fhl5fj1Pp1\r\nAnHGClSrI0Gg82KVMwEWJKBQfhLepC1yJVWewM7Lr6uns1QUZpca6SSI/jMz\r\nq42I499VdfOuQjDaXSu508DEc4yzPoeCWUwCZHPsnxZxlL1PeORBPv3/HBcB\r\ndsntg1GWOm+LfqBeslWhIJpCW24dO3Sj4MGGx450Y5f8OuteDVIcCCK/4+Ls\r\n+pMowZGcqDJT2UMv7gKiqPAw8/+NfRuPomUr0kliqkDK35xxym/dcieFrjDs\r\no8ArqHHvGuXsmTlK3K2vDYkAqoyi0fQo0+irJRrXfYCwsMEvnSYe0XS3UuRr\r\nPiXNZMCc1rNUGTQ3APjK4dvr3kg32CbE8x7Q2V7PhtpHQ4XUFFWuYIydXtDp\r\nvBp+CBv2FMJbasGHdvXyzQj6+nKyCm4WGlk=\r\n=yK/0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"},"directories":{},"maintainers":[{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hot-persist_1.0.1_1675018352377_0.41243003089764985"},"_hasShrinkwrap":false},"1.1.0":{"name":"@dkamyshov/hot-persist","version":"1.1.0","description":"The persistence API for HMR in webpack 4/5, vite 2/3/4, parcel 2.","keywords":["hot-reload","hmr","webpack","vite","parcel","persist","persistence"],"repository":{"type":"git","url":"git+https://github.com/dkamyshov/hot-persist.git"},"license":"MIT","main":"./lib/cjs/persist.js","module":"./lib/esm/persist.js","types":"./lib/esm/persist.d.ts","engines":{"node":">=0.12.0"},"scripts":{"lint:prettier":"prettier -c \"**/*\"","lint:eslint":"eslint -c .eslintrc.js --ext .js,.ts . --color","prettier:fix":"prettier --write \"**/*\"","typecheck":"tsc","test":"KEY_TOKEN=test_key_token jest","test:integration":"bash scripts/run-integration-tests.sh","build:esm":"BABEL_ENV=esm babel src --out-dir lib/esm --extensions .ts,.js","build:cjs":"BABEL_ENV=cjs babel src --out-dir lib/cjs --extensions .ts,.js","build:types":"tsc -p tsconfig.build.json","build":"export KEY_TOKEN=$(node ./scripts/generate-random-id.js) && yarn build:esm && yarn build:cjs && yarn build:types","clean":"rm -rf lib","prepare":"yarn clean && yarn test && yarn build"},"devDependencies":{"@babel/cli":"^7.23.9","@babel/core":"^7.24.0","@babel/plugin-proposal-nullish-coalescing-operator":"^7.18.6","@babel/plugin-proposal-optional-chaining":"^7.21.0","@babel/plugin-transform-modules-commonjs":"^7.23.3","@babel/preset-typescript":"^7.23.3","@types/jest":"^29.5.12","@typescript-eslint/eslint-plugin":"^7.1.0","@typescript-eslint/parser":"^7.1.0","babel-plugin-transform-define":"^2.1.4","eslint":"^8.57.0","jest":"^29.7.0","prettier":"^3.2.5","typescript":"^5.3.3"},"peerDependencies":{"@types/node":"*","@types/parcel-env":"*","@types/webpack-env":"*","parcel":">=2","vite":">=2","webpack":">=4"},"peerDependenciesMeta":{"@types/node":{"optional":true},"@types/webpack-env":{"optional":true},"@types/parcel-env":{"optional":true},"webpack":{"optional":true},"vite":{"optional":true},"parcel":{"optional":true}},"_id":"@dkamyshov/hot-persist@1.1.0","gitHead":"368b4cd14127d0701111da9737b7dc1726261596","bugs":{"url":"https://github.com/dkamyshov/hot-persist/issues"},"homepage":"https://github.com/dkamyshov/hot-persist#readme","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-YWWLoYac6tcJy73ZZI67ahc4E3d5pZfEm3ma1S3fFTPBU8uk2Vt46hvKwJF+g1Sdv6g4QGANP3XDz0dpyDlIXg==","shasum":"64974959d30b06803989f992bae3e1a3cc6afa12","tarball":"https://registry.npmjs.org/@dkamyshov/hot-persist/-/hot-persist-1.1.0.tgz","fileCount":33,"unpackedSize":44747,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG5fdCWXi3EyA7N6tE8oirImqzxOjQSu4Ij/QiBRbGBIAiAITn/IA+HdwIwdkADRaplDVcXqeydVOi85mUZOk32WuA=="}]},"_npmUser":{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"},"directories":{},"maintainers":[{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hot-persist_1.1.0_1709378804018_0.7139489034206317"},"_hasShrinkwrap":false},"1.1.1":{"name":"@dkamyshov/hot-persist","version":"1.1.1","description":"The persistence API for HMR in webpack 4/5, vite 2/3/4, parcel 2.","keywords":["hot-reload","hmr","webpack","vite","parcel","persist","persistence"],"repository":{"type":"git","url":"git+https://github.com/dkamyshov/hot-persist.git"},"license":"MIT","main":"./lib/cjs/persist.js","module":"./lib/esm/persist.js","types":"./lib/esm/persist.d.ts","engines":{"node":">=0.12.0"},"scripts":{"lint:prettier":"prettier -c \"**/*\"","lint:eslint":"eslint -c .eslintrc.js --ext .js,.ts . --color","prettier:fix":"prettier --write \"**/*\"","typecheck":"tsc","test":"KEY_TOKEN=test_key_token jest","test:integration":"bash scripts/run-integration-tests.sh","build:esm":"BABEL_ENV=esm babel src --out-dir lib/esm --extensions .ts,.js","build:cjs":"BABEL_ENV=cjs babel src --out-dir lib/cjs --extensions .ts,.js","build:types":"tsc -p tsconfig.build.json","build":"export KEY_TOKEN=$(node ./scripts/generate-random-id.js) && yarn build:esm && yarn build:cjs && yarn build:types","clean":"rm -rf lib","prepare":"yarn clean && yarn test && yarn build"},"devDependencies":{"@babel/cli":"^7.23.9","@babel/core":"^7.24.0","@babel/plugin-proposal-nullish-coalescing-operator":"^7.18.6","@babel/plugin-proposal-optional-chaining":"^7.21.0","@babel/plugin-transform-modules-commonjs":"^7.23.3","@babel/preset-typescript":"^7.23.3","@types/jest":"^29.5.12","@typescript-eslint/eslint-plugin":"^7.1.0","@typescript-eslint/parser":"^7.1.0","babel-plugin-transform-define":"^2.1.4","eslint":"^8.57.0","jest":"^29.7.0","prettier":"^3.2.5","typescript":"^5.3.3"},"peerDependencies":{"@types/node":"*","@types/parcel-env":"*","@types/webpack-env":"*","parcel":">=2","vite":">=2","webpack":">=4"},"peerDependenciesMeta":{"@types/node":{"optional":true},"@types/webpack-env":{"optional":true},"@types/parcel-env":{"optional":true},"webpack":{"optional":true},"vite":{"optional":true},"parcel":{"optional":true}},"_id":"@dkamyshov/hot-persist@1.1.1","gitHead":"e7293a38ad0cacd57e33a648b0becf078b6a9862","bugs":{"url":"https://github.com/dkamyshov/hot-persist/issues"},"homepage":"https://github.com/dkamyshov/hot-persist#readme","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-bIfoCRTucWst/43l8Zoi5SR+Uqk6628Z4tGh1Ek3MwNyI/L0lERnjQhMGSbj9B+DE2xz/zx9xXqHnxLWLOXeLQ==","shasum":"aad0f50db7df42d2eb696b4a821077b9c96ae950","tarball":"https://registry.npmjs.org/@dkamyshov/hot-persist/-/hot-persist-1.1.1.tgz","fileCount":33,"unpackedSize":44749,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEtAfwzjttB+h7TCpwE5JVFglNfALp8hv3ykT0Vg6EjlAiEA6sDucftlkScAQ5A34RGP21pKge5BeEDLyjE5C1u70g4="}]},"_npmUser":{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"},"directories":{},"maintainers":[{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hot-persist_1.1.1_1709378875681_0.7611315751882302"},"_hasShrinkwrap":false}},"maintainers":[{"name":"dkamyshov","email":"danil.kamyshov@gmail.com"}],"description":"The persistence API for HMR in webpack 4/5, vite 2/3/4, parcel 2.","homepage":"https://github.com/dkamyshov/hot-persist#readme","keywords":["hot-reload","hmr","webpack","vite","parcel","persist","persistence"],"repository":{"type":"git","url":"git+https://github.com/dkamyshov/hot-persist.git"},"bugs":{"url":"https://github.com/dkamyshov/hot-persist/issues"},"license":"MIT","readme":"# @dkamyshov/hot-persist\n\nDead simple persistence API for preserving data across hot reloads (supports webpack 4/5, vite 2/3/4/5, parcel 2). Zero dependencies!\n\n## Installation\n\n```sh\n$ npm i --save-dev @dkamyshov/hot-persist\n# or\n$ yarn add -D @dkamyshov/hot-persist\n```\n\n- Using TypeScript with `webpack`?\n\n  You should also install `@types/webpack-env` and `@types/node`.\n\n- Using TypeScript with `parcel`?\n\n  You should also install `@types/parcel-env`.\n\nRegardless of what bundler you use, if you use TypeScript, you should consider disabling type checking of declaration files: https://www.typescriptlang.org/tsconfig#skipLibCheck.\n\n## Usage\n\nThe HMR API is not standardised, so there are several ways to use this package. Examples (see below) use the \"legacy\" API for brevity.\n\n```js\nimport { persist } from '@dkamyshov/hot-persist';\n\n// webpack 4/5 (legacy way)\nconst instance = persist(module)(() => {\n  return {\n    /* ... */\n  };\n});\n\nif (module.hot) {\n  module.hot.accept();\n}\n\n// webpack 5 (modern way)\nconst instance = persist(() => import.meta.webpackHot)(() => {\n  return {\n    /* ... */\n  };\n});\n\nif (import.meta.webpackHot) {\n  import.meta.webpackHot.accept();\n}\n\n// vite 2/3/4\nconst instance = persist(() => import.meta.hot)(() => {\n  return {\n    /* ... */\n  };\n});\n\nif (import.meta.hot) {\n  import.meta.hot.accept();\n}\n```\n\nThe `persist` function accepts the object with `hot` API exposed (or a getter function) and then returns a new function which accepts 3 parameters:\n\n1. The `factory` function that returns the instance.\n2. The optional `dependencies` parameter, which is used to decide whether the instance should be recreated.\n\n   This works pretty much like React hooks' `dependencies` (it requires referential equality) with a slight difference: if the `dependencies` are not specified, the instance is never updated (unlike in React, where it means \"update on each run\").\n\n3. The optional `options` parameter.\n\n   1. `options.key` - the optional string key which is used to distinguish between multiple instances in a single module.\n   2. `options.cleanup` - the optional callback which is invoked if the instance is updated. The old instance is passed to the callback.\n\n   Instead of passing an object, you may pass a string here. The string will be treated as `options.key`.\n\n   If the `key` is not specified, the `persist` function automatically infers it based on the order of calls (much like hooks in React):\n\n   ```js\n   const a = persist(module)(() => ({})); // `key` is `0`\n   const b = persist(module)(() => ({})); // `key` is `1`\n   const c = persist(module)(() => ({})); // `key` is `2`\n   ```\n\nNote: in production (NODE_ENV === 'production') the `persist` function immediately calls `factory` and returns with the new result on each run. The same happens when HMR is not enabled.\n\n## Examples\n\n```js\nimport { persist } from '@dkamyshov/hot-persist';\n\n// Example 1. This instance never updates.\nconst value = persist(module)(() => {\n  return {\n    value: 0,\n  };\n});\n\n// Example 2. Same as above.\nconst value = persist(module)(() => {\n  return {\n    value: 0,\n  };\n}, []);\n\n// Example 3. The connection will be recreated\n// when the URL changes.\n\n// constants.js\nexport const URL = 'ws://localhost:8080/chat';\n\n// index.js\nimport { URL } from './constants';\n\nconst socket = persist(module)(() => new WebSocket(URL), [URL], {\n  cleanup: (socket) => {\n    socket.close();\n  },\n});\n\n// Example 4. The dependencies may be cascaded.\n// If `add.js` is updated, both `b` and `c` are\n// recreated. If `multiply.js` is updated, only `c`\n// is recreated.\n\n// add.js\nexport const add = (a, b) => a + b;\n\n// multiply.js\nexport const multiply = (a, b) => a * b;\n\n// index.js\nimport { add } from './add';\nimport { multiply } from './multiply';\n\nconst a = persist(module)(() => {\n  return { value: 0 };\n});\n\nconst b = persist(module)(() => {\n  return { value: add(a.value, 1) };\n}, [add, a]);\n\nconst c = persist(module)(() => {\n  return { value: multiply(b.value, 2) };\n}, [multiply, b]);\n```\n","readmeFilename":"README.md"}