From fda245fb02621996bd7ebef4d937fab2f320c480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=98=9F?= Date: Fri, 6 Feb 2026 11:13:50 +0800 Subject: [PATCH 1/6] feat: add build step to output compiled JS - Add build script with tsc - Update exports to point to dist/ - Add prepublishOnly hook - Set type: module for ESM output Co-authored-by: Cursor --- .gitignore | 5 ++++- package.json | 19 +++++++++++-------- tsconfig.json | 6 +++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 0638af9..f71b69b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # Dependencies -node_modules/ \ No newline at end of file +node_modules/ + +# Build output +dist/ \ No newline at end of file diff --git a/package.json b/package.json index 9a059b2..1ae6090 100644 --- a/package.json +++ b/package.json @@ -2,24 +2,27 @@ "name": "@lovart-open/flags", "version": "0.0.2", "description": "Feature flag management with multi-layer priority system (client-side)", - "main": "src/index.ts", - "types": "src/index.ts", + "type": "module", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": { - "types": "./src/index.ts", - "default": "./src/index.ts" + "types": "./dist/index.d.ts", + "import": "./dist/index.js" }, "./statsig": { - "types": "./src/statsig/index.ts", - "default": "./src/statsig/index.ts" + "types": "./dist/statsig/index.d.ts", + "import": "./dist/statsig/index.js" } }, "files": [ - "src" + "dist" ], "scripts": { + "build": "tsc", "typecheck": "tsc --noEmit", - "test": "vitest run" + "test": "vitest run", + "prepublishOnly": "pnpm build" }, "keywords": [ "feature-flag", diff --git a/tsconfig.json b/tsconfig.json index fbc8113..e7013d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ES2020", - "module": "commonjs", + "module": "ESNext", "lib": ["ES2020", "DOM", "DOM.Iterable"], "outDir": "./dist", "rootDir": "./src", @@ -12,8 +12,8 @@ "declaration": true, "declarationMap": true, "sourceMap": true, - "moduleResolution": "node" + "moduleResolution": "bundler" }, "include": ["src"], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist", "src/__tests__"] } From c3a980251e00a0e6293208c11dfaa860d06c2113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=98=9F?= Date: Fri, 6 Feb 2026 11:43:55 +0800 Subject: [PATCH 2/6] chore: update build script and add tsup dependency --- package.json | 3 +- pnpm-lock.yaml | 280 +++++++++++++++++++++++++++++++++++++++++++++++++ tsup.config.ts | 24 +++++ 3 files changed, 306 insertions(+), 1 deletion(-) create mode 100644 tsup.config.ts diff --git a/package.json b/package.json index 1ae6090..e78b9e7 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dist" ], "scripts": { - "build": "tsc", + "build": "tsup", "typecheck": "tsc --noEmit", "test": "vitest run", "prepublishOnly": "pnpm build" @@ -42,6 +42,7 @@ "@types/lodash": "^4.17.0", "@types/react": "^18.0.0 || ^19.0.0", "jsdom": "^23.0.1", + "tsup": "^8.5.1", "typescript": "^5.6.3", "vitest": "^3.2.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4cf4a4f..0b309e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,9 @@ importers: jsdom: specifier: ^23.0.1 version: 23.2.0 + tsup: + specifier: ^8.5.1 + version: 8.5.1(postcss@8.5.6)(typescript@5.9.3) typescript: specifier: ^5.6.3 version: 5.9.3 @@ -247,9 +250,19 @@ packages: cpu: [x64] os: [win32] + '@jridgewell/gen-mapping@0.3.13': + resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==} + + '@jridgewell/resolve-uri@3.1.2': + resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} + engines: {node: '>=6.0.0'} + '@jridgewell/sourcemap-codec@1.5.5': resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==} + '@jridgewell/trace-mapping@0.3.31': + resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==} + '@rollup/rollup-android-arm-eabi@4.57.1': resolution: {integrity: sha512-A6ehUVSiSaaliTxai040ZpZ2zTevHYbvu/lDoeAteHI8QnaosIzm4qwtezfRg1jOYaUmnzLX1AOD6Z+UJjtifg==} cpu: [arm] @@ -452,6 +465,11 @@ packages: '@vitest/utils@3.2.4': resolution: {integrity: sha512-fB2V0JFrQSMsCo9HiSq3Ezpdv4iYaXRG1Sx8edX3MwxfyNn83mKiGzOcH+Fkxt4MHxr3y42fQi1oeAInqgX2QA==} + acorn@8.15.0: + resolution: {integrity: sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==} + engines: {node: '>=0.4.0'} + hasBin: true + agent-base@7.1.4: resolution: {integrity: sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==} engines: {node: '>= 14'} @@ -464,6 +482,9 @@ packages: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} engines: {node: '>=10'} + any-promise@1.3.0: + resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} + aria-query@5.3.0: resolution: {integrity: sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==} @@ -477,6 +498,12 @@ packages: bidi-js@1.0.3: resolution: {integrity: sha512-RKshQI1R3YQ+n9YJz2QQ147P66ELpa1FQEg20Dk8oW9t2KgLbpDLLp9aGZ7y8WHSshDknG0bknqGw5/tyCs5tw==} + bundle-require@5.1.0: + resolution: {integrity: sha512-3WrrOuZiyaaZPWiEt4G3+IffISVC9HYlWueJEBWED4ZH4aIAC2PnkdnuRrR94M+w6yGWn4AglWtJtBI8YqvgoA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + peerDependencies: + esbuild: '>=0.18' + cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -493,10 +520,25 @@ packages: resolution: {integrity: sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==} engines: {node: '>= 16'} + chokidar@4.0.3: + resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} + engines: {node: '>= 14.16.0'} + combined-stream@1.0.8: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} + commander@4.1.1: + resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} + engines: {node: '>= 6'} + + confbox@0.1.8: + resolution: {integrity: sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==} + + consola@3.4.2: + resolution: {integrity: sha512-5IKcdX0nnYavi6G7TtOhwkYzyjfJlatbjMjuLSfE2kYT5pMDOilZ4OvMhi637CcDICTmz3wARPoyhqyX1Y+XvA==} + engines: {node: ^14.18.0 || >=16.10.0} + css-tree@2.3.1: resolution: {integrity: sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==} engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0} @@ -587,6 +629,9 @@ packages: picomatch: optional: true + fix-dts-default-cjs-exports@1.0.1: + resolution: {integrity: sha512-pVIECanWFC61Hzl2+oOCtoJ3F17kglZC/6N94eRWycFgBH35hHx0Li604ZIzhseh97mf2p0cv7vVrOZGoqhlEg==} + form-data@4.0.5: resolution: {integrity: sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==} engines: {node: '>= 6'} @@ -642,6 +687,10 @@ packages: is-potential-custom-element-name@1.0.1: resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} + joycon@3.1.1: + resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} + engines: {node: '>=10'} + js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -657,6 +706,17 @@ packages: canvas: optional: true + lilconfig@3.1.3: + resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} + engines: {node: '>=14'} + + lines-and-columns@1.2.4: + resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} + + load-tsconfig@0.2.5: + resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + lodash@4.17.23: resolution: {integrity: sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==} @@ -688,14 +748,24 @@ packages: resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} engines: {node: '>= 0.6'} + mlly@1.8.0: + resolution: {integrity: sha512-l8D9ODSRWLe2KHJSifWGwBqpTZXIXTeo8mlKjY+E2HAakaTeNpqAyBZ8GSqLzHgw4XmHmC8whvpjJNMbFZN7/g==} + ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + mz@2.7.0: + resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} + nanoid@3.3.11: resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + object-assign@4.1.1: + resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} + engines: {node: '>=0.10.0'} + parse5@7.3.0: resolution: {integrity: sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==} @@ -713,6 +783,31 @@ packages: resolution: {integrity: sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==} engines: {node: '>=12'} + pirates@4.0.7: + resolution: {integrity: sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==} + engines: {node: '>= 6'} + + pkg-types@1.3.1: + resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==} + + postcss-load-config@6.0.1: + resolution: {integrity: sha512-oPtTM4oerL+UXmx+93ytZVN82RrlY/wPUV8IeDxFrzIjXOLF1pN+EmKPLbubvKHT2HC20xXsCAH2Z+CKV6Oz/g==} + engines: {node: '>= 18'} + peerDependencies: + jiti: '>=1.21.0' + postcss: '>=8.0.9' + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + jiti: + optional: true + postcss: + optional: true + tsx: + optional: true + yaml: + optional: true + postcss@8.5.6: resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} engines: {node: ^10 || ^12 || >=14} @@ -743,6 +838,10 @@ packages: resolution: {integrity: sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ==} engines: {node: '>=0.10.0'} + readdirp@4.1.2: + resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==} + engines: {node: '>= 14.18.0'} + require-from-string@2.0.2: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} @@ -750,6 +849,10 @@ packages: requires-port@1.0.0: resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} + resolve-from@5.0.0: + resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} + engines: {node: '>=8'} + rollup@4.57.1: resolution: {integrity: sha512-oQL6lgK3e2QZeQ7gcgIkS2YZPg5slw37hYufJ3edKlfQSGGm8ICoxswK15ntSzF/a8+h7ekRy7k7oWc3BQ7y8A==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -778,6 +881,10 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} + source-map@0.7.6: + resolution: {integrity: sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ==} + engines: {node: '>= 12'} + stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} @@ -787,9 +894,21 @@ packages: strip-literal@3.1.0: resolution: {integrity: sha512-8r3mkIM/2+PpjHoOtiAW8Rg3jJLHaV7xPwG+YRGrv6FP0wwk/toTpATxWYOW0BKdWwl82VT2tFYi5DlROa0Mxg==} + sucrase@3.35.1: + resolution: {integrity: sha512-DhuTmvZWux4H1UOnWMB3sk0sbaCVOoQZjv8u1rDoTV0HTdGem9hkAZtl4JZy8P2z4Bg0nT+YMeOFyVr4zcG5Tw==} + engines: {node: '>=16 || 14 >=14.17'} + hasBin: true + symbol-tree@3.2.4: resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} + thenify-all@1.6.0: + resolution: {integrity: sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==} + engines: {node: '>=0.8'} + + thenify@3.3.1: + resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} + tinybench@2.9.0: resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} @@ -820,11 +939,40 @@ packages: resolution: {integrity: sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==} engines: {node: '>=18'} + tree-kill@1.2.2: + resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} + hasBin: true + + ts-interface-checker@0.1.13: + resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} + + tsup@8.5.1: + resolution: {integrity: sha512-xtgkqwdhpKWr3tKPmCkvYmS9xnQK3m3XgxZHwSUjvfTjp7YfXe5tT3GgWi0F2N+ZSMsOeWeZFh7ZZFg5iPhing==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + '@microsoft/api-extractor': ^7.36.0 + '@swc/core': ^1 + postcss: ^8.4.12 + typescript: '>=4.5.0' + peerDependenciesMeta: + '@microsoft/api-extractor': + optional: true + '@swc/core': + optional: true + postcss: + optional: true + typescript: + optional: true + typescript@5.9.3: resolution: {integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==} engines: {node: '>=14.17'} hasBin: true + ufo@1.6.3: + resolution: {integrity: sha512-yDJTmhydvl5lJzBmy/hyOAA0d+aqCBuwl818haVdYCRrWV84o7YyeVm4QlVHStqNrrJSTb6jKuFAVqAFsr+K3Q==} + universalify@0.2.0: resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} engines: {node: '>= 4.0.0'} @@ -1077,8 +1225,20 @@ snapshots: '@esbuild/win32-x64@0.27.2': optional: true + '@jridgewell/gen-mapping@0.3.13': + dependencies: + '@jridgewell/sourcemap-codec': 1.5.5 + '@jridgewell/trace-mapping': 0.3.31 + + '@jridgewell/resolve-uri@3.1.2': {} + '@jridgewell/sourcemap-codec@1.5.5': {} + '@jridgewell/trace-mapping@0.3.31': + dependencies: + '@jridgewell/resolve-uri': 3.1.2 + '@jridgewell/sourcemap-codec': 1.5.5 + '@rollup/rollup-android-arm-eabi@4.57.1': optional: true @@ -1245,12 +1405,16 @@ snapshots: loupe: 3.2.1 tinyrainbow: 2.0.0 + acorn@8.15.0: {} + agent-base@7.1.4: {} ansi-regex@5.0.1: {} ansi-styles@5.2.0: {} + any-promise@1.3.0: {} + aria-query@5.3.0: dependencies: dequal: 2.0.3 @@ -1263,6 +1427,11 @@ snapshots: dependencies: require-from-string: 2.0.2 + bundle-require@5.1.0(esbuild@0.27.2): + dependencies: + esbuild: 0.27.2 + load-tsconfig: 0.2.5 + cac@6.7.14: {} call-bind-apply-helpers@1.0.2: @@ -1280,10 +1449,20 @@ snapshots: check-error@2.1.3: {} + chokidar@4.0.3: + dependencies: + readdirp: 4.1.2 + combined-stream@1.0.8: dependencies: delayed-stream: 1.0.0 + commander@4.1.1: {} + + confbox@0.1.8: {} + + consola@3.4.2: {} + css-tree@2.3.1: dependencies: mdn-data: 2.0.30 @@ -1379,6 +1558,12 @@ snapshots: optionalDependencies: picomatch: 4.0.3 + fix-dts-default-cjs-exports@1.0.1: + dependencies: + magic-string: 0.30.21 + mlly: 1.8.0 + rollup: 4.57.1 + form-data@4.0.5: dependencies: asynckit: 0.4.0 @@ -1446,6 +1631,8 @@ snapshots: is-potential-custom-element-name@1.0.1: {} + joycon@3.1.1: {} + js-tokens@4.0.0: {} js-tokens@9.0.1: {} @@ -1478,6 +1665,12 @@ snapshots: - supports-color - utf-8-validate + lilconfig@3.1.3: {} + + lines-and-columns@1.2.4: {} + + load-tsconfig@0.2.5: {} + lodash@4.17.23: {} loupe@3.2.1: {} @@ -1500,10 +1693,25 @@ snapshots: dependencies: mime-db: 1.52.0 + mlly@1.8.0: + dependencies: + acorn: 8.15.0 + pathe: 2.0.3 + pkg-types: 1.3.1 + ufo: 1.6.3 + ms@2.1.3: {} + mz@2.7.0: + dependencies: + any-promise: 1.3.0 + object-assign: 4.1.1 + thenify-all: 1.6.0 + nanoid@3.3.11: {} + object-assign@4.1.1: {} + parse5@7.3.0: dependencies: entities: 6.0.1 @@ -1516,6 +1724,20 @@ snapshots: picomatch@4.0.3: {} + pirates@4.0.7: {} + + pkg-types@1.3.1: + dependencies: + confbox: 0.1.8 + mlly: 1.8.0 + pathe: 2.0.3 + + postcss-load-config@6.0.1(postcss@8.5.6): + dependencies: + lilconfig: 3.1.3 + optionalDependencies: + postcss: 8.5.6 + postcss@8.5.6: dependencies: nanoid: 3.3.11 @@ -1545,10 +1767,14 @@ snapshots: react@19.2.4: {} + readdirp@4.1.2: {} + require-from-string@2.0.2: {} requires-port@1.0.0: {} + resolve-from@5.0.0: {} + rollup@4.57.1: dependencies: '@types/estree': 1.0.8 @@ -1596,6 +1822,8 @@ snapshots: source-map-js@1.2.1: {} + source-map@0.7.6: {} + stackback@0.0.2: {} std-env@3.10.0: {} @@ -1604,8 +1832,26 @@ snapshots: dependencies: js-tokens: 9.0.1 + sucrase@3.35.1: + dependencies: + '@jridgewell/gen-mapping': 0.3.13 + commander: 4.1.1 + lines-and-columns: 1.2.4 + mz: 2.7.0 + pirates: 4.0.7 + tinyglobby: 0.2.15 + ts-interface-checker: 0.1.13 + symbol-tree@3.2.4: {} + thenify-all@1.6.0: + dependencies: + thenify: 3.3.1 + + thenify@3.3.1: + dependencies: + any-promise: 1.3.0 + tinybench@2.9.0: {} tinyexec@0.3.2: {} @@ -1632,8 +1878,42 @@ snapshots: dependencies: punycode: 2.3.1 + tree-kill@1.2.2: {} + + ts-interface-checker@0.1.13: {} + + tsup@8.5.1(postcss@8.5.6)(typescript@5.9.3): + dependencies: + bundle-require: 5.1.0(esbuild@0.27.2) + cac: 6.7.14 + chokidar: 4.0.3 + consola: 3.4.2 + debug: 4.4.3 + esbuild: 0.27.2 + fix-dts-default-cjs-exports: 1.0.1 + joycon: 3.1.1 + picocolors: 1.1.1 + postcss-load-config: 6.0.1(postcss@8.5.6) + resolve-from: 5.0.0 + rollup: 4.57.1 + source-map: 0.7.6 + sucrase: 3.35.1 + tinyexec: 0.3.2 + tinyglobby: 0.2.15 + tree-kill: 1.2.2 + optionalDependencies: + postcss: 8.5.6 + typescript: 5.9.3 + transitivePeerDependencies: + - jiti + - supports-color + - tsx + - yaml + typescript@5.9.3: {} + ufo@1.6.3: {} + universalify@0.2.0: {} url-parse@1.5.10: diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000..82ff474 --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,24 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig([ + // 主入口 + { + entry: { index: 'src/index.ts' }, + format: ['esm'], + dts: true, + sourcemap: true, + clean: true, + outDir: 'dist', + }, + // statsig 子模块 + { + entry: { 'statsig/index': 'src/statsig/index.ts' }, + format: ['esm'], + dts: true, + sourcemap: true, + outDir: 'dist', + // 不打包依赖,保持代码分离 + noExternal: [/^\.\.?\//], + bundle: true, + }, +]); From e65a8281ddeb7b83c950ef3d06ec9bfbb5ac14ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=98=9F?= Date: Fri, 6 Feb 2026 11:49:08 +0800 Subject: [PATCH 3/6] fix: add default export condition for CJS compatibility ts-node with commonjs module cannot resolve subpath exports without a default fallback condition. Co-authored-by: Cursor --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e78b9e7..47faf06 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,13 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.js" + "import": "./dist/index.js", + "default": "./dist/index.js" }, "./statsig": { "types": "./dist/statsig/index.d.ts", - "import": "./dist/statsig/index.js" + "import": "./dist/statsig/index.js", + "default": "./dist/statsig/index.js" } }, "files": [ From d5dbf796955d26fc3d277ae813f87efedc7f9a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=98=9F?= Date: Fri, 6 Feb 2026 11:58:54 +0800 Subject: [PATCH 4/6] fix: replace lodash with lodash-es for ESM compatibility lodash is CJS-only and breaks named imports in ESM context. Co-authored-by: Cursor --- package.json | 3 ++- pnpm-lock.yaml | 20 +++++++++++++++----- src/statsig/params.ts | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 47faf06..1089eb1 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,13 @@ "dependencies": { "@statsig/js-client": "^3.30.0", "@statsig/react-bindings": "^3.30.2", - "lodash": "^4.17.21", + "lodash-es": "^4.17.23", "zod": "^3.23.0" }, "devDependencies": { "@testing-library/react": "^16.3.0", "@types/lodash": "^4.17.0", + "@types/lodash-es": "^4.17.12", "@types/react": "^18.0.0 || ^19.0.0", "jsdom": "^23.0.1", "tsup": "^8.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b309e3..161eebe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,8 +14,8 @@ importers: '@statsig/react-bindings': specifier: ^3.30.2 version: 3.31.2(react@19.2.4) - lodash: - specifier: ^4.17.21 + lodash-es: + specifier: ^4.17.23 version: 4.17.23 react: specifier: ^18.0.0 || ^19.0.0 @@ -30,6 +30,9 @@ importers: '@types/lodash': specifier: ^4.17.0 version: 4.17.23 + '@types/lodash-es': + specifier: ^4.17.12 + version: 4.17.12 '@types/react': specifier: ^18.0.0 || ^19.0.0 version: 19.2.11 @@ -430,6 +433,9 @@ packages: '@types/estree@1.0.8': resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} + '@types/lodash-es@4.17.12': + resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==} + '@types/lodash@4.17.23': resolution: {integrity: sha512-RDvF6wTulMPjrNdCoYRC8gNR880JNGT8uB+REUpC2Ns4pRqQJhGz90wh7rgdXDPpCczF3VGktDuFGVnz8zP7HA==} @@ -717,8 +723,8 @@ packages: resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - lodash@4.17.23: - resolution: {integrity: sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==} + lodash-es@4.17.23: + resolution: {integrity: sha512-kVI48u3PZr38HdYz98UmfPnXl2DXrpdctLrFLCd3kOx1xUkOmpFPx7gCWWM5MPkL/fD8zb+Ph0QzjGFs4+hHWg==} loupe@3.2.1: resolution: {integrity: sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==} @@ -1357,6 +1363,10 @@ snapshots: '@types/estree@1.0.8': {} + '@types/lodash-es@4.17.12': + dependencies: + '@types/lodash': 4.17.23 + '@types/lodash@4.17.23': {} '@types/react@19.2.11': @@ -1671,7 +1681,7 @@ snapshots: load-tsconfig@0.2.5: {} - lodash@4.17.23: {} + lodash-es@4.17.23: {} loupe@3.2.1: {} diff --git a/src/statsig/params.ts b/src/statsig/params.ts index 19752e5..a06410e 100644 --- a/src/statsig/params.ts +++ b/src/statsig/params.ts @@ -3,7 +3,7 @@ * Use createParamStore to create type-safe parameter stores and hooks. */ -import { merge, set } from 'lodash'; +import { merge, set } from 'lodash-es'; import { useParameterStore } from '@statsig/react-bindings'; import z from 'zod'; From 161cab358b77ae1b9a14fb988c71e059c4d2a889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=98=9F?= Date: Fri, 6 Feb 2026 12:09:27 +0800 Subject: [PATCH 5/6] chore: remove unused @types/lodash dependency from package.json and pnpm-lock.yaml --- package.json | 1 - pnpm-lock.yaml | 3 --- 2 files changed, 4 deletions(-) diff --git a/package.json b/package.json index 1089eb1..2938674 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ }, "devDependencies": { "@testing-library/react": "^16.3.0", - "@types/lodash": "^4.17.0", "@types/lodash-es": "^4.17.12", "@types/react": "^18.0.0 || ^19.0.0", "jsdom": "^23.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 161eebe..38f4ed4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,9 +27,6 @@ importers: '@testing-library/react': specifier: ^16.3.0 version: 16.3.2(@testing-library/dom@10.4.1)(@types/react@19.2.11)(react-dom@19.2.4(react@19.2.4))(react@19.2.4) - '@types/lodash': - specifier: ^4.17.0 - version: 4.17.23 '@types/lodash-es': specifier: ^4.17.12 version: 4.17.12 From 7e6331eec603caa85c3e6106519f93de67de7cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=98=9F?= Date: Fri, 6 Feb 2026 18:36:52 +0800 Subject: [PATCH 6/6] fix: graceful fallback when statsig client is not initialized FlagStore.resolve() and ParamStore.resolve() now catch the getStatsigClientSync() throw and return fallback values instead of crashing, preventing module-level side-effects from blowing up when the entry point has not called initStatsigClient() yet. Co-authored-by: Cursor --- src/statsig/client.ts | 2 +- src/statsig/flags.ts | 14 +++++++++----- src/statsig/params.ts | 17 +++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/statsig/client.ts b/src/statsig/client.ts index 6bcbb05..f6c72b4 100644 --- a/src/statsig/client.ts +++ b/src/statsig/client.ts @@ -109,7 +109,7 @@ export function initStatsigClient( */ export function getStatsigClientSync(): StatsigClient { if (!client) { - throw new Error('[@lovart-open/statsig] Not initialized. Call initStatsigClient() first.'); + throw new Error('[@lovart-open/flags/statsig] Not initialized. Call initStatsigClient() first.'); } return client; } diff --git a/src/statsig/flags.ts b/src/statsig/flags.ts index b76bfbb..ed259a1 100644 --- a/src/statsig/flags.ts +++ b/src/statsig/flags.ts @@ -88,11 +88,15 @@ export class FlagStore> { } // 4. Remote value from Statsig - const currentGate = gate ?? getStatsigClientSync().getFeatureGate(keyStr, evaluationOptions); - return { - flag: currentGate.value, - source: currentGate.idType ? 'remote' : 'fallback', - }; + try { + const currentGate = gate ?? getStatsigClientSync().getFeatureGate(keyStr, evaluationOptions); + return { + flag: currentGate.value, + source: currentGate.idType ? 'remote' : 'fallback', + }; + } catch { + return { flag: false, source: 'fallback' }; + } } } diff --git a/src/statsig/params.ts b/src/statsig/params.ts index a06410e..1748ca1 100644 --- a/src/statsig/params.ts +++ b/src/statsig/params.ts @@ -245,12 +245,17 @@ export class ParamStore } // 4. Remote value from Statsig else { - const clientStore = statsigStore ?? getStatsigClientSync().getParameterStore(storeKey as string, evaluationOptions); - const config = (clientStore as any)?.__configuration?.[paramKey as string]; - if (config !== undefined) { - value = clientStore.get(paramKey as string, def.fallback); - source = 'remote'; - } else { + try { + const clientStore = statsigStore ?? getStatsigClientSync().getParameterStore(storeKey as string, evaluationOptions); + const config = (clientStore as any)?.__configuration?.[paramKey as string]; + if (config !== undefined) { + value = clientStore.get(paramKey as string, def.fallback); + source = 'remote'; + } else { + value = def.fallback; + source = 'fallback'; + } + } catch { value = def.fallback; source = 'fallback'; }