Skip to content

Commit

Permalink
{chore} strip esbuild
Browse files Browse the repository at this point in the history
Packaging everything into a single file is not needed
any longer, after the rewrite to zero-deps. It's also
starting to be counter-productive, with the benchmark
consistently showing the built file to be slower.
  • Loading branch information
bgotink committed Oct 8, 2024
1 parent 07a998f commit c46ea74
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 277 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@types/benchmark": "^2.1.5",
"@types/node": "^22",
"benchmark": "^2.1.4",
"esbuild": "^0.20.0",
"express-check-in": "^0.2.0",
"husky": "^9.0.11",
"is-ci": "^3.0.1",
Expand Down
29 changes: 5 additions & 24 deletions scripts/bench.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import bench from "benchmark";
import * as kdljs from "kdljs";
import {stderr} from "node:process";

import * as dev from "../src/index.js";

let built;
try {
built = await import("../out/index.js");
} catch {
stderr.write(
"No out folder found, run `yarn build` to include the built version of @bgotink/kdl\n",
);
built = null;
}
import * as self from "../src/index.js";

const suite = new bench.Suite();

Expand Down Expand Up @@ -49,32 +38,24 @@ const documentV1 = document.replace(/(\s)(#+")/g, "$1r$2");
// sanity check: assert document parses
if (kdljs.parse(documentV1).errors?.length)
throw new Error("kdljs failed to parse");
dev.parse(document);
built?.parse(document);
self.parse(document);

suite.add("kdljs #parse", () => {
kdljs.parse(documentV1);
});

suite.add("development #parse", () => {
dev.parse(document);
self.parse(document);
});

suite.add("development #parse {graphemeLocations: true}", () => {
dev.parse(document, {graphemeLocations: true});
self.parse(document, {graphemeLocations: true});
});

suite.add("development #parse {storeLocations: true}", () => {
dev.parse(document, {storeLocations: true});
self.parse(document, {storeLocations: true});
});

if (built) {
const _built = built;
suite.add("built #parse", () => {
_built.parse(document);
});
}

// add listeners
suite
.on(
Expand Down
8 changes: 1 addition & 7 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ mkdirSync("out");
// TypeScript

execSync("tsc -p tsconfig.compile.json");
// tsc doesn't copy .d.ts files out of the source folder
copyFileSync("src/parse.d.ts", "out/parse.d.ts");
copyFileSync("src/json.d.ts", "out/json.d.ts");
copyFileSync("src/model/whitespace.d.ts", "out/model/whitespace.d.ts");

// JavaScript

execSync(
"esbuild --bundle --external:@bgotink/kdl --platform=neutral src/index.js src/json.js --outdir=out --target=node18 --format=esm",
);
execSync("cp -a src/* out");

// Write metadata

Expand Down
2 changes: 1 addition & 1 deletion src/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Node,
parse as parseKdl,
format as formatKdl,
} from "@bgotink/kdl";
} from "./index.js";

const arrayItemKey = "-";

Expand Down
4 changes: 2 additions & 2 deletions src/parser/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,6 @@ function mkError(message) {
*/
function cleanup() {
text = "";
iterator = null;
currentIter = null;
// @ts-ignore
iterator = currentIter = null;
}
242 changes: 0 additions & 242 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ __metadata:
"@types/benchmark": "npm:^2.1.5"
"@types/node": "npm:^22"
benchmark: "npm:^2.1.4"
esbuild: "npm:^0.20.0"
express-check-in: "npm:^0.2.0"
husky: "npm:^9.0.11"
is-ci: "npm:^3.0.1"
Expand Down Expand Up @@ -61,167 +60,6 @@ __metadata:
languageName: node
linkType: hard

"@esbuild/aix-ppc64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/aix-ppc64@npm:0.20.0"
conditions: os=aix & cpu=ppc64
languageName: node
linkType: hard

"@esbuild/android-arm64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/android-arm64@npm:0.20.0"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard

"@esbuild/android-arm@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/android-arm@npm:0.20.0"
conditions: os=android & cpu=arm
languageName: node
linkType: hard

"@esbuild/android-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/android-x64@npm:0.20.0"
conditions: os=android & cpu=x64
languageName: node
linkType: hard

"@esbuild/darwin-arm64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/darwin-arm64@npm:0.20.0"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"@esbuild/darwin-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/darwin-x64@npm:0.20.0"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"@esbuild/freebsd-arm64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/freebsd-arm64@npm:0.20.0"
conditions: os=freebsd & cpu=arm64
languageName: node
linkType: hard

"@esbuild/freebsd-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/freebsd-x64@npm:0.20.0"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard

"@esbuild/linux-arm64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-arm64@npm:0.20.0"
conditions: os=linux & cpu=arm64
languageName: node
linkType: hard

"@esbuild/linux-arm@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-arm@npm:0.20.0"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard

"@esbuild/linux-ia32@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-ia32@npm:0.20.0"
conditions: os=linux & cpu=ia32
languageName: node
linkType: hard

"@esbuild/linux-loong64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-loong64@npm:0.20.0"
conditions: os=linux & cpu=loong64
languageName: node
linkType: hard

"@esbuild/linux-mips64el@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-mips64el@npm:0.20.0"
conditions: os=linux & cpu=mips64el
languageName: node
linkType: hard

"@esbuild/linux-ppc64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-ppc64@npm:0.20.0"
conditions: os=linux & cpu=ppc64
languageName: node
linkType: hard

"@esbuild/linux-riscv64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-riscv64@npm:0.20.0"
conditions: os=linux & cpu=riscv64
languageName: node
linkType: hard

"@esbuild/linux-s390x@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-s390x@npm:0.20.0"
conditions: os=linux & cpu=s390x
languageName: node
linkType: hard

"@esbuild/linux-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/linux-x64@npm:0.20.0"
conditions: os=linux & cpu=x64
languageName: node
linkType: hard

"@esbuild/netbsd-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/netbsd-x64@npm:0.20.0"
conditions: os=netbsd & cpu=x64
languageName: node
linkType: hard

"@esbuild/openbsd-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/openbsd-x64@npm:0.20.0"
conditions: os=openbsd & cpu=x64
languageName: node
linkType: hard

"@esbuild/sunos-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/sunos-x64@npm:0.20.0"
conditions: os=sunos & cpu=x64
languageName: node
linkType: hard

"@esbuild/win32-arm64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/win32-arm64@npm:0.20.0"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"@esbuild/win32-ia32@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/win32-ia32@npm:0.20.0"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard

"@esbuild/win32-x64@npm:0.20.0":
version: 0.20.0
resolution: "@esbuild/win32-x64@npm:0.20.0"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard

"@shikijs/core@npm:1.22.0":
version: 1.22.0
resolution: "@shikijs/core@npm:1.22.0"
Expand Down Expand Up @@ -443,86 +281,6 @@ __metadata:
languageName: node
linkType: hard

"esbuild@npm:^0.20.0":
version: 0.20.0
resolution: "esbuild@npm:0.20.0"
dependencies:
"@esbuild/aix-ppc64": "npm:0.20.0"
"@esbuild/android-arm": "npm:0.20.0"
"@esbuild/android-arm64": "npm:0.20.0"
"@esbuild/android-x64": "npm:0.20.0"
"@esbuild/darwin-arm64": "npm:0.20.0"
"@esbuild/darwin-x64": "npm:0.20.0"
"@esbuild/freebsd-arm64": "npm:0.20.0"
"@esbuild/freebsd-x64": "npm:0.20.0"
"@esbuild/linux-arm": "npm:0.20.0"
"@esbuild/linux-arm64": "npm:0.20.0"
"@esbuild/linux-ia32": "npm:0.20.0"
"@esbuild/linux-loong64": "npm:0.20.0"
"@esbuild/linux-mips64el": "npm:0.20.0"
"@esbuild/linux-ppc64": "npm:0.20.0"
"@esbuild/linux-riscv64": "npm:0.20.0"
"@esbuild/linux-s390x": "npm:0.20.0"
"@esbuild/linux-x64": "npm:0.20.0"
"@esbuild/netbsd-x64": "npm:0.20.0"
"@esbuild/openbsd-x64": "npm:0.20.0"
"@esbuild/sunos-x64": "npm:0.20.0"
"@esbuild/win32-arm64": "npm:0.20.0"
"@esbuild/win32-ia32": "npm:0.20.0"
"@esbuild/win32-x64": "npm:0.20.0"
dependenciesMeta:
"@esbuild/aix-ppc64":
optional: true
"@esbuild/android-arm":
optional: true
"@esbuild/android-arm64":
optional: true
"@esbuild/android-x64":
optional: true
"@esbuild/darwin-arm64":
optional: true
"@esbuild/darwin-x64":
optional: true
"@esbuild/freebsd-arm64":
optional: true
"@esbuild/freebsd-x64":
optional: true
"@esbuild/linux-arm":
optional: true
"@esbuild/linux-arm64":
optional: true
"@esbuild/linux-ia32":
optional: true
"@esbuild/linux-loong64":
optional: true
"@esbuild/linux-mips64el":
optional: true
"@esbuild/linux-ppc64":
optional: true
"@esbuild/linux-riscv64":
optional: true
"@esbuild/linux-s390x":
optional: true
"@esbuild/linux-x64":
optional: true
"@esbuild/netbsd-x64":
optional: true
"@esbuild/openbsd-x64":
optional: true
"@esbuild/sunos-x64":
optional: true
"@esbuild/win32-arm64":
optional: true
"@esbuild/win32-ia32":
optional: true
"@esbuild/win32-x64":
optional: true
bin:
esbuild: bin/esbuild
checksum: 355f13fe91110155404b12b4e0eeb840aceddffb609e63ebd03bf039b9576db791d51fcd22992b155ad9249bcd9cab838e34577770cff974ecf1d245dcb1b16e
languageName: node
linkType: hard

"express-check-in@npm:^0.2.0":
version: 0.2.0
resolution: "express-check-in@npm:0.2.0"
Expand Down

0 comments on commit c46ea74

Please sign in to comment.