Complete Pack Publishing Guide

A comprehensive walkthrough of the entire package publishing process, from validation to WebAssembly compilation and CDN distribution.

🚀 Publishing Overview

PackCDN provides a complete end-to-end solution for publishing and distributing code packages. The process involves multiple stages of validation, processing, and optimization before your code becomes globally available via our CDN network.

7
Processing Stages
50+
Validation Rules
4
Package Types
Global Distribution

🔄 The Publishing Process

1
📦

Package Creation

Define package metadata and structure with pack.json

2
🔍

Validation

Comprehensive validation of name, files, and content

3
⚙️

WASM Compilation

Optional JavaScript to WebAssembly compilation

4
🔒

Security Scan

Security analysis and sandbox configuration

5
💾

Database Storage

Store in Supabase with versioning and metadata

6
🌍

CDN Distribution

Deploy to Cloudflare Workers edge network

7
🎉

Delivery

Generate URLs and installation commands

Step 1: Package Structure

📁 example-package/
  • 📄 pack.json 1.2 KB
  • 📄 index.js 2.4 KB
  • 📄 package.json 0.8 KB
  • 📁 src/
  • 📁 dist/
// pack.json - Required package metadata { "name": "example-package", "version": "1.0.0", "description": "An example package for PackCDN", "type": "standard", "sandbox": { "level": "moderate", "memoryLimit": 67108864, "timeout": 5000 } }

🔌 API Request & Response

# Publishing a package via API curl -X POST https://pack-cdn.vercel.app/api/publish \ -H "Content-Type: application/json" \ -d '{ "name": "my-awesome-package", "packJson": "{\"name\":\"my-awesome-package\",\"version\":\"1.0.0\",\"description\":\"...\"}", "files": { "index.js": "export default function greet() { return \"Hello, World!\"; }", "utils.js": "export function add(a, b) { return a + b; }" }, "packageType": "standard", "compileToWasm": true, "isPublic": true, "version": "1.0.0" }'

Complete API Request Structure

{ // Required fields "name": "package-name", // Package name (2-50 chars) "packJson": "...", // JSON string of pack.json "files": { // Files object "filename.js": "content" }, // Optional fields with defaults "packageType": "basic", // basic|standard|advanced|wasm "version": "1.0.0", // Semantic version "isPublic": true, // Package visibility "isNewVersion": false, // Create new version "basePackId": null, // Base package ID for new versions "userId": null, // User ID for ownership "editToken": null, // Edit token for permissions "collaborators": [], // Array of user IDs "compileToWasm": false, // Enable WASM compilation "wasmConfig": {} // WASM compilation configuration }

Success Response

{ "success": true, "packId": "pack_abc123xyz789", "urlId": "abc123xyz789", "cdnUrl": "https://packcdn.firefly-worker.workers.dev/cdn/abc123xyz789", "workerUrl": "https://packcdn.firefly-worker.workers.dev/pack/abc123xyz789", "wasmUrl": "https://packcdn.firefly-worker.workers.dev/cdn/abc123xyz789/compiled.wasm", "installCommand": "pack install my-awesome-package@1.0.0 https://...", "version": "1.0.0", "metadata": { "name": "my-awesome-package", "packageType": "standard", "fileCount": 2, "totalSize": 1024, "wasmGenerated": true, "wasmFunctions": ["greet", "add"] }, "processingTime": "245ms" }

🔍 Comprehensive Validation

Package Type Max Files Max Size Node Modules WASM Support Features
Basic 20 5MB Simple packages, sandboxed
Standard 50 10MB ✅ (25) ✅ (5MB) NPM modules, basic WASM
Advanced 100 50MB ✅ (50+) ✅ (25MB) Full ecosystem, compile to WASM
WASM 30 100MB ✅ (100MB) Pure WebAssembly, complex modules

Package Name Validation

Must start with lowercase letter
2-50 characters in length
Only lowercase letters, numbers, hyphens, underscores
⚠️ Cannot end with hyphen or underscore
Cannot contain consecutive hyphens/underscores

File & Content Validation Rules

// JavaScript Security Validation function validateJavaScript(content, packageType) { const dangerousPatterns = [ /\beval\s*\(/i, // eval() calls /\bFunction\s*\(/i, // Function constructor /new\s+Function\s*\(/i, // New Function() /\brequire\s*\([^)]*\)/i, // Dynamic require (basic) /\bprocess\s*\./i, // Process access (basic) /\bfs\s*\./i // Filesystem access ]; for (const pattern of dangerousPatterns) { if (pattern.test(content)) { return { valid: false, reason: 'JavaScript contains potentially dangerous patterns' }; } } return { valid: true }; }

WebAssembly Compilation

Real JavaScript to WASM Compilation

// PackWASMCompiler - Real compilation engine class PackWASMCompiler { async compileJavaScriptToWasm(jsCode, config = {}) { try { // Step 1: Parse JavaScript and extract functions const functions = this.extractJSFunctions(jsCode); // Step 2: Generate WebAssembly Text (WAT) format const wat = this.generateWatModule(functions, config); // Step 3: Convert WAT to WASM binary const wasmBinary = await this.compileWatToWasm(wat); // Step 4: Optimize WASM binary const optimizedWasm = await this.optimizeWasmBinary(wasmBinary); // Step 5: Validate and return const isValid = await this.validateWasm(optimizedWasm); return { success: isValid, wasm: optimizedWasm, metadata: { functions: functions.map(f => f.name), wasmSize: optimizedWasm.length } }; } catch (error) { throw new Error('WASM compilation failed: ' + error.message); } } generateWatModule(functions, config) { // Generate complete WAT module from functions return `(module (memory (export "memory") ${config.initialMemory || 1} ${config.maxMemory || 65536}) ${functions.map((func, i) => ` (func $${func.name} (export "${func.name}") (result i32) i32.const ${func.returnValue || 42} )).join('')} )`; } }

📦 Generated WASM Wrapper

// Auto-generated wrapper for compiled WebAssembly export class ExamplePackageWASM { constructor() { this.instance = null; this.exports = null; this.memory = null; } async init() { const wasmBase64 = "AGFzbQEAAAAGgweBAYMAgweCAY..."; const wasmBuffer = Uint8Array.from(atob(wasmBase64), c => c.charCodeAt(0)); const importObject = { env: { memory: new WebAssembly.Memory({ initial: 256 }), abort: (msg) => console.error('WASM abort:', msg) } }; const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject); this.instance = instance; this.exports = instance.exports; this.memory = this.exports.memory; return this; } greet() { return this.exports.greet(); } add(a, b) { return this.exports.add(a, b); } }

🎮 Interactive Publishing Demo

🚀 Starting PackCDN Publishing Demo...
📦 Package: example-package
🔍 Validation: Pending
⚙️ WASM Compilation: Pending
💾 Database: Pending
🌍 CDN Distribution: Pending
✅ Complete: Pending

🏗️ Advanced Features

🔐

Advanced Security

Comprehensive validation with banned module detection

📊

Real-time Analytics

Track views, downloads, and package performance

🤝

Collaboration

Multi-user editing with permission levels

🔄

Version Control

Full version history and rollback capability

Edge Caching

Global CDN with instant cache invalidation

🔧

Custom Builds

Compile Rust, Go, Zig to WebAssembly