Skip to content

Commit

Permalink
Remove additional files from shortenedFiles (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
steinybot committed Jul 29, 2024
1 parent ab30985 commit f601d46
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ object LibTsSource {
def fromFileEntry(fromFolder: LibTsSource.FromFolder, files: Option[IArray[String]]): IArray[InFile] =
files.getOrElse(IArray.Empty).mapNotNone(file => LibraryResolver.file(fromFolder.folder, file))

def fromFilesGlobEntry(fromFolder: LibTsSource.FromFolder, globs: Option[IArray[String]]): IArray[InFile] = {
val baseDirectory = fromFolder.folder.path
val files = globs.fold(os.walk(baseDirectory))(GlobWalker.walkFiles(baseDirectory, _)).map(InFile(_))
IArray.fromTraversable(files)
}

def fromModuleDeclaration(
fromFolder: LibTsSource.FromFolder,
files: Option[Map[String, String]],
Expand All @@ -80,13 +74,8 @@ object LibTsSource {
fromTypingsJson(f, f.packageJsonOpt.flatMap(_.parsedTypings)),
).flatten

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

val filesTypings = fromFilesGlobEntry(f, f.packageJsonOpt.flatMap(_.files))

(mainTypings ++ filesTypings).distinct
if (fromTypings.nonEmpty) fromTypings
else fromModuleDeclaration(f, f.packageJsonOpt.flatMap(_.parsedModules))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package importer

import com.olvind.logging.{Formatter, Logger}
import org.scalablytyped.converter.Selection
import org.scalablytyped.converter.internal.importer.Phase1ReadTypescript.fromFilesGlobEntry
import org.scalablytyped.converter.internal.maps._
import org.scalablytyped.converter.internal.phases.{GetDeps, IsCircular, Phase, PhaseRes}
import org.scalablytyped.converter.internal.ts.TsTreeScope.LoopDetector
Expand Down Expand Up @@ -57,7 +58,8 @@ class Phase1ReadTypescript(
f.shortenedFiles
case f: LibTsSource.FromFolder =>
/* 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).distinct
val filesTypings = fromFilesGlobEntry(f, f.packageJsonOpt.flatMap(_.files))
val bound = (f.shortenedFiles ++ filesTypings).map(_.folder)
val boundOrParent = if (bound.isEmpty) IArray(f.folder) else bound
boundOrParent.flatMap(PathsFromTsLibSource.filesFrom).distinct
}
Expand Down Expand Up @@ -342,4 +344,10 @@ object Phase1ReadTypescript {
T.VarToNamespace // after ExtractClasses
).visitTsParsedFile(scope.caching),
)

private def fromFilesGlobEntry(fromFolder: LibTsSource.FromFolder, globs: Option[IArray[String]]): IArray[InFile] = {
val baseDirectory = fromFolder.folder.path
val files = globs.fold(os.walk(baseDirectory))(GlobWalker.walkFiles(baseDirectory, _)).map(InFile(_))
IArray.fromTraversable(files)
}
}
2 changes: 1 addition & 1 deletion tests/stripe/check-3/s/stripe-js/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "stripe-js"
version := "4.1.0-e39ecd"
version := "4.1.0-f7b2da"
scalaVersion := "3.3.1"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
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 distMod {

@JSImport("stripe-js/dist", 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)
}
}
}
}
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
@@ -1,6 +1,8 @@
package typings.stripeJs

import typings.stripeJs.anon.SetLoadParameters
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}
Expand All @@ -11,98 +13,9 @@ object mod {
@js.native
val ^ : js.Any = js.native

@JSImport("stripe-js", "loadStripe")
@js.native
val loadStripe: (/* import warning: importer.ImportType#apply Failed type conversion: typeof _loadStripe */ js.Any) & SetLoadParameters = 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]]

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)
}
}

object global {

trait Window extends StObject {
Expand Down

0 comments on commit f601d46

Please sign in to comment.