Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pun"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
authors = ["Pun Contributors"]
description = "A fast all-in-one JavaScript runtime, package manager, bundler, and test runner"
Expand Down Expand Up @@ -51,6 +51,7 @@ rusqlite = { version = "0.30", features = ["bundled"] }
# Utilities
anyhow = "1.0"
thiserror = "1.0"
atty = "0.2"
lazy_static = "1.4"
once_cell = "1.19"
regex = "1.10"
Expand Down
24 changes: 24 additions & 0 deletions bin/pun
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');

// This is a shim for the pun binary
// In a real npm package, this would point to the platform-specific binary
const binaryPath = path.join(__dirname, 'pun-bin');

const child = spawn(binaryPath, process.argv.slice(2), {
stdio: 'inherit'
});

child.on('exit', (code) => {
process.exit(code);
});

child.on('error', (err) => {
if (err.code === 'ENOENT') {
console.error('Pun binary not found. Please make sure Pun is correctly installed.');
} else {
console.error('Error running Pun:', err.message);
}
process.exit(1);
});
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PUN_VERSION="latest"

echo -e "${CYAN}"
echo "╔═══════════════════════════════════════╗"
echo "║ Pun Installer v1.1.0 ║"
echo "║ Pun Installer v1.1.1 ║"
echo "║ JavaScript Runtime for the Modern ║"
echo "╚═══════════════════════════════════════╝"
echo -e "${NC}"
Expand Down
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "pun.js",
"version": "1.1.1",
"description": "A fast all-in-one JavaScript runtime, package manager, bundler, and test runner",
"main": "index.js",
"bin": {
"pun": "bin/pun"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/red-creators/pun.git"
},
"keywords": [
"javascript",
"runtime",
"typescript",
"bundler",
"package manager",
"rust"
],
"author": "Pun Contributors",
"license": "MIT",
"bugs": {
"url": "https://github.com/red-creators/pun/issues"
},
"homepage": "https://github.com/red-creators/pun#readme"
}
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ pub enum Commands {
/// Packages to remove
packages: Vec<String>,
},

/// Upgrade Pun to the latest version
Upgrade,
}
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod runtime;
mod server;
mod test_runner;
mod utils;
mod version_check;

use clap::Parser;
use cli::{Cli, Commands};
Expand All @@ -18,6 +19,9 @@ async fn main() {

let cli = Cli::parse();

// Check for updates
version_check::check_for_updates().await;

let result = match cli.command {
Commands::Run { file, watch, hot } => runtime::run_file(&file, watch, hot).await,
Commands::Install { packages } => package_manager::install(packages).await,
Expand All @@ -35,6 +39,7 @@ async fn main() {
Commands::Init => package_manager::init().await,
Commands::Add { packages } => package_manager::add(packages).await,
Commands::Remove { packages } => package_manager::remove(packages).await,
Commands::Upgrade => version_check::upgrade().await,
};

if let Err(e) = result {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ globalThis.process = {
versions: {
node: '20.0.0',
v8: '11.0.0',
pun: '1.1.0'
pun: '1.1.1'
},
platform: 'linux',
arch: 'x64',
Expand Down
60 changes: 60 additions & 0 deletions src/version_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use anyhow::Result;
use colored::Colorize;
use reqwest::Client;
use std::time::Duration;

pub async fn check_for_updates() {
let current_version = env!("CARGO_PKG_VERSION");
let client = Client::builder()
.timeout(Duration::from_millis(500))
.build();

if let Ok(client) = client {
let response = client
.get("https://raw.githubusercontent.com/red-creators/pun-release-version/main/bumper")
.send()
.await;

if let Ok(resp) = response {
if let Ok(latest_version) = resp.text().await {
let latest_version = latest_version.trim();
let current_version_with_v = format!("v{}", current_version);

if latest_version != current_version && latest_version != current_version_with_v {
// Only warn if it's a TTY to avoid breaking scripts
if atty::is(atty::Stream::Stdout) {
eprintln!(
"\n{} A new version of Pun is available: {} (current: v{})",
"warning:".yellow().bold(),
latest_version,
current_version
);
eprintln!("Run {} to update.\n", "pun upgrade".cyan());
}
}
}
}
}
}

pub async fn upgrade() -> Result<()> {
println!("Upgrading Pun to the latest version...");

// Check if we are on a platform that supports the install script
if cfg!(windows) {
anyhow::bail!("Automatic upgrade is not yet supported on Windows. Please download the latest version manually.");
}

let status = std::process::Command::new("sh")
.arg("-c")
.arg("curl -fsSL https://raw.githubusercontent.com/red-creators/pun/main/install.sh | bash")
.status()?;

if status.success() {
println!("Pun upgraded successfully!");
} else {
anyhow::bail!("Failed to upgrade Pun.");
}

Ok(())
}
Loading