Code Monkey home page Code Monkey logo

Comments (4)

webpro avatar webpro commented on September 24, 2024

Actually, this path means

As you mentioned already, this is what it means to Webpack. Knip indeed does not copy all module resolution internals out there but has a generic solution.

Can I ask how knip can be configured to adapt to such a file path?

Regular module resolution should be fine, so I'd expect only the ./index.vue to be found an issue here, no? Unfortunately this can't be configured with Knip.

In general, I would recommend to go with more ES Modules-like semantics, i.e. don't rely on the dir/index lookup and don't omit the extension.

If it is not supported currently, if I want to develop the knip source code by fork repo, which function and file should I start with to modify the path finder code logic?

  1. Some work has been done recently to try and see if custom module resolution is feasible. In #126 a solution for React Native/Metro is discussed, and a working version has been published. That idea could probably be used to cover the use case you are describing as well, maybe by exporting a module resolver from the Webpack plugin. If that effort continues, I'm not yet sure yet how it should be configured. It's in the feat/react-native-metro branch of this repo and most of the work is in this commit: bdae3d6).

  2. If you're still interested in forking and modifying the current implementation yourself you can start here: https://github.com/webpro/knip/blob/main/packages/knip/src/typescript/resolveModuleNames.ts.

from knip.

fatyrify avatar fatyrify commented on September 24, 2024

Thanks for the reply.

Regular module resolution should be fine, so I'd expect only the ./index.vue to be found an issue here

I checked the knip execution results and found that **/index.js or **/index.vue were both output as unused files, (both path omit index.js | index.vue)

It's in the feat/react-native-metro branch of this repo and most of the work is in this commit: bdae3d6).

I looked at this part and tried using "knip": "^0.0.0-metro.1", and this is my metro.config.js configuration

module.exports.__KNIP_PLATFORMS__ = {
    vue: [
        ['/index', ''],
        ['.vue', ''],
    ],
    js: [
        ['/index', ''],
        ['.js', ''],
    ],
    ts: [
        ['/index', ''],
        ['.ts', ''],
    ],
};

and this is my knip.json configuration

{
    "entry": ["src/index.js"],
    "project": ["src/**/*.{js,jsx,ts,tsx,vue}"],
    "paths": {
        "@/*": ["src/*"]
    },
    "includeEntryExports": true,
    "exclude": ["dependencies", "unlisted", "unresolved", "enumMembers", "types", "exports"]
}

The analysis results are still not within expectations, and more .vue files appear in unused files
I don't know whether the problem is caused by the missing extension of .vue or the problem caused by omitting index.vue. I need to keep researching this.

I will also take the time to look at the source code you mentioned above.

Thanks

from knip.

webpro avatar webpro commented on September 24, 2024

The analysis results are still not within expectations

The module resolver in the Metro plugin is indeed not what you need to suit your needs with your Webpack setup. It does not cater for omitted extensions (because I think it's not needed there). Sorry if that was confusing. I was saying that we would need a new module resolver in the Webpack plugin.

from knip.

fatyrify avatar fatyrify commented on September 24, 2024

Sorry if that was confusing

It's ok :)

I was saying that we would need a new module resolver in the Webpack plugin.

Yeah, this may be the solution

from knip.

Related Issues (20)

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.