Skip to content

Commit

Permalink
Fix issue with imports from sibling to main typings (ScalablyTyped#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
steinybot committed Jul 28, 2024
1 parent e3d39fb commit 5fb57cb
Show file tree
Hide file tree
Showing 16 changed files with 299 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,17 @@ object LibTsSource {
fromTypingsJson(f, f.packageJsonOpt.flatMap(_.parsedTypings)),
).flatten

if (fromTypings.nonEmpty) fromTypings
else fromModuleDeclaration(f, f.packageJsonOpt.flatMap(_.parsedModules))
val mainTypings =
if (fromTypings.nonEmpty) fromTypings
else fromModuleDeclaration(f, f.packageJsonOpt.flatMap(_.parsedModules))

// This used to only find files from the types and typings fields but that is far too limited.
// At the very least we need to also include any types specified in the files field.
// FIXME: The files field includes file patterns but this assumes that they are all files/folders pointing to
// modules.
val filesTypings = fromFileEntry(f, f.packageJsonOpt.flatMap(_.files))

(mainTypings ++ filesTypings).distinct
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class Phase1ReadTypescript(
/* don't include std */
f.shortenedFiles
case f: LibTsSource.FromFolder =>
/* 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)
/* There are often whole trees parallel to what is specified in `typings` (or similar). This ignores some of them. */
val bound = f.shortenedFiles.map(_.folder)
val boundOrParent = if (bound.isEmpty) IArray(f.folder) else bound
boundOrParent.flatMap(PathsFromTsLibSource.filesFrom).distinct
}

val includedViaDirective = mutable.Set.empty[InFile]
Expand Down
10 changes: 10 additions & 0 deletions tests/stripe/check-3/s/std/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
organization := "org.scalablytyped"
name := "std"
version := "0.0-unknown-5a9d90"
scalaVersion := "3.3.1"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.olvind" %%% "scalablytyped-runtime" % "2.4.2")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future")
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
1 change: 1 addition & 0 deletions tests/stripe/check-3/s/std/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.6
1 change: 1 addition & 0 deletions tests/stripe/check-3/s/std/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.11.0")
15 changes: 15 additions & 0 deletions tests/stripe/check-3/s/std/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Scala.js typings for std




## Note
This library has been generated from typescript code from first party type definitions.

Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped)

## Usage
See [the main readme](../../readme.md) for instructions.


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package typings.std

import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

trait Array[T] extends StObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package typings.std

import scala.concurrent.Future
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

trait Promise[T] extends StObject
object Promise {

@scala.inline
implicit open class PromiseOps[T] (val promise: Promise[T]) extends AnyVal {

def toFuture: Future[T] = toPromise.toFuture

def toPromise: js.Promise[T] = promise.asInstanceOf[js.Promise[T]]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package typings.std

import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

/* This can be used to `require` the library as a side effect.
If it is a global library this will make scalajs-bundler include it */
@JSImport("std", JSImport.Namespace)
@js.native
object stdRequire extends StObject
5 changes: 3 additions & 2 deletions tests/stripe/check-3/s/stripe-js/build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
organization := "org.scalablytyped"
name := "stripe-js"
version := "4.1.0-084381"
version := "4.1.0-a4332d"
scalaVersion := "3.3.1"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.olvind" %%% "scalablytyped-runtime" % "2.4.2")
"com.olvind" %%% "scalablytyped-runtime" % "2.4.2",
"org.scalablytyped" %%% "std" % "0.0-unknown-5a9d90")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future")
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package typings.stripeJs

import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object anon {

trait AdvancedFraudSignals extends StObject {

var advancedFraudSignals: Boolean
}
object AdvancedFraudSignals {

inline def apply(advancedFraudSignals: Boolean): AdvancedFraudSignals = {
val __obj = js.Dynamic.literal(advancedFraudSignals = advancedFraudSignals.asInstanceOf[js.Any])
__obj.asInstanceOf[AdvancedFraudSignals]
}

@scala.inline
implicit open class MutableBuilder[Self <: AdvancedFraudSignals] (val x: Self) extends AnyVal {

inline def setAdvancedFraudSignals(value: Boolean): Self = StObject.set(x, "advancedFraudSignals", value.asInstanceOf[js.Any])
}
}

trait SetLoadParameters extends StObject {

def setLoadParameters(params: AdvancedFraudSignals): Unit
}
object SetLoadParameters {

inline def apply(setLoadParameters: AdvancedFraudSignals => Unit): SetLoadParameters = {
val __obj = js.Dynamic.literal(setLoadParameters = js.Any.fromFunction1(setLoadParameters))
__obj.asInstanceOf[SetLoadParameters]
}

@scala.inline
implicit open class MutableBuilder[Self <: SetLoadParameters] (val x: Self) extends AnyVal {

inline def setSetLoadParameters(value: AdvancedFraudSignals => Unit): Self = StObject.set(x, "setLoadParameters", js.Any.fromFunction1(value))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package typings.stripeJs

import typings.stripeJs.anon.SetLoadParameters
import typings.stripeJs.distStripeJsStripeMod.Stripe
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object distPureMod {

@JSImport("stripe-js/dist/pure", "loadStripe")
@js.native
val loadStripe: (js.Function2[
/* publishableKey */ String,
/* options */ js.UndefOr[StripeConstructorOptions],
js.Promise[Stripe | Null]
]) & SetLoadParameters = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package typings.stripeJs

import typings.stripeJs.distStripeJsStripeMod.Stripe
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object distSharedMod {

@JSImport("stripe-js/dist/shared", JSImport.Namespace)
@js.native
val ^ : js.Any = js.native

inline def loadStripe(publishableKey: String): js.Promise[Stripe | Null] = ^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any]).asInstanceOf[js.Promise[Stripe | Null]]
inline def loadStripe(publishableKey: String, options: StripeConstructorOptions): js.Promise[Stripe | Null] = (^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any], options.asInstanceOf[js.Any])).asInstanceOf[js.Promise[Stripe | Null]]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package typings.stripeJs

import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object distStripeJsStripeMod {

trait Stripe extends StObject {

def foo(): Unit
}
object Stripe {

inline def apply(foo: () => Unit): Stripe = {
val __obj = js.Dynamic.literal(foo = js.Any.fromFunction0(foo))
__obj.asInstanceOf[Stripe]
}

@scala.inline
implicit open class MutableBuilder[Self <: Stripe] (val x: Self) extends AnyVal {

inline def setFoo(value: () => Unit): Self = StObject.set(x, "foo", js.Any.fromFunction0(value))
}
}

type StripeConstructor = js.Function2[
/* publishableKey */ String,
/* options */ js.UndefOr[StripeConstructorOptions],
Stripe
]

trait StripeConstructorOptions extends StObject {

/**
* Override your account's [API version](https://stripe.com/docs/api/versioning).
*/
var apiVersion: js.UndefOr[String] = js.undefined

/**
* Opt-in to prerelease Stripe.js features by passing `betas` when instantiating a `Stripe` object.
*
* Supported values for the `betas` option can be found in integration guides for prerelease features.
* Most users of Stripe.js do not pass this option.
*/
var betas: js.UndefOr[js.Array[String]] = js.undefined

/**
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) used to globally configure localization in Stripe.js.
* Setting the locale here will localize error strings for all Stripe.js methods.
* It will also configure the locale for [Elements](#element_mount) and [Checkout](https://stripe.com/docs/js/checkout/redirect_to_checkout). Default is `auto` (Stripe detects the locale of the browser).
*
* Supported values depend on which features you are using.
* Checkout supports a slightly different set of locales than the rest of Stripe.js.
* If you are planning on using Checkout, make sure to use a [value](#checkout_redirect_to_checkout-options-locale) that it supports.
*/
var locale: js.UndefOr[String] = js.undefined

/**
* For usage with [Connect](https://stripe.com/docs/connect) only.
* Specifying a connected account ID (e.g., `acct_24BFMpJ1svR5A89k`) allows you to perform actions on behalf of that account.
*/
var stripeAccount: js.UndefOr[String] = js.undefined
}
object StripeConstructorOptions {

inline def apply(): StripeConstructorOptions = {
val __obj = js.Dynamic.literal()
__obj.asInstanceOf[StripeConstructorOptions]
}

@scala.inline
implicit open class MutableBuilder[Self <: StripeConstructorOptions] (val x: Self) extends AnyVal {

inline def setApiVersion(value: String): Self = StObject.set(x, "apiVersion", value.asInstanceOf[js.Any])

inline def setApiVersionUndefined: Self = StObject.set(x, "apiVersion", js.undefined)

inline def setBetas(value: js.Array[String]): Self = StObject.set(x, "betas", value.asInstanceOf[js.Any])

inline def setBetasUndefined: Self = StObject.set(x, "betas", js.undefined)

inline def setBetasVarargs(value: String*): Self = StObject.set(x, "betas", js.Array(value*))

inline def setLocale(value: String): Self = StObject.set(x, "locale", value.asInstanceOf[js.Any])

inline def setLocaleUndefined: Self = StObject.set(x, "locale", js.undefined)

inline def setStripeAccount(value: String): Self = StObject.set(x, "stripeAccount", value.asInstanceOf[js.Any])

inline def setStripeAccountUndefined: Self = StObject.set(x, "stripeAccount", js.undefined)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package typings.stripeJs

import typings.stripeJs.distStripeJsStripeMod.Stripe
import typings.stripeJs.distStripeJsStripeMod.StripeConstructor
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object mod {

@JSImport("stripe-js", JSImport.Namespace)
@js.native
val ^ : js.Any = js.native

inline def loadStripe(publishableKey: String): js.Promise[Stripe | Null] = ^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any]).asInstanceOf[js.Promise[Stripe | Null]]
inline def loadStripe(publishableKey: String, options: StripeConstructorOptions): js.Promise[Stripe | Null] = (^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any], options.asInstanceOf[js.Any])).asInstanceOf[js.Promise[Stripe | Null]]

object global {

trait Window extends StObject {

// Stripe.js must be loaded directly from https://js.stripe.com/v3, which
// places a `Stripe` object on the window
var Stripe: js.UndefOr[StripeConstructor] = js.undefined
}
object Window {

inline def apply(): Window = {
val __obj = js.Dynamic.literal()
__obj.asInstanceOf[Window]
}

@scala.inline
implicit open class MutableBuilder[Self <: Window] (val x: Self) extends AnyVal {

inline def setStripe(value: (/* publishableKey */ String, /* options */ js.UndefOr[StripeConstructorOptions]) => Stripe): Self = StObject.set(x, "Stripe", js.Any.fromFunction2(value))

inline def setStripeUndefined: Self = StObject.set(x, "Stripe", js.undefined)
}
}
}
}
5 changes: 1 addition & 4 deletions tests/stripe/in/stripe-js/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//export * from '../dist';

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

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

Expand Down

0 comments on commit 5fb57cb

Please sign in to comment.