Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alecgibson opened this issue Mar 16, 2023 · 0 comments

Comments

@alecgibson
Copy link

alecgibson commented Mar 16, 2023

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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant