mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
implement cmd wrapper for node gyp
This commit is contained in:
@@ -2540,10 +2540,9 @@ pub const PackageManager = struct {
|
||||
}
|
||||
|
||||
pub fn ensureTempNodeGypScript(this: *PackageManager) !void {
|
||||
if (comptime Environment.isWindows) {
|
||||
return;
|
||||
if (Environment.isWindows) {
|
||||
Output.debug("TODO: VERIFY ensureTempNodeGypScript WORKS!!", .{});
|
||||
}
|
||||
|
||||
if (this.node_gyp_tempdir_name.len > 0) return;
|
||||
|
||||
const tempdir = this.getTemporaryDirectory();
|
||||
@@ -2564,13 +2563,25 @@ pub const PackageManager = struct {
|
||||
};
|
||||
defer node_gyp_tempdir.close();
|
||||
|
||||
var node_gyp_file = node_gyp_tempdir.createFile("node-gyp", .{ .mode = 0o777 }) catch |err| {
|
||||
const file_name = switch (Environment.os) {
|
||||
else => "node-gyp",
|
||||
.windows => "node-gyp.cmd",
|
||||
};
|
||||
const mode = switch (Environment.os) {
|
||||
else => 0o755,
|
||||
.windows => 0, // windows does not have an executable bit
|
||||
};
|
||||
|
||||
var node_gyp_file = node_gyp_tempdir.createFile(file_name, .{ .mode = mode }) catch |err| {
|
||||
Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> creating node-gyp tempdir", .{@errorName(err)});
|
||||
Global.crash();
|
||||
};
|
||||
defer node_gyp_file.close();
|
||||
|
||||
var bytes: string = "#!/usr/bin/env node\nrequire(\"child_process\").spawnSync(\"bun\",[\"x\",\"node-gyp\",...process.argv.slice(2)],{stdio:\"inherit\"})";
|
||||
var bytes: string = switch (Environment.os) {
|
||||
else => "#!/usr/bin/env node\nrequire(\"child_process\").spawnSync(\"bun\",[\"x\",\"node-gyp\",...process.argv.slice(2)],{stdio:\"inherit\"})",
|
||||
.windows => "@node -e \"require('child_process').spawnSync('bun',['x','node-gyp',...process.argv.slice(2)],{stdio:'inherit'})\"",
|
||||
};
|
||||
var index: usize = 0;
|
||||
while (index < bytes.len) {
|
||||
switch (bun.sys.write(bun.toFD(node_gyp_file.handle), bytes[index..])) {
|
||||
@@ -2578,7 +2589,7 @@ pub const PackageManager = struct {
|
||||
index += written;
|
||||
},
|
||||
.err => |err| {
|
||||
Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> writing to node-gyp file", .{@tagName(err.getErrno())});
|
||||
Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> writing to " ++ file_name ++ " file", .{@tagName(err.getErrno())});
|
||||
Global.crash();
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user