GithubHelp home page GithubHelp logo

detective-typescript's Issues

Publish in NPM registry

Hi there,

the README.md suggests running

npm install detective-typescript

Unfortunately there is no such package in the npmjs.com registry.

Could you please publish it or redirect me to the correct package?

Thanks!

wonderful with ts files but breaks w/ tsx files

thank you for this excellent tool :)

I've been using this with a typescript application and today I added a tsx file and found that detective-typescript throws an error which looks like this,

{ index: 727,
  lineNumber: 48,
  column: 14,
  message: '\'>\' expected.' }

what is the best way to resolve this? will you publish this module to npm?

Support ESM typescript modules

If your tsconfig.json has "module": "ES2020" or later (e.g you are outputting ESM and not CJS), TypeScript doesn't rewrite import './foo' to import './foo.js' in the transpiled output - instead you have to use import './foo.js' in your .ts file.

This module then breaks because it (quite reasonably) detects './foo.js' as a dependency which of course doesn't exist.

I've hacked round it by replacing the file extension here and here but it doesn't take into account if ./foo.js does actually exist and that's what you meant to import. I don't know the AST well enough to make that change, but a simple fs.existsSync should be enough?

Another workaround is to run the dep checker over the transpiled output instead of the ts source, but then you lose any import type declarations, so it's not ideal.

Refs: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#type-in-package-json-and-new-extensions

Add support for es6 import specifier details

Currently, given an import such as import { Foo, Bar } from './utilities', the returned dependencies will only give ['utilities'], and no other details about what specifically was imported.

For example, the previous import in the page.ts file:

// Directory Structure
├── page.ts
└── utilities
    ├── index.ts
    ├── foo.ts
    ├── bar.ts
    └── baz.ts

// utilities/index.ts
export * from './foo'
export * from './bar'
export * from './baz'

These details would be incredibly useful in other places such as dependency-tree so that the specific imports could be traced.

Currently when getting the dependencies for page.ts it would be utilities/index.ts, and utilities/index.ts would depend on foo, bar, and baz. This gives the appearance that page.ts depends on foo, bar, and baz, even though it only imports Foo and Bar.

I would be happy to PR this improvement to this package if this is an acceptable addition. When implementing it, I would add an opt-in config option to retrieve the extra import declaration data, and then pass it to the onAfterFile callback for use in other locations.

Fails to recognize import expressions

In some situations the detective fails to recognize ImportExpression (import('...')) that imports a tsx file. In that case the imports that are inside the file that got imported by that expression are not recognised.

Repository to reproduce the issue:
https://github.com/leanazulyoro/test_depscheck

  1. npm install

  2. npm run deps:check
    It will fail with Fail! Modules in package.json not used in code: lodash even when lodash is imported in TestFile2.ts

  3. change the extension of TestFile.tsx to TestFile.ts and it works fine. So the issue might be in the @fatso83/detective-tsx package, that uses the typescript-detective's tsx version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.