mirror of
https://github.com/oven-sh/bun
synced 2026-02-17 14:22:01 +00:00
Compare commits
3 Commits
deps/updat
...
claude/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d98f005c1 | ||
|
|
77ca318336 | ||
|
|
6b776ab56a |
@@ -1087,10 +1087,33 @@ pub const WindowsSpawnOptions = struct {
|
||||
dup2: struct { out: bun.jsc.Subprocess.StdioKind, to: bun.jsc.Subprocess.StdioKind },
|
||||
|
||||
pub fn deinit(this: *const Stdio) void {
|
||||
if (this.* == .buffer) {
|
||||
bun.default_allocator.destroy(this.buffer);
|
||||
switch (this.*) {
|
||||
.buffer => |pipe| closePipeAndDestroy(pipe),
|
||||
.ipc => |pipe| closePipeAndDestroy(pipe),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
/// Close a pipe that may have been initialized with uv_pipe_init.
|
||||
/// If the pipe was initialized, we must call uv_close before freeing
|
||||
/// to properly remove it from the loop's handle queue; otherwise
|
||||
/// the handle queue linked list becomes corrupted.
|
||||
fn closePipeAndDestroy(pipe: *bun.windows.libuv.Pipe) void {
|
||||
if (pipe.loop == null or pipe.isClosed()) {
|
||||
// Never initialized or already fully closed — safe to free directly.
|
||||
bun.default_allocator.destroy(pipe);
|
||||
} else if (!pipe.isClosing()) {
|
||||
// Initialized and not yet closing — must uv_close to remove from handle queue.
|
||||
pipe.close(&onPipeCloseForDeinit);
|
||||
}
|
||||
// else: isClosing — uv_close was already called, the pending close
|
||||
// callback owns the lifetime. This shouldn't happen in practice since
|
||||
// deinit is only called on the error path before any close is initiated.
|
||||
}
|
||||
|
||||
fn onPipeCloseForDeinit(pipe: *bun.windows.libuv.Pipe) callconv(.c) void {
|
||||
bun.default_allocator.destroy(pipe);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn deinit(this: *const WindowsSpawnOptions) void {
|
||||
@@ -1629,9 +1652,10 @@ pub fn spawnProcessWindows(
|
||||
stdio.flags = uv.UV_INHERIT_FD;
|
||||
stdio.data.fd = fd_i;
|
||||
},
|
||||
.ipc => |my_pipe| {
|
||||
// ipc option inside stdin, stderr or stdout are not supported
|
||||
bun.default_allocator.destroy(my_pipe);
|
||||
.ipc => {
|
||||
// ipc option inside stdin, stderr or stdout are not supported.
|
||||
// Don't destroy the pipe here — the caller's deinit() will handle it
|
||||
// (the pipe was never uv_pipe_init'd so it can be freed directly).
|
||||
stdio.flags = uv.UV_IGNORE;
|
||||
},
|
||||
.ignore => {
|
||||
|
||||
@@ -235,10 +235,10 @@ pub const Stdio = union(enum) {
|
||||
return .{ .err = .blob_used_as_out };
|
||||
}
|
||||
|
||||
break :brk .{ .buffer = bun.handleOom(bun.default_allocator.create(uv.Pipe)) };
|
||||
break :brk .{ .buffer = createZeroedPipe() };
|
||||
},
|
||||
.ipc => .{ .ipc = bun.handleOom(bun.default_allocator.create(uv.Pipe)) },
|
||||
.capture, .pipe, .array_buffer, .readable_stream => .{ .buffer = bun.handleOom(bun.default_allocator.create(uv.Pipe)) },
|
||||
.ipc => .{ .ipc = createZeroedPipe() },
|
||||
.capture, .pipe, .array_buffer, .readable_stream => .{ .buffer = createZeroedPipe() },
|
||||
.fd => |fd| .{ .pipe = fd },
|
||||
.dup2 => .{ .dup2 = .{ .out = stdio.dup2.out, .to = stdio.dup2.to } },
|
||||
.path => |pathlike| .{ .path = pathlike.slice() },
|
||||
@@ -487,6 +487,15 @@ pub const Stdio = union(enum) {
|
||||
}
|
||||
};
|
||||
|
||||
/// Allocate a zero-initialized uv.Pipe. Zero-init is required so that
|
||||
/// `pipe.loop` is null for pipes that were never passed to `uv_pipe_init`,
|
||||
/// which `closePipeAndDestroy` relies on to decide whether `uv_close` is needed.
|
||||
fn createZeroedPipe() *bun.windows.libuv.Pipe {
|
||||
const pipe = bun.handleOom(bun.default_allocator.create(bun.windows.libuv.Pipe));
|
||||
pipe.* = std.mem.zeroes(bun.windows.libuv.Pipe);
|
||||
return pipe;
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const bun = @import("bun");
|
||||
|
||||
@@ -12,24 +12,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
|
||||
// Shared getter/setter functions: .bind(obj, key) avoids creating a closure
|
||||
// and JSLexicalEnvironment per property. BoundFunction is much cheaper.
|
||||
// Must be regular functions (not arrows) so .bind() can set `this`.
|
||||
function __accessProp(key) {
|
||||
return this[key];
|
||||
}
|
||||
|
||||
// This is used to implement "export * from" statements. It copies properties
|
||||
// from the imported module to the current module's ESM export object. If the
|
||||
// current module is an entry point and the target format is CommonJS, we
|
||||
// also copy the properties to "module.exports" in addition to our module's
|
||||
// internal ESM export object.
|
||||
export var __reExport = (target, mod, secondTarget) => {
|
||||
for (let key of __getOwnPropNames(mod))
|
||||
var keys = __getOwnPropNames(mod);
|
||||
for (let key of keys)
|
||||
if (!__hasOwnProp.call(target, key) && key !== "default")
|
||||
__defProp(target, key, {
|
||||
get: () => mod[key],
|
||||
get: __accessProp.bind(mod, key),
|
||||
enumerable: true,
|
||||
});
|
||||
|
||||
if (secondTarget) {
|
||||
for (let key of __getOwnPropNames(mod))
|
||||
for (let key of keys)
|
||||
if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
|
||||
__defProp(secondTarget, key, {
|
||||
get: () => mod[key],
|
||||
get: __accessProp.bind(mod, key),
|
||||
enumerable: true,
|
||||
});
|
||||
|
||||
@@ -37,11 +45,22 @@ export var __reExport = (target, mod, secondTarget) => {
|
||||
}
|
||||
};
|
||||
|
||||
/*__PURE__*/
|
||||
var __toESMCache_node;
|
||||
/*__PURE__*/
|
||||
var __toESMCache_esm;
|
||||
|
||||
// Converts the module from CommonJS to ESM. When in node mode (i.e. in an
|
||||
// ".mjs" file, package.json has "type: module", or the "__esModule" export
|
||||
// in the CommonJS file is falsy or missing), the "default" property is
|
||||
// overridden to point to the original CommonJS exports object instead.
|
||||
export var __toESM = (mod, isNodeMode, target) => {
|
||||
var canCache = mod != null && typeof mod === "object";
|
||||
if (canCache) {
|
||||
var cache = isNodeMode ? (__toESMCache_node ??= new WeakMap()) : (__toESMCache_esm ??= new WeakMap());
|
||||
var cached = cache.get(mod);
|
||||
if (cached) return cached;
|
||||
}
|
||||
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
||||
const to =
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
||||
@@ -53,34 +72,34 @@ export var __toESM = (mod, isNodeMode, target) => {
|
||||
for (let key of __getOwnPropNames(mod))
|
||||
if (!__hasOwnProp.call(to, key))
|
||||
__defProp(to, key, {
|
||||
get: () => mod[key],
|
||||
get: __accessProp.bind(mod, key),
|
||||
enumerable: true,
|
||||
});
|
||||
|
||||
if (canCache) cache.set(mod, to);
|
||||
return to;
|
||||
};
|
||||
|
||||
// Converts the module from ESM to CommonJS. This clones the input module
|
||||
// object with the addition of a non-enumerable "__esModule" property set
|
||||
// to "true", which overwrites any existing export named "__esModule".
|
||||
var __moduleCache = /* @__PURE__ */ new WeakMap();
|
||||
export var __toCommonJS = /* @__PURE__ */ from => {
|
||||
var entry = __moduleCache.get(from),
|
||||
export var __toCommonJS = from => {
|
||||
var entry = (__moduleCache ??= new WeakMap()).get(from),
|
||||
desc;
|
||||
if (entry) return entry;
|
||||
entry = __defProp({}, "__esModule", { value: true });
|
||||
if ((from && typeof from === "object") || typeof from === "function")
|
||||
__getOwnPropNames(from).map(
|
||||
key =>
|
||||
!__hasOwnProp.call(entry, key) &&
|
||||
for (var key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(entry, key))
|
||||
__defProp(entry, key, {
|
||||
get: () => from[key],
|
||||
get: __accessProp.bind(from, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
||||
}),
|
||||
);
|
||||
});
|
||||
__moduleCache.set(from, entry);
|
||||
return entry;
|
||||
};
|
||||
/*__PURE__*/
|
||||
var __moduleCache;
|
||||
|
||||
// When you do know the module is CJS
|
||||
export var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
||||
@@ -97,6 +116,10 @@ export var __name = (target, name) => {
|
||||
|
||||
// ESM export -> CJS export
|
||||
// except, writable incase something re-exports
|
||||
var __returnValue = v => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
|
||||
export var __export = /* @__PURE__ */ (target, all) => {
|
||||
for (var name in all)
|
||||
@@ -104,15 +127,19 @@ export var __export = /* @__PURE__ */ (target, all) => {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: newValue => (all[name] = () => newValue),
|
||||
set: __exportSetter.bind(all, name),
|
||||
});
|
||||
};
|
||||
|
||||
function __exportValueSetter(name, newValue) {
|
||||
this[name] = newValue;
|
||||
}
|
||||
|
||||
export var __exportValue = (target, all) => {
|
||||
for (var name in all) {
|
||||
__defProp(target, name, {
|
||||
get: () => all[name],
|
||||
set: newValue => (all[name] = newValue),
|
||||
get: __accessProp.bind(all, name),
|
||||
set: __exportValueSetter.bind(all, name),
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
|
||||
exports[`Bun.build Bun.write(BuildArtifact) 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __returnValue = (v) => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: (newValue) => all[name] = () => newValue
|
||||
set: __exportSetter.bind(all, name)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -31,13 +35,17 @@ NS.then(({ fn: fn2 }) => {
|
||||
|
||||
exports[`Bun.build outdir + reading out blobs works 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __returnValue = (v) => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: (newValue) => all[name] = () => newValue
|
||||
set: __exportSetter.bind(all, name)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -58,23 +66,27 @@ NS.then(({ fn: fn2 }) => {
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Bun.build BuildArtifact properties: hash 1`] = `"d1c7nm6t"`;
|
||||
exports[`Bun.build BuildArtifact properties: hash 1`] = `"est79qzq"`;
|
||||
|
||||
exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"rm7e36cf"`;
|
||||
exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"7gfnt0h6"`;
|
||||
|
||||
exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"d1c7nm6t"`;
|
||||
exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"est79qzq"`;
|
||||
|
||||
exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"00000000"`;
|
||||
|
||||
exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __returnValue = (v) => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: (newValue) => all[name] = () => newValue
|
||||
set: __exportSetter.bind(all, name)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1113,7 +1113,7 @@ describe("bundler", () => {
|
||||
snapshotSourceMap: {
|
||||
"entry.js.map": {
|
||||
files: ["../node_modules/react/index.js", "../entry.js"],
|
||||
mappingsExactMatch: "qYACA,WAAW,IAAQ,EAAE,ICDrB,eACA,QAAQ,IAAI,CAAK",
|
||||
mappingsExactMatch: "miBACA,WAAW,IAAQ,EAAE,ICDrB,eACA,QAAQ,IAAI,CAAK",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -57,17 +57,17 @@ describe("bundler", () => {
|
||||
"../entry.tsx",
|
||||
],
|
||||
mappings: [
|
||||
["react.development.js:524:'getContextName'", "1:5412:Y1"],
|
||||
["react.development.js:524:'getContextName'", "1:5567:Y1"],
|
||||
["react.development.js:2495:'actScopeDepth'", "23:4082:GJ++"],
|
||||
["react.development.js:696:''Component'", '1:7474:\'Component "%s"'],
|
||||
["entry.tsx:6:'\"Content-Type\"'", '100:18809:"Content-Type"'],
|
||||
["entry.tsx:11:'<html>'", "100:19063:void"],
|
||||
["entry.tsx:23:'await'", "100:19163:await"],
|
||||
["react.development.js:696:''Component'", '1:7629:\'Component "%s"'],
|
||||
["entry.tsx:6:'\"Content-Type\"'", '100:18808:"Content-Type"'],
|
||||
["entry.tsx:11:'<html>'", "100:19062:void"],
|
||||
["entry.tsx:23:'await'", "100:19161:await"],
|
||||
],
|
||||
},
|
||||
},
|
||||
expectExactFilesize: {
|
||||
"out/entry.js": 221720,
|
||||
"out/entry.js": 221895,
|
||||
},
|
||||
run: {
|
||||
stdout: "<!DOCTYPE html><html><body><h1>Hello World</h1><p>This is an example.</p></body></html>",
|
||||
|
||||
@@ -76,13 +76,17 @@ describe("bundler", () => {
|
||||
|
||||
expect(bundled).toMatchInlineSnapshot(`
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __returnValue = (v) => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: (newValue) => all[name] = () => newValue
|
||||
set: __exportSetter.bind(all, name)
|
||||
});
|
||||
};
|
||||
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
||||
@@ -160,7 +164,7 @@ describe("bundler", () => {
|
||||
var { AsyncEntryPoint: AsyncEntryPoint2 } = await Promise.resolve().then(() => exports_AsyncEntryPoint);
|
||||
AsyncEntryPoint2();
|
||||
|
||||
//# debugId=5E85CC0956C6307964756E2164756E21
|
||||
//# debugId=42062903F19477CF64756E2164756E21
|
||||
//# sourceMappingURL=out.js.map
|
||||
"
|
||||
`);
|
||||
@@ -337,13 +341,17 @@ describe("bundler", () => {
|
||||
|
||||
expect(bundled).toMatchInlineSnapshot(`
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __returnValue = (v) => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: (newValue) => all[name] = () => newValue
|
||||
set: __exportSetter.bind(all, name)
|
||||
});
|
||||
};
|
||||
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
||||
@@ -402,7 +410,7 @@ describe("bundler", () => {
|
||||
var { AsyncEntryPoint: AsyncEntryPoint2 } = await Promise.resolve().then(() => exports_AsyncEntryPoint);
|
||||
AsyncEntryPoint2();
|
||||
|
||||
//# debugId=C92CBF0103732ECC64756E2164756E21
|
||||
//# debugId=BF876FBF618133C264756E2164756E21
|
||||
//# sourceMappingURL=out.js.map
|
||||
"
|
||||
`);
|
||||
|
||||
@@ -103,11 +103,11 @@ console.log(favicon);
|
||||
"files": [
|
||||
{
|
||||
"input": "client.html",
|
||||
"path": "./client-s249t5qg.js",
|
||||
"path": "./client-b5m4ng86.js",
|
||||
"loader": "js",
|
||||
"isEntry": true,
|
||||
"headers": {
|
||||
"etag": "fxoJ6L-0X3o",
|
||||
"etag": "Ax71YVYyZQc",
|
||||
"content-type": "text/javascript;charset=utf-8"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -92,13 +92,17 @@ test("cyclic imports with async dependencies should generate async wrappers", as
|
||||
|
||||
expect(bundled).toMatchInlineSnapshot(`
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __returnValue = (v) => v;
|
||||
function __exportSetter(name, newValue) {
|
||||
this[name] = __returnValue.bind(null, newValue);
|
||||
}
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, {
|
||||
get: all[name],
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
set: (newValue) => all[name] = () => newValue
|
||||
set: __exportSetter.bind(all, name)
|
||||
});
|
||||
};
|
||||
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
||||
@@ -176,7 +180,7 @@ test("cyclic imports with async dependencies should generate async wrappers", as
|
||||
var { AsyncEntryPoint: AsyncEntryPoint2 } = await Promise.resolve().then(() => exports_AsyncEntryPoint);
|
||||
AsyncEntryPoint2();
|
||||
|
||||
//# debugId=986E7BD819E590FD64756E2164756E21
|
||||
//# debugId=2020261114B67BB564756E2164756E21
|
||||
//# sourceMappingURL=entryBuild.js.map
|
||||
"
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user