Giter VIP home page Giter VIP logo

Comments (8)

Boshen avatar Boshen commented on June 10, 2024

It seems like we'll need to add a new @types lookup feature, to align with TypeScript's @types resolution.


I don't know anything about @types lookup, I can't even figure out how it goes from @google/maps to https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google__maps and not https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google-maps 😅

from oxc-resolver.

bradzacher avatar bradzacher commented on June 10, 2024

https://github.com/microsoft/TypeScript/blob/952dfc508256fea697aacc431edb81e3f23033b5/src/compiler/moduleNameResolver.ts#L3133-L3147

It looks like hard-coded behaviour.
TL;DR:

`@types/${packageName.startsWith('@') ? packageName.slice(1).replace('/', '__') : packageName}`

from oxc-resolver.

Boshen avatar Boshen commented on June 10, 2024

I think I can get this implemented if it's trivial:

  • add an option to enable @types lookup
  • do the naming conversion
  • do the resolution
  • return an extra field for @types resolution

from oxc-resolver.

Boshen avatar Boshen commented on June 10, 2024

Is it possible to create another resolver instance with the modules option pointing to the @types directory? I think @Dunqing figure it out somehow.

Here's a similar example to resolve tsconfig.json:

oxc-resolver/src/lib.rs

Lines 1061 to 1066 in 4226f7a

.clone_with_options(ResolveOptions {
description_files: vec![],
extensions: vec![".json".into()],
main_files: vec!["tsconfig.json".into()],
..ResolveOptions::default()
})

from oxc-resolver.

Dunqing avatar Dunqing commented on June 10, 2024

Is it possible to create another resolver instance with the modules option pointing to the @types directory? I think @Dunqing figure it out somehow.

I want to confirm the scope of this instance. Just resolve @types/* packages? Or for all packages, resolve out the corresponding type declarations.

Here are the different types of packages that I have listed

// no type declarations but has @types
import { LatLng } from '@google/maps'; // resolved path: file:///node_modules/@types/google__maps/index

// type only package
import {} from 'undici-types' // resolved path: file:///node_modules/undici-types/index

// both js source files and corresponding type declarations
import { } from 'vite' // resolved path: file:///node_modules/vite/dist/node/index

// js only package
import {} from 'js-only-pacakage' // resolved nothing

If that's what we're going to do, I think we can do a lot of linter rules about .d.ts

from oxc-resolver.

Boshen avatar Boshen commented on June 10, 2024

The resolution will return both the package path as well its types packages.

I was thinking about implementing this in user land, but seems a bit difficult after a second thought.

from oxc-resolver.

Dunqing avatar Dunqing commented on June 10, 2024

If my understanding is correct, I think we should do this

  • add an option to enable type resolution
  • try to look at types and typings fields in package.json if not do the @types lookup
  • do the resolution
  • return an extra field for type resolution

from oxc-resolver.

Sec-ant avatar Sec-ant commented on June 10, 2024

Just being curious, are ambient modules also in the scope of this issue/package?

image

from oxc-resolver.

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.