From 263382103f47ce6f7063ad07d34664718b4c1ea7 Mon Sep 17 00:00:00 2001 From: Samuel Rigaud <46346622+s-rigaud@users.noreply.github.com> Date: Tue, 12 Sep 2023 21:50:05 -0400 Subject: docs: fix typos (#5151) --- docs/api/workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/api/workers.md') diff --git a/docs/api/workers.md b/docs/api/workers.md index 417b77148..1a4a09965 100644 --- a/docs/api/workers.md +++ b/docs/api/workers.md @@ -123,7 +123,7 @@ By default, an active `Worker` will keep the main (spawning) process alive, so a ### `worker.unref()` -To stop a running worker from keeping the process alive, call `worker.unref()`. This decouples the lifetime of the worker to the lifetime of the main process, and is equivlent to what Node.js' `worker_threads` does. +To stop a running worker from keeping the process alive, call `worker.unref()`. This decouples the lifetime of the worker to the lifetime of the main process, and is equivalent to what Node.js' `worker_threads` does. ```ts const worker = new Worker(new URL("worker.ts", import.meta.url).href); -- cgit v1.2.3 From cb01cb0d4ad67aace33ae603938d1a28a7c10ca7 Mon Sep 17 00:00:00 2001 From: James Gordo <14321895+jamesgordo@users.noreply.github.com> Date: Thu, 14 Sep 2023 07:36:11 +0800 Subject: Fixed api & cli docs typo. (#5262) * Fixed api & cli docs typo. * Fix --------- Co-authored-by: Colin McDonnell --- docs/api/http.md | 2 +- docs/api/workers.md | 4 ++-- docs/cli/bun-install.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/api/workers.md') diff --git a/docs/api/http.md b/docs/api/http.md index 629570335..cd20a9931 100644 --- a/docs/api/http.md +++ b/docs/api/http.md @@ -71,7 +71,7 @@ In development mode, Bun will surface errors in-browser with a built-in error pa {% image src="/images/exception_page.png" caption="Bun's built-in 500 page" /%} -To handle server-side errors, implement an `error` handler. This function should return a `Response` to served to the client when an error occurs. This response will supercede Bun's default error page in `development` mode. +To handle server-side errors, implement an `error` handler. This function should return a `Response` to serve to the client when an error occurs. This response will supersede Bun's default error page in `development` mode. ```ts Bun.serve({ diff --git a/docs/api/workers.md b/docs/api/workers.md index 1a4a09965..50fdb9c3d 100644 --- a/docs/api/workers.md +++ b/docs/api/workers.md @@ -130,7 +130,7 @@ const worker = new Worker(new URL("worker.ts", import.meta.url).href); worker.unref(); ``` -Note: `worker.unref()` is not available in browers. +Note: `worker.unref()` is not available in browsers. ### `worker.ref()` @@ -151,7 +151,7 @@ const worker = new Worker(new URL("worker.ts", import.meta.url).href, { }); ``` -Note: `worker.ref()` is not available in browers. +Note: `worker.ref()` is not available in browsers. ## Memory usage with `smol` diff --git a/docs/cli/bun-install.md b/docs/cli/bun-install.md index 8050070be..e705a2172 100644 --- a/docs/cli/bun-install.md +++ b/docs/cli/bun-install.md @@ -47,7 +47,7 @@ registry = "https://registry.yarnpkg.com/" # Install for production? This is the equivalent to the "--production" CLI argument production = false -# Disallow changes to lockfile? This is the equivalent to the "--fozen-lockfile" CLI argument +# Disallow changes to lockfile? This is the equivalent to the "--frozen-lockfile" CLI argument frozenLockfile = false # Don't actually install -- cgit v1.2.3 From 4fce34854be8e1f29bf89f02f7a2541ef5e1d3a8 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Tue, 19 Sep 2023 16:31:38 -0700 Subject: Doc updates (#5759) * WIP * WIP --- docs/api/workers.md | 15 ++++++++++++--- docs/bundler/index.md | 4 ++++ docs/runtime/plugins.md | 15 ++++++++++----- packages/bun-types/bun-test.d.ts | 2 +- packages/bun-types/tests/test.test-d.ts | 5 +++++ 5 files changed, 32 insertions(+), 9 deletions(-) (limited to 'docs/api/workers.md') diff --git a/docs/api/workers.md b/docs/api/workers.md index 50fdb9c3d..2b8c4fe13 100644 --- a/docs/api/workers.md +++ b/docs/api/workers.md @@ -10,7 +10,7 @@ Bun implements a minimal version of the [Web Workers API](https://developer.mozi Like in browsers, [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) is a global. Use it to create a new worker thread. -From the main thread: +### From the main thread ```js#Main_thread const workerURL = new URL("worker.ts", import.meta.url).href; @@ -22,16 +22,25 @@ worker.onmessage = event => { }; ``` -Worker thread: +### Worker thread ```ts#worker.ts_(Worker_thread) +// prevents TS errors +declare var self: Worker; + self.onmessage = (event: MessageEvent) => { console.log(event.data); postMessage("world"); }; ``` -You can use `import`/`export` syntax in your worker code. Unlike in browsers, there's no need to specify `{type: "module"}` to use ES Modules. +To prevent TypeScript errors when using `self`, add this line to the top of your worker file. + +```ts +declare var self: Worker; +``` + +You can use `import` and `export` syntax in your worker code. Unlike in browsers, there's no need to specify `{type: "module"}` to use ES Modules. To simplify error handling, the initial script to load is resolved at the time `new Worker(url)` is called. diff --git a/docs/bundler/index.md b/docs/bundler/index.md index 8db531ce5..9b8029db1 100644 --- a/docs/bundler/index.md +++ b/docs/bundler/index.md @@ -29,6 +29,10 @@ The bundler is a key piece of infrastructure in the JavaScript ecosystem. As a b Let's jump into the bundler API. +{% callout %} +Note that the Bun bundler is not intended to replace `tsc` for typechecking or generating type declarations. +{% /callout %} + ## Basic example Let's build our first bundle. You have the following two files, which implement a simple client-side rendered React app. diff --git a/docs/runtime/plugins.md b/docs/runtime/plugins.md index 8f5bf21e2..a422fdc40 100644 --- a/docs/runtime/plugins.md +++ b/docs/runtime/plugins.md @@ -61,7 +61,7 @@ Plugins are primarily used to extend Bun with loaders for additional file types. ```ts#yamlPlugin.ts import { plugin } from "bun"; -plugin({ +await plugin({ name: "YAML", async setup(build) { const { load } = await import("js-yaml"); @@ -84,15 +84,20 @@ plugin({ }); ``` -With this plugin, data can be directly imported from `.yaml` files. +Register this file in `preload`: + +```toml#bunfig.toml +preload = ["./yamlPlugin.ts"] +``` + +Once the plugin is registed, `.yaml` and `.yml` files can be directly imported. {% codetabs %} ```ts#index.ts -import "./yamlPlugin.ts" -import {name, releaseYear} from "./data.yml" +import data from "./data.yml" -console.log(name, releaseYear); +console.log(data); ``` ```yaml#data.yml diff --git a/packages/bun-types/bun-test.d.ts b/packages/bun-types/bun-test.d.ts index 03a067dc2..b32ffb4f7 100644 --- a/packages/bun-types/bun-test.d.ts +++ b/packages/bun-types/bun-test.d.ts @@ -114,7 +114,7 @@ declare module "bun:test" { export function spyOn( obj: T, methodOrPropertyValue: K, - ): Mock<() => T[K]>; + ): Mock; /** * Describes a group of related tests. diff --git a/packages/bun-types/tests/test.test-d.ts b/packages/bun-types/tests/test.test-d.ts index 1d504272d..831b18e2e 100644 --- a/packages/bun-types/tests/test.test-d.ts +++ b/packages/bun-types/tests/test.test-d.ts @@ -6,7 +6,12 @@ import { afterAll, beforeEach, afterEach, + spyOn, } from "bun:test"; +import { expectType } from "tsd"; + +const spy = spyOn(console, "log"); +expectType(spy.mock.calls); const hooks = [beforeAll, beforeEach, afterAll, afterEach]; -- cgit v1.2.3