Skip to content

Commit

Permalink
🔨 (repo) [NO-ISSUE]: Update esbuild config to not use bundling (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman authored Oct 18, 2024
2 parents 4599774 + e3ff1e4 commit 0bcb392
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 29 deletions.
11 changes: 7 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
"./lib",
"package.json"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down
8 changes: 5 additions & 3 deletions packages/signer/context-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down
8 changes: 5 additions & 3 deletions packages/signer/keyring-btc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down
8 changes: 5 additions & 3 deletions packages/signer/keyring-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down
26 changes: 22 additions & 4 deletions packages/tools/esbuild-tools/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import "zx/globals";
import esbuild from "esbuild";
import { nodeExternalsPlugin } from "esbuild-node-externals";
import { replaceTscAliasPaths } from "tsc-alias";

const config = {
minify: false,
bundle: true,
minify: true,
bundle: false,
treeShaking: true,
sourcemap: true,
color: true,
Expand All @@ -26,31 +27,48 @@ if (!tsconfig) {
console.error(chalk.red("TSConfig file is required"));
process.exit(1);
}

const entryPointsArray = entryPoints.includes(",")
? entryPoints.split(",")
: [entryPoints];

const buildBrowser = async () => {
console.log(chalk.blue("Building browser bundle..."));
return esbuild.build({
await esbuild.build({
...config,
entryPoints: entryPointsArray,
outdir: "lib/esm",
format: "esm",
platform: "browser",
});

await $`cp package.json lib/esm/package.json`;

await replaceTscAliasPaths({
configFile: tsconfig,
outDir: "lib/esm",
watch: false,
});
};

const buildNode = async () => {
console.log(chalk.blue("Building node bundle..."));
return esbuild.build({
await esbuild.build({
...config,
entryPoints: entryPointsArray,
outdir: "lib/cjs",
format: "cjs",
platform: "node",
plugins: [nodeExternalsPlugin()],
});

await $`cp package.json lib/cjs/package.json`;

await replaceTscAliasPaths({
configFile: tsconfig,
outDir: "lib/cjs",
watch: false,
});
};

const buildTypes = async () => {
Expand Down
28 changes: 25 additions & 3 deletions packages/tools/esbuild-tools/watch.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env zx

import esbuild from "esbuild";
import { replaceTscAliasPaths } from "tsc-alias";

const config = {
entryPoints: ["index.ts"],
minify: true,
bundle: true,
bundle: false,
treeShaking: true,
sourcemap: true,
color: true,
Expand All @@ -25,30 +26,51 @@ if (!tsconfig) {
console.error(chalk.red("TSConfig file is required"));
process.exit(1);
}

const entryPointsArray = entryPoints.includes(",")
? entryPoints.split(",")
: [entryPoints];

const getBrowserContext = async () => {
console.log(chalk.blue("Watching browser bundle..."));
return esbuild.context({
const result = await esbuild.context({
...config,
entryPoints: entryPointsArray,
outdir: "lib/esm",
format: "esm",
platform: "browser",
});

await $`cp package.json lib/esm/package.json`;

await replaceTscAliasPaths({
configFile: tsconfig,
outDir: "lib/esm",
watch: false,
});

return result;
};

const getNodeContext = async () => {
console.log(chalk.blue("Watching node bundle..."));
return esbuild.context({
const res = await esbuild.context({
...config,
entryPoints: entryPointsArray,
outdir: "lib/cjs",
format: "cjs",
platform: "node",
});

await $`cp package.json lib/cjs/package.json`;

await replaceTscAliasPaths({
configFile: tsconfig,
outDir: "lib/cjs",
watch: false,
});

return res;
};

const watch = async () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/transport-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down
8 changes: 5 additions & 3 deletions packages/trusted-apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*"
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts --tsconfig tsconfig.prod.json",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
Expand Down

0 comments on commit 0bcb392

Please sign in to comment.