Skip to content

Commit

Permalink
esbuild client
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 1, 2023
1 parent 74db43e commit 1d980e3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"dependencies": {
"@observablehq/runtime": "^5.9.4",
"@rollup/plugin-terser": "^0.4.4",
"acorn": "^8.11.2",
"acorn-walk": "^8.3.0",
"fast-array-diff": "^1.1.0",
Expand All @@ -59,6 +58,7 @@
"mime": "^3.0.0",
"open": "^9.1.0",
"rollup": "^4.6.0",
"rollup-plugin-esbuild": "^6.1.0",
"send": "^0.18.0",
"tar-stream": "^3.1.6",
"tsx": "^3.13.0",
Expand Down
14 changes: 7 additions & 7 deletions src/client/toc.js → src/client/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ if (toc) {
const highlight = toc.appendChild(document.createElement("div"));
highlight.classList.add("observablehq-secondary-link-highlight");
const headings = Array.from(document.querySelectorAll("#observablehq-main h2")).reverse();
const links = toc.querySelectorAll(".observablehq-secondary-link");
const relink = () => {
const links = toc.querySelectorAll(".observablehq-secondary-link") as any as Iterable<HTMLElement>;
const relink = (): HTMLElement | undefined => {
for (const link of links) {
link.classList.remove("observablehq-secondary-link-active");
}
// If there’s a location.hash, highlight that if it’s at the top of the viewport.
if (location.hash) {
for (const heading of headings) {
const hash = heading.querySelector("a[href]")?.hash;
const hash = heading.querySelector<HTMLAnchorElement>("a[href]")?.hash;
if (hash === location.hash) {
const top = heading.getBoundingClientRect().top;
if (0 < top && top < 40) {
for (const link of links) {
if (link.querySelector("a[href]")?.hash === hash) {
if (link.querySelector<HTMLAnchorElement>("a[href]")?.hash === hash) {
link.classList.add("observablehq-secondary-link-active");
return link;
}
Expand All @@ -30,9 +30,9 @@ if (toc) {
// Otherwise, highlight the last one that’s above the center of the viewport.
for (const heading of headings) {
if (heading.getBoundingClientRect().top >= innerHeight * 0.5) continue;
const hash = heading.querySelector("a[href]")?.hash;
const hash = heading.querySelector<HTMLAnchorElement>("a[href]")?.hash;
for (const link of links) {
if (link.querySelector("a[href]")?.hash === hash) {
if (link.querySelector<HTMLAnchorElement>("a[href]")?.hash === hash) {
link.classList.add("observablehq-secondary-link-active");
return link;
}
Expand All @@ -42,7 +42,7 @@ if (toc) {
};
const intersected = () => {
const link = relink();
highlight.style = link ? `top: ${link.offsetTop}px; height: ${link.offsetHeight}px;` : "";
highlight.style.cssText = link ? `top: ${link.offsetTop}px; height: ${link.offsetHeight}px;` : "";
};
const observer = new IntersectionObserver(intersected, {rootMargin: "0px 0px -50% 0px"});
for (const heading of headings) observer.observe(heading);
Expand Down
7 changes: 4 additions & 3 deletions src/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {dirname, join, relative} from "node:path";
import {cwd} from "node:process";
import {fileURLToPath} from "node:url";
import terser from "@rollup/plugin-terser";
import {type OutputChunk, rollup} from "rollup";
import esbuild from "rollup-plugin-esbuild";

export async function rollupClient(clientPath = getClientPath(), {minify = false} = {}): Promise<string> {
const bundle = await rollup({
Expand All @@ -16,11 +16,12 @@ export async function rollupClient(clientPath = getClientPath(), {minify = false
? {id: `https://cdn.jsdelivr.net/npm/${specifier.slice("npm:".length)}/+esm`}
: null;
}
}
},
(esbuild as any)({minify})
]
});
try {
const output = await bundle.generate({format: "es", plugins: minify ? [(terser as any)()] : []});
const output = await bundle.generate({format: "es"});
return output.output.find((o): o is OutputChunk => o.type === "chunk")!.code; // XXX
} finally {
await bundle.close();
Expand Down
96 changes: 36 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,39 +183,17 @@
resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.3.tgz#e45e384e4b8ec16bce2fd903af78450f6bf7ec98"
integrity sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==

"@jridgewell/gen-mapping@^0.3.0":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098"
integrity sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==
dependencies:
"@jridgewell/set-array" "^1.0.1"
"@jridgewell/sourcemap-codec" "^1.4.10"
"@jridgewell/trace-mapping" "^0.3.9"

"@jridgewell/resolve-uri@^3.1.0":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721"
integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==

"@jridgewell/set-array@^1.0.1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==

"@jridgewell/source-map@^0.3.3":
version "0.3.5"
resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.5.tgz#a3bb4d5c6825aab0d281268f47f6ad5853431e91"
integrity sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==
dependencies:
"@jridgewell/gen-mapping" "^0.3.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14":
"@jridgewell/sourcemap-codec@^1.4.14":
version "1.4.15"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==

"@jridgewell/trace-mapping@^0.3.12", "@jridgewell/trace-mapping@^0.3.9":
"@jridgewell/trace-mapping@^0.3.12":
version "0.3.20"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz#72e45707cf240fa6b081d0366f8265b0cd10197f"
integrity sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==
Expand Down Expand Up @@ -280,14 +258,14 @@
picocolors "^1.0.0"
tslib "^2.6.0"

"@rollup/plugin-terser@^0.4.4":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz#15dffdb3f73f121aa4fbb37e7ca6be9aeea91962"
integrity sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==
"@rollup/pluginutils@^5.0.5":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.1.0.tgz#7e53eddc8c7f483a4ad0b94afb1f7f5fd3c771e0"
integrity sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==
dependencies:
serialize-javascript "^6.0.1"
smob "^1.0.0"
terser "^5.17.4"
"@types/estree" "^1.0.0"
estree-walker "^2.0.2"
picomatch "^2.3.1"

"@rollup/rollup-android-arm-eabi@4.6.0":
version "4.6.0"
Expand Down Expand Up @@ -359,6 +337,11 @@
resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.5.tgz#14a3e83fa641beb169a2dd8422d91c3c345a9a78"
integrity sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==

"@types/estree@^1.0.0":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==

"@types/he@^1.2.3":
version "1.2.3"
resolved "https://registry.yarnpkg.com/@types/he/-/he-1.2.3.tgz#c33ca3096f30cbd5d68d78211572de3f9adff75a"
Expand Down Expand Up @@ -554,7 +537,7 @@ acorn-walk@^8.3.0:
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.0.tgz#2097665af50fd0cf7a2dfccd2b9368964e66540f"
integrity sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==

acorn@^8.11.2, acorn@^8.8.2, acorn@^8.9.0:
acorn@^8.11.2, acorn@^8.9.0:
version "8.11.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.2.tgz#ca0d78b51895be5390a5903c5b3bdcdaf78ae40b"
integrity sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==
Expand Down Expand Up @@ -906,11 +889,6 @@ commander@7:
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==

commander@^2.20.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

component-emitter@^1.3.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.1.tgz#ef1d5796f7d93f135ee6fb684340b26403c97d17"
Expand Down Expand Up @@ -1215,6 +1193,11 @@ es-abstract@^1.22.1:
unbox-primitive "^1.0.2"
which-typed-array "^1.1.13"

es-module-lexer@^1.3.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.4.1.tgz#41ea21b43908fe6a287ffcbe4300f790555331f5"
integrity sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w==

es-set-tostringtag@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.0.2.tgz#11f7cc9f63376930a5f20be4915834f4bc74f9c9"
Expand Down Expand Up @@ -1425,6 +1408,11 @@ estraverse@^5.1.0, estraverse@^5.2.0:
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123"
integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==

estree-walker@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==

esutils@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
Expand Down Expand Up @@ -2751,6 +2739,16 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rollup-plugin-esbuild@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-esbuild/-/rollup-plugin-esbuild-6.1.0.tgz#966d297fe9edea3e6ba5dfd8ca3208825c82d7ce"
integrity sha512-HPpXU65V8bSpW8eSYPahtUJaJHmbxJGybuf/M8B3bz/6i11YaYHlNNJIQ38gSEV0FyohQOgVxJ2YMEEZtEmwvA==
dependencies:
"@rollup/pluginutils" "^5.0.5"
debug "^4.3.4"
es-module-lexer "^1.3.1"
get-tsconfig "^4.7.2"

rollup@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.6.0.tgz#4f966f6dd3f6bafd01b864d68ba078d308b864fa"
Expand Down Expand Up @@ -2869,13 +2867,6 @@ serialize-javascript@6.0.0:
dependencies:
randombytes "^2.1.0"

serialize-javascript@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.1.tgz#b206efb27c3da0b0ab6b52f48d170b7996458e5c"
integrity sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==
dependencies:
randombytes "^2.1.0"

set-function-length@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.1.1.tgz#4bc39fafb0307224a33e106a7d35ca1218d659ed"
Expand Down Expand Up @@ -2936,12 +2927,7 @@ slash@^3.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

smob@^1.0.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/smob/-/smob-1.4.1.tgz#66270e7df6a7527664816c5b577a23f17ba6f5b5"
integrity sha512-9LK+E7Hv5R9u4g4C3p+jjLstaLe11MDsL21UpYaCNmapvMkYhqCV4A/f/3gyH8QjMyh6l68q9xC85vihY9ahMQ==

source-map-support@^0.5.21, source-map-support@~0.5.20:
source-map-support@^0.5.21:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
Expand Down Expand Up @@ -3099,16 +3085,6 @@ tar-stream@^3.1.6:
fast-fifo "^1.2.0"
streamx "^2.15.0"

terser@^5.17.4:
version "5.24.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.24.0.tgz#4ae50302977bca4831ccc7b4fef63a3c04228364"
integrity sha512-ZpGR4Hy3+wBEzVEnHvstMvqpD/nABNelQn/z2r0fjVWGQsN3bpOLzQlqDxmb4CDZnXq5lpjnQ+mHQLAOpfM5iw==
dependencies:
"@jridgewell/source-map" "^0.3.3"
acorn "^8.8.2"
commander "^2.20.0"
source-map-support "~0.5.20"

test-exclude@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
Expand Down

0 comments on commit 1d980e3

Please sign in to comment.