build: unified rollup pipeline with generation-time headers and per-file declarations (#13)

* fix: complete license headers on all compiled outputs

tsc's comment emitter is unreliable for file headers: it drops them
from .d.ts entirely and truncates the copy it keeps on .js at the
first empty comment line, so compiled lib files shipped a partial
header that license checks reject. The post-build pass now covers
every .js and .d.ts under lib/dist/build: it strips any truncated
remnant and prepends the complete header, matching how other Apache
npm packages ship banners on their outputs (echarts, ts-sdk).
Verified against ATR's exact header comparator across all 137
output files; the pass is idempotent.

* chore: license headers on tool configuration dotfiles

The extensionless rc files are parsed leniently by their tools (YAML
for eslint's loader, JSON5/YAML for prettier) and accept comments -
'#' uniformly satisfies every consumer, verified by running the lint
suites of packages carrying .eslintrc/.prettierrc/.eslintignore.
Adds the Apache-2.0 header to all 29 tool configuration dotfiles; the
generated lockfiles remain the only headerless text files and stay
excluded from checks.

* fix: drop prepare hooks that rebuild over the header pass

pnpm pack fires the prepare script, and four packages still carried
prepare: npm run build from upstream - packing rebuilt lib/ with tsc
and silently replaced the completed headers with truncated ones,
defeating the post-build header pass. The pipeline builds explicitly
(via build:all) before packing, so the hooks are redundant and
harmful; verified end to end: 133/133 tarball members carry the full
header after packing, and all 20 packages install and load from the
final tarballs.

* fix: restore the rbac_policy.csv fixture header

The file-adapter test suite saves policy rules back into the example
fixture during test runs, which strips its license header; the
mutated file was then swept into the prepare-removal commit by a
broad git add. Restores the headed version - the gate had caught it
in CI while a stale local run still showed it passing.

* fix: review findings - src archive hygiene, NOTICE accuracy, publish metadata

- .licenserc.yaml joins the export-ignore list (a dotfile at the
  source archive root)
- NOTICE: JSEP is a runtime dependency of @casbin/expression-eval,
  not bundled within it (rollup keeps jsep external); the wording
  now matches reality
- express-authz: fix the 'testt' files typo
- expression-eval: drop phantom files entries (index.js,
  package-lock.json)
- publishConfig.registry normalized to registry.npmjs.org in every
  package (five deviated; yarnpkg endpoints could hijack npm stage
  publish)

* build: unify package builds on rollup with generation-time banners

Replaces the per-package tsc builds (and the tsc-era quirks they
carried) with one shared preset (scripts/rollup.preset.js): a
preserveModules pass per package that keeps the existing output
layout (lib/adapter.js, lib/cjs + lib/esm, one file per source
module, entry fields unchanged) while emitting the Apache-2.0 banner
and aligned source maps at generation time - the same architecture
apache/echarts uses. Declaration files still come from the typescript
compiler via declarationDir (rollup banners never reach them, and a
transformers.afterDeclarations synthetic comment is dropped by the
plugin's declaration printer), so the post-build header step remains
for .d.ts only.

- typescript unified at ^5.1.6 (the plugin does not support the 3.x
  pins two watchers carried)
- tslib ^2 becomes a dependency of the migrated packages: rollup's
  commonjs interop helpers (__export/__reExport) import it at runtime
- nest-authz's output flattens from dist/src/** (a tsc rootDir quirk)
  to dist/** - same modules, cleaner layout, main unchanged
- mongoose-adapter and mongo-changestream-watcher get explicit files
  lists (lib, src, test); their previous empty field shipped every
  dotfile and would have shipped rollup.config.js too

Verification: 20/20 packages install and load from the new tarballs;
layout diff vs the tsc-era tarballs shows only .map additions (and
the nest flatten); the license gate and the ATR header comparator
pass on every output file; expression-eval/file-adapter/koa suites
green.

* fix: whitelist typescript helper globals for hapi-authz lab tests

With typescript 5, lab-transform-typescript declares the full TS
helper set as globals; lab's leak detection fails the suite. The
globals are whitelisted via .labrc.js (lab expects a comma-separated
string, not an array).

* build: bundle declarations through rollup; retire the header post-step

The declaration pipeline is now fully generation-time: the typescript
pass emits per-file .d.ts into a temporary directory inside the output
(necessary - the plugin requires declarationDir inside the rollup
dir), then a second rollup invocation (ROLLUP_STAGE=dts, selected
because rollup evaluates all configs before building any, so the two
stages cannot share one invocation) bundles the tree with
rollup-plugin-dts into the single file each package's types field
already points at - through rollup, so output.banner applies and
scripts/add-output-headers.js is deleted. redis-adapter joins the
migrated set (it had been missed).

Also removes the legacy 'typings' fields from 14 packages; the
redis-adapter one pointed at the never-existing index.d.ts, which is
why its types never resolved for consumers - found by a tsc
--traceResolution smoke that now compiles 18 typed packages from the
real tarballs with zero errors. Runtime consumers: 20/20 require.

* fix: bring expression-eval fully into the shared build pipeline

Review follow-ups: expression-eval's declaration was the one output
still bypassing the banner (its bespoke config emitted d.ts straight
from the typescript plugin), so it now runs the same two-stage flow as
the other 17 packages (ROLLUP_STAGE=dts + rollup-plugin-dts bundle to
dist/index.d.ts). Its config drops the ESM syntax that only worked on
node 26 (module-level import in a CJS package - Cannot use import
statement outside a module on node 18/22) for require() style, and
typescript moves to ^5.1.6 with tslib added - the plugin forces
importHelpers:true, so without a resolvable tslib every build logged
a TS2354 error diagnostic. express-authz's files list drops a
duplicate entry.

* ci: build fails fast - a single package failure must not be masked

--no-bail let the build jobs go green while individual packages
failed to compile (the review caught expression-eval's node-18/22
config break being invisible this way); release builds must fail on
the first error.

* build: fail-fast build:all with prisma-adapter split

The root build:all kept --no-bail, so a package build failure during
release would be masked and pack would pick up stale outputs with G3/G4
still green - exactly the scenario ci.yml now guards against. prisma-
adapter builds separately because its script runs prisma generate first.

* fix: breadth-first declaration entry search; explicit files lists

The declaration entry finder descended depth-first, so a nested module
sharing the entry's basename (nest-authz's src/decorators/index.d.ts
next to src/index.d.ts) could win depending on readdir order - which
differs between macOS and Linux CI. Files at the current level are now
matched before descending.

koa-authz, egg-authz, redis-adapter, mongoose-adapter and
mongo-changestream-watcher get explicit files lists so NOTICE and
DISCLAIMER ship in every tarball (the source-shipped middlewares had
none at all, and the empty-files adapters relied on implicit
inclusion).

* ci: drop the last two --no-bail build invocations

test-mongo and test-misc built their package subsets with --no-bail,
the same failure-masking the build job dropped.

* build: single rollup invocation per package

The declaration bundle no longer needs a second ROLLUP_STAGE=dts
invocation: rollup builds config-array entries sequentially, so the
dts build is appended as the last entry and resolves its input in an
options hook - by the time it starts, the JS pass has already written
the per-file .d.ts into the temporary directory. Every build script
collapses to 'rimraf <out> && rollup -c'; expression-eval's bespoke
config uses the same exported declarationBuild helper. Verified with
a from-scratch workspace build (rc=0, comparator clean on all
published outputs, 20/20 consumer loads).

* build: per-file declarations with headers; explicit types fields

- declarationDir writes per-file .d.ts into each format's output dir
  (cjs + esm), matching the tsc-era npm layout; dtsHeaderPlugin prepends
  the Apache header idempotently at closeBundle; rollup-plugin-dts
  bundling removed
- expression-eval: same per-file flow with declaration: false on the
  later outputs so they cannot rewrite the headed index.d.ts via tsconfig
- explicit types field on 13 packages; all 18 TS packages now declare
  types, header coverage verified 0 missing

* build: named CJS exports, drop rollup-plugin-dts, pin declaration rootDir

- output.exports: 'named' keeps default-exported modules in the tsc-era
  CJS shape (exports.default = ...), matching the published npm packages
  and silencing rollup's MIXED_EXPORTS warning
- per-file declarations no longer need rollup-plugin-dts: removed from
  all 18 package devDependencies
- rootDir pinned to src so per-file .d.ts land next to their
  preserveModules .js (fixes nest-authz's dist/src nesting)
- verified end to end: 20/20 tarballs install and require in a clean
  project, deep imports resolve, tsc --strict consumer compile clean
77 files changed
tree: e05414781531cae5fa6a2834daa3663f1f27b06e
  1. .changeset/
  2. .github/
  3. examples/
  4. packages/
  5. scripts/
  6. .asf.yaml
  7. .gitattributes
  8. .gitignore
  9. .licenserc.yaml
  10. DISCLAIMER
  11. LICENSE
  12. NOTICE
  13. package.json
  14. pnpm-lock.yaml
  15. pnpm-workspace.yaml
  16. README.md
README.md

Apache Casbin Node Extensions

Monorepo for the Apache Casbin Node.js extensions: storage adapters, watchers, framework middlewares, and utilities. Each package keeps its own npm package name and semantic version.

Layout

packages/
├── adapters/       # storage adapters (file, redis, sequelize, typeorm, ...)
├── watchers/       # multi-instance policy synchronization
├── middlewares/    # framework integrations (express, koa, egg, nest, hapi)
├── role-managers/  # role managers (session-based)
└── utils/          # shared utilities
examples/           # runnable examples (not published to npm)

Development

Requires pnpm.

pnpm install
pnpm -r build
pnpm -r test

Import history

Packages were imported from their original repositories with full git history preserved (authors, dates, tags) via git filter-repo --to-subdirectory-filter, with tags renamed to <package>-<version>.

License

Apache License 2.0. See LICENSE and NOTICE.