How imvu/imvujs works
Project Type and Purpose
• imvujs is an open-source JavaScript “standard library and toolchain” for writing modular JS, combining/minifying modules, and running unit tests both in Node.js and browsers.
• Key features: optional module loader, module combiner, build/minify pipeline, unit-testing framework, bundled common libs (jQuery, Backbone, Underscore), support for headless browsers (PhantomJS, Leprechaun).
High-Level Component Analysis
A. Core Library (src/)
• src/*.js and .d.ts: JavaScript core (Promise, EventLoop, Module system, ServiceProvider, Timer, etc.)
• imvujstest sub-directory: the in-house unit testing framework modules (Runner, Reporter, Fixture, AssertionError, etc.)
B. Build & CLI Tools
• SConstruct and bin/: entry points for SCons and small command-line utilities (combine, fix-imports, scan-dependencies, test runners).
• s/ directory: convenience shell scripts that wrap common tasks (build, runtests, browsertest, install hooks).
• scons-tools/: custom SCons extension modules (closure.py, uglify.py, module_combine.py).
C. External Dependencies
• ext/: pre-bundled libraries (jQuery, Underscore, Backbone, esprima).
• third-party/: larger external binaries and libs (Closure Compiler, UglifyJS, Node distributions, RequireJS).
D. Tests
• tests/: integration and browser-based tests, organized by functionality (module resolution, combiners, async, CSS, plugin).
• fakes/: fake implementations (FakeTimer, FakeXMLHttpRequestFactory, FakeEventLoop) to support unit tests.
1. “Invoke Build / Test Scripts” → s/ shell scripts or bin/*.js
2. “Import Library” → end users consuming the combined library in Browser or Node.
• Build & Test Path:
• s/ scripts / bin/ tools
↓
• SCons Engine (SConstruct + scons-tools/*)
↓
• Module Combiner & Minifier (module_combine.py + closure.py/uglify.py)
↓
• Output: dist/imvujs.js (minified bundle)
• Test Path:
• s/runtests or bin/node-runner.js / bin/leprechaun-runner.js
↓
• imvujstest framework (src/imvujstest)
↓
• Test adapters: Node.js, PhantomJS, Leprechaun
↓
• Test results (console or HTML reporter)
• Library Runtime:
• Core Modules (src/*.js) ←→ Module Loader (src/module-common.js / web-module.js / node-module.js)
↓
• ServiceProvider (DOM or Node)
↓
• Application code (user modules)
• External Services:
• Closure Compiler / UglifyJS (via scons-tools)
• RequireJS (optional loader)
• Git hooks (githooks/pre-commit)
Architectural Patterns & Principles
• Modular design: each feature in its own file under src/, resolved via a custom AMD-like loader.
• Pluggable build pipeline: SCons with custom extension modules driving combine/minify.
• Environment abstraction: ServiceProvider real vs fake for browser/Node test isolation.
• Test sandboxing: fakes/ to isolate global timers, XHR, randomness.