Skip to content

Commit

Permalink
chore: last polishes on config
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-chillios committed Feb 13, 2025
1 parent 3b6e473 commit 3293930
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ coverage/
.DS_Store
*.log
.npmrc
bunfig.toml
.aider*
6 changes: 2 additions & 4 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pre-commit:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
run: |
bun --filter='./packages/toolboxes' lint && bun --filter='./packages/toolboxes' type-check
bun --filter='./packages/wallets' lint && bun --filter='./packages/wallets' type-check
bun --filter='./packages/plugins' lint && bun --filter='./packages/plugins' type-check
bun --filter='./packages/swapkit' lint && bun --filter='./packages/swapkit/**' type-check
bun lint
bun type-check
git update-index --again
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
"private": true,
"scripts": {
"bootstrap": "bun clean; bun install --force; bun run build",
"build": "bun --filter '*' build",
"build": "bun --filter '*' --elide-lines=100 build",
"build:debug": "DEBUG=true bun --filter '*' build",
"clean": "bun --filter '*' clean && rm -rf node_modules; bun install",
"deps": "bun ncu --root -u -i -ws",
"generate:tokens": "bun --filter '@swapkit/helpers' build; bun --cwd packages/helpers generate-tokens; bun lint",
"lint": "bun --filter '*' lint",
"lint": "bun --filter '*' --elide-lines=100 lint",
"lint:ci": "bun lint && bun type-check",
"lint:ws": "bun x sherif@latest",
"playground:next": "bun --cwd ./playgrounds/nextjs",
"playground:node": "bun --cwd ./playgrounds/node",
"playground:vite": "bun --cwd ./playgrounds/vite",
"postinstall": "lefthook install; bun lint:ws",
"publish-packages": "bun run build && bun version-bump && bun changeset publish",
"test": "bun --filter '*' test",
"test": "bun --filter '*' --elide-lines=1000 test",
"test:coverage": "bun --filter '*' test:coverage",
"type-check": "bun --filter '*' type-check",
"type-check": "bun --filter '*' --elide-lines=100 type-check",
"version-bump": "bun changeset version",
"wizard": "bun --cwd ./packages/swapkit/wizard"
},
Expand Down
62 changes: 43 additions & 19 deletions tools/builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BuildConfig } from "bun";
import type { BuildArtifact, BuildConfig } from "bun";

export async function buildPackage({
entrypoints = ["./src/index.ts"],
Expand Down Expand Up @@ -48,32 +48,56 @@ export async function buildPackage({
);
}

const esmFiles = buildESM.outputs
.filter((file) => file.path.endsWith(".js"))
.map(({ size, path }) => {
const [name, fileName] = path.split("/").slice(-2);
const exportName = name === "dist" ? (fileName === "index.js" ? "" : "shared-chunk") : name;
return { size, path, exportName };
});
const cjsFiles = buildCJS.outputs
.filter((file) => file.path.endsWith(".cjs"))
.map(({ size, path }) => {
const [name, fileName] = path.split("/").slice(-2);
const exportName = name === "dist" ? (fileName === "index.cjs" ? "" : "shared-chunk") : name;
return { size, path, exportName };
});
function mapFiles({ files, type }: { files: BuildArtifact[]; type: "esm" | "cjs" }) {
const ext = type === "esm" ? "js" : "cjs";
return files
.filter((file) => file.path.endsWith(`.${ext}`))
.sort((a, b) => {
const fileNameA = a.path.split("/").pop() || "";
const fileNameB = b.path.split("/").pop() || "";
return fileNameA.startsWith("chunk")
? 1
: fileNameB.startsWith("chunk")
? -1
: a.path.localeCompare(b.path);
})
.map(({ size, path }) => {
const [name, fileName] = path.split("/").slice(-2);
const params =
name === "dist"
? fileName === `index.${ext}`
? { exportName: "", type: "root" }
: { exportName: fileName, type: "chunk" }
: { exportName: name, type: "package" };
return { size, path, ...params };
});
}

const esmFiles = mapFiles({ files: buildESM.outputs, type: "esm" });
const cjsFiles = mapFiles({ files: buildCJS.outputs, type: "cjs" });

console.info(`✅ Build successful: ${buildESM.outputs.length} files`);
console.info("📦 ESM Import Sizes:");
for (const { size, exportName } of esmFiles) {
console.info(` ${pkgJson.name}${exportName ? `/${exportName}` : ""}: ${formatBytes(size)}`);
for (const { size, exportName, type } of esmFiles) {
console.info(`${importName({ pkgName: pkgJson.name, exportName, type })}${formatBytes(size)}`);
}
console.info("📦 CJS Import Sizes:");
for (const { size, exportName } of cjsFiles) {
console.info(` ${pkgJson.name}${exportName ? `/${exportName}` : ""}: ${formatBytes(size)}`);
for (const { size, exportName, type } of cjsFiles) {
console.info(`${importName({ pkgName: pkgJson.name, exportName, type })}${formatBytes(size)}`);
}
}

function importName({
pkgName,
exportName,
type,
}: { pkgName: string; exportName?: string; type: string }) {
const base =
type === "package" ? `${pkgName}/${exportName}` : type === "chunk" ? ` ${exportName}` : "";

return ` ${base}: `;
}

function formatBytes(bytes: number) {
const units = ["B", "KB", "MB"];
let index = 0;
Expand Down

0 comments on commit 3293930

Please sign in to comment.