Skip to content

Commit

Permalink
Merge branch 'main' into jarred/s3-
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari authored Jan 4, 2025
2 parents 9186443 + 2043613 commit 18e2081
Show file tree
Hide file tree
Showing 24 changed files with 1,115 additions and 286 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Configuring a development environment for Bun can take 10-30 minutes depending on your internet connection and computer speed. You will need ~10GB of free disk space for the repository and build artifacts.

If you are using Windows, please refer to [this guide](/docs/project/building-windows)
If you are using Windows, please refer to [this guide](https://bun.sh/docs/project/building-windows)

## Install Dependencies

Expand Down
2 changes: 1 addition & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")

if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION c30d63fe69913f17dce5fcbe17d06e670e0eaeff)
set(WEBKIT_VERSION e1a802a2287edfe7f4046a9dd8307c8b59f5d816)
endif()

if(WEBKIT_LOCAL)
Expand Down
8 changes: 7 additions & 1 deletion docs/install/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ To exclude dependency types from installing, use `--omit` with `dev`, `optional`
$ bun install --omit=dev --omit=optional
```

To perform a dry run (i.e. don't actually install anything):
To perform a dry run (i.e. don't actually install anything or update the lockfile):

```bash
$ bun install --dry-run
```

To generate a lockfile without install packages:

```bash
$ bun install --lockfile-only
```

To modify logging verbosity:

```bash
Expand Down
12 changes: 12 additions & 0 deletions docs/install/lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ Packages, metadata for those packages, the hoisted install order, dependencies f

It uses linear arrays for all data. [Packages](https://github.com/oven-sh/bun/blob/be03fc273a487ac402f19ad897778d74b6d72963/src/install/install.zig#L1825) are referenced by an auto-incrementing integer ID or a hash of the package name. Strings longer than 8 characters are de-duplicated. Prior to saving on disk, the lockfile is garbage-collected & made deterministic by walking the package tree and cloning the packages in dependency order.

#### Generate a lockfile without installing?

To generate a lockfile without installing to `node_modules` you can use the `--lockfile-only` flag. The lockfile will always be saved to disk, even if it is up-to-date with the `package.json`(s) for your project.

```bash
$ bun install --lockfile-only
```

{% callout %}
**Note** - using `--lockfile-only` will still populate the global install cache with registry metadata and git/tarball dependencies.
{% endcallout %}

#### Can I opt out?

To install without creating a lockfile:
Expand Down
261 changes: 197 additions & 64 deletions packages/bun-vscode/example/bun.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/HTMLScanner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ pub fn deinit(this: *HTMLScanner) void {
this.import_records.deinitWithAllocator(this.allocator);
}

fn createImportRecord(this: *HTMLScanner, path: []const u8, kind: ImportKind) !void {
fn createImportRecord(this: *HTMLScanner, input_path: []const u8, kind: ImportKind) !void {
// In HTML, sometimes people do /src/index.js
// In that case, we don't want to use the absolute filesystem path, we want to use the path relative to the project root
const path_to_use = if (input_path.len > 1 and input_path[0] == '/')
bun.path.joinAbsString(bun.fs.FileSystem.instance.top_level_dir, &[_][]const u8{input_path[1..]}, .auto)
else
input_path;

const record = ImportRecord{
.path = fs.Path.init(try this.allocator.dupe(u8, path)),
.path = fs.Path.init(try this.allocator.dupeZ(u8, path_to_use)),
.kind = kind,
.range = logger.Range.None,
};

try this.import_records.push(this.allocator, record);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/glob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ pub fn match(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame
var str = str_arg.toSlice(globalThis, arena.allocator());
defer str.deinit();

if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImpl.Ascii.match(this.pattern, str.slice()));
if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImpl.Ascii.match(this.pattern, str.slice()).matches());

const codepoints = codepoints: {
if (this.pattern_codepoints) |cp| break :codepoints cp.items[0..];
Expand Down
36 changes: 6 additions & 30 deletions src/cli/outdated_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const FileSystem = bun.fs.FileSystem;
const path = bun.path;
const glob = bun.glob;
const Table = bun.fmt.Table;
const WorkspaceFilter = PackageManager.WorkspaceFilter;
const OOM = bun.OOM;

pub const OutdatedCommand = struct {
pub fn exec(ctx: Command.Context) !void {
Expand Down Expand Up @@ -138,7 +140,7 @@ pub const OutdatedCommand = struct {
original_cwd: string,
manager: *PackageManager,
filters: []const string,
) error{OutOfMemory}![]const PackageID {
) OOM![]const PackageID {
const lockfile = manager.lockfile;
const packages = lockfile.packages.slice();
const pkg_names = packages.items(.name);
Expand All @@ -152,36 +154,10 @@ pub const OutdatedCommand = struct {
}

const converted_filters = converted_filters: {
const buf = try allocator.alloc(FilterType, filters.len);
const buf = try allocator.alloc(WorkspaceFilter, filters.len);
var path_buf: bun.PathBuffer = undefined;
for (filters, buf) |filter, *converted| {
if ((filter.len == 1 and filter[0] == '*') or strings.eqlComptime(filter, "**")) {
converted.* = .all;
continue;
}

const is_path = filter.len > 0 and filter[0] == '.';

const joined_filter = if (is_path)
strings.withoutTrailingSlash(path.joinAbsString(original_cwd, &[_]string{filter}, .posix))
else
filter;

if (joined_filter.len == 0) {
converted.* = FilterType.init(&.{}, is_path);
continue;
}

const length = bun.simdutf.length.utf32.from.utf8.le(joined_filter);
const convert_buf = try allocator.alloc(u32, length);

const convert_result = bun.simdutf.convert.utf8.to.utf32.with_errors.le(joined_filter, convert_buf);
if (!convert_result.isSuccessful()) {
// nothing would match
converted.* = FilterType.init(&.{}, false);
continue;
}

converted.* = FilterType.init(convert_buf[0..convert_result.count], is_path);
converted.* = try WorkspaceFilter.init(allocator, filter, original_cwd, &path_buf);
}
break :converted_filters buf;
};
Expand Down
2 changes: 1 addition & 1 deletion src/glob/GlobWalker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ pub fn GlobWalker_(
return GlobAscii.match(
pattern_component.patternSlice(this.pattern),
filepath,
);
).matches();
}
const codepoints = this.componentStringUnicode(pattern_component);
return matchImpl(
Expand Down
32 changes: 22 additions & 10 deletions src/glob/ascii.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ pub fn valid_glob_indices(glob: []const u8, indices: std.ArrayList(BraceIndex))
}
}

pub const MatchResult = enum {
no_match,
match,

negate_no_match,
negate_match,

pub fn matches(this: MatchResult) bool {
return this == .match or this == .negate_match;
}
};

/// This function checks returns a boolean value if the pathname `path` matches
/// the pattern `glob`.
///
Expand Down Expand Up @@ -208,7 +220,7 @@ pub fn valid_glob_indices(glob: []const u8, indices: std.ArrayList(BraceIndex))
/// Multiple "!" characters negate the pattern multiple times.
/// "\"
/// Used to escape any of the special characters above.
pub fn match(glob: []const u8, path: []const u8) bool {
pub fn match(glob: []const u8, path: []const u8) MatchResult {
// This algorithm is based on https://research.swtch.com/glob
var state = State{};
// Store the state when we see an opening '{' brace in a stack.
Expand Down Expand Up @@ -290,7 +302,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
(glob[state.glob_index] == ',' or glob[state.glob_index] == '}'))
{
if (state.skipBraces(glob, false) == .Invalid)
return false; // invalid pattern!
return .no_match; // invalid pattern!
}

continue;
Expand Down Expand Up @@ -321,7 +333,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
while (state.glob_index < glob.len and (first or glob[state.glob_index] != ']')) {
var low = glob[state.glob_index];
if (!unescape(&low, glob, &state.glob_index))
return false; // Invalid pattern
return .no_match; // Invalid pattern
state.glob_index += 1;

// If there is a - and the following character is not ],
Expand All @@ -332,7 +344,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
state.glob_index += 1;
var h = glob[state.glob_index];
if (!unescape(&h, glob, &state.glob_index))
return false; // Invalid pattern!
return .no_match; // Invalid pattern!
state.glob_index += 1;
break :blk h;
} else low;
Expand All @@ -342,7 +354,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
first = false;
}
if (state.glob_index >= glob.len)
return false; // Invalid pattern!
return .no_match; // Invalid pattern!
state.glob_index += 1;
if (is_match != class_negated) {
state.path_index += 1;
Expand All @@ -351,7 +363,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
},
'{' => if (state.path_index < path.len) {
if (brace_stack.len >= brace_stack.stack.len)
return false; // Invalid pattern! Too many nested braces.
return .no_match; // Invalid pattern! Too many nested braces.

// Push old state to the stack, and reset current state.
state = brace_stack.push(&state);
Expand Down Expand Up @@ -380,7 +392,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
var cc = c;
// Match escaped characters as literals.
if (!unescape(&cc, glob, &state.glob_index))
return false; // Invalid pattern;
return .no_match; // Invalid pattern;

const is_match = if (cc == '/')
isSeparator(path[state.path_index])
Expand Down Expand Up @@ -416,7 +428,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
if (brace_stack.len > 0) {
// If in braces, find next option and reset path to index where we saw the '{'
switch (state.skipBraces(glob, true)) {
.Invalid => return false,
.Invalid => return .no_match,
.Comma => {
state.path_index = brace_stack.last().path_index;
continue;
Expand All @@ -440,10 +452,10 @@ pub fn match(glob: []const u8, path: []const u8) bool {
}
}

return negated;
return if (negated) .negate_match else .no_match;
}

return !negated;
return if (!negated) .match else .negate_no_match;
}

inline fn isSeparator(c: u8) bool {
Expand Down
13 changes: 12 additions & 1 deletion src/install/bun.lock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,17 @@ pub const Stringifier = struct {
// need a way to detect new/deleted workspaces
if (pkg_id == 0) {
try writer.writeAll("\"\": {");
const root_name = pkg_names[0].slice(buf);
if (root_name.len > 0) {
try writer.writeByte('\n');
try incIndent(writer, indent);
try writer.print("\"name\": {}", .{
bun.fmt.formatJSONStringUTF8(root_name, .{}),
});

// TODO(dylan-conway) should we save version?
any = true;
}
} else {
try writer.print("{}: {{", .{
bun.fmt.formatJSONStringUTF8(res.slice(buf), .{}),
Expand Down Expand Up @@ -1625,7 +1636,7 @@ pub fn parseIntoBinaryLockfile(
}
}

lockfile.hoist(log, .resolvable, {}) catch |err| {
lockfile.resolve(log) catch |err| {
switch (err) {
error.OutOfMemory => |oom| return oom,
else => {
Expand Down
Loading

0 comments on commit 18e2081

Please sign in to comment.