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

Importing @stripe/stripe-js generates no types #638

Open
steinybot opened this issue Jul 25, 2024 · 9 comments · May be fixed by #639
Open

Importing @stripe/stripe-js generates no types #638

steinybot opened this issue Jul 25, 2024 · 9 comments · May be fixed by #639

Comments

@steinybot
Copy link
Contributor

importing "@stripe/stripe-js" -> "4.1.0" does not generate any types (besides stripeStripeJsRequire).

The package.json has:

  "types": "lib/index.d.ts",

and lib/index.d.ts has:

export * from '../dist';

It looks to me like the issue is here:

ModuleNameParser(
source.libName.`__value` +: file.path.relativeTo(source.folder.path).segments.to[List],
keepIndexPath,
)

file.path is /Users/jason/src/ScalablyTyped/Converter/tests/stripe/in/dist/index.d.ts
source.folder.path is /Users/jason/src/ScalablyTyped/Converter/tests/stripe/in/lib
relativeTo returns ../dist/index.d.ts but the segments doesn't contain the .. it is only ["dist", "index.d.ts"] so the result is IArray(TsIdentModule(None,List(lib, dist))) which is wrong.

@steinybot
Copy link
Contributor Author

I think it might need to be something like:

      val relative = file.path.relativeTo(source.folder.path)
      val ups = List.fill(relative.ups)("..")
      val downs = relative.segments.toList

      ModuleNameParser(
        source.libName.`__value` +: ups ++: downs,
        keepIndexPath,
      )

That is assuming that the .. segments are handled correctly.

@steinybot
Copy link
Contributor Author

Ah nope that doesn't work.

Maybe this?

      val relative = file.path.relativeTo(source.folder.path)
      val downs = relative.segments.toList
      val fragments = relative.ups match {
        case 0 => source.libName.`__value` +: downs
        case 1 => downs
        case _ => ???
      }

      ModuleNameParser(fragments, keepIndexPath)

But now the scope.moduleScopes are wrong. They only have:

scope.moduleScopes = {Map$Map4@8516} size = 4
 0 = {Tuple2@8546} (TsIdentModule(None,List(lib)),TreeScope(TsParsedFile() / TsDeclModule(lib)))
 1 = {Tuple2@8547} (TsIdentModule(None,List(es, index)),TreeScope(TsParsedFile() / TsDeclModule(lib)))
 2 = {Tuple2@8548} (TsIdentModule(None,List(es)),TreeScope(TsParsedFile() / TsDeclModule(lib)))
 3 = {Tuple2@8549} (TsIdentModule(None,List(lib, index)),TreeScope(TsParsedFile() / TsDeclModule(lib)))

@steinybot
Copy link
Contributor Author

Hmm lib and dist are being treated as different roots. I would have thought . would be the root of both of them.

@steinybot
Copy link
Contributor Author

Oh wait is this issue with moduleScopes just an ImporterHarness problem? It is creating a separate LibTsSource and running the full phase on each one individually. I'll try publish the fix locally and see if it fixes my stripe import issue.

@steinybot
Copy link
Contributor Author

Surely relative imports must work...

I tried:

import {loadStripe} from '../dist';
export {loadStripe};

but org.scalablytyped.converter.internal.ts.modules.Exports#expandExport fails for that.

@steinybot
Copy link
Contributor Author

steinybot commented Jul 26, 2024

This also doesn't work:

import {StripeConstructor} from "../dist/stripe-js";

Local "modules" (they aren't separate modules) aren't considered dependencies?

/* Resolve all references to other modules in `from` clauses, rename modules */
val ResolveExternalReferences.Result(withExternals, resolvedModules, unresolvedModules) =
ResolveExternalReferences(resolve, source, file.folder, withInferredModule, logger)
resolvedModules.foreach {
case ResolvedModule.NotLocal(source, _) => deps += source
case _ => ()
}

@steinybot
Copy link
Contributor Author

This also doesn't work:

import {StripeConstructor} from "../dist/stripe-js";

declare global {
  interface Window {
    // Stripe.js must be loaded directly from https://js.stripe.com/v3, which
    // places a `Stripe` object on the window
    Stripe?: StripeConstructor;
  }
}

org.scalablytyped.converter.internal.ts.modules.Imports#lookupFromImports has chosenImport as TsImport(false,IArray(Destructured(IArray((TsIdentSimple(StripeConstructor),None)))),From(TsIdentModule(None,List(stripe-js, dist, stripe-js)))) which is weird. Why stripe-js/dist/stripe-js?

I realise this makes little sense without the test I am using. It is in steinybot@e3d39fb. Apologies for the ramblings. I'm attempting to document my process so that when I come back to it on Monday I know what I did.

@steinybot
Copy link
Contributor Author

steinybot commented Jul 26, 2024

stripe-js/dist/stripe-js is correct but it is another star export

@steinybot
Copy link
Contributor Author

steinybot commented Jul 28, 2024

This seems relevant.

/* There are often whole trees parallel to what is specified in `typings` (or similar). This ignores them */
val bound = f.shortenedFiles.headOption.map(_.folder).getOrElse(f.folder)
PathsFromTsLibSource.filesFrom(bound)

steinybot added a commit to steinybot/Converter that referenced this issue Jul 29, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Jul 29, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Jul 29, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Jul 29, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 7, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 7, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 7, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 7, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 7, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 8, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 12, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
steinybot added a commit to steinybot/Converter that referenced this issue Aug 13, 2024
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

Successfully merging a pull request may close this issue.

1 participant