Skip to content
Draft
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ target
/target
/tmp
/node_modules
/dist
/dist
/pkg
*.tgz
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
],
Expand Down
38 changes: 38 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -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);
}