fix: migrate to TypeScript 6 — nodenext resolution + subpath imports#1147
Conversation
504f551
into
dependabot/npm_and_yarn/typescript-6.0.2
There was a problem hiding this comment.
Pull request overview
Migrates the project to TypeScript 6 by switching to nodenext module/moduleResolution, adding rootDir, and updating code/tests to use explicit .js extensions and internal #/ subpath imports.
Changes:
- Update
tsconfig.jsonfor TS6 (module/moduleResolution: nodenext, addrootDir, simplifylib, settypes: ["node"]). - Convert internal source imports to
#/.../*.jsand update tests to import../src/.../*.js. - Add
package.json#importsandjest.config.js#moduleNameMapperto support#/and.js-suffixed specifiers in TS/Jest.
Reviewed changes
Copilot reviewed 25 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Switch compiler to nodenext, set rootDir, adjust libs/types for TS6. |
| package.json | Add imports map for #/ self-references. |
| jest.config.js | Add moduleNameMapper to resolve .js-suffixed specifiers + #/ to src/ in tests. |
| src/JsonDB.ts | Replace relative imports with #/ imports and add .js extensions; update re-exports accordingly. |
| src/lib/JsonDBConfig.ts | Update adapter/lib imports to #/.../*.js. |
| src/lib/DBParentData.ts | Update imports to #/.../*.js. |
| src/lib/ArrayInfo.ts | Update imports to #/.../*.js. |
| src/lock/ReadWriteLock.ts | Update imports to #/.../*.js. |
| src/lock/Lock.ts | Update imports to #/.../*.js. |
| src/lock/Error.ts | Update imports to #/.../*.js. |
| src/adapter/data/JsonAdapter.ts | Update imports to #/.../*.js. |
| src/adapter/data/Serializers.ts | Update imports to #/.../*.js. |
| src/adapter/file/FileAdapter.ts | Update imports to #/.../*.js. |
| src/adapter/file/CipheredFileAdapter.ts | Update imports to #/.../*.js. |
| test/01-utils.test.ts | Add .js extensions to project-local imports. |
| test/02-jsondb.test.ts | Add .js extensions to project-local imports. |
| test/03-existing-db.test.ts | Add .js extensions to project-local imports. |
| test/04-array-utils.test.ts | Add .js extensions to project-local imports. |
| test/06-concurrency.test.ts | Add .js extensions to project-local imports. |
| test/07-cyphered.test.ts | Add .js extensions to project-local imports. |
| test/JsonDB.test.ts | Add .js extensions to project-local imports. |
| test/DBParentData.test.ts | Update mock/import paths to match new resolution approach. |
| test/ArrayInfo.test.ts | Add .js extensions to project-local imports. |
| test/adapter/Serializers.test.ts | Add .js extensions to project-local imports. |
| test/adapter/adapters.test.ts | Add .js extensions to project-local imports (and one local require). |
| test/lock/locks.test.ts | Add .js extensions to project-local imports. |
| test/lock/performance.test.ts | Add .js extensions to project-local imports. |
| "types": "dist/JsonDB.d.ts", | ||
| "imports": { | ||
| "#/*": { | ||
| "types": "./src/*", |
There was a problem hiding this comment.
package.json sets imports["#/*"].types to ./src/*, but src/ is not included in the published files list (only dist/, README, LICENSE, CHANGELOG). That will break TypeScript resolution of the package’s internal #/... specifiers for consumers because the .d.ts files in dist/ will reference #/... and TS will follow the types condition to a path that isn’t shipped. Fix by either publishing src/ (add it to files) or by pointing the types condition at ./dist/* and using a separate dev-only mapping (e.g. tsconfig.paths) for building from src/.
| "types": "./src/*", | |
| "types": "./dist/*", |
TypeScript 6 deprecates
moduleResolution: "node"(errors on build) and requires an explicitrootDir. This PR fixes all TS6 breaking changes and adopts modern Node.js subpath imports (#/).tsconfig.jsonmodule+moduleResolution:"commonjs"/"node"→"nodenext"— correct semantic choice for a Node.js library; keeps CJS output (no"type": "module")rootDir: "src"(now required by TS6)lib: simplified to["es2020", "dom"]; added explicittypes: ["node"]experimentalDecorators/emitDecoratorMetadataExplicit
.jsextensions on all importsnodenextresolution requires explicit extensions on relative imports (mirrors what Node.js needs at runtime). Updated allsrc/andtest/files.jest.config.jsgains amoduleNameMapperto strip.jsso ts-jest resolves.tssource files:#/subpath imports insrc/All intra-package imports now use Node.js subpath imports instead of relative paths:
package.jsonimportsfield wires the resolution:typescondition →src/(TypeScript resolves.js→.tsduring compilation)defaultcondition →dist/(Node.js runtime on published package)