Skip to content

Commit

Permalink
Automatically install pnpm in the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Oct 20, 2023
1 parent 28f2ebc commit bee07a0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- name: Install npm
run: sudo apt-get install -y curl unzip && curl -fsSL https://fnm.vercel.app/install | bash && export PATH="/$HOME/.local/share/fnm:$PATH" && eval "`fnm env`" && fnm install v20.6.1 && fnm use v20.6.1 && npm -g i npm@latest
- name: Install Deno and Bun
run: npm install -g npm@latest; npm install -g bun deno-bin pnpm
run: npm install -g npm@latest; npm install -g bun deno-bin
- name: Run tests
run: zig build test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
**/pnpm-lock.yaml
**/package-lock.json
bench/faker/data/*
!bench/faker/data/README.md
!bench/faker/data/README.md
perf.data
2 changes: 1 addition & 1 deletion bench/bench-with-builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
import { Kivi } from "../src/drivers/js/index.js";
import { isNotNodeJS, isBun } from "../src/drivers/js/runtime.js";

const benchmarkRepeat = 100;
const benchmarkRepeat = 5;

const average = (arr) => arr.reduce((a, b) => a + b, 0) / arr.length;
const resolveOnEmit = (event) => {
Expand Down
25 changes: 23 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const cwd = std.fs.cwd();
var optimize: std.builtin.OptimizeMode = undefined;

/// Build static and shared libraries given name and path
const Libs = struct {
Expand Down Expand Up @@ -71,9 +70,27 @@ const FFI = struct {
}
};

fn install_pnpm() !void {
const command_res = try std.ChildProcess.exec(.{ .allocator = std.heap.page_allocator, .argv = &[_][]const u8{ "npm", "install", "-g", "pnpm@latest" } });
if (command_res.stderr.len > 0) {
std.debug.print("{s}\n", .{command_res.stderr});
return error.PnpmNotFoundAndFailedToInstall;
}
}
fn install_pnpm_if_needed() !void {
const pnpm_version_command = std.ChildProcess.exec(.{ .allocator = std.heap.page_allocator, .argv = &[_][]const u8{ "pnpm", "--version" } });
if (pnpm_version_command) |command_res| {
if (command_res.stderr.len > 0) {
try install_pnpm();
}
} else |_| {
try install_pnpm();
}
}

pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
optimize = b.standardOptimizeOption(.{});
const optimize = b.standardOptimizeOption(.{});
const target_info = try std.zig.system.NativeTargetInfo.detect(target);
const arch = @tagName(target_info.target.cpu.arch);
const os = @tagName(target_info.target.os.tag);
Expand Down Expand Up @@ -122,6 +139,9 @@ pub fn build(b: *std.Build) !void {
const codegen_run = b.addRunArtifact(codegen);
codegen_step.dependOn(&b.addRunArtifact(codegen).step);

// Install pnpm if needed
try install_pnpm_if_needed();

// Runs all tests
const test_step = b.step("test", "Runs all tests");
test_step.dependOn(&b.addRunArtifact(core_targets.tests).step);
Expand All @@ -143,6 +163,7 @@ pub fn build(b: *std.Build) !void {
inline for (@typeInfo(FFI).Struct.fields) |field| {
test_step.dependOn(&b.addRunArtifact(@field(ffi, field.name)).step);
}

const js_driver_test_commad1 = b.addSystemCommand(&[_][]const u8{ "pnpm", "-C", "src/drivers/js", "run", "nodejs-test" });
js_driver_test_commad1.step.dependOn(drivers_build_step);
test_step.dependOn(&js_driver_test_commad1.step);
Expand Down

0 comments on commit bee07a0

Please sign in to comment.