Skip to content

Commit

Permalink
feat(build): use esbuild instead of tsc
Browse files Browse the repository at this point in the history
Replace the tsc command with esbuild package to optimize our build process as well as overall
package

Fix #4

Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
  • Loading branch information
niloysikdar committed Nov 4, 2022
1 parent cf727b3 commit d9a17c0
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 20 deletions.
32 changes: 32 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const esbuild = require('esbuild');

// Build for ESM
esbuild
.build({
logLevel: 'info',
entryPoints: ['src/index.ts'],
outdir: 'dist/esm',
platform: 'node',
bundle: true,
sourcemap: false,
minify: true,
splitting: true,
format: 'esm',
target: ['ESNext'],
})
.catch(() => process.exit(1));

// Build for CJS
esbuild
.build({
logLevel: 'info',
entryPoints: ['src/index.ts', 'src/generate.ts'],
outdir: 'dist/cjs',
platform: 'node',
bundle: true,
sourcemap: false,
minify: true,
format: 'cjs',
})
.catch(() => process.exit(1));
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
"license": "Apache-2.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"types": "dist/types/index.d.ts",
"files": [
"dist"
],
"bin": "dist/cjs/generate.js",
"scripts": {
"prepare": "husky install",
"watch": "tsc --watch",
"build": "rm -rf dist && yarn build:esm && yarn build:cjs",
"build:esm": "tsc -p tsconfig.json",
"build:cjs": "tsc -p tsconfig.json --module commonjs --outDir dist/cjs --target es5",
"ts-types": " tsc --emitDeclarationOnly --outDir dist/types",
"build": "rm -rf dist && yarn ts-types && node build.js",
"postbuild": "chmod u+rx ./postbuild.sh && ./postbuild.sh",
"release": "semantic-release --branches main",
"lint": "eslint src/**",
Expand Down Expand Up @@ -62,6 +61,7 @@
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"cz-conventional-changelog": "^3.3.0",
"esbuild": "^0.15.13",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
18 changes: 2 additions & 16 deletions postbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@
# Exit immediately if a command exits with a non-zero status.
set -e

# Add type commonjs to the package.json file in the dist/cjs folder
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

# Add type module to the package.json file in the dist/esm folder
cat >dist/esm/package.json <<!EOF
{
"type": "module"
}
!EOF

# Adding shebang to the top of the file
sed -i '1i #!/usr/bin/env node' dist/cjs/generate.js

# Removing the generate.js and generate.d.ts files from the dist/esm folder
rm -rf dist/esm/generate.js dist/esm/generate.d.ts
# Removing the generate.d.ts and templates.d.ts files from the dist/types folder
rm -rf dist/types/generate.d.ts dist/types/templates.d.ts

echo "Fixup done."
138 changes: 138 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@esbuild/android-arm@0.15.13":
version "0.15.13"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.15.13.tgz#ce11237a13ee76d5eae3908e47ba4ddd380af86a"
integrity sha512-RY2fVI8O0iFUNvZirXaQ1vMvK0xhCcl0gqRj74Z6yEiO1zAUa7hbsdwZM1kzqbxHK7LFyMizipfXT3JME+12Hw==

"@esbuild/linux-loong64@0.15.13":
version "0.15.13"
resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.15.13.tgz#64e8825bf0ce769dac94ee39d92ebe6272020dfc"
integrity sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag==

"@eslint/eslintrc@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.3.2.tgz#58b69582f3b7271d8fa67fe5251767a5b38ea356"
Expand Down Expand Up @@ -1623,6 +1633,134 @@ error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

esbuild-android-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.15.13.tgz#5f25864055dbd62e250f360b38b4c382224063af"
integrity sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g==

esbuild-android-arm64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.15.13.tgz#d8820f999314efbe8e0f050653a99ff2da632b0f"
integrity sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w==

esbuild-darwin-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.15.13.tgz#99ae7fdaa43947b06cd9d1a1c3c2c9f245d81fd0"
integrity sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg==

esbuild-darwin-arm64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.13.tgz#bafa1814354ad1a47adcad73de416130ef7f55e3"
integrity sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A==

esbuild-freebsd-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.13.tgz#84ef85535c5cc38b627d1c5115623b088d1de161"
integrity sha512-whItJgDiOXaDG/idy75qqevIpZjnReZkMGCgQaBWZuKHoElDJC1rh7MpoUgupMcdfOd+PgdEwNQW9DAE6i8wyA==

esbuild-freebsd-arm64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.13.tgz#033f21de434ec8e0c478054b119af8056763c2d8"
integrity sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q==

esbuild-linux-32@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.15.13.tgz#54290ea8035cba0faf1791ce9ae6693005512535"
integrity sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w==

esbuild-linux-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.15.13.tgz#4264249281ea388ead948614b57fb1ddf7779a2c"
integrity sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A==

esbuild-linux-arm64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.13.tgz#9323c333924f97a02bdd2ae8912b36298acb312d"
integrity sha512-alEMGU4Z+d17U7KQQw2IV8tQycO6T+rOrgW8OS22Ua25x6kHxoG6Ngry6Aq6uranC+pNWNMB6aHFPh7aTQdORQ==

esbuild-linux-arm@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.15.13.tgz#b407f47b3ae721fe4e00e19e9f19289bef87a111"
integrity sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ==

esbuild-linux-mips64le@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.13.tgz#bdf905aae5c0bcaa8f83567fe4c4c1bdc1f14447"
integrity sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A==

esbuild-linux-ppc64le@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.13.tgz#2911eae1c90ff58a3bd3259cb557235df25aa3b4"
integrity sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA==

esbuild-linux-riscv64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.13.tgz#1837c660be12b1d20d2a29c7189ea703f93e9265"
integrity sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow==

esbuild-linux-s390x@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.13.tgz#d52880ece229d1bd10b2d936b792914ffb07c7fc"
integrity sha512-BMeXRljruf7J0TMxD5CIXS65y7puiZkAh+s4XFV9qy16SxOuMhxhVIXYLnbdfLrsYGFzx7U9mcdpFWkkvy/Uag==

esbuild-netbsd-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.13.tgz#de14da46f1d20352b43e15d97a80a8788275e6ed"
integrity sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ==

esbuild-openbsd-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.13.tgz#45e8a5fd74d92ad8f732c43582369c7990f5a0ac"
integrity sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w==

esbuild-sunos-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.15.13.tgz#f646ac3da7aac521ee0fdbc192750c87da697806"
integrity sha512-jVeu2GfxZQ++6lRdY43CS0Tm/r4WuQQ0Pdsrxbw+aOrHQPHV0+LNOLnvbN28M7BSUGnJnHkHm2HozGgNGyeIRw==

esbuild-windows-32@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.15.13.tgz#fb4fe77c7591418880b3c9b5900adc4c094f2401"
integrity sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA==

esbuild-windows-64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.15.13.tgz#1fca8c654392c0c31bdaaed168becfea80e20660"
integrity sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ==

esbuild-windows-arm64@0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.13.tgz#4ffd01b6b2888603f1584a2fe96b1f6a6f2b3dd8"
integrity sha512-3bv7tqntThQC9SWLRouMDmZnlOukBhOCTlkzNqzGCmrkCJI7io5LLjwJBOVY6kOUlIvdxbooNZwjtBvj+7uuVg==

esbuild@^0.15.13:
version "0.15.13"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.13.tgz#7293480038feb2bafa91d3f6a20edab3ba6c108a"
integrity sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ==
optionalDependencies:
"@esbuild/android-arm" "0.15.13"
"@esbuild/linux-loong64" "0.15.13"
esbuild-android-64 "0.15.13"
esbuild-android-arm64 "0.15.13"
esbuild-darwin-64 "0.15.13"
esbuild-darwin-arm64 "0.15.13"
esbuild-freebsd-64 "0.15.13"
esbuild-freebsd-arm64 "0.15.13"
esbuild-linux-32 "0.15.13"
esbuild-linux-64 "0.15.13"
esbuild-linux-arm "0.15.13"
esbuild-linux-arm64 "0.15.13"
esbuild-linux-mips64le "0.15.13"
esbuild-linux-ppc64le "0.15.13"
esbuild-linux-riscv64 "0.15.13"
esbuild-linux-s390x "0.15.13"
esbuild-netbsd-64 "0.15.13"
esbuild-openbsd-64 "0.15.13"
esbuild-sunos-64 "0.15.13"
esbuild-windows-32 "0.15.13"
esbuild-windows-64 "0.15.13"
esbuild-windows-arm64 "0.15.13"

escalade@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
Expand Down

0 comments on commit d9a17c0

Please sign in to comment.