Repository navigation
feat!: prepare ESM-only v3 and drop NestJS 8/9 support - #65
Conversation
dleo9307
left a comment
There was a problem hiding this comment.
Review summary
Recommendation: request changes (policy decision needed before merge). The code changes themselves are clean, and the runtime behavior is unchanged. The concern is an inconsistency in the support policy: NestJS 10/11 stay in peerDependencies, but the package ships in a format that breaks the default toolchain for those versions (the Nest CLI starter template).
CI is green on all 10 jobs, and I reproduced lint, build and 19 tests / 12 snapshots locally (Node 24.19.0, pnpm 11.23.0).
What I measured
I built a project shaped like the Nest 11 CLI starter: CommonJS package, module: nodenext, Jest 29.7 + ts-jest, "test": "jest". I installed the published v2.2.0 from npm and this PR's packed tarball into it, and compared them on Node 24.19.0.
| Scenario | v2.2.0 | v3 (this PR) |
|---|---|---|
tsc (TS 5.7.3, nodenext) |
✅ | ❌ TS1479 |
tsc (TS 5.8.3, nodenext) |
not measured | ✅ |
tsc (TS 5.8.3, node16) |
not measured | ❌ TS1479 |
jest 29.7, no flag |
✅ | ❌ Jest encountered an unexpected token |
jest 29.7 + --experimental-vm-modules |
not measured | ❌ Must use import to load ES Module |
jest 30.4, no flag |
not measured | ❌ SyntaxError: Unexpected token 'export' |
jest 30.4 + VM flag |
not measured | ✅ |
Nest 10 starter shape (module: commonjs): tsc, then run |
not measured | ✅ |
| Run on Node 22.12.0 | not measured | ✅ but prints an ExperimentalWarning |
| Run on Node 22.13.0 / 22.14.0 | not measured | ✅ no warning |
🔴 Decision needed before merge
1. NestJS 10/11 are listed as supported, but their default template breaks
- What a Nest 11 user must change:
- Upgrade TypeScript to 5.8 or later, and use
nodenext(notnode16). - Upgrade Jest from 29 to 30, and add the VM flag to the test command.
- Even then, Node 24.9 or later is required. On Node 22, the Jest setup has to move fully to ESM mode, including changes to how mocks are written (
jest.unstable_mockModule, etc.).
- Upgrade TypeScript to 5.8 or later, and use
- What it gains: as the baseline in the PR description shows, v2.2.0 already works on Nest 12 in both CJS and ESM apps. The only newly fixed case is "Nest 12 + Jest ESM + static import", and that case already has a workaround. The related issue #59 asked for Nest 12 installability; 2.2.0 already closed it. It did not ask for ESM.
- Options:
- (a) Dual build: ship CJS and ESM with separate
import/requireconditions inexports. This fixes the Nest 12 Jest ESM case without breaking Nest 10/11.- One prerequisite:
ASPECT = Symbol('ASPECT')insrc/aspect.ts:3is created separately per module copy. If the CJS and ESM copies are both loaded in one process,AutoAspectExecutorfrom the CJS copy cannot find metadata set by@Aspectfrom the ESM copy. It would need to becomeSymbol.for('@toss/nestjs-aop/ASPECT').
- One prerequisite:
- (b) To keep v3 ESM-only, narrow
peerDependenciesto^12and state clearly: v3 is for Nest 12; Nest 10/11 stay on v2. - (c) I'd avoid the current option: Nest 10/11 stay "supported" while their default template breaks.
- (a) Dual build: ship CJS and ESM with separate
🟠 Fix before release
2. The guide has no TypeScript floor, and CI hides the problem
scripts/verify-packed.mjs:33pinstypescript@5.8.3. The.ctsfixture only passes because TS 5.8 added require(esm) support. On TS 5.7 or earlier, or withmodule: node16, it fails with TS1479.docs/migrations/v3.mdonly says "CommonJS applications may use require()". It should state the conditions:- With
module: commonjs(node10 resolution, using the top-leveltypesfield), it works. - With
nodenext, TS 5.8 or later is required.
- With
- I'd also add a
module: commonjscase and a TS 5.7 failure case to CI.
3. The Node 22.12.0 floor prints a warning
- On Node 22.12.0, a CJS app prints this warning at runtime when it
require()s the package. From 22.13.0 onward it does not.ExperimentalWarning: CommonJS module ... is loading ES Module ... using require(). Support for loading ES Module in require() is an experimental feature - I suggest raising
enginesto>=22.13.0and updating the CI matrix, the changeset and the guide to match. If 22.12.0 stays, the warning should at least be documented.
4. The migration guide links are pinned to a commit on the PR branch
README.md:67,readme_kr.md:67and.changeset/modern-aspects-migrate.md:10all point toblob/f467f9c…/docs/migrations/v3.md.- According to CONTRIBUTING, this repo squash-merges PRs, so this commit will never land on
main:- The link shows a "This commit does not belong to any branch" banner.
- Later fixes to the guide will not show up.
- The changeset text stays permanently in the CHANGELOG and the GitHub Release.
- I suggest
blob/main/...or a release-tag path (blob/v3.0.0/...). The language link in the same README already usesblob/main/. - The pinned guide also contains PR-process notes. These should not be in a user-facing document:
- "The package version stays at 2.2.0 in this implementation PR"
- "Merge and publish v3 only after reviewing…"
- The notes about #63
- The "Packaging references" section
🟡 Suggestions
- CI no longer catches regressions in new Nest releases (
ci.yml):- The previous
^Nfollowed the latest release of each major; the matrix is now pinned to10.4.22/11.2.6/12.1.0. ^10claims support for all of 10.x, which no longer matches the "verified claim" comment above the matrix.- I'd keep the pinned versions for reproducibility and add one latest-per-major case.
- The previous
- CI does not verify the guide's ts-jest ESM config. The Jest cases in verify-packed run plain .mjs/.cjs files with
transform: {}. Adding the ts-jest path that Nest users actually use would let CI catch the guide's example breaking. - "ESM only" in the README is misleading. CJS apps do work through require(esm), but the wording reads as "can't be used from CJS". I'd put the TS floor and the Jest requirement (Jest ESM mode, or Jest 30 + VM flag) on the README requirements line.
pnpm packin CI rebuilds with the default Node, not the matrix Node.prepackrebuilds with the default Node (24.19), so the tarball under test isn't built by the matrix Node, and the earlier Build step is duplicated. tsc output doesn't vary by Node version, so the impact is small.exportshas no"./package.json"entry. Any tool that reads@toss/nestjs-aop/package.jsondirectly will fail (optional).
⚪ Nits
@types/nodeis^20, whileenginesis>=22.12..babelrcand the two@babel/*devDependencies aren't used anywhere. Theesmentries left in the tsconfigexcludeand the eslintignoresare leftovers from an earlier dual build. A major release is a good time to clean these up.- The comment at
src/auto-aspect-executor.ts:54("for support nestjs 8") is stale now that Nest 8 support is dropped. scripts/verify-packed.mjs:- The
MIGRATION_V3.mdcheck at:110is dead code left over from an earlier iteration. - The win32
npm.cmdbranch at:18doesn't work anyway: recent Node versions throw EINVAL whenexecFileSyncruns a.cmdfile without a shell. - The two
ifs with opposite conditions at:68/:77could be oneif/else.
- The
- The existing guide is
docs/migration-guide-v2.md, but the new one isdocs/migrations/v3.md, so the path conventions differ. prepackusesnpm run buildin a pnpm repo.
✅ What's good
- The
srcchanges only add.jsto import paths and makeimport typeexplicit, so runtime behavior is unchanged. - Raising the target to ES2022 flips TS's default for class fields, and setting
useDefineForClassFields: falseexplicitly keeps the existing class-field behavior. Good call. - The type import from
@nestjs/core/injector/instance-wrapper.jsis erased at build time and doesn't leak into the shipped.d.ts(checkeddist/auto-aspect-executor.d.ts).- In Nest 12,
InstanceWrappermoved to@nestjs/core/internaland isn't exported from the package root. - So this is the only path that works across Nest 10, 11 and 12, which makes it a reasonable choice.
- In Nest 12,
- The tarball contains only
dist(30 files). The source maps embed the original sources, and there are no.d.ts.mapfiles. - CI that installs the actual tarball into independent projects (what users receive, not workspace symlinks) is a clear improvement.
Out of scope (existing bug, separate PR suggested)
applyDecorators(SetMetadata(ASPECT, metadataKey), Injectable) in src/aspect.ts:10 passes the Injectable function itself instead of calling Injectable(). As a result, classes decorated with @Aspect never get the __injectable__ metadata (checked: undefined, versus true when @Injectable() is applied directly). It works today only because SetMetadata is itself a decorator, so design:paramtypes is still emitted.
|
@dleo9307 Thanks for the detailed review. I addressed the documentation and coverage gaps in 1dd51beb:
I kept the proposed ESM-only / Nest 10–12 / Node >=22.12 policy: native CJS/ESM applications and the configured tests pass on Nest 10/11, so narrowing the peers would exclude working combinations. The default-starter migration cost is real; the requirements are now explicit, and this remains a draft pending the support-policy decision. The Node 22.12 warning is documented rather than raising the floor. The existing Injectable() issue was fixed separately in #66, now merged. CI #127 passed all 16 jobs on 1dd51be. |
|
@WhiteKiwi Thanks for the quick and thorough follow-up. I checked 1dd51beb against the earlier points: the TS-floor docs and the expected-TS1479 checks, the guide config being diffed against what CI runs, 1. The branch now conflicts with
However, the new CI won't catch this:
So the errors would only show up as editor errors. On the PR head alone, the same command exits 0. When rebasing, I'd suggest:
2. The source-map assertion doesn't check subdirectories
3. Remaining nits (optional)
Open question on the policy Your point about narrowing the peers is fair: Nest 10/11 apps do run, and the requirements are now explicit. One option still has no answer, though. Was a dual build considered? It would fix the Nest 12 Jest ESM case without changing anything for Nest 10/11 default-starter users. If it's ruled out, it would help to record the reason in the PR or the guide, for example the dual-package hazard. If it's ever revisited, I'm happy to leave the final policy call to the maintainers. |
|
@dleo9307 Thanks for re-checking. Both new issues are fixed in 2e1b7f4:
CI #129 passed all 16 jobs on this head. Local typechecks and all 22 tests also pass on Nest 10/11/12. For v3, I've chosen the ESM-only direction for this PR, considering the move toward ESM-only publishing among libraries and the maintenance benefit of a single build. One implementation artifact for import and supported require consumers keeps the build, exports, declarations and compatibility testing simpler. Nest 10/11 remain supported with the tested Node, TypeScript and Jest configurations. This deliberately accepts the compiler and Jest migration cost for existing CJS setups as a documented major-version change. Dual builds remain technically viable and would preserve more of the default CJS toolchain. The current ASPECT symbol would require a namespaced shared key such as Symbol.for, plus mixed-loader regression tests. That is a manageable tradeoff; the single-build approach is the direction I've chosen here. The optional nits remain unchanged, and the PR stays draft for maintainer review. |
Summary
Prepare the next major release on top of the 2.2.1 main-branch baseline. NestJS 12 support was introduced in 2.2.0. Related to #59; independent of the typed-decorator work in #63.
type: module, explicit types/default root export (no legacy main), NodeNext build resolution and .js relative specifiers.Release boundary
Draft only: do not merge or publish until the support policy below is reviewed. The package version remains 2.2.1;
changeset statusreports one major release to 3.0.0. No version command or publish was run.Includes main
be825e60e62351dbc222030d57c623349317d0db(2.2.1, including #66 and #67), integrated without rewriting the reviewed branch history. PR #63 is not included. If it merges first, rebase and rerun the consumer matrix; do not inadvertently combine an intended separate minor release into the major.Published 2.2.0 baseline (fresh npm consumer)
On Node 24.19.0, independently installed
@toss/nestjs-aop@2.2.0+ Nest 12.1.0 peers, with no workspace symlinks:--experimental-vm-modules; default Jest without the flag fails on Nest's ESM.Candidate verification
Current head:
2e1b7f486d69d3e7152013e708b94adc3ac2a93d.Review follow-up
npm run test:packed, avoiding Windows .cmd execution. Windows itself was not run locally.Second review follow-up
Proposed support contract — maintainer decision
Keep Node >=22.12 runtime support and require Node 22 users to migrate Jest tests to ESM mode. Modern Node 24.9+ / recent Jest may use synchronous ESM loading with the VM flag, but old CJS test/mocking workflows are not universally compatible.
This policy is a proposal in this draft, not a final approval of the migration cost. No dual build is introduced. The migration guide also records the exports/deep-import break and ESM mock differences.
Why this draft uses one ESM artifact
A dual build is a viable alternative for preserving Nest 10/11's default CommonJS toolchain. This draft favors one implementation artifact for both import and supported require consumers, avoiding separate CJS/ESM module copies and parallel build/export/declaration outputs. The cost is the explicitly documented compiler and Jest migration.
With the current ASPECT = Symbol('ASPECT'), independently loaded CJS and ESM builds would not share the aspect metadata key. A dual-build implementation would need a namespaced shared key such as Symbol.for, plus mixed-loader regression tests; the hazard is manageable, not a claim that dual publishing is impossible. Maintainers still need to decide whether this single-artifact tradeoff is appropriate before merging.
Pure-ESM packaging references
Reviewed current p-queue (TypeScript), p-limit, p-retry and Sindre Sorhus's guide.
Adopted type:module, types/default exports in that order, no legacy main, dist-only allowlist, a top-level types pointer, Node-aware compiler resolution and prepack build. Keep the tested Node floor and Nest legacy decorator metadata rather than copying unrelated compiler/test presets. ES2022 output retains the previous class-field semantics explicitly. No blanket sideEffects:false assertion is added to this decorator/metadata library.
Local build, lint, 22 tests and fresh packed Nest 12 consumer pass. Packed artifact has 30 files, no source/doc trees or declaration maps, and all 9 JS maps contain embedded source without absolute source paths. The CI consumer test now also enforces this packaging contract.
CI
CI #129 passed on exact head
2e1b7f486d69d3e7152013e708b94adc3ac2a93d: all 16 jobs, including 15 packed-consumer jobs with the expanded compiler/Jest and packaging checks.The PR remains draft and has not been merged into main. No version command or publish was run for this proposal. The support-policy decision above is still required before release.