Skip to content

Commit

Permalink
Merge branch 'main' into dylan/remove-unused-registry-option
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway authored Oct 25, 2024
2 parents 650fe74 + eb6995e commit 08d4997
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: clang
name: clang-format

permissions:
contents: write
Expand All @@ -15,8 +15,8 @@ env:
LLVM_VERSION_MAJOR: "18"

jobs:
clang:
name: clang
clang-format:
name: clang-format
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -35,11 +35,6 @@ jobs:
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-format
- name: Clang Tidy
env:
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-tidy:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: clang-tidy

permissions:
contents: write

on:
workflow_call:
workflow_dispatch:
pull_request:
merge_group:

env:
BUN_VERSION: "1.1.27"
LLVM_VERSION: "18.1.8"
LLVM_VERSION_MAJOR: "18"

jobs:
clang-tidy:
name: clang-tidy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Install LLVM
run: |
curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ env.LLVM_VERSION_MAJOR }} all
- name: Clang Tidy
env:
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-tidy:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run clang-tidy`"
123 changes: 64 additions & 59 deletions docs/guides/ecosystem/sveltekit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,62 @@
name: Build an app with SvelteKit and Bun
---

Use `bun create` to scaffold your app with the `svelte` package. Answer the prompts to select a template and set up your development environment.
Use `sv create my-app` to create a SvelteKit project with SvelteKit CLI. Answer the prompts to select a template and set up your development environment.

```sh
$ bun create svelte@latest my-app
┌ Welcome to SvelteKit!
$ bunx sv create my-app
┌ Welcome to the Svelte CLI! (v0.5.7)
◇ Which Svelte app template?
│ SvelteKit demo app
◇ Which template would you like?
│ SvelteKit demo
◇ Add type checking with TypeScript?
│ Yes, using TypeScript syntax
◇ Add type checking with Typescript?
│ Yes, using Typescript syntax
◇ Select additional options (use arrow keys/space bar)
│ None
◆ Project created
└ Your project is ready!

✔ Typescript
Inside Svelte components, use <script lang="ts">

Install community-maintained integrations:
https://github.com/svelte-add/svelte-add
◇ What would you like to add to your project?
│ none
◇ Which package manager do you want to install dependencies with?
│ bun
◇ Successfully installed dependencies
◇ Project next steps ─────────────────────────────────────────────────────╮
│ │
│ 1: cd my-app │
│ 2: git init && git add -A && git commit -m "Initial commit" (optional) │
│ 3: bun run dev -- --open │
│ │
│ To close the dev server, hit Ctrl-C │
│ │
│ Stuck? Visit us at https://svelte.dev/chat │
│ │
├──────────────────────────────────────────────────────────────────────────╯
└ You're all set!
```
---
Once the project is initialized, `cd` into the new project and install dependencies.

```sh
$ cd my-app
$ bun install
```

---
Once the project is initialized, `cd` into the new project. You don't need to run 'bun install' since the dependencies are already installed.

Then start the development server with `bun --bun run dev`.

To run the dev server with Node.js instead of Bun, you can omit the `--bun` flag.

```sh
$ cd my-app
$ bun --bun run dev
$ vite dev

Forced re-optimization of dependencies

VITE v4.4.9 ready in 895 ms

VITE v5.4.10 ready in 424 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h to show help
➜ press h + enter to show help
```

---
Expand All @@ -75,16 +81,22 @@ Now, make the following changes to your `svelte.config.js`.
```ts-diff
- import adapter from "@sveltejs/adapter-auto";
+ import adapter from "svelte-adapter-bun";
import { vitePreprocess } from "@sveltejs/kit/vite";
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
},
preprocess: vitePreprocess(),
// Consult https://svelte.dev/docs/kit/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;
```
Expand All @@ -93,28 +105,21 @@ Now, make the following changes to your `svelte.config.js`.
To build a production bundle:
```sh
$ bun run build
$ vite build

vite v4.4.9 building SSR bundle for production...
transforming (60) node_modules/@sveltejs/kit/src/utils/escape.js

✓ 98 modules transformed.
Generated an empty chunk: "entries/endpoints/waitlist/_server.ts".

vite v4.4.9 building for production...
✓ 92 modules transformed.
Generated an empty chunk: "7".
.svelte-kit/output/client/_app/version.json 0.03 kB │ gzip: 0.05 kB

...

.svelte-kit/output/server/index.js 86.47 kB

Run npm run preview to preview your production build locally.

> Using svelte-adapter-bun
✔ Start server with: bun ./build/index.js
done
✓ built in 7.81s
$ bun --bun run build
$ vite build
vite v5.4.10 building SSR bundle for production...
"confetti" is imported from external module "@neoconfetti/svelte" but never used in "src/routes/sverdle/+page.svelte".
✓ 130 modules transformed.
vite v5.4.10 building for production...
✓ 148 modules transformed.
...
✓ built in 231ms
...
✓ built in 899ms
Run npm run preview to preview your production build locally.
> Using svelte-adapter-bun
✔ Start server with: bun ./build/index.js
✔ done
```
30 changes: 15 additions & 15 deletions src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4980,6 +4980,21 @@ pub const Package = extern struct {
};
}

if (json.asProperty("patchedDependencies")) |patched_deps| {
const obj = patched_deps.expr.data.e_object;
lockfile.patched_dependencies.ensureTotalCapacity(allocator, obj.properties.len) catch unreachable;
for (obj.properties.slice()) |prop| {
const key = prop.key.?;
const value = prop.value.?;
if (key.isString() and value.isString()) {
var sfb = std.heap.stackFallback(1024, allocator);
const keyhash = try key.asStringHash(sfb.get(), String.Builder.stringHash) orelse unreachable;
const patch_path = string_builder.append(String, value.asString(allocator).?);
lockfile.patched_dependencies.put(allocator, keyhash, .{ .path = patch_path }) catch unreachable;
}
}
}

bin: {
if (json.asProperty("bin")) |bin| {
switch (bin.expr.data) {
Expand Down Expand Up @@ -5042,21 +5057,6 @@ pub const Package = extern struct {
}
}

if (json.asProperty("patchedDependencies")) |patched_deps| {
const obj = patched_deps.expr.data.e_object;
lockfile.patched_dependencies.ensureTotalCapacity(allocator, obj.properties.len) catch unreachable;
for (obj.properties.slice()) |prop| {
const key = prop.key.?;
const value = prop.value.?;
if (key.isString() and value.isString()) {
var sfb = std.heap.stackFallback(1024, allocator);
const keyhash = try key.asStringHash(sfb.get(), String.Builder.stringHash) orelse unreachable;
const patch_path = string_builder.append(String, value.asString(allocator).?);
lockfile.patched_dependencies.put(allocator, keyhash, .{ .path = patch_path }) catch unreachable;
}
}
}

if (json.asProperty("directories")) |dirs| {
// https://docs.npmjs.com/cli/v8/configuring-npm/package-json#directoriesbin
// Because of the way the bin directive works,
Expand Down
Binary file modified test/bun.lockb
Binary file not shown.
13 changes: 1 addition & 12 deletions test/cli/install/bun-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,7 @@ it("should link dependency without crashing", async () => {
expect(await new Response(stdout1).text()).toContain(`Success! Registered "${link_name}"`);
expect(await exited1).toBe(0);

const {
stdout: stdout2,
stderr: stderr2,
exited: exited2,
} = spawn({
cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: "pipe",
stdin: "pipe",
stderr: "pipe",
env,
});
const { out: stdout2, err: stderr2, exited: exited2 } = await runBunInstall(env, package_dir);
const err2 = await new Response(stderr2).text();
expect(err2.split(/\r?\n/)).toEqual(["Saved lockfile", ""]);
const out2 = await new Response(stdout2).text();
Expand Down
4 changes: 2 additions & 2 deletions test/cli/install/bun-run.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { file, spawn, spawnSync } from "bun";
import { beforeEach, describe, expect, it } from "bun:test";
import { exists, mkdir, rm, writeFile } from "fs/promises";
import { bunEnv, bunExe, bunEnv as env, isWindows, tempDirWithFiles, tmpdirSync } from "harness";
import { bunEnv, bunExe, bunEnv as env, isWindows, tempDirWithFiles, tmpdirSync, stderrForInstall } from "harness";
import { join } from "path";
import { readdirSorted } from "./dummy.registry";

Expand Down Expand Up @@ -300,7 +300,7 @@ console.log(minify("print(6 * 7)").code);
BUN_INSTALL_CACHE_DIR: join(run_dir, ".cache"),
},
});
const err2 = await new Response(stderr2).text();
const err2 = stderrForInstall(await new Response(stderr2).text());
expect(err2).toBe("");
expect(await readdirSorted(run_dir)).toEqual([".cache", "test.js"]);
expect(await readdirSorted(join(run_dir, ".cache"))).toContain("uglify-js");
Expand Down
Loading

0 comments on commit 08d4997

Please sign in to comment.