Skip to content

refactor: build dist one file per module instead of bundling - #152

Merged
Shinrai merged 1 commit into
nextfrom
fix/138-per-module-build
Nov 30, 2026
Merged

Shinrai merged 1 commit into
nextfrom
fix/138-per-module-build

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

No bug fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

👥 Contributors

The tsup bundles are replaced by scripts/build.mjs, which runs esbuild over every src/**/*.mjs file with bundle: false. Each module is minified on its own with names kept and written to the same path under dist/, with a source map. Nothing is merged or copied between entries any more, so the code the subpaths share exists once. The @cldmv/uuid/rng, /bytes and /hash self-imports stay as written, so the browser variants are still picked through the exports map. src/index.cjs is copied verbatim.

The CJS entry test now checks that dist/ mirrors src/, that only dist/uuid.mjs defines the UUID class, and that the subpath imports and inlined issuer data are still there.

Resolves #138
@cldmv-bot cldmv-bot Bot added the ! fix → next v4 flow: fix contributor PR targeting the next integration branch label Nov 30, 2026
@cldmv-bot cldmv-bot Bot changed the title docs: cover #150 in the v3.0.0 changelog (#151) refactor: build dist one file per module instead of bundling Nov 30, 2026
@cldmv-bot

cldmv-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Auto-normalized PR title: rewrote PR title to match the highest-priority commit type (refactor).

  • Before: docs: cover #150 in the v3.0.0 changelog (#151)
  • After: refactor: build dist one file per module instead of bundling

If this isn't what you want, edit the title. The normalizer leaves it alone as long as it stays conventional, ranks at least as high as the commits' type, and its summary matches one of the commit subjects.

@cldmv-bot cldmv-bot Bot added area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure type: ci Changes to CI workflows, actions, or build pipelines type: config Changes to repository or project configuration files type: dependencies Relates to dependency updates, version bumps, or package management type: documentation Relates to docs, README updates, guides, or inline code comments labels Nov 30, 2026
@Shinrai
Shinrai merged commit 45f5cc0 into next Nov 30, 2026
37 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/138-per-module-build branch November 30, 2026 06:49
Shinrai added a commit that referenced this pull request Nov 30, 2026
## 🚀 What's Changed

### 💥 Breaking Changes
- refactor!: drop the deprecated @cldmv/uuid/main alias (d06be44)

### ✨ Features
_No new features_

### 🐛 Bug Fixes
_No bug fixes_

### 📦 Dependencies
_No dependency updates_

### 🔧 Other Changes
- refactor: build dist one file per module instead of bundling (#152)
(09b063d)



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>
cldmv-bot Bot added a commit that referenced this pull request Nov 30, 2026
# `@cldmv/uuid` v3.0.0 Changelog

**Release Date**: November 2026
**Release Type**: Major
**Branch**: `release/3.0.0`

---

## Overview

v3.0.0 switches the CommonJS entry to the generic `index.cjs` shim used across the CLDMV libraries. `require("@cldmv/uuid")` now returns the module object, the same exports `import` gives, instead of the `UUID` class with properties attached.

There are two breaking changes. The `require()` shape changes, which only affects code that treats the result as the `UUID` class, and the deprecated `@cldmv/uuid/main` alias is removed ([#154](#154)). ESM `import` is unchanged, and so is every `UUID` method. The release also closes off the issuer registry: its bundled data and its entries are now private, and the registry won't let a ratified entry change ([#148](#148)). `dist/` is now built one file per module instead of as tsup bundles, so the code the subpaths share ships once ([#152](#152)).

---

## 💥 Breaking Changes

### `require("@cldmv/uuid")` returns the module object ([#141](#141), fixes [#140](#140))

The ESM entry exports two distinct values, the `UUID` class (also exported as `uuid` and `default`) and `ISSUER_CATEGORIES`, so the shim hands back the module object:

```javascript
const uuid = require("@cldmv/uuid");
// => { __esModule, default: UUID, UUID, uuid, ISSUER_CATEGORIES }

const { UUID } = require("@cldmv/uuid");
UUID.TB();
```

- `new (require(x))()` becomes `new (require(x).UUID)()`, or `const { UUID } = require(x)`.
- Statics called on the result, such as `require(x).v4()`, `require(x).NIL` and `require(x).DNS`, move to the class: `require(x).UUID.v4()`, `UUID.NIL`, `UUID.DNS`.
- `require(x).UUID`, `require(x).uuid` and destructuring keep working.
- `require(x).default` and `require(x).ISSUER_CATEGORIES` are newly available.

`src/index.cjs` is now the generic shim used by the other CLDMV libraries: the Node version guard, then `require("./index.mjs")`. With one distinct exported value it returns that value with `.default` and every export name attached; with several, as here, it returns the module object untouched. The build still copies it unchanged to `dist/index.cjs`. The CJS test expects the module object and checks that the statics are no longer top-level keys.

The first cut of the shim in [#141](#141) returned the single value or the module object without the `.default` and name aliases for the single-value case. [#147](#147) syncs `src/index.cjs` with the corrected template. Nothing changes for uuid, since its entry has two distinct values and `require()` still gives the module object, and the CJS test now also asserts that `UUID` isn't decorated with `.default` or `ISSUER_CATEGORIES`.

### The deprecated `@cldmv/uuid/main` alias is removed ([#154](#154))

`@cldmv/uuid/main` has been a deprecated alias of the package root since v1.3.0, with a one-time `DeprecationWarning` (`CLDMV_UUID_MAIN`), and was kept until the next major. The `./main` export, `src/main.mjs` and its declaration are gone, so importing `@cldmv/uuid/main` now fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Import `@cldmv/uuid` instead; it exports the same objects. With the alias gone nothing in the package has import-time side effects, so `package.json` sets `"sideEffects": false`.

---

## 🐛 Bug Fixes

### The issuer data and registry are private, and ratified entries can't change ([#148](#148))

The bundled Category A and B issuer data and the registry's entries could be reached and changed from outside the registry. Now:

- The bundled data is a frozen constant inside `issuer-registry.mjs`, no longer a separate `src/data/issuers.json` import, and the registry keeps its entries in a private field.
- Everything the registry returns is a frozen copy, or a fresh copy for `export()`, so `UUID.getIssuerInfo()` hands back a read-only object. `ISSUER_CATEGORIES` is frozen too.
- The shared registry instance lives in module scope instead of `UUID._registryInstance`, and concurrent first calls to `UUID.getRegistry()` share one instance.
- The reserved IDs (0, 1 and 404) and the bundled Category A and B issuers are ratified: entries carry `ratified: true` and nothing can change, replace or remove them. Entries added at runtime carry `ratified: false`. `import()` throws if it would alter a ratified entry or mark an entry ratified; an export from before the flag existed still imports when its ratified entries match.

If you were mutating a returned issuer object or reading `UUID._registryInstance`, that no longer works. Registering and looking up issuers through the public API is unchanged.

### The package loads on its stated Node.js floor again ([#148](#148))

v2.1.0 loaded the issuer data with `import issuers from "../data/issuers.json" with { type: "json" }`. The `with` form of import attributes needs Node.js 18.20, or 20.10 on the 20 line, so on the older versions `engines.node` (`>=16.12.0`) still allowed, importing the package failed with a `SyntaxError`. With the data inlined there is no JSON import left, and the built `dist/` loads and runs on Node.js 16.12.0. The `engines.node` floor of `>=16.12.0` is unchanged and now holds.

---

## 🔧 Build

### `dist/` mirrors `src/`, one minified file per module ([#152](#152), fixes [#138](#138))

The tsup build made a separate bundle for each export (`.`, `./main`, `./rng`, `./bytes`, `./hash` and `./entropy`), so the code they share was copied into several files. An app that imported more than one subpath loaded it more than once. `scripts/build.mjs` now runs esbuild over every `src/**/*.mjs` file with `bundle: false` and the `node16` target. Each module is minified on its own with names kept and written to the same path under `dist/`, so `UUID` and every helper exist once. The `@cldmv/uuid/rng`, `/bytes` and `/hash` imports are left as written, so a browser bundler still picks the browser variants through the exports map. `src/index.cjs` is still copied verbatim.

The `exports` map, the entry points and what each subpath exports are unchanged. The tarball now holds one `.mjs` file per source module, and the `.map` files are still left out by `files`.

## 🔧 CI & tooling

- `ci.yml` adopts the CLDMV/.github v4.46.0 concurrency block, so superseded runs on `next`, `hotfixes` and feature branches are cancelled ([#142](#142), fixes [#139](#139)).

## 📚 Documentation

- **NEW:** [docs/changelog/v3/v3.0.0.md](https://github.com/CLDMV/uuid/blob/v3.0.0/docs/changelog/v3/v3.0.0.md): this changelog.
- README: the CommonJS requirements note and example show the module object.
- README What's New promoted to v3.0.0.

## 🔧 Dependencies

- **CLDMV dev tools** ([#145](#145), [#150](#150)): `@cldmv/vitest-runner` 1.5.6 → 1.11.5, `@cldmv/configs` 1.4.0 → 1.5.1 and `@cldmv/fix-headers` 2.2.4 → 2.6.2, plus `npm update` for the rest. `fix-headers` 2.6.1 restamped the file headers, which now write `@Filename` without a leading slash, and `dependabot.yml` takes the npm groups from the CLDMV/.github v4.47.0 template. Development only; nothing changes for consumers.
- `esbuild` added and `tsup` removed ([#152](#152)).

---

## Upgrade notes

- `require("@cldmv/uuid")` no longer returns the `UUID` class. Use `const { UUID } = require("@cldmv/uuid")`, and call statics on `UUID` (`UUID.v4()`, `UUID.NIL`, `UUID.DNS`).
- `require(x).UUID`, `.uuid` and destructuring work as before; `.default` and `.ISSUER_CATEGORIES` are new.
- `@cldmv/uuid/main` is gone. Import `@cldmv/uuid` instead, which exports the same objects.
- ESM `import` from `@cldmv/uuid` and its other subpaths is unchanged.
- On Node.js 16.12 to 18.19 (and 20.0 to 20.9), the package loads again; v2.1.0 failed there.



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>

---

<!-- coverage-start -->

![coverage](https://img.shields.io/badge/coverage-100.0%25-brightgreen?style=for-the-badge&logo=vitest&logoColor=white)

| Metric | Coverage |
|--------|----------|
| Statements | 100.0% |
| Branches   | 100.0% |
| Functions  | 100.0% |
| Lines      | 100.0% |

*Avg: **100.0%** · `3fdb25a` · Node lts/**

<!-- coverage-end -->

<!-- co-authors -->

Co-authored-by: Shinrai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch type: ci Changes to CI workflows, actions, or build pipelines type: config Changes to repository or project configuration files type: dependencies Relates to dependency updates, version bumps, or package management type: documentation Relates to docs, README updates, guides, or inline code comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant