Skip to content

Conversation

@dbolotin
Copy link
Member

@dbolotin dbolotin commented Jul 6, 2025

Implement the @milaboratories/npm-asset-packer package for efficient management and distribution of binary assets in NPM.

@changeset-bot
Copy link

changeset-bot bot commented Jul 6, 2025

🦋 Changeset detected

Latest commit: d7ae5ae

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…olding

- Created package directory structure in tools/npm-asset-packer
- Added package to pnpm-workspace.yaml
- Set up package.json with Oclif configuration and dependencies
- Created standard configuration files (tsconfig.json, vite.config.mts, eslint.config.mjs, vitest.config.mts)
- Created bin executables for cross-platform CLI usage
- Created placeholder source files
- Verified pnpm install works correctly
Task 2 & 3: Implemented build command with runtime code generation
- Created build command that scans assets directory and calculates SHA256 hashes
- Generates manifest.json file with asset metadata
- Creates hard links for npm mode
- Generates TypeScript definitions with strongly typed asset keys
- Generates both CommonJS and ESM runtime implementations
- Implements 4-stage asset resolution: Local-First, Packaged, Global Cache, Download
- Uses Node.js native https module for downloads to avoid runtime dependencies

Task 4: Implemented upload and prepare commands
- Upload command uploads assets to S3 with content-addressable storage
- Checks for existing objects to avoid re-uploading
- Prepare command downloads assets for eager loading strategy
- Both commands validate configuration and handle errors gracefully

All commands are now functional and CLI help works correctly
Task 5: Set up test packages and integration tests
- Created test-assets package with sample assets in etc/test-assets/
- Added assets-test-mjs and assets-test-cjs packages for ESM/CommonJS integration testing
- Added all test packages to pnpm-workspace.yaml
- Created sample test files (test-file.txt, data/sample.json) for testing
- Generated manifest and runtime code using npm-asset-packer build command

Task 6: Implemented integration tests
- Created comprehensive tests for both ESM and CommonJS module systems
- Tests verify asset metadata (SHA256, size, downloadUrl)
- Tests verify 4-stage asset resolution strategy works correctly
- Tests verify linked assets (development mode) and bundled assets (production mode)
- Tests verify relative path handling and JSON asset loading
- All integration tests pass successfully (5/5 tests in each suite)
- Fixed vitest configuration to use non-interactive mode (vitest run)
- Fixed test content expectations to match actual file content with newlines

Both ESM and CommonJS integration test suites are now passing!
✅ IMPLEMENTATION COMPLETE - All tasks from todo.md completed successfully:

Phase 1: Scaffolding and Initial Setup
- ✅ Task 1: Set up @milaboratories/npm-asset-packer package
  - Created package directory structure and configuration
  - Added to pnpm-workspace.yaml
  - Set up Oclif CLI tool with all dependencies
  - Created standard build configs and TypeScript setup

Phase 2: Core Logic and Code Generation
- ✅ Task 2: Implement build command
  - Asset scanning and SHA256 hash calculation
  - Manifest generation with metadata
  - Hard-linking for npm mode
- ✅ Task 3: Implement Runtime Code Generation
  - Strongly-typed TypeScript definitions
  - Dual CommonJS/ESM runtime generation
  - 4-stage asset resolution (Local-First → Packaged → Global Cache → Download)
  - Zero runtime dependencies using Node.js native modules
- ✅ Task 4: Implement upload and prepare commands
  - S3 upload with deduplication
  - Asset preparation for eager loading
  - AWS SDK v3 integration

Phase 3: Testing
- ✅ Task 5: Set up Test Packages
  - Created test-assets provider package
  - Created ESM and CommonJS consumer test packages
  - Added to pnpm-workspace.yaml
- ✅ Task 6: Implement Integration Tests
  - Comprehensive test coverage (10 total tests, all passing)
  - Both linked and bundled asset resolution testing
  - ESM and CommonJS compatibility verification

📚 Documentation:
- Complete README with usage examples and API documentation
- CHANGELOG documenting all implemented features
- TypeScript interface documentation
- Configuration examples for both npm and remote modes

🧪 All verification commands pass:
- pnpm build --filter='@milaboratories/assets-test-mjs...' && (cd tests/assets-test-mjs && pnpm test) ✅
- pnpm build --filter='@milaboratories/assets-test-cjs...' && (cd tests/assets-test-cjs && pnpm test) ✅

The @milaboratories/npm-asset-packer tool is now fully functional and ready for use!
@dbolotin dbolotin force-pushed the cursor/implement-npm-asset-packer-package-fed4 branch from 9472496 to 1ce0da3 Compare July 6, 2025 16:44
dbolotin added 3 commits July 6, 2025 19:58
…t configurations

- Added the `@milaboratories/npm-asset-packer` package for efficient binary asset management in NPM.
- Updated all `vitest.config.mts` files to set `watch: false`, ensuring a non-interactive testing environment.
…pendency

- Added '@types/fs-extra' version 11.0.4 to pnpm-lock.yaml and pnpm-workspace.yaml for improved type definitions.
- Removed the 'test' script from etc/test-assets/package.json to streamline the package configuration.
- Updated dependency references in tools/npm-asset-packer/package.json to use 'catalog:' for '@types/fs-extra'.
- Introduced a new document outlining markdown formatting conventions, including guidelines for headers, lists, spacing, and code usage.
- Provided examples for correct and incorrect formatting to ensure clarity and uniformity across documents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants