Skip to content

Refactor: Library + CLI Architecture#137

Merged
slimbuck merged 6 commits intoplaycanvas:mainfrom
slimbuck:lib-dev
Jan 14, 2026
Merged

Refactor: Library + CLI Architecture#137
slimbuck merged 6 commits intoplaycanvas:mainfrom
slimbuck:lib-dev

Conversation

@slimbuck
Copy link
Member

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

  • Reorganized source into src/lib/ (platform-agnostic library) and src/cli/ (Node.js CLI)
  • Library exports all public APIs via src/lib/index.ts
  • Dual build outputs: dist/index.mjs (library) and dist/cli.mjs (CLI)

Package Configuration

  • Added main, module, types, and exports fields for library consumption
  • Added playcanvas as peer dependency (previously bundled)
  • Switched from @rollup/plugin-typescript to rollup-plugin-esbuild for faster builds
  • Added separate TypeScript config for type generation (tsconfig.types.json)

Platform-Agnostic Utilities

  • New path.ts: Browser-safe path utilities (dirname, basename, join, resolve)
  • New logger.ts: Injectable logger with quiet mode support and browser-safe defaults
  • New types.ts: Shared Options and Param types

API

  • Library exports: DataTable, Column, readFile, writeFile, processDataTable, file system abstractions, individual readers/writers
  • Injectable logger via logger.setLogger() and logger.setQuiet()
  • DeviceCreator type for GPU device injection

Usage

import { readFile, writeFile, DataTable, logger } from 'splat-transform';

// Optional: configure logging
logger.setQuiet(true);

// Read a PLY file
const dataTables = await readFile({
  filename: 'model.ply',
  inputFormat: 'ply',
  options: { iterations: 10, ... },
  params: [],
  fileSystem: new UrlReadFileSystem()
});

// Process and write
await writeFile({ ... }, memoryFileSystem);

@slimbuck slimbuck requested review from a team and Copilot January 14, 2026 11:23
@slimbuck slimbuck self-assigned this Jan 14, 2026
@slimbuck slimbuck added the enhancement New feature or request label Jan 14, 2026
@slimbuck slimbuck changed the title Separate Library from CLI for Browser/Library Usage Refactor: Library + CLI Architecture Jan 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and src/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.

Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool. 🔥

@slimbuck slimbuck merged commit 7dc1da4 into playcanvas:main Jan 14, 2026
2 checks passed
@slimbuck slimbuck deleted the lib-dev branch January 14, 2026 11:50
@joaomelorodrigues
Copy link

joaomelorodrigues commented Jan 17, 2026

I guess this only works for type:"module" apps, are there plans to support other type?

Screenshot 2026-01-17 at 14 50 03

@willeastcott
Copy link
Contributor

I guess this only works for type:"module" apps, are there plans to support other type?

At the moment, yes. So you want CommonJS support? Or can you switch to ESM?

@joaomelorodrigues
Copy link

I guess this only works for type:"module" apps, are there plans to support other type?

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.

@willeastcott
Copy link
Contributor

I guess this only works for type:"module" apps, are there plans to support other type?

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

@joaomelorodrigues
Copy link

Thank you very much! Hope it also helps others :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants