Refactor: Library + CLI Architecture#137
Conversation
There was a problem hiding this comment.
Pull request overview
This PR restructures the project to separate platform-agnostic library code from Node.js CLI code, enabling programmatic use in browsers and Node.js environments.
Changes:
- Split source into
src/lib/(platform-agnostic) andsrc/cli/(Node.js-specific) directories - Introduced injectable logger and browser-safe path utilities to replace Node.js dependencies
- Updated build configuration to produce separate library and CLI outputs with dual package exports
Reviewed changes
Copilot reviewed 22 out of 58 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.types.json | New TypeScript config for library type generation |
| src/utils/path.ts | Removed old utils (moved to lib) |
| src/utils/logger.ts | Removed old logger (replaced with injectable version) |
| src/types.ts | Removed old types (moved to lib) |
| src/lib/writers/write-sog.ts | Updated imports and logger calls for library |
| src/lib/writers/write-lod.ts | Updated imports and logger calls for library |
| src/lib/writers/write-html.ts | Updated path imports for library |
| src/lib/writers/write-compressed-ply.ts | Updated package.json import path |
| src/lib/write.ts | Updated logger call for library |
| src/lib/utils/webp-codec.ts | Updated webp module import path |
| src/lib/utils/path.ts | New platform-agnostic path utilities |
| src/lib/utils/logger.ts | New injectable logger implementation |
| src/lib/types.ts | New library types (subset of CLI options) |
| src/lib/read.ts | Updated logger call for library |
| src/lib/io/read/index.ts | Removed Node.js filesystem from exports |
| src/lib/index.ts | New library entry point with public API |
| src/lib/data-table/data-table.ts | Added missing type exports |
| src/cli/node-file-system.ts | Updated import paths for CLI |
| src/cli/node-device.ts | Updated logger import and calls for CLI |
| src/cli/index.ts | Restructured to use library and inject Node.js logger |
| rollup.config.mjs | Split into separate library and CLI builds |
| package.json | Added library entry points and peer dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
willeastcott
left a comment
There was a problem hiding this comment.
This is very cool. 🔥
At the moment, yes. So you want CommonJS support? Or can you switch to ESM? |
Would be nice to support it yes. For sure more people will bump into that issue. |
I have added support for CommonJS for you: https://github.com/playcanvas/splat-transform/releases/tag/v1.1.0 |
|
Thank you very much! Hope it also helps others :) |

Refactor: Library + CLI Architecture
Restructures the project to expose a platform-agnostic library alongside the existing CLI, enabling programmatic use in browsers and Node.js.
Changes
Project Structure
src/lib/(platform-agnostic library) andsrc/cli/(Node.js CLI)src/lib/index.tsdist/index.mjs(library) anddist/cli.mjs(CLI)Package Configuration
main,module,types, andexportsfields for library consumptionplaycanvasas peer dependency (previously bundled)@rollup/plugin-typescripttorollup-plugin-esbuildfor faster buildstsconfig.types.json)Platform-Agnostic Utilities
path.ts: Browser-safe path utilities (dirname,basename,join,resolve)logger.ts: Injectable logger with quiet mode support and browser-safe defaultstypes.ts: SharedOptionsandParamtypesAPI
DataTable,Column,readFile,writeFile,processDataTable, file system abstractions, individual readers/writerslogger.setLogger()andlogger.setQuiet()DeviceCreatortype for GPU device injectionUsage