ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

`preferTsExts` incorrectly imports `.js` instead of `.ts` when importing an inferred `index` file

Open alecgibson opened this issue 2 years ago • 0 comments

Search Terms

"preferTsExts", "coverage", "index"

Expected Behavior

Following the below steps should result in 100% code coverage at all times

Actual Behavior

Coverage is not 100%

Steps to reproduce the problem

  1. Clone this repo
  2. npm i
  3. npm test
  4. Note 100% coverage, including packages/object-id/index.ts
  5. npm run build
  6. npm test
  7. Now note less coverage: packages/object-id/index.ts is uncovered, because packages/object-id/index.js is being used instead
  8. Reset using npm run build:clean, and coverage returns to 100%

Minimal reproduction

https://github.com/alecgibson/ts-node-prefer-ts-exts-bug

Specifications

  • ts-node version: 10.9.1
  • node version: v18.10.0
  • TypeScript version: ^4.9.5
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {},
  "include": [
    "lib/",
    "packages/",
  ],
  "ts-node": {
    "preferTsExts": true,
  },
}
  • package.json:
{
  "name": "ts-node-prefer-ts-exts-bug",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "tsc",
    "build:clean": "tsc --build --clean",
    "test": "nyc mocha -r ts-node/register 'lib/**/*.spec.ts' 'packages/**/*.spec.ts'"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/alecgibson/ts-node-prefer-ts-exts-bug.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/alecgibson/ts-node-prefer-ts-exts-bug/issues"
  },
  "homepage": "https://github.com/alecgibson/ts-node-prefer-ts-exts-bug#readme",
  "devDependencies": {
    "@types/chai": "^4.3.4",
    "@types/mocha": "^10.0.1",
    "chai": "^4.3.7",
    "mocha": "^10.2.0",
    "nyc": "^15.1.0",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.5"
  },
  "dependencies": {
  }
}
  • Operating system and version: macOS 13.2.1 (22D68)

Notes

Here are some things I've noted trying to put together the MWE:

- import {isObjectId} from '.';
+ import {isObjectId} from './index';
- import {isObjectId} from '../packages/object-id';
+ import {isObjectId} from '../packages/object-id/index';

alecgibson avatar Mar 16 '23 13:03 alecgibson