diff --git a/.gitignore b/.gitignore index 2e25c5c..360988f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ target /target /tmp /node_modules -/dist \ No newline at end of file +/dist +/pkg +*.tgz diff --git a/Cargo.toml b/Cargo.toml index e0d192c..2ee2582 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ name = "postcss-plugin-random" version = "0.1.2" edition = "2024" +[package.metadata.wasm-pack.profile.release] +wasm-opt = ["-O3"] + [lib] crate-type = ["cdylib"] diff --git a/README.md b/README.md index 0f63d88..7a078dc 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,23 @@ - Scanning is naive: we don't skip comments/strings yet; nested functions are handled via basic parentheses counting only. - Type consistency is verified via unit strings; more advanced CSS type resolution (percentages, font-relative units) would require layout context. +## Installation + +Install via npm: +```shell +npm install @kingoftac/postcss-plugin-random +``` + +The package includes pre-built WASM binaries that work across all platforms (Linux, macOS, Windows, etc.). If you're installing from source or the git repository, the package will automatically build the WASM binary during installation if it's not present. + +### Requirements for Building from Source + +If installing from the git repository or if the pre-built binary is missing, you'll need: +- [Rust](https://rustup.rs/) toolchain +- [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/): `cargo install wasm-pack` + +The build happens automatically via postinstall script, but you can also build manually with `npm run build`. + ## Dev install `wasm-pack` if you haven't already: ```shell diff --git a/package-lock.json b/package-lock.json index 653e1c6..7f9af75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kingoftac/postcss-plugin-random", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kingoftac/postcss-plugin-random", - "version": "0.1.2", + "version": "0.1.3", "license": "MIT", "devDependencies": { "esbuild": "^0.27.0", diff --git a/package.json b/package.json index 54e1ea6..a00ece3 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ }, "scripts": { "build": "wasm-pack build --target nodejs && node esbuild.mjs", - "dev": "node esbuild.dev.mjs && http-server -o" + "dev": "node esbuild.dev.mjs && http-server -o", + "postinstall": "node scripts/postinstall.js", + "prepare": "node scripts/postinstall.js" }, "repository": { "type": "git", @@ -44,6 +46,12 @@ "homepage": "https://github.com/KingOfTac/postcss-plugin-random#readme", "files": [ "dist", + "scripts", + "Cargo.toml", + "Cargo.lock", + "src", + "esbuild.mjs", + "index.js", "README.md", "package.json" ], diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100755 index 0000000..d168537 --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,38 @@ +#!/usr/bin/env node +import { existsSync } from 'node:fs'; +import { resolve, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { execSync } from 'node:child_process'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// Check if WASM binary exists +const wasmPath = resolve(__dirname, '..', 'dist', 'postcss_plugin_random_bg.wasm'); + +if (existsSync(wasmPath)) { + // WASM binary already exists (from published package) + process.exit(0); +} + +console.log('WASM binary not found. Building from source...'); +console.log('This requires wasm-pack to be installed.'); +console.log('To install wasm-pack: cargo install wasm-pack'); + +try { + // Try to build the WASM binary + execSync('npm run build', { + stdio: 'inherit', + cwd: resolve(__dirname, '..') + }); + console.log('Build successful!'); +} catch (error) { + console.error('Build failed. The package may not work correctly.'); + console.error('Please ensure you have Rust and wasm-pack installed.'); + console.error('For installation instructions, visit:'); + console.error(' Rust: https://rustup.rs/'); + console.error(' wasm-pack: https://rustwasm.github.io/wasm-pack/installer/'); + // Don't fail the install - the user might be installing the published package + // and the WASM binary should already be present + process.exit(0); +}