diff --git a/wasm/.gitignore b/wasm/.gitignore index c5163388..a2eba98a 100644 --- a/wasm/.gitignore +++ b/wasm/.gitignore @@ -1,5 +1,7 @@ stylua.web/ stylua_lib.cjs +stylua_lib.mjs LICENSE.md README.md *.tgz +node_modules diff --git a/wasm/build-wasm.sh b/wasm/build-wasm.sh index 08c630dd..38d824df 100755 --- a/wasm/build-wasm.sh +++ b/wasm/build-wasm.sh @@ -1,10 +1,19 @@ # TODO: Ensure that version is up to date cp README.md wasm/ cp LICENSE.md wasm/ + +# Build WASM with wasm-pack npx wasm-pack@0.10.3 build --target web --out-dir wasm/stylua.web -- --features lua52,lua53,lua54,luajit,luau,cfxlua # workaround for bundler usage -echo "export { getImports as __getImports, finalizeInit as __finalizeInit }" >> wasm/stylua.web/stylua_lib.js +echo "export { __wbg_get_imports as __getImports, __wbg_finalize_init as __finalizeInit }" >> wasm/stylua.web/stylua_lib.js # bundle for node CommonJS -npx rollup@4.9.5 wasm/src/stylua_lib_node.cjs --file wasm/stylua_lib.cjs --format cjs +cd wasm && ./node_modules/.bin/rollup src/stylua_lib_node.mjs --file stylua_lib.cjs --format cjs \ + --external 'node:fs,node:path,node:url' --plugin @rollup/plugin-node-resolve --plugin @rollup/plugin-commonjs +cd .. + +# bundle for node ESM +cd wasm && ./node_modules/.bin/rollup src/stylua_lib_node.mjs --file stylua_lib.mjs --format es \ + --external 'node:fs,node:path,node:url' +cd .. diff --git a/wasm/package-lock.json b/wasm/package-lock.json new file mode 100644 index 00000000..800cc900 --- /dev/null +++ b/wasm/package-lock.json @@ -0,0 +1,608 @@ +{ + "name": "@johnnymorganz/stylua", + "version": "2.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@johnnymorganz/stylua", + "version": "2.1.0", + "license": "MPL-2.0", + "devDependencies": { + "@rollup/plugin-commonjs": "^28.0.6", + "@rollup/plugin-node-resolve": "^16.0.1", + "rollup": "^4.44.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@rollup/plugin-commonjs": { + "version": "28.0.6", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-28.0.6.tgz", + "integrity": "sha512-XSQB1K7FUU5QP+3lOQmVCE3I0FcbbNvmNT4VJSj93iUjayaARrTQeoRdiYQoftAJBLrR9t2agwAd3ekaTgHNlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "commondir": "^1.0.1", + "estree-walker": "^2.0.2", + "fdir": "^6.2.0", + "is-reference": "1.2.1", + "magic-string": "^0.30.3", + "picomatch": "^4.0.2" + }, + "engines": { + "node": ">=16.0.0 || 14 >= 14.17" + }, + "peerDependencies": { + "rollup": "^2.68.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-node-resolve": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-16.0.1.tgz", + "integrity": "sha512-tk5YCxJWIG81umIvNkSod2qK5KyQW19qcBF/B78n1bjtOON6gzKoVeSzAE8yHCZEDmqkHKkxplExA8KzdJLJpA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "@types/resolve": "1.20.2", + "deepmerge": "^4.2.2", + "is-module": "^1.0.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.78.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.2.0.tgz", + "integrity": "sha512-qWJ2ZTbmumwiLFomfzTyt5Kng4hwPi9rwCYN4SHb6eaRU1KNO4ccxINHr/VhH4GgPlt1XfSTLX2LBTme8ne4Zw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^4.0.2" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.44.0.tgz", + "integrity": "sha512-xEiEE5oDW6tK4jXCAyliuntGR+amEMO7HLtdSshVuhFnKTYoeYMyXQK7pLouAJJj5KHdwdn87bfHAR2nSdNAUA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.44.0.tgz", + "integrity": "sha512-uNSk/TgvMbskcHxXYHzqwiyBlJ/lGcv8DaUfcnNwict8ba9GTTNxfn3/FAoFZYgkaXXAdrAA+SLyKplyi349Jw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.44.0.tgz", + "integrity": "sha512-VGF3wy0Eq1gcEIkSCr8Ke03CWT+Pm2yveKLaDvq51pPpZza3JX/ClxXOCmTYYq3us5MvEuNRTaeyFThCKRQhOA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.44.0.tgz", + "integrity": "sha512-fBkyrDhwquRvrTxSGH/qqt3/T0w5Rg0L7ZIDypvBPc1/gzjJle6acCpZ36blwuwcKD/u6oCE/sRWlUAcxLWQbQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.44.0.tgz", + "integrity": "sha512-u5AZzdQJYJXByB8giQ+r4VyfZP+walV+xHWdaFx/1VxsOn6eWJhK2Vl2eElvDJFKQBo/hcYIBg/jaKS8ZmKeNQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.44.0.tgz", + "integrity": "sha512-qC0kS48c/s3EtdArkimctY7h3nHicQeEUdjJzYVJYR3ct3kWSafmn6jkNCA8InbUdge6PVx6keqjk5lVGJf99g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.44.0.tgz", + "integrity": "sha512-x+e/Z9H0RAWckn4V2OZZl6EmV0L2diuX3QB0uM1r6BvhUIv6xBPL5mrAX2E3e8N8rEHVPwFfz/ETUbV4oW9+lQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.44.0.tgz", + "integrity": "sha512-1exwiBFf4PU/8HvI8s80icyCcnAIB86MCBdst51fwFmH5dyeoWVPVgmQPcKrMtBQ0W5pAs7jBCWuRXgEpRzSCg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.44.0.tgz", + "integrity": "sha512-ZTR2mxBHb4tK4wGf9b8SYg0Y6KQPjGpR4UWwTFdnmjB4qRtoATZ5dWn3KsDwGa5Z2ZBOE7K52L36J9LueKBdOQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.44.0.tgz", + "integrity": "sha512-GFWfAhVhWGd4r6UxmnKRTBwP1qmModHtd5gkraeW2G490BpFOZkFtem8yuX2NyafIP/mGpRJgTJ2PwohQkUY/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loongarch64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loongarch64-gnu/-/rollup-linux-loongarch64-gnu-4.44.0.tgz", + "integrity": "sha512-xw+FTGcov/ejdusVOqKgMGW3c4+AgqrfvzWEVXcNP6zq2ue+lsYUgJ+5Rtn/OTJf7e2CbgTFvzLW2j0YAtj0Gg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.44.0.tgz", + "integrity": "sha512-bKGibTr9IdF0zr21kMvkZT4K6NV+jjRnBoVMt2uNMG0BYWm3qOVmYnXKzx7UhwrviKnmK46IKMByMgvpdQlyJQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.44.0.tgz", + "integrity": "sha512-vV3cL48U5kDaKZtXrti12YRa7TyxgKAIDoYdqSIOMOFBXqFj2XbChHAtXquEn2+n78ciFgr4KIqEbydEGPxXgA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.44.0.tgz", + "integrity": "sha512-TDKO8KlHJuvTEdfw5YYFBjhFts2TR0VpZsnLLSYmB7AaohJhM8ctDSdDnUGq77hUh4m/djRafw+9zQpkOanE2Q==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.44.0.tgz", + "integrity": "sha512-8541GEyktXaw4lvnGp9m84KENcxInhAt6vPWJ9RodsB/iGjHoMB2Pp5MVBCiKIRxrxzJhGCxmNzdu+oDQ7kwRA==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.44.0.tgz", + "integrity": "sha512-iUVJc3c0o8l9Sa/qlDL2Z9UP92UZZW1+EmQ4xfjTc1akr0iUFZNfxrXJ/R1T90h/ILm9iXEY6+iPrmYB3pXKjw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.44.0.tgz", + "integrity": "sha512-PQUobbhLTQT5yz/SPg116VJBgz+XOtXt8D1ck+sfJJhuEsMj2jSej5yTdp8CvWBSceu+WW+ibVL6dm0ptG5fcA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.44.0.tgz", + "integrity": "sha512-M0CpcHf8TWn+4oTxJfh7LQuTuaYeXGbk0eageVjQCKzYLsajWS/lFC94qlRqOlyC2KvRT90ZrfXULYmukeIy7w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.44.0.tgz", + "integrity": "sha512-3XJ0NQtMAXTWFW8FqZKcw3gOQwBtVWP/u8TpHP3CRPXD7Pd6s8lLdH3sHWh8vqKCyyiI8xW5ltJScQmBU9j7WA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.44.0.tgz", + "integrity": "sha512-Q2Mgwt+D8hd5FIPUuPDsvPR7Bguza6yTkJxspDGkZj7tBRn2y4KSWYuIXpftFSjBra76TbKerCV7rgFPQrn+wQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@types/estree": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", + "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "dev": true, + "license": "MIT" + }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/fdir": { + "version": "6.4.6", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.6.tgz", + "integrity": "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/is-core-module": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", + "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", + "dev": true, + "license": "MIT", + "dependencies": { + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", + "dev": true, + "license": "MIT" + }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "*" + } + }, + "node_modules/magic-string": { + "version": "0.30.17", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", + "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true, + "license": "MIT" + }, + "node_modules/picomatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/resolve": { + "version": "1.22.10", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz", + "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-core-module": "^2.16.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/rollup": { + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.44.0.tgz", + "integrity": "sha512-qHcdEzLCiktQIfwBq420pn2dP+30uzqYxv9ETm91wdt2R9AFcWfjNAmje4NWlnCIQ5RMTzVf0ZyisOKqHR6RwA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "1.0.8" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.44.0", + "@rollup/rollup-android-arm64": "4.44.0", + "@rollup/rollup-darwin-arm64": "4.44.0", + "@rollup/rollup-darwin-x64": "4.44.0", + "@rollup/rollup-freebsd-arm64": "4.44.0", + "@rollup/rollup-freebsd-x64": "4.44.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.44.0", + "@rollup/rollup-linux-arm-musleabihf": "4.44.0", + "@rollup/rollup-linux-arm64-gnu": "4.44.0", + "@rollup/rollup-linux-arm64-musl": "4.44.0", + "@rollup/rollup-linux-loongarch64-gnu": "4.44.0", + "@rollup/rollup-linux-powerpc64le-gnu": "4.44.0", + "@rollup/rollup-linux-riscv64-gnu": "4.44.0", + "@rollup/rollup-linux-riscv64-musl": "4.44.0", + "@rollup/rollup-linux-s390x-gnu": "4.44.0", + "@rollup/rollup-linux-x64-gnu": "4.44.0", + "@rollup/rollup-linux-x64-musl": "4.44.0", + "@rollup/rollup-win32-arm64-msvc": "4.44.0", + "@rollup/rollup-win32-ia32-msvc": "4.44.0", + "@rollup/rollup-win32-x64-msvc": "4.44.0", + "fsevents": "~2.3.2" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + } + } +} diff --git a/wasm/package.json b/wasm/package.json index 20ba8135..aee2c12e 100644 --- a/wasm/package.json +++ b/wasm/package.json @@ -16,45 +16,20 @@ "stylua.web/stylua_lib_bg.wasm", "stylua.web/stylua_lib.d.ts", "stylua.web/stylua_lib.js", - "stylua_lib_bundler_wbg.cjs", - "stylua_lib_bundler.d.ts", - "stylua_lib_bundler.js", "stylua_lib.cjs", - "stylua_lib.d.cts", - "stylua_lib.d.mts", "stylua_lib.mjs", "LICENSE.md" ], "type": "module", "main": "stylua_lib.cjs", - "module": "stylua_lib_bundler.js", + "module": "stylua_lib.mjs", "types": "stylua.web/stylua_lib.d.ts", "exports": { ".": { - "webpack": { - "node": "./stylua_lib.mjs", - "default": "./stylua_lib_bundler.js" - }, - "require": { - "types": "./stylua_lib.d.cts", - "default": "./stylua_lib.cjs" - }, - "node": { - "types": "./stylua_lib.d.mts", - "default": "./stylua_lib.mjs" - }, - "deno": { - "types": "./stylua_lib.d.mts", - "default": "./stylua_lib.mjs" - }, - "bun": { - "types": "./stylua_lib.d.mts", - "default": "./stylua_lib.mjs" - }, - "default": { - "types": "./stylua_lib_bundler.d.ts", - "default": "./stylua_lib_bundler.js" - } + "types": "./stylua.web/stylua_lib.d.ts", + "require": "./stylua_lib.cjs", + "import": "./stylua_lib.mjs", + "default": "./stylua_lib.mjs" }, "./web": { "types": "./stylua.web/stylua_lib.d.ts", @@ -62,15 +37,12 @@ }, "./web/*": "./stylua.web/*", "./stylua_lib_bg.wasm": "./stylua.web/stylua_lib_bg.wasm", - "./package.josn": "./package.josn", + "./package.json": "./package.json", "./*": "./*" }, - "browser": { - "wbg": "./stylua_lib_bundler_wbg.cjs" - }, "sideEffects": [ "stylua_lib.mjs", - "stylua_lib_bundler.js" + "stylua_lib.cjs" ], "keywords": [ "cli", @@ -78,5 +50,10 @@ "lua", "lua51", "formatter" - ] + ], + "devDependencies": { + "@rollup/plugin-commonjs": "^28.0.6", + "@rollup/plugin-node-resolve": "^16.0.1", + "rollup": "^4.44.0" + } } diff --git a/wasm/src/stylua_lib_node.cjs b/wasm/src/stylua_lib_node.cjs deleted file mode 100644 index 7853d558..00000000 --- a/wasm/src/stylua_lib_node.cjs +++ /dev/null @@ -1,7 +0,0 @@ -export * from "../stylua.web/stylua_lib.js"; -import { initSync } from "../stylua.web/stylua_lib.js"; - -const path = require("path").join(__dirname, "stylua.web/stylua_lib_bg.wasm"); -const bytes = require("fs").readFileSync(path); - -initSync(bytes); diff --git a/wasm/src/stylua_lib_node.mjs b/wasm/src/stylua_lib_node.mjs new file mode 100644 index 00000000..14d4e733 --- /dev/null +++ b/wasm/src/stylua_lib_node.mjs @@ -0,0 +1,16 @@ +import { readFileSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { initSync } from '../stylua.web/stylua_lib.js'; + +// Get current file location for relative path resolution +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// Load and initialize the WASM module +const wasmPath = join(__dirname, 'stylua.web', 'stylua_lib_bg.wasm'); +const wasmBytes = readFileSync(wasmPath); +initSync(wasmBytes); + +// Re-export everything from the WASM library +export * from '../stylua.web/stylua_lib.js'; diff --git a/wasm/stylua_lib.d.cts b/wasm/stylua_lib.d.cts index 533f4e60..30cf753f 100644 --- a/wasm/stylua_lib.d.cts +++ b/wasm/stylua_lib.d.cts @@ -1,2 +1,2 @@ -export type * from "./stylua.web/stylua_lib"; +export * from './stylua.web/stylua_lib'; export declare const initSync: never; diff --git a/wasm/stylua_lib.d.mts b/wasm/stylua_lib.d.mts index 533f4e60..30cf753f 100644 --- a/wasm/stylua_lib.d.mts +++ b/wasm/stylua_lib.d.mts @@ -1,2 +1,2 @@ -export type * from "./stylua.web/stylua_lib"; +export * from './stylua.web/stylua_lib'; export declare const initSync: never; diff --git a/wasm/stylua_lib.mjs b/wasm/stylua_lib.mjs index 196e3558..d2f04d28 100644 --- a/wasm/stylua_lib.mjs +++ b/wasm/stylua_lib.mjs @@ -1,7 +1,742 @@ -import fs from "node:fs"; -import { initSync } from "./stylua.web/stylua_lib.js"; +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; -const wasm = new URL("./stylua.web/stylua_lib_bg.wasm", import.meta.url); -initSync(fs.readFileSync(wasm)); +let wasm; -export * from "./stylua.web/stylua_lib.js"; +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); } +let cachedUint8Memory0 = null; + +function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +let cachedInt32Memory0 = null; + +function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} + +function isLikeNone(x) { + return x === undefined || x === null; +} + +function _assertClass(instance, klass) { + if (!(instance instanceof klass)) { + throw new Error(`expected instance of ${klass.name}`); + } + return instance.ptr; +} + +let WASM_VECTOR_LEN = 0; + +const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +function passStringToWasm0(arg, malloc, realloc) { + + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8Memory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function getObject(idx) { return heap[idx]; } + +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} +/** +* @param {string} code +* @param {Config} config +* @param {Range | undefined} range +* @param {OutputVerification} verify_output +* @returns {string} +*/ +function formatCode(code, config, range, verify_output) { + let deferred5_0; + let deferred5_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(config, Config); + var ptr1 = config.__destroy_into_raw(); + let ptr2 = 0; + if (!isLikeNone(range)) { + _assertClass(range, Range); + ptr2 = range.__destroy_into_raw(); + } + wasm.formatCode(retptr, ptr0, len0, ptr1, ptr2, verify_output); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + var ptr4 = r0; + var len4 = r1; + if (r3) { + ptr4 = 0; len4 = 0; + throw takeObject(r2); + } + deferred5_0 = ptr4; + deferred5_1 = len4; + return getStringFromWasm0(ptr4, len4); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred5_0, deferred5_1, 1); + } +} + +/** +* What mode to use if we want to collapse simple functions / guard statements +*/ +const CollapseSimpleStatement = Object.freeze({ +/** +* Never collapse +*/ +Never:0,"0":"Never", +/** +* Collapse simple functions onto a single line +*/ +FunctionOnly:1,"1":"FunctionOnly", +/** +* Collapse simple if guards onto a single line +*/ +ConditionalOnly:2,"2":"ConditionalOnly", +/** +* Collapse all simple statements onto a single line +*/ +Always:3,"3":"Always", }); +/** +* When to use call parentheses +*/ +const CallParenType = Object.freeze({ +/** +* Use call parentheses all the time +*/ +Always:0,"0":"Always", +/** +* Skip call parentheses when only a string argument is used. +*/ +NoSingleString:1,"1":"NoSingleString", +/** +* Skip call parentheses when only a table argument is used. +*/ +NoSingleTable:2,"2":"NoSingleTable", +/** +* Skip call parentheses when only a table or string argument is used. +*/ +None:3,"3":"None", +/** +* Keep call parentheses based on its presence in input code. +*/ +Input:4,"4":"Input", }); +/** +* When to use spaces after function names +*/ +const SpaceAfterFunctionNames = Object.freeze({ +/** +* Never use spaces after function names. +*/ +Never:0,"0":"Never", +/** +* Use spaces after function names only for function definitions. +*/ +Definitions:1,"1":"Definitions", +/** +* Use spaces after function names only for function calls. +*/ +Calls:2,"2":"Calls", +/** +* Use spaces after function names in definitions and calls. +*/ +Always:3,"3":"Always", }); +/** +* The style of quotes to use within string literals +*/ +const QuoteStyle = Object.freeze({ +/** +* Use double quotes where possible, but change to single quotes if it produces less escapes +*/ +AutoPreferDouble:0,"0":"AutoPreferDouble", +/** +* Use single quotes where possible, but change to double quotes if it produces less escapes +*/ +AutoPreferSingle:1,"1":"AutoPreferSingle", +/** +* Always use double quotes in all strings +*/ +ForceDouble:2,"2":"ForceDouble", +/** +* Always use single quotes in all strings +*/ +ForceSingle:3,"3":"ForceSingle", }); +/** +* The Lua syntax version to use +*/ +const LuaVersion = Object.freeze({ +/** +* Parse all syntax versions at the same time. This allows most general usage. +* For overlapping syntaxes (e.g., Lua5.2 label syntax and Luau type assertions), select a +* specific syntax version +*/ +All:0,"0":"All", +/** +* Parse Lua 5.1 code +*/ +Lua51:1,"1":"Lua51", +/** +* Parse Lua 5.2 code +*/ +Lua52:2,"2":"Lua52", +/** +* Parse Lua 5.3 code +*/ +Lua53:3,"3":"Lua53", +/** +* Parse Lua 5.4 code +*/ +Lua54:4,"4":"Lua54", +/** +* Parse Luau code +*/ +Luau:5,"5":"Luau", +/** +* Parse LuaJIT code +*/ +LuaJIT:6,"6":"LuaJIT", +/** +* Parse Cfx Lua code +*/ +CfxLua:7,"7":"CfxLua", }); +/** +* The type of line endings to use at the end of a line +*/ +const LineEndings = Object.freeze({ +/** +* Unix Line Endings (LF) - `\n` +*/ +Unix:0,"0":"Unix", +/** +* Windows Line Endings (CRLF) - `\r\n` +*/ +Windows:1,"1":"Windows", }); +/** +* The type of indents to use when indenting +*/ +const IndentType = Object.freeze({ +/** +* Indent using tabs (`\t`) +*/ +Tabs:0,"0":"Tabs", +/** +* Indent using spaces (` `) +*/ +Spaces:1,"1":"Spaces", }); +/** +* The type of verification to perform to validate that the output AST is still correct. +*/ +const OutputVerification = Object.freeze({ +/** +* Reparse the generated output to detect any changes to code correctness. +*/ +Full:0,"0":"Full", +/** +* Perform no verification of the output. +*/ +None:1,"1":"None", }); +/** +* The configuration to use when formatting. +*/ +class Config { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Config.prototype); + obj.__wbg_ptr = ptr; + + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_config_free(ptr); + } + /** + * The type of Lua syntax to parse. + * @returns {LuaVersion} + */ + get syntax() { + const ret = wasm.__wbg_get_config_syntax(this.__wbg_ptr); + return ret; + } + /** + * The type of Lua syntax to parse. + * @param {LuaVersion} arg0 + */ + set syntax(arg0) { + wasm.__wbg_set_config_syntax(this.__wbg_ptr, arg0); + } + /** + * The approximate line length to use when printing the code. + * This is used as a guide to determine when to wrap lines, but note + * that this is not a hard upper bound. + * @returns {number} + */ + get column_width() { + const ret = wasm.__wbg_get_config_column_width(this.__wbg_ptr); + return ret >>> 0; + } + /** + * The approximate line length to use when printing the code. + * This is used as a guide to determine when to wrap lines, but note + * that this is not a hard upper bound. + * @param {number} arg0 + */ + set column_width(arg0) { + wasm.__wbg_set_config_column_width(this.__wbg_ptr, arg0); + } + /** + * The type of line endings to use. + * @returns {LineEndings} + */ + get line_endings() { + const ret = wasm.__wbg_get_config_line_endings(this.__wbg_ptr); + return ret; + } + /** + * The type of line endings to use. + * @param {LineEndings} arg0 + */ + set line_endings(arg0) { + wasm.__wbg_set_config_line_endings(this.__wbg_ptr, arg0); + } + /** + * The type of indents to use. + * @returns {IndentType} + */ + get indent_type() { + const ret = wasm.__wbg_get_config_indent_type(this.__wbg_ptr); + return ret; + } + /** + * The type of indents to use. + * @param {IndentType} arg0 + */ + set indent_type(arg0) { + wasm.__wbg_set_config_indent_type(this.__wbg_ptr, arg0); + } + /** + * The width of a single indentation level. + * If `indent_type` is set to [`IndentType::Spaces`], then this is the number of spaces to use. + * If `indent_type` is set to [`IndentType::Tabs`], then this is used as a heuristic to guide when to wrap lines. + * @returns {number} + */ + get indent_width() { + const ret = wasm.__wbg_get_config_indent_width(this.__wbg_ptr); + return ret >>> 0; + } + /** + * The width of a single indentation level. + * If `indent_type` is set to [`IndentType::Spaces`], then this is the number of spaces to use. + * If `indent_type` is set to [`IndentType::Tabs`], then this is used as a heuristic to guide when to wrap lines. + * @param {number} arg0 + */ + set indent_width(arg0) { + wasm.__wbg_set_config_indent_width(this.__wbg_ptr, arg0); + } + /** + * The style of quotes to use in string literals. + * @returns {QuoteStyle} + */ + get quote_style() { + const ret = wasm.__wbg_get_config_quote_style(this.__wbg_ptr); + return ret; + } + /** + * The style of quotes to use in string literals. + * @param {QuoteStyle} arg0 + */ + set quote_style(arg0) { + wasm.__wbg_set_config_quote_style(this.__wbg_ptr, arg0); + } + /** + * Whether to omit parentheses around function calls which take a single string literal or table. + * This is added for adoption reasons only, and is not recommended for new work. + * @returns {boolean} + */ + get no_call_parentheses() { + const ret = wasm.__wbg_get_config_no_call_parentheses(this.__wbg_ptr); + return ret !== 0; + } + /** + * Whether to omit parentheses around function calls which take a single string literal or table. + * This is added for adoption reasons only, and is not recommended for new work. + * @param {boolean} arg0 + */ + set no_call_parentheses(arg0) { + wasm.__wbg_set_config_no_call_parentheses(this.__wbg_ptr, arg0); + } + /** + * When to use call parentheses. + * if call_parentheses is set to [`CallParenType::Always`] call parentheses is always applied. + * if call_parentheses is set to [`CallParenType::NoSingleTable`] call parentheses is omitted when + * function is called with only one string argument. + * if call_parentheses is set to [`CallParenType::NoSingleTable`] call parentheses is omitted when + * function is called with only one table argument. + * if call_parentheses is set to [`CallParenType::None`] call parentheses is omitted when + * function is called with only one table or string argument (same as no_call_parentheses). + * @returns {CallParenType} + */ + get call_parentheses() { + const ret = wasm.__wbg_get_config_call_parentheses(this.__wbg_ptr); + return ret; + } + /** + * When to use call parentheses. + * if call_parentheses is set to [`CallParenType::Always`] call parentheses is always applied. + * if call_parentheses is set to [`CallParenType::NoSingleTable`] call parentheses is omitted when + * function is called with only one string argument. + * if call_parentheses is set to [`CallParenType::NoSingleTable`] call parentheses is omitted when + * function is called with only one table argument. + * if call_parentheses is set to [`CallParenType::None`] call parentheses is omitted when + * function is called with only one table or string argument (same as no_call_parentheses). + * @param {CallParenType} arg0 + */ + set call_parentheses(arg0) { + wasm.__wbg_set_config_call_parentheses(this.__wbg_ptr, arg0); + } + /** + * Whether we should collapse simple structures like functions or guard statements + * if set to [`CollapseSimpleStatement::None`] structures are never collapsed. + * if set to [`CollapseSimpleStatement::FunctionOnly`] then simple functions (i.e., functions with a single laststmt) can be collapsed + * @returns {CollapseSimpleStatement} + */ + get collapse_simple_statement() { + const ret = wasm.__wbg_get_config_collapse_simple_statement(this.__wbg_ptr); + return ret; + } + /** + * Whether we should collapse simple structures like functions or guard statements + * if set to [`CollapseSimpleStatement::None`] structures are never collapsed. + * if set to [`CollapseSimpleStatement::FunctionOnly`] then simple functions (i.e., functions with a single laststmt) can be collapsed + * @param {CollapseSimpleStatement} arg0 + */ + set collapse_simple_statement(arg0) { + wasm.__wbg_set_config_collapse_simple_statement(this.__wbg_ptr, arg0); + } + /** + * Configuration for the sort requires codemod + * @returns {SortRequiresConfig} + */ + get sort_requires() { + const ret = wasm.__wbg_get_config_sort_requires(this.__wbg_ptr); + return SortRequiresConfig.__wrap(ret); + } + /** + * Configuration for the sort requires codemod + * @param {SortRequiresConfig} arg0 + */ + set sort_requires(arg0) { + _assertClass(arg0, SortRequiresConfig); + var ptr0 = arg0.__destroy_into_raw(); + wasm.__wbg_set_config_sort_requires(this.__wbg_ptr, ptr0); + } + /** + * Whether we should include a space between the function name and arguments. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Never`] a space is never used. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Definitions`] a space is used only for definitions. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Calls`] a space is used only for calls. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Always`] a space is used for both definitions and calls. + * @returns {SpaceAfterFunctionNames} + */ + get space_after_function_names() { + const ret = wasm.__wbg_get_config_space_after_function_names(this.__wbg_ptr); + return ret; + } + /** + * Whether we should include a space between the function name and arguments. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Never`] a space is never used. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Definitions`] a space is used only for definitions. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Calls`] a space is used only for calls. + * * if space_after_function_names is set to [`SpaceAfterFunctionNames::Always`] a space is used for both definitions and calls. + * @param {SpaceAfterFunctionNames} arg0 + */ + set space_after_function_names(arg0) { + wasm.__wbg_set_config_space_after_function_names(this.__wbg_ptr, arg0); + } + /** + * Creates a new Config with the default values + * @returns {Config} + */ + static new() { + const ret = wasm.config_new(); + return Config.__wrap(ret); + } +} +/** +* An optional formatting range. +* If provided, only content within these boundaries (inclusive) will be formatted. +* Both boundaries are optional, and are given as byte offsets from the beginning of the file. +*/ +class Range { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Range.prototype); + obj.__wbg_ptr = ptr; + + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_range_free(ptr); + } + /** + * @returns {number | undefined} + */ + get start() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_range_start(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + return r0 === 0 ? undefined : r1 >>> 0; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {number | undefined} [arg0] + */ + set start(arg0) { + wasm.__wbg_set_range_start(this.__wbg_ptr, !isLikeNone(arg0), isLikeNone(arg0) ? 0 : arg0); + } + /** + * @returns {number | undefined} + */ + get end() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_range_end(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + return r0 === 0 ? undefined : r1 >>> 0; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {number | undefined} [arg0] + */ + set end(arg0) { + wasm.__wbg_set_range_end(this.__wbg_ptr, !isLikeNone(arg0), isLikeNone(arg0) ? 0 : arg0); + } + /** + * Creates a new formatting range from the given start and end point. + * All content within these boundaries (inclusive) will be formatted. + * @param {number | undefined} [start] + * @param {number | undefined} [end] + * @returns {Range} + */ + static from_values(start, end) { + const ret = wasm.range_from_values(!isLikeNone(start), isLikeNone(start) ? 0 : start, !isLikeNone(end), isLikeNone(end) ? 0 : end); + return Range.__wrap(ret); + } +} +/** +* Configuration for the Sort Requires codemod +*/ +class SortRequiresConfig { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(SortRequiresConfig.prototype); + obj.__wbg_ptr = ptr; + + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_sortrequiresconfig_free(ptr); + } + /** + * Whether the sort requires codemod is enabled + * @returns {boolean} + */ + get enabled() { + const ret = wasm.__wbg_get_sortrequiresconfig_enabled(this.__wbg_ptr); + return ret !== 0; + } + /** + * Whether the sort requires codemod is enabled + * @param {boolean} arg0 + */ + set enabled(arg0) { + wasm.__wbg_set_sortrequiresconfig_enabled(this.__wbg_ptr, arg0); + } + /** + * @returns {SortRequiresConfig} + */ + static new() { + const ret = wasm.sortrequiresconfig_new(); + return SortRequiresConfig.__wrap(ret); + } + /** + * @param {boolean} enabled + * @returns {SortRequiresConfig} + */ + set_enabled(enabled) { + const ret = wasm.sortrequiresconfig_set_enabled(this.__wbg_ptr, enabled); + return SortRequiresConfig.__wrap(ret); + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + + return imports; +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + cachedInt32Memory0 = null; + cachedUint8Memory0 = null; + + + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + const imports = __wbg_get_imports(); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance); +} + +// Get current file location for relative path resolution +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// Load and initialize the WASM module +const wasmPath = join(__dirname, 'stylua.web', 'stylua_lib_bg.wasm'); +const wasmBytes = readFileSync(wasmPath); +initSync(wasmBytes); + +export { CallParenType, CollapseSimpleStatement, Config, IndentType, LineEndings, LuaVersion, OutputVerification, QuoteStyle, Range, SortRequiresConfig, SpaceAfterFunctionNames, __wbg_finalize_init as __finalizeInit, __wbg_get_imports as __getImports, formatCode, initSync }; diff --git a/wasm/stylua_lib_bundler.d.ts b/wasm/stylua_lib_bundler.d.ts index 533f4e60..30cf753f 100644 --- a/wasm/stylua_lib_bundler.d.ts +++ b/wasm/stylua_lib_bundler.d.ts @@ -1,2 +1,2 @@ -export type * from "./stylua.web/stylua_lib"; +export * from './stylua.web/stylua_lib'; export declare const initSync: never; diff --git a/wasm/stylua_lib_bundler.js b/wasm/stylua_lib_bundler.js index 6622d86b..20cac9e7 100644 --- a/wasm/stylua_lib_bundler.js +++ b/wasm/stylua_lib_bundler.js @@ -1,7 +1,2 @@ -import * as wasm from "./stylua.web/stylua_lib_bg.wasm"; - -import { __finalizeInit } from "./stylua.web/stylua_lib.js"; - -__finalizeInit({ exports: wasm }); - -export * from "./stylua.web/stylua_lib.js"; +// Bundler version that re-exports from the web build +export * from './stylua.web/stylua_lib.js'; diff --git a/wasm/stylua_lib_bundler_wbg.cjs b/wasm/stylua_lib_bundler_wbg.cjs index 9137e89f..924fe56c 100644 --- a/wasm/stylua_lib_bundler_wbg.cjs +++ b/wasm/stylua_lib_bundler_wbg.cjs @@ -1 +1,2 @@ -module.exports = require("./stylua.web/stylua_lib.js").__getImports().wbg; +// CommonJS wrapper for bundler usage +module.exports = require('./stylua.web/stylua_lib.js');