@depup/jotai 2.18.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/babel/plugin-debug-label.d.ts +5 -0
- package/babel/plugin-debug-label.js +54 -0
- package/babel/plugin-react-refresh.d.ts +5 -0
- package/babel/plugin-react-refresh.js +72 -0
- package/babel/preset.d.ts +6 -0
- package/babel/preset.js +110 -0
- package/babel/utils.d.ts +5 -0
- package/benchmarks/simple-read.d.ts +2 -0
- package/benchmarks/simple-write.d.ts +2 -0
- package/benchmarks/subscribe-write.d.ts +2 -0
- package/changes.json +5 -0
- package/esm/babel/plugin-debug-label.d.mts +5 -0
- package/esm/babel/plugin-debug-label.mjs +103 -0
- package/esm/babel/plugin-react-refresh.d.mts +5 -0
- package/esm/babel/plugin-react-refresh.mjs +121 -0
- package/esm/babel/preset.d.mts +6 -0
- package/esm/babel/preset.mjs +179 -0
- package/esm/babel/utils.d.mts +5 -0
- package/esm/index.d.mts +2 -0
- package/esm/index.mjs +2 -0
- package/esm/react/Provider.d.mts +16 -0
- package/esm/react/useAtom.d.mts +13 -0
- package/esm/react/useAtomValue.d.mts +9 -0
- package/esm/react/useSetAtom.d.mts +7 -0
- package/esm/react/utils/useAtomCallback.d.mts +5 -0
- package/esm/react/utils/useHydrateAtoms.d.mts +14 -0
- package/esm/react/utils/useReducerAtom.d.mts +14 -0
- package/esm/react/utils/useResetAtom.d.mts +6 -0
- package/esm/react/utils.d.mts +4 -0
- package/esm/react/utils.mjs +57 -0
- package/esm/react.d.mts +4 -0
- package/esm/react.mjs +182 -0
- package/esm/utils.d.mts +2 -0
- package/esm/utils.mjs +2 -0
- package/esm/vanilla/atom.d.mts +47 -0
- package/esm/vanilla/internals.d.mts +164 -0
- package/esm/vanilla/internals.mjs +715 -0
- package/esm/vanilla/store.d.mts +5 -0
- package/esm/vanilla/typeUtils.d.mts +7 -0
- package/esm/vanilla/utils/atomFamily.d.mts +55 -0
- package/esm/vanilla/utils/atomWithDefault.d.mts +6 -0
- package/esm/vanilla/utils/atomWithLazy.d.mts +2 -0
- package/esm/vanilla/utils/atomWithObservable.d.mts +32 -0
- package/esm/vanilla/utils/atomWithReducer.d.mts +3 -0
- package/esm/vanilla/utils/atomWithRefresh.d.mts +6 -0
- package/esm/vanilla/utils/atomWithReset.d.mts +8 -0
- package/esm/vanilla/utils/atomWithStorage.d.mts +50 -0
- package/esm/vanilla/utils/constants.d.mts +1 -0
- package/esm/vanilla/utils/freezeAtom.d.mts +6 -0
- package/esm/vanilla/utils/loadable.d.mts +33 -0
- package/esm/vanilla/utils/selectAtom.d.mts +2 -0
- package/esm/vanilla/utils/splitAtom.d.mts +16 -0
- package/esm/vanilla/utils/unwrap.d.mts +5 -0
- package/esm/vanilla/utils.d.mts +14 -0
- package/esm/vanilla/utils.mjs +736 -0
- package/esm/vanilla.d.mts +4 -0
- package/esm/vanilla.mjs +59 -0
- package/index.d.ts +2 -0
- package/index.js +19 -0
- package/package.json +125 -0
- package/react/Provider.d.ts +16 -0
- package/react/useAtom.d.ts +13 -0
- package/react/useAtomValue.d.ts +9 -0
- package/react/useSetAtom.d.ts +7 -0
- package/react/utils/useAtomCallback.d.ts +5 -0
- package/react/utils/useHydrateAtoms.d.ts +14 -0
- package/react/utils/useReducerAtom.d.ts +14 -0
- package/react/utils/useResetAtom.d.ts +6 -0
- package/react/utils.d.ts +4 -0
- package/react/utils.js +100 -0
- package/react.d.ts +4 -0
- package/react.js +182 -0
- package/system/babel/plugin-debug-label.development.js +113 -0
- package/system/babel/plugin-debug-label.production.js +4 -0
- package/system/babel/plugin-react-refresh.development.js +131 -0
- package/system/babel/plugin-react-refresh.production.js +11 -0
- package/system/babel/preset.development.js +189 -0
- package/system/babel/preset.production.js +14 -0
- package/system/index.development.js +27 -0
- package/system/index.production.js +1 -0
- package/system/react/utils.development.js +79 -0
- package/system/react/utils.production.js +2 -0
- package/system/react.development.js +210 -0
- package/system/react.production.js +2 -0
- package/system/utils.development.js +27 -0
- package/system/utils.production.js +1 -0
- package/system/vanilla/internals.development.js +735 -0
- package/system/vanilla/internals.production.js +1 -0
- package/system/vanilla/utils.development.js +764 -0
- package/system/vanilla/utils.production.js +1 -0
- package/system/vanilla.development.js +75 -0
- package/system/vanilla.production.js +1 -0
- package/ts3.8/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/babel/preset.d.ts +7 -0
- package/ts3.8/babel/utils.d.ts +6 -0
- package/ts3.8/benchmarks/simple-read.d.ts +3 -0
- package/ts3.8/benchmarks/simple-write.d.ts +3 -0
- package/ts3.8/benchmarks/subscribe-write.d.ts +3 -0
- package/ts3.8/esm/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/esm/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/esm/babel/preset.d.ts +7 -0
- package/ts3.8/esm/babel/utils.d.ts +6 -0
- package/ts3.8/esm/index.d.ts +3 -0
- package/ts3.8/esm/react/Provider.d.ts +17 -0
- package/ts3.8/esm/react/useAtom.d.ts +28 -0
- package/ts3.8/esm/react/useAtomValue.d.ts +10 -0
- package/ts3.8/esm/react/useSetAtom.d.ts +8 -0
- package/ts3.8/esm/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/esm/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/esm/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/esm/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/esm/react/utils.d.ts +5 -0
- package/ts3.8/esm/react.d.ts +5 -0
- package/ts3.8/esm/utils.d.ts +3 -0
- package/ts3.8/esm/vanilla/atom.d.ts +48 -0
- package/ts3.8/esm/vanilla/internals.d.ts +165 -0
- package/ts3.8/esm/vanilla/store.d.ts +6 -0
- package/ts3.8/esm/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/esm/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/esm/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/esm/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/esm/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/esm/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/esm/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/esm/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/esm/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/esm/vanilla/utils.d.ts +15 -0
- package/ts3.8/esm/vanilla.d.ts +5 -0
- package/ts3.8/index.d.ts +3 -0
- package/ts3.8/react/Provider.d.ts +17 -0
- package/ts3.8/react/useAtom.d.ts +28 -0
- package/ts3.8/react/useAtomValue.d.ts +10 -0
- package/ts3.8/react/useSetAtom.d.ts +8 -0
- package/ts3.8/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/react/utils.d.ts +5 -0
- package/ts3.8/react.d.ts +5 -0
- package/ts3.8/utils.d.ts +3 -0
- package/ts3.8/vanilla/atom.d.ts +48 -0
- package/ts3.8/vanilla/internals.d.ts +165 -0
- package/ts3.8/vanilla/store.d.ts +6 -0
- package/ts3.8/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/vanilla/utils.d.ts +15 -0
- package/ts3.8/vanilla.d.ts +5 -0
- package/ts_version_3.8_and_above_is_required.d.ts +0 -0
- package/umd/babel/plugin-debug-label.development.js +58 -0
- package/umd/babel/plugin-debug-label.production.js +1 -0
- package/umd/babel/plugin-react-refresh.development.js +76 -0
- package/umd/babel/plugin-react-refresh.production.js +1 -0
- package/umd/babel/preset.development.js +114 -0
- package/umd/babel/preset.production.js +1 -0
- package/umd/index.development.js +20 -0
- package/umd/index.production.js +1 -0
- package/umd/react/utils.development.js +101 -0
- package/umd/react/utils.production.js +1 -0
- package/umd/react.development.js +184 -0
- package/umd/react.production.js +1 -0
- package/umd/utils.development.js +20 -0
- package/umd/utils.production.js +1 -0
- package/umd/vanilla/internals.development.js +785 -0
- package/umd/vanilla/internals.production.js +1 -0
- package/umd/vanilla/utils.development.js +858 -0
- package/umd/vanilla/utils.production.js +1 -0
- package/umd/vanilla.development.js +64 -0
- package/umd/vanilla.production.js +1 -0
- package/utils.d.ts +2 -0
- package/utils.js +19 -0
- package/vanilla/atom.d.ts +47 -0
- package/vanilla/internals.d.ts +164 -0
- package/vanilla/internals.js +779 -0
- package/vanilla/store.d.ts +5 -0
- package/vanilla/typeUtils.d.ts +7 -0
- package/vanilla/utils/atomFamily.d.ts +55 -0
- package/vanilla/utils/atomWithDefault.d.ts +6 -0
- package/vanilla/utils/atomWithLazy.d.ts +2 -0
- package/vanilla/utils/atomWithObservable.d.ts +32 -0
- package/vanilla/utils/atomWithReducer.d.ts +3 -0
- package/vanilla/utils/atomWithRefresh.d.ts +6 -0
- package/vanilla/utils/atomWithReset.d.ts +8 -0
- package/vanilla/utils/atomWithStorage.d.ts +50 -0
- package/vanilla/utils/constants.d.ts +1 -0
- package/vanilla/utils/freezeAtom.d.ts +6 -0
- package/vanilla/utils/loadable.d.ts +33 -0
- package/vanilla/utils/selectAtom.d.ts +2 -0
- package/vanilla/utils/splitAtom.d.ts +16 -0
- package/vanilla/utils/unwrap.d.ts +5 -0
- package/vanilla/utils.d.ts +14 -0
- package/vanilla/utils.js +854 -0
- package/vanilla.d.ts +4 -0
- package/vanilla.js +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Poimandres
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @depup/jotai
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [jotai](https://www.npmjs.com/package/jotai)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/jotai
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [jotai](https://www.npmjs.com/package/jotai) @ 2.18.0 |
|
|
17
|
+
| Processed | 2026-03-09 |
|
|
18
|
+
| Smoke test | failed |
|
|
19
|
+
| Deps updated | 0 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/jotai
|
|
24
|
+
|
|
25
|
+
License inherited from the original package.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-debug-label` instead. */
|
|
5
|
+
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _templateBuilder = require('@babel/template');
|
|
4
|
+
|
|
5
|
+
function isAtom(t, callee, customAtomNames) {
|
|
6
|
+
if (customAtomNames === void 0) {
|
|
7
|
+
customAtomNames = [];
|
|
8
|
+
}
|
|
9
|
+
var atomNames = [].concat(atomFunctionNames, customAtomNames);
|
|
10
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (t.isMemberExpression(callee)) {
|
|
14
|
+
var property = callee.property;
|
|
15
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var atomFunctionNames = ['atom', 'atomFamily', 'atomWithDefault', 'atomWithObservable', 'atomWithReducer', 'atomWithReset', 'atomWithStorage', 'freezeAtom', 'loadable', 'selectAtom', 'splitAtom', 'unwrap', 'atomWithMachine', 'atomWithImmer', 'atomWithProxy', 'atomWithQuery', 'atomWithMutation', 'atomWithSubscription', 'atomWithStore', 'atomWithHash', 'atomWithLocation', 'focusAtom', 'atomWithValidate', 'validateAtoms', 'atomWithCache', 'atomWithRecoilValue'];
|
|
22
|
+
|
|
23
|
+
var templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
24
|
+
function debugLabelPlugin(_ref, options) {
|
|
25
|
+
var t = _ref.types;
|
|
26
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
27
|
+
return {
|
|
28
|
+
visitor: {
|
|
29
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
30
|
+
var node = nodePath.node;
|
|
31
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
32
|
+
var filename = (state.filename || 'unknown').replace(/\.\w+$/, '');
|
|
33
|
+
var displayName = filename.split('/').pop();
|
|
34
|
+
if (displayName === 'index') {
|
|
35
|
+
displayName = filename.slice(0, -'/index'.length).split('/').pop() || 'unknown';
|
|
36
|
+
}
|
|
37
|
+
var buildExport = templateBuilder("\n const %%atomIdentifier%% = %%atom%%;\n export default %%atomIdentifier%%\n ");
|
|
38
|
+
var ast = buildExport({
|
|
39
|
+
atomIdentifier: t.identifier(displayName),
|
|
40
|
+
atom: node.declaration
|
|
41
|
+
});
|
|
42
|
+
nodePath.replaceWithMultiple(ast);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
VariableDeclarator: function VariableDeclarator(path) {
|
|
46
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
47
|
+
path.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(path.node.id.name), t.identifier('debugLabel')), t.stringLiteral(path.node.id.name))));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = debugLabelPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-react-refresh` instead. */
|
|
5
|
+
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _templateBuilder = require('@babel/template');
|
|
4
|
+
|
|
5
|
+
function isAtom(t, callee, customAtomNames) {
|
|
6
|
+
if (customAtomNames === void 0) {
|
|
7
|
+
customAtomNames = [];
|
|
8
|
+
}
|
|
9
|
+
var atomNames = [].concat(atomFunctionNames, customAtomNames);
|
|
10
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (t.isMemberExpression(callee)) {
|
|
14
|
+
var property = callee.property;
|
|
15
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var atomFunctionNames = ['atom', 'atomFamily', 'atomWithDefault', 'atomWithObservable', 'atomWithReducer', 'atomWithReset', 'atomWithStorage', 'freezeAtom', 'loadable', 'selectAtom', 'splitAtom', 'unwrap', 'atomWithMachine', 'atomWithImmer', 'atomWithProxy', 'atomWithQuery', 'atomWithMutation', 'atomWithSubscription', 'atomWithStore', 'atomWithHash', 'atomWithLocation', 'focusAtom', 'atomWithValidate', 'validateAtoms', 'atomWithCache', 'atomWithRecoilValue'];
|
|
22
|
+
|
|
23
|
+
var templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
24
|
+
function reactRefreshPlugin(_ref, options) {
|
|
25
|
+
var t = _ref.types;
|
|
26
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
27
|
+
return {
|
|
28
|
+
pre: function pre(_ref2) {
|
|
29
|
+
var opts = _ref2.opts;
|
|
30
|
+
if (!opts.filename) {
|
|
31
|
+
throw new Error('Filename must be available');
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
visitor: {
|
|
35
|
+
Program: {
|
|
36
|
+
exit: function exit(path) {
|
|
37
|
+
var jotaiAtomCache = templateBuilder("\n globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {\n cache: new Map(),\n get(name, inst) { \n if (this.cache.has(name)) {\n return this.cache.get(name)\n }\n this.cache.set(name, inst)\n return inst\n },\n }")();
|
|
38
|
+
path.unshiftContainer('body', jotaiAtomCache);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
42
|
+
var node = nodePath.node;
|
|
43
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
44
|
+
var filename = state.filename || 'unknown';
|
|
45
|
+
var atomKey = filename + "/defaultExport";
|
|
46
|
+
var buildExport = templateBuilder("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
47
|
+
var ast = buildExport({
|
|
48
|
+
atomKey: t.stringLiteral(atomKey),
|
|
49
|
+
atom: node.declaration
|
|
50
|
+
});
|
|
51
|
+
nodePath.replaceWith(ast);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
VariableDeclarator: function VariableDeclarator(nodePath, state) {
|
|
55
|
+
var _nodePath$parentPath$, _nodePath$parentPath$2;
|
|
56
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && ((_nodePath$parentPath$ = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$.isProgram() || (_nodePath$parentPath$2 = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$2.isExportNamedDeclaration())) {
|
|
57
|
+
var filename = state.filename || 'unknown';
|
|
58
|
+
var atomKey = filename + "/" + nodePath.node.id.name;
|
|
59
|
+
var buildAtomDeclaration = templateBuilder("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
60
|
+
var ast = buildAtomDeclaration({
|
|
61
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
62
|
+
atomKey: t.stringLiteral(atomKey),
|
|
63
|
+
atom: nodePath.node.init
|
|
64
|
+
});
|
|
65
|
+
nodePath.parentPath.replaceWith(ast);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = reactRefreshPlugin;
|
package/babel/preset.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _templateBuilder = require('@babel/template');
|
|
4
|
+
|
|
5
|
+
function isAtom(t, callee, customAtomNames) {
|
|
6
|
+
if (customAtomNames === void 0) {
|
|
7
|
+
customAtomNames = [];
|
|
8
|
+
}
|
|
9
|
+
var atomNames = [].concat(atomFunctionNames, customAtomNames);
|
|
10
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (t.isMemberExpression(callee)) {
|
|
14
|
+
var property = callee.property;
|
|
15
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var atomFunctionNames = ['atom', 'atomFamily', 'atomWithDefault', 'atomWithObservable', 'atomWithReducer', 'atomWithReset', 'atomWithStorage', 'freezeAtom', 'loadable', 'selectAtom', 'splitAtom', 'unwrap', 'atomWithMachine', 'atomWithImmer', 'atomWithProxy', 'atomWithQuery', 'atomWithMutation', 'atomWithSubscription', 'atomWithStore', 'atomWithHash', 'atomWithLocation', 'focusAtom', 'atomWithValidate', 'validateAtoms', 'atomWithCache', 'atomWithRecoilValue'];
|
|
22
|
+
|
|
23
|
+
var templateBuilder$1 = _templateBuilder.default || _templateBuilder;
|
|
24
|
+
function debugLabelPlugin(_ref, options) {
|
|
25
|
+
var t = _ref.types;
|
|
26
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
27
|
+
return {
|
|
28
|
+
visitor: {
|
|
29
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
30
|
+
var node = nodePath.node;
|
|
31
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
32
|
+
var filename = (state.filename || 'unknown').replace(/\.\w+$/, '');
|
|
33
|
+
var displayName = filename.split('/').pop();
|
|
34
|
+
if (displayName === 'index') {
|
|
35
|
+
displayName = filename.slice(0, -'/index'.length).split('/').pop() || 'unknown';
|
|
36
|
+
}
|
|
37
|
+
var buildExport = templateBuilder$1("\n const %%atomIdentifier%% = %%atom%%;\n export default %%atomIdentifier%%\n ");
|
|
38
|
+
var ast = buildExport({
|
|
39
|
+
atomIdentifier: t.identifier(displayName),
|
|
40
|
+
atom: node.declaration
|
|
41
|
+
});
|
|
42
|
+
nodePath.replaceWithMultiple(ast);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
VariableDeclarator: function VariableDeclarator(path) {
|
|
46
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
47
|
+
path.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(path.node.id.name), t.identifier('debugLabel')), t.stringLiteral(path.node.id.name))));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
55
|
+
function reactRefreshPlugin(_ref, options) {
|
|
56
|
+
var t = _ref.types;
|
|
57
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
58
|
+
return {
|
|
59
|
+
pre: function pre(_ref2) {
|
|
60
|
+
var opts = _ref2.opts;
|
|
61
|
+
if (!opts.filename) {
|
|
62
|
+
throw new Error('Filename must be available');
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
visitor: {
|
|
66
|
+
Program: {
|
|
67
|
+
exit: function exit(path) {
|
|
68
|
+
var jotaiAtomCache = templateBuilder("\n globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {\n cache: new Map(),\n get(name, inst) { \n if (this.cache.has(name)) {\n return this.cache.get(name)\n }\n this.cache.set(name, inst)\n return inst\n },\n }")();
|
|
69
|
+
path.unshiftContainer('body', jotaiAtomCache);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
73
|
+
var node = nodePath.node;
|
|
74
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
75
|
+
var filename = state.filename || 'unknown';
|
|
76
|
+
var atomKey = filename + "/defaultExport";
|
|
77
|
+
var buildExport = templateBuilder("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
78
|
+
var ast = buildExport({
|
|
79
|
+
atomKey: t.stringLiteral(atomKey),
|
|
80
|
+
atom: node.declaration
|
|
81
|
+
});
|
|
82
|
+
nodePath.replaceWith(ast);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
VariableDeclarator: function VariableDeclarator(nodePath, state) {
|
|
86
|
+
var _nodePath$parentPath$, _nodePath$parentPath$2;
|
|
87
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && ((_nodePath$parentPath$ = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$.isProgram() || (_nodePath$parentPath$2 = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$2.isExportNamedDeclaration())) {
|
|
88
|
+
var filename = state.filename || 'unknown';
|
|
89
|
+
var atomKey = filename + "/" + nodePath.node.id.name;
|
|
90
|
+
var buildAtomDeclaration = templateBuilder("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
91
|
+
var ast = buildAtomDeclaration({
|
|
92
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
93
|
+
atomKey: t.stringLiteral(atomKey),
|
|
94
|
+
atom: nodePath.node.init
|
|
95
|
+
});
|
|
96
|
+
nodePath.parentPath.replaceWith(ast);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function jotaiPreset(_, options) {
|
|
104
|
+
console.warn('[DEPRECATED] jotai/babel/preset is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
105
|
+
return {
|
|
106
|
+
plugins: [[debugLabelPlugin, options], [reactRefreshPlugin, options]]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = jotaiPreset;
|
package/babel/utils.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { types } from '@babel/core';
|
|
2
|
+
export interface PluginOptions {
|
|
3
|
+
customAtomNames?: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare function isAtom(t: typeof types, callee: babel.types.Expression | babel.types.V8IntrinsicIdentifier, customAtomNames?: PluginOptions['customAtomNames']): boolean;
|
package/changes.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils.mjs';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-debug-label` instead. */
|
|
5
|
+
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import '@babel/core';
|
|
2
|
+
import _templateBuilder from '@babel/template';
|
|
3
|
+
|
|
4
|
+
function isAtom(t, callee, customAtomNames = []) {
|
|
5
|
+
const atomNames = [...atomFunctionNames, ...customAtomNames];
|
|
6
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (t.isMemberExpression(callee)) {
|
|
10
|
+
const { property } = callee;
|
|
11
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const atomFunctionNames = [
|
|
18
|
+
// Core
|
|
19
|
+
"atom",
|
|
20
|
+
"atomFamily",
|
|
21
|
+
"atomWithDefault",
|
|
22
|
+
"atomWithObservable",
|
|
23
|
+
"atomWithReducer",
|
|
24
|
+
"atomWithReset",
|
|
25
|
+
"atomWithStorage",
|
|
26
|
+
"freezeAtom",
|
|
27
|
+
"loadable",
|
|
28
|
+
"selectAtom",
|
|
29
|
+
"splitAtom",
|
|
30
|
+
"unwrap",
|
|
31
|
+
// jotai-xstate
|
|
32
|
+
"atomWithMachine",
|
|
33
|
+
// jotai-immer
|
|
34
|
+
"atomWithImmer",
|
|
35
|
+
// jotai-valtio
|
|
36
|
+
"atomWithProxy",
|
|
37
|
+
// jotai-trpc + jotai-relay
|
|
38
|
+
"atomWithQuery",
|
|
39
|
+
"atomWithMutation",
|
|
40
|
+
"atomWithSubscription",
|
|
41
|
+
// jotai-redux + jotai-zustand
|
|
42
|
+
"atomWithStore",
|
|
43
|
+
// jotai-location
|
|
44
|
+
"atomWithHash",
|
|
45
|
+
"atomWithLocation",
|
|
46
|
+
// jotai-optics
|
|
47
|
+
"focusAtom",
|
|
48
|
+
// jotai-form
|
|
49
|
+
"atomWithValidate",
|
|
50
|
+
"validateAtoms",
|
|
51
|
+
// jotai-cache
|
|
52
|
+
"atomWithCache",
|
|
53
|
+
// jotai-recoil
|
|
54
|
+
"atomWithRecoilValue"
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
58
|
+
function debugLabelPlugin({ types: t }, options) {
|
|
59
|
+
console.warn(
|
|
60
|
+
"[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
61
|
+
);
|
|
62
|
+
return {
|
|
63
|
+
visitor: {
|
|
64
|
+
ExportDefaultDeclaration(nodePath, state) {
|
|
65
|
+
const { node } = nodePath;
|
|
66
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
67
|
+
const filename = (state.filename || "unknown").replace(/\.\w+$/, "");
|
|
68
|
+
let displayName = filename.split("/").pop();
|
|
69
|
+
if (displayName === "index") {
|
|
70
|
+
displayName = filename.slice(0, -"/index".length).split("/").pop() || "unknown";
|
|
71
|
+
}
|
|
72
|
+
const buildExport = templateBuilder(`
|
|
73
|
+
const %%atomIdentifier%% = %%atom%%;
|
|
74
|
+
export default %%atomIdentifier%%
|
|
75
|
+
`);
|
|
76
|
+
const ast = buildExport({
|
|
77
|
+
atomIdentifier: t.identifier(displayName),
|
|
78
|
+
atom: node.declaration
|
|
79
|
+
});
|
|
80
|
+
nodePath.replaceWithMultiple(ast);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
VariableDeclarator(path) {
|
|
84
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
85
|
+
path.parentPath.insertAfter(
|
|
86
|
+
t.expressionStatement(
|
|
87
|
+
t.assignmentExpression(
|
|
88
|
+
"=",
|
|
89
|
+
t.memberExpression(
|
|
90
|
+
t.identifier(path.node.id.name),
|
|
91
|
+
t.identifier("debugLabel")
|
|
92
|
+
),
|
|
93
|
+
t.stringLiteral(path.node.id.name)
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { debugLabelPlugin as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils.mjs';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-react-refresh` instead. */
|
|
5
|
+
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import '@babel/core';
|
|
2
|
+
import _templateBuilder from '@babel/template';
|
|
3
|
+
|
|
4
|
+
function isAtom(t, callee, customAtomNames = []) {
|
|
5
|
+
const atomNames = [...atomFunctionNames, ...customAtomNames];
|
|
6
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (t.isMemberExpression(callee)) {
|
|
10
|
+
const { property } = callee;
|
|
11
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const atomFunctionNames = [
|
|
18
|
+
// Core
|
|
19
|
+
"atom",
|
|
20
|
+
"atomFamily",
|
|
21
|
+
"atomWithDefault",
|
|
22
|
+
"atomWithObservable",
|
|
23
|
+
"atomWithReducer",
|
|
24
|
+
"atomWithReset",
|
|
25
|
+
"atomWithStorage",
|
|
26
|
+
"freezeAtom",
|
|
27
|
+
"loadable",
|
|
28
|
+
"selectAtom",
|
|
29
|
+
"splitAtom",
|
|
30
|
+
"unwrap",
|
|
31
|
+
// jotai-xstate
|
|
32
|
+
"atomWithMachine",
|
|
33
|
+
// jotai-immer
|
|
34
|
+
"atomWithImmer",
|
|
35
|
+
// jotai-valtio
|
|
36
|
+
"atomWithProxy",
|
|
37
|
+
// jotai-trpc + jotai-relay
|
|
38
|
+
"atomWithQuery",
|
|
39
|
+
"atomWithMutation",
|
|
40
|
+
"atomWithSubscription",
|
|
41
|
+
// jotai-redux + jotai-zustand
|
|
42
|
+
"atomWithStore",
|
|
43
|
+
// jotai-location
|
|
44
|
+
"atomWithHash",
|
|
45
|
+
"atomWithLocation",
|
|
46
|
+
// jotai-optics
|
|
47
|
+
"focusAtom",
|
|
48
|
+
// jotai-form
|
|
49
|
+
"atomWithValidate",
|
|
50
|
+
"validateAtoms",
|
|
51
|
+
// jotai-cache
|
|
52
|
+
"atomWithCache",
|
|
53
|
+
// jotai-recoil
|
|
54
|
+
"atomWithRecoilValue"
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
58
|
+
function reactRefreshPlugin({ types: t }, options) {
|
|
59
|
+
console.warn(
|
|
60
|
+
"[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
61
|
+
);
|
|
62
|
+
return {
|
|
63
|
+
pre({ opts }) {
|
|
64
|
+
if (!opts.filename) {
|
|
65
|
+
throw new Error("Filename must be available");
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
visitor: {
|
|
69
|
+
Program: {
|
|
70
|
+
exit(path) {
|
|
71
|
+
const jotaiAtomCache = templateBuilder(`
|
|
72
|
+
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
|
|
73
|
+
cache: new Map(),
|
|
74
|
+
get(name, inst) {
|
|
75
|
+
if (this.cache.has(name)) {
|
|
76
|
+
return this.cache.get(name)
|
|
77
|
+
}
|
|
78
|
+
this.cache.set(name, inst)
|
|
79
|
+
return inst
|
|
80
|
+
},
|
|
81
|
+
}`)();
|
|
82
|
+
path.unshiftContainer("body", jotaiAtomCache);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
ExportDefaultDeclaration(nodePath, state) {
|
|
86
|
+
const { node } = nodePath;
|
|
87
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
88
|
+
const filename = state.filename || "unknown";
|
|
89
|
+
const atomKey = `${filename}/defaultExport`;
|
|
90
|
+
const buildExport = templateBuilder(
|
|
91
|
+
`export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
|
|
92
|
+
);
|
|
93
|
+
const ast = buildExport({
|
|
94
|
+
atomKey: t.stringLiteral(atomKey),
|
|
95
|
+
atom: node.declaration
|
|
96
|
+
});
|
|
97
|
+
nodePath.replaceWith(ast);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
VariableDeclarator(nodePath, state) {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && // Make sure atom declaration is in module scope
|
|
103
|
+
(((_a = nodePath.parentPath.parentPath) == null ? void 0 : _a.isProgram()) || ((_b = nodePath.parentPath.parentPath) == null ? void 0 : _b.isExportNamedDeclaration()))) {
|
|
104
|
+
const filename = state.filename || "unknown";
|
|
105
|
+
const atomKey = `${filename}/${nodePath.node.id.name}`;
|
|
106
|
+
const buildAtomDeclaration = templateBuilder(
|
|
107
|
+
`const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
|
|
108
|
+
);
|
|
109
|
+
const ast = buildAtomDeclaration({
|
|
110
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
111
|
+
atomKey: t.stringLiteral(atomKey),
|
|
112
|
+
atom: nodePath.node.init
|
|
113
|
+
});
|
|
114
|
+
nodePath.parentPath.replaceWith(ast);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { reactRefreshPlugin as default };
|