Skip to content

Commit

Permalink
Merge branch 'main' into ben/bump-webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Jan 8, 2025
2 parents 2236526 + 783c2b4 commit f42a28d
Show file tree
Hide file tree
Showing 44 changed files with 1,792 additions and 1,738 deletions.
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# To learn more about git's mailmap: https://ntietz.com/blog/git-mailmap-for-name-changes
chloe caruso <[email protected]> <[email protected]>
9 changes: 5 additions & 4 deletions docs/api/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const writer = s3file.writer({
queueSize: 10,

// Upload in 5 MB chunks
partSize: 5,
partSize: 5 * 1024 * 1024,
});
for (let i = 0; i < 10; i++) {
await writer.write(bigFile);
Expand Down Expand Up @@ -614,9 +614,10 @@ const credentials = {

const stat = await S3Client.stat("my-file.txt", credentials);
// {
// etag: "\"7a30b741503c0b461cc14157e2df4ad8\"",
// lastModified: 2025-01-07T00:19:10.000Z,
// size: 1024,
// etag: "1234567890",
// lastModified: new Date(),
// type: "text/plain;charset=utf-8",
// }
```

Expand Down Expand Up @@ -661,7 +662,7 @@ const response = await fetch("s3://my-bucket/my-file.txt", {
endpoint: "https://s3.us-east-1.amazonaws.com",
},
headers: {
"x-amz-meta-foo": "bar",
"range": "bytes=0-1023",
},
});
```
Expand Down
67 changes: 50 additions & 17 deletions docs/cli/filter.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
Use the `--filter` flag to execute lifecycle scripts in multiple packages at once:
The `--filter` (or `-F`) flag is used for selecting packages by pattern in a monorepo. Patterns can be used to match package names or package paths, with full glob syntax support.

Currently `--filter` is supported by `bun install` and `bun outdated`, and can also be used to run scripts for multiple packages at once.

## Matching

### Package Name `--filter <pattern>`

Name patterns select packages based on the package name, as specified in `package.json`. For example, if you have packages `pkg-a`, `pkg-b` and `other`, you can match all packages with `*`, only `pkg-a` and `pkg-b` with `pkg*`, and a specific package by providing the full name of the package.

### Package Path `--filter ./<glob>`

Path patterns are specified by starting the pattern with `./`, and will select all packages in directories that match the pattern. For example, to match all packages in subdirectories of `packages`, you can use `--filter './packages/**'`. To match a package located in `packages/foo`, use `--filter ./packages/foo`.

## `bun install` and `bun outdated`

Both `bun install` and `bun outdated` support the `--filter` flag.

`bun install` by default will install dependencies for all packages in the monorepo. To install dependencies for specific packages, use `--filter`.

Given a monorepo with workspaces `pkg-a`, `pkg-b`, and `pkg-c` under `./packages`:

```bash
# Install dependencies for all workspaces except `pkg-c`
$ bun install --filter '!pkg-c'

# Install dependencies for packages in `./packages` (`pkg-a`, `pkg-b`, `pkg-c`)
$ bun install --filter './packages/*'

# Save as above, but exclude the root package.json
$ bun install --filter --filter '!./' --filter './packages/*'
```

Similarly, `bun outdated` will display outdated dependencies for all packages in the monorepo, and `--filter` can be used to restrict the command to a subset of the packages:

```bash
# Display outdated dependencies for workspaces starting with `pkg-`
$ bun outdated --filter 'pkg-*'

# Display outdated dependencies for only the root package.json
$ bun outdated --filter './'
```

For more infomation on both these commands, see [`bun install`](https://bun.sh/docs/cli/install) and [`bun outdated`](https://bun.sh/docs/cli/outdated).

## Running scripts with `--filter`

Use the `--filter` flag to execute scripts in multiple packages at once:

```bash
bun --filter <pattern> <script>
Expand All @@ -24,19 +71,7 @@ bun --filter '*' dev
Both commands will be run in parallel, and you will see a nice terminal UI showing their respective outputs:
![Terminal Output](https://github.com/oven-sh/bun/assets/48869301/2a103e42-9921-4c33-948f-a1ad6e6bac71)

## Matching

`--filter` accepts a pattern to match specific packages, either by name or by path. Patterns have full support for glob syntax.

### Package Name `--filter <pattern>`

Name patterns select packages based on the package name, as specified in `package.json`. For example, if you have packages `pkga`, `pkgb` and `other`, you can match all packages with `*`, only `pkga` and `pkgb` with `pkg*`, and a specific package by providing the full name of the package.

### Package Path `--filter ./<glob>`

Path patterns are specified by starting the pattern with `./`, and will select all packages in directories that match the pattern. For example, to match all packages in subdirectories of `packages`, you can use `--filter './packages/**'`. To match a package located in `pkgs/foo`, use `--filter ./pkgs/foo`.

## Workspaces
### Running scripts in workspaces

Filters respect your [workspace configuration](https://bun.sh/docs/install/workspaces): If you have a `package.json` file that specifies which packages are part of the workspace,
`--filter` will be restricted to only these packages. Also, in a workspace you can use `--filter` to run scripts in packages that are located anywhere in the workspace:
Expand All @@ -50,8 +85,6 @@ Filters respect your [workspace configuration](https://bun.sh/docs/install/works
bun run --filter foo myscript
```

## Dependency Order
### Dependency Order

Bun will respect package dependency order when running scripts. Say you have a package `foo` that depends on another package `bar` in your workspace, and both packages have a `build` script. When you run `bun --filter '*' build`, you will notice that `foo` will only start running once `bar` is done.

### Cyclic Dependencies
14 changes: 14 additions & 0 deletions docs/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ Bun supports `"workspaces"` in package.json. For complete documentation refer to
}
```

## Installing dependencies for specific packages

In a monorepo, you can install the dependencies for a subset of packages using the `--filter` flag.

```bash
# Install dependencies for all workspaces except `pkg-c`
$ bun install --filter '!pkg-c'

# Install dependencies for only `pkg-a` in `./packages/pkg-a`
$ bun install --filter './packages/pkg-a'
```

For more information on filtering with `bun install`, refer to [Package Manager > Filtering](https://bun.sh/docs/cli/install#bun-install-and-bun-outdated)

## Overrides and resolutions

Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies. Refer to [Package manager > Overrides and resolutions](https://bun.sh/docs/install/overrides) for complete documentation.
Expand Down
2 changes: 2 additions & 0 deletions docs/cli/outdated.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ If you want to do the same, but exclude the `./apps/api` workspace:
```sh
$ bun outdated --filter './apps/*' --filter '!./apps/api'
```

Refer to [Package Manager > Filtering](https://bun.sh/docs/cli/filter#bun-install-and-bun-outdated) for more information on `--filter`.
4 changes: 2 additions & 2 deletions docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ $ bun run --bun vite

### Filtering

in monorepos containing multiple packages, you can use the `--filter` argument to execute scripts in many packages at once.
In monorepos containing multiple packages, you can use the `--filter` argument to execute scripts in many packages at once.

Use `bun run --filter <name_pattern> <script>` to execute `<script>` in all packages whose name matches `<name_pattern>`.
For example, if you have subdirectories containing packages named `foo`, `bar` and `baz`, running
Expand All @@ -164,7 +164,7 @@ bun run --filter 'ba*' <script>

will execute `<script>` in both `bar` and `baz`, but not in `foo`.

Find more details in the docs page for [filter](https://bun.sh/docs/cli/filter).
Find more details in the docs page for [filter](https://bun.sh/docs/cli/filter#running-scripts-with-filter).

## `bun run -` to pipe code from stdin

Expand Down
4 changes: 3 additions & 1 deletion packages/bun-types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ declare module "bun:test" {
*
* @example
* const o = { a: 'foo', b: 'bar', c: 'baz' };
` * expect(o).toContainAnyValues(['qux', 'foo']);
* expect(o).toContainAnyValues(['qux', 'foo']);
* expect(o).toContainAnyValues(['qux', 'bar']);
* expect(o).toContainAnyValues(['qux', 'baz']);
* expect(o).not.toContainAnyValues(['qux']);
Expand All @@ -1060,6 +1060,8 @@ declare module "bun:test" {

/**
* Asserts that an `object` contains all the provided keys.
*
* @example
* expect({ a: 'foo', b: 'bar', c: 'baz' }).toContainKeys(['a', 'b']);
* expect({ a: 'foo', b: 'bar', c: 'baz' }).toContainKeys(['a', 'b', 'c']);
* expect({ a: 'foo', b: 'bar', c: 'baz' }).not.toContainKeys(['a', 'b', 'e']);
Expand Down
4 changes: 3 additions & 1 deletion src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ const JSPromise = bun.JSC.JSPromise;
const JSInternalPromise = bun.JSC.JSInternalPromise;
const JSModuleLoader = bun.JSC.JSModuleLoader;
const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation;
const Exception = bun.JSC.Exception;
const ErrorableZigString = bun.JSC.ErrorableZigString;
const ZigGlobalObject = bun.JSC.ZigGlobalObject;
const VM = bun.JSC.VM;
Expand Down Expand Up @@ -831,6 +830,9 @@ pub fn sleepSync(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) b
pub fn gc(vm: *JSC.VirtualMachine, sync: bool) usize {
return vm.garbageCollect(sync);
}
export fn Bun__gc(vm: *JSC.VirtualMachine, sync: bool) callconv(.C) usize {
return @call(.always_inline, gc, .{ vm, sync });
}

pub fn shrink(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue {
globalObject.vm().shrinkFootprint();
Expand Down
1 change: 0 additions & 1 deletion src/bun.js/api/ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const JSPromise = bun.JSC.JSPromise;
const JSInternalPromise = bun.JSC.JSInternalPromise;
const JSModuleLoader = bun.JSC.JSModuleLoader;
const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation;
const Exception = bun.JSC.Exception;
const ErrorableZigString = bun.JSC.ErrorableZigString;
const ZigGlobalObject = bun.JSC.ZigGlobalObject;
const VM = bun.JSC.VM;
Expand Down
1 change: 0 additions & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const JSPromise = bun.JSC.JSPromise;
const JSInternalPromise = bun.JSC.JSInternalPromise;
const JSModuleLoader = bun.JSC.JSModuleLoader;
const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation;
const Exception = bun.JSC.Exception;
const ErrorableZigString = bun.JSC.ErrorableZigString;
const ZigGlobalObject = bun.JSC.ZigGlobalObject;
const VM = bun.JSC.VM;
Expand Down
1 change: 0 additions & 1 deletion src/bun.js/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "JavaScriptCore/PutPropertySlot.h"
#include "ScriptExecutionContext.h"
#include "headers-handwritten.h"
#include "node_api.h"
#include "ZigGlobalObject.h"
#include "headers.h"
#include "JSEnvironmentVariableMap.h"
Expand Down
88 changes: 61 additions & 27 deletions src/bun.js/bindings/CallSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#include "JavaScriptCore/CallData.h"
#include "helpers.h"
#include "wtf/text/OrdinalNumber.h"

#include <JavaScriptCore/JSCInlines.h>
#include <optional>

using namespace JSC;
using namespace WebCore;
Expand All @@ -30,8 +32,8 @@ void CallSite::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSCStac
* Thus, if we've already encountered a strict frame, we'll treat our frame as strict too. */

bool isStrictFrame = encounteredStrictFrame;
JSC::CodeBlock* codeBlock = stackFrame.codeBlock();
if (!isStrictFrame) {
JSC::CodeBlock* codeBlock = stackFrame.codeBlock();
if (codeBlock) {
isStrictFrame = codeBlock->ownerExecutable()->isInStrictContext();
}
Expand Down Expand Up @@ -65,6 +67,8 @@ void CallSite::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSCStac

if (stackFrame.isEval()) {
m_flags |= static_cast<unsigned int>(Flags::IsEval);
} else if (stackFrame.isFunctionOrEval()) {
m_flags |= static_cast<unsigned int>(Flags::IsFunction);
}
if (stackFrame.isConstructor()) {
m_flags |= static_cast<unsigned int>(Flags::IsConstructor);
Expand Down Expand Up @@ -102,49 +106,79 @@ JSValue createNativeFrameForTesting(Zig::GlobalObject* globalObject)

void CallSite::formatAsString(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WTF::StringBuilder& sb)
{
JSString* myFunctionName = functionName().toString(globalObject);
JSString* mySourceURL = sourceURL().toString(globalObject);
JSValue thisValue = jsUndefined();
if (m_thisValue) {
thisValue = m_thisValue.get();
}

JSString* myFunctionName = functionName().toStringOrNull(globalObject);
JSString* mySourceURL = sourceURL().toStringOrNull(globalObject);

String functionName;
if (myFunctionName && myFunctionName->length() > 0) {
functionName = myFunctionName->getString(globalObject);
} else if (m_flags & (static_cast<unsigned int>(Flags::IsFunction) | static_cast<unsigned int>(Flags::IsEval))) {
functionName = "<anonymous>"_s;
}

JSString* myColumnNumber = columnNumber().zeroBasedInt() >= 0 ? JSValue(columnNumber().oneBasedInt()).toString(globalObject) : jsEmptyString(vm);
JSString* myLineNumber = lineNumber().zeroBasedInt() >= 0 ? JSValue(lineNumber().oneBasedInt()).toString(globalObject) : jsEmptyString(vm);
std::optional<OrdinalNumber> column = columnNumber().zeroBasedInt() >= 0 ? std::optional(columnNumber()) : std::nullopt;
std::optional<OrdinalNumber> line = lineNumber().zeroBasedInt() >= 0 ? std::optional(lineNumber()) : std::nullopt;

bool myIsConstructor = isConstructor();
if (functionName.length() > 0) {

if (myFunctionName->length() > 0) {
if (myIsConstructor) {
if (isConstructor()) {
sb.append("new "_s);
} else {
// TODO: print type or class name if available
// sb.append(myTypeName->getString(globalObject));
// sb.append(" "_s);
}
sb.append(myFunctionName->getString(globalObject));
} else {
sb.append("<anonymous>"_s);

if (auto* object = thisValue.getObject()) {
auto catchScope = DECLARE_CATCH_SCOPE(vm);
auto className = object->calculatedClassName(object);
if (catchScope.exception()) {
catchScope.clearException();
}

if (className.length() > 0) {
sb.append(className);
sb.append("."_s);
}
}

sb.append(functionName);
}
sb.append(" ("_s);

if (isNative()) {
if (functionName.length() > 0) {
sb.append(" ("_s);
}
sb.append("native"_s);
if (functionName.length() > 0) {
sb.append(")"_s);
}
} else {
if (mySourceURL->length() == 0) {
if (functionName.length() > 0) {
sb.append(" ("_s);
}
if (!mySourceURL || mySourceURL->length() == 0) {
sb.append("unknown"_s);
} else {
sb.append(mySourceURL->getString(globalObject));
}

if (myLineNumber->length() > 0 && myColumnNumber->length() > 0) {
sb.append(":"_s);
sb.append(myLineNumber->getString(globalObject));
sb.append(":"_s);
sb.append(myColumnNumber->getString(globalObject));
} else if (myLineNumber->length() > 0) {
sb.append(":"_s);
sb.append(myLineNumber->getString(globalObject));
if (line && column) {
sb.append(':');
sb.append(line.value().oneBasedInt());
sb.append(':');
sb.append(column.value().oneBasedInt());
} else if (line) {
sb.append(':');
sb.append(line.value().oneBasedInt());
}

if (functionName.length() > 0) {
sb.append(')');
}
}
sb.append(")"_s);
}

DEFINE_VISIT_CHILDREN(CallSite);

}
2 changes: 2 additions & 0 deletions src/bun.js/bindings/CallSite.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CallSite final : public JSC::JSNonFinalObject {
IsEval = 2,
IsConstructor = 4,
IsNative = 8,
IsWasm = 16,
IsFunction = 32,
};

private:
Expand Down
Loading

0 comments on commit f42a28d

Please sign in to comment.