Skip to content

Commit ecf479f

Browse files
jziggasterragon-labs[bot]
andauthored
Add Rollup bundling and update dependencies for dice package; add bundling for monte-carlo package (#13)
* feat(build): add rollup bundler with UMD, ESM, and CJS outputs - Introduce rollup.config.js for bundling with plugins for typescript, node resolve, commonjs, and terser - Add tsconfig.rollup.json for rollup-specific TypeScript config - Update package.json to include rollup scripts and outputs for main, module, browser, and types - Add rollup and related plugins as devDependencies - Update package-lock.json with new dependencies This enables building the package into multiple module formats for better compatibility and distribution. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com> * test(hints): improve test formatting and assertions for hint display - Refactor test cases for better readability and consistency - Ensure proper formatting of multiline strings in tests - Add checks for uppercase 'OR' in hint cost display - Validate hint cost and description structure more thoroughly - Clean up whitespace and arrow function usage in tests - Confirm presence of hints with multiple cost options and specific symbols - Enhance dice roll tests with stricter property checks and limits These changes improve the reliability and clarity of tests related to hint display and dice rolling. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com> * feat(build): add rollup bundler for UMD, ESM, and CJS outputs - Add rollup configuration for creating self-contained bundles - Update package.json exports to support multiple module formats - Fix direct dist import of DiceResult type - Bundle includes all dependencies for standalone usage Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com> --------- Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
1 parent 876598f commit ecf479f

File tree

9 files changed

+636
-73
lines changed

9 files changed

+636
-73
lines changed

monte-carlo-bundling-prompt.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Task: Add Bundling to @swrpg-online/monte-carlo Package
2+
3+
## Context
4+
5+
The @swrpg-online/monte-carlo package currently only provides CommonJS modules that require external dependencies at runtime. Users consuming the dist folder directly (e.g., in browser environments or without a bundler) encounter issues with module resolution and the "exports is undefined" error. The dependency @swrpg-online/dice has already been updated with proper bundling.
6+
7+
## Current Issues
8+
9+
1. The dist folder contains CommonJS modules that use `require()` statements
10+
2. External dependency (@swrpg-online/dice) is not bundled, causing resolution issues
11+
3. No browser-compatible build is available
12+
4. Import path `@swrpg-online/dice/dist/types` directly references dist folder (bad practice)
13+
14+
## Required Changes
15+
16+
### 1. Fix the problematic import
17+
18+
- In `src/MonteCarlo.ts`, change line 2 from:
19+
```typescript
20+
import { DiceResult } from "@swrpg-online/dice/dist/types";
21+
```
22+
To:
23+
```typescript
24+
import type { DiceResult } from "@swrpg-online/dice";
25+
```
26+
- Note: First verify if DiceResult is exported from the main @swrpg-online/dice package. If not, you may need to keep the current import until the dice package exports it properly.
27+
28+
### 2. Add Rollup for bundling
29+
30+
Install the following dev dependencies:
31+
32+
```bash
33+
npm install --save-dev rollup @rollup/plugin-typescript @rollup/plugin-node-resolve @rollup/plugin-commonjs @rollup/plugin-terser tslib
34+
```
35+
36+
### 3. Create rollup.config.js
37+
38+
Create a Rollup configuration that generates three bundle formats (UMD, ESM, CJS) with all dependencies included:
39+
40+
- UMD bundle for browsers (dist/bundle.umd.js) with global name "SwrpgMonteCarlo"
41+
- ESM bundle for modern bundlers (dist/bundle.esm.js)
42+
- CJS bundle for Node.js (dist/bundle.cjs.js)
43+
- Include source maps for all bundles
44+
- Mark @swrpg-online/dice as external OR bundle it (depending on use case)
45+
46+
### 4. Create tsconfig.rollup.json
47+
48+
Create a TypeScript config for Rollup that extends tsconfig.json but sets `"module": "esnext"`
49+
50+
### 5. Update package.json
51+
52+
- Add a "bundle" script: `"bundle": "rollup -c"`
53+
- Update "build" script to: `"build": "tsc && npm run bundle"`
54+
- Update package.json exports to support multiple module formats:
55+
```json
56+
"main": "dist/bundle.cjs.js",
57+
"module": "dist/bundle.esm.js",
58+
"browser": "dist/bundle.umd.js",
59+
"types": "dist/index.d.ts",
60+
"exports": {
61+
".": {
62+
"types": "./dist/index.d.ts",
63+
"import": "./dist/bundle.esm.js",
64+
"require": "./dist/bundle.cjs.js",
65+
"browser": "./dist/bundle.umd.js",
66+
"default": "./dist/index.js"
67+
}
68+
}
69+
```
70+
71+
### 6. Test the bundles
72+
73+
Create simple test files to verify:
74+
75+
- UMD bundle works in browser (create test HTML file)
76+
- CJS bundle works with require() in Node.js
77+
- ESM bundle works with import in Node.js
78+
- Verify the monte-carlo simulation functions work correctly
79+
80+
### 7. Run prettier and tests
81+
82+
- Run `npm run test` to ensure all tests pass
83+
- Run `npx prettier --write .` to format all files
84+
- Ensure the build completes successfully
85+
86+
### 8. Commit with semantic-release format
87+
88+
Since this repo uses semantic-release with Angular commit conventions, commit with:
89+
90+
```
91+
feat(build): add rollup bundler for UMD, ESM, and CJS outputs
92+
93+
- Add rollup configuration for creating self-contained bundles
94+
- Update package.json exports to support multiple module formats
95+
- Fix direct dist import of DiceResult type
96+
- Bundle includes all dependencies for standalone usage
97+
```
98+
99+
## Expected Outcome
100+
101+
After these changes:
102+
103+
1. Users can use the monte-carlo dist folder directly in browsers via the UMD bundle
104+
2. The package works with both require() and import statements
105+
3. No external dependency resolution issues
106+
4. The package maintains backward compatibility with existing users
107+
108+
## Important Notes
109+
110+
- Maintain backward compatibility - keep the original dist/index.js working
111+
- This repo uses semantic-release, so use proper commit message format
112+
- The GitHub Actions workflow must pass (especially Prettier checks)
113+
- Consider whether to bundle @swrpg-online/dice or keep it as external dependency based on package size and use cases

0 commit comments

Comments
 (0)