@lomray/react-mobx-manager 2.0.0-beta.16 → 2.0.0-beta.18
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.
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type ICache = Map<string, {
|
|
2
|
+
storeId: string;
|
|
3
|
+
classname: string;
|
|
4
|
+
}>;
|
|
5
|
+
/**
|
|
6
|
+
* Load cached store id's by file name
|
|
7
|
+
*/
|
|
8
|
+
declare const loadCache: (isProd?: boolean) => ICache;
|
|
9
|
+
/**
|
|
10
|
+
* Save store id's cache
|
|
11
|
+
*/
|
|
12
|
+
declare const saveCache: (cache: ICache) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Get next letter
|
|
15
|
+
*/
|
|
16
|
+
declare const getNextLetter: (str?: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Store is generator
|
|
19
|
+
*/
|
|
20
|
+
declare class Generator {
|
|
21
|
+
cache: ICache;
|
|
22
|
+
protected root: string;
|
|
23
|
+
protected lastId: string;
|
|
24
|
+
// keep last generated production store id (letter)
|
|
25
|
+
constructor(root: string, isProd?: boolean);
|
|
26
|
+
/**
|
|
27
|
+
* Inject store id
|
|
28
|
+
*/
|
|
29
|
+
injectId: (code: string, fileId: string) => string;
|
|
30
|
+
/**
|
|
31
|
+
* Get development id
|
|
32
|
+
*/
|
|
33
|
+
getDevId: (id: string, classname: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Get production store id
|
|
36
|
+
*/
|
|
37
|
+
getProdId: () => string;
|
|
38
|
+
/**
|
|
39
|
+
* Try to find mobx store
|
|
40
|
+
*/
|
|
41
|
+
matchMobxStore: (code: string) => string | undefined;
|
|
42
|
+
}
|
|
43
|
+
export { saveCache, loadCache, getNextLetter, Generator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("node:fs"));const r=`${__dirname.split("node_modules")[0]}node_modules/.cache/@lomray/react-mobx-manager`,s=`${r}/store-ids.json`,a=(e=!1)=>{if(e&&t.default.existsSync(s)){const e=JSON.parse(t.default.readFileSync(s,{encoding:"utf-8"}));return new Map(e)}return new Map},i=(e="")=>{var t;const r=e.split(""),s=null!==(t=r.pop())&&void 0!==t?t:"`";if("z"===s)return[...r,"A"].join("");if("Z"===s){const e=r.pop();return e?[i([...r,e].join("")),"a"].join(""):"aa"}return[...r,String.fromCharCode(s.charCodeAt(0)+1)].join("")};exports.Generator=class{constructor(e,t=!1){Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lastId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"injectId",{enumerable:!0,configurable:!0,writable:!0,value:(e,t)=>{const{classname:r,storeId:s}=this.cache.get(t),a=new RegExp(`(class\\s${r}\\s+?{)`);return e.replace(a,`$1static id = '${s}';`)}}),Object.defineProperty(this,"getDevId",{enumerable:!0,configurable:!0,writable:!0,value:(e,t)=>`${e.replace(this.root,"").replace(/\/index.(js|ts|tsx)/,"").split("/").filter(Boolean).join("-")}-${t}`}),Object.defineProperty(this,"getProdId",{enumerable:!0,configurable:!0,writable:!0,value:()=>{const e=i(this.lastId),t=`S${e}`;return this.lastId=e,t}}),Object.defineProperty(this,"matchMobxStore",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var t,r,s,a;const{classname:i}=null!==(r=null===(t=e.match(/class\s(?<classname>\w+)\s+?{(?!.*static\sid\s*=.*).+(makeObservable|makeAutoObservable)(?!.*persistStore\(\1.*)/s))||void 0===t?void 0:t.groups)&&void 0!==r?r:{};if(i)return i;const{classname:n}=null!==(a=null===(s=e.match(/(@mobx-store).+class\s(?<classname>\w+)\s+?{(?!.*static\sid\s*=.*).+}(?!.*persistStore.*)/s))||void 0===s?void 0:s.groups)&&void 0!==a?a:{};return n}}),this.cache=a(t)}},exports.getNextLetter=i,exports.loadCache=a,exports.saveCache=e=>{t.default.existsSync(r)||t.default.mkdirSync(r,{recursive:!0}),t.default.writeFileSync(s,JSON.stringify([...e.entries()],null,2),{encoding:"utf-8"})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("node:path"),r=require("node:process"),t=require("../helpers.js");module.exports=function({root:s=r.cwd(),isProd:a=!1}={}){const n=new t.Generator(s,a);return{name:"@lomray/react-mobx-manager-id-generator",transform(r,t){const s=e.extname(t).split("?")[0];if(t.includes("node_modules")||![".js",".ts",".tsx"].includes(s)||!/(makeObservable|makeAutoObservable)\(/.test(r))return;if(n.cache.has(t))return{code:n.injectId(r,t),map:{mappings:""}};const o=n.matchMobxStore(r);if(o){if(!n.cache.has(t)){const e=a?n.getProdId():n.getDevId(t,o);n.cache.set(t,{classname:o,storeId:e})}return{code:n.injectId(r,t),map:{mappings:""}}}},buildEnd(){a&&t.saveCache(n.cache)}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:process"),r=require("./hydration-update-fix.js"),t=require("./id-generator.js");function
|
|
1
|
+
"use strict";var e=require("node:process"),r=require("./hydration-update-fix.js"),t=require("./id-generator.js");function n(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var o=n(e);const i=e=>"production"===e||"production"===o.env.NODE_ENV;module.exports=function(){let e;return[{...r(),apply:()=>!i()},{name:t().name,configResolved({root:r}){e=t({root:r,isProd:i()})},transform(...r){var t;return null===(t=e.transform)||void 0===t?void 0:t.call(this,...r)},buildEnd(...r){var t;null===(t=e.buildEnd)||void 0===t||t.call(this,...r)}}]};
|