Skip to content

Commit 20f0939

Browse files
committed
Remove additional files from shortenedFiles (#638)
1 parent 16861a5 commit 20f0939

File tree

8 files changed

+188
-105
lines changed

8 files changed

+188
-105
lines changed

importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/LibTsSource.scala

+2-13
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ object LibTsSource {
4848
def fromFileEntry(fromFolder: LibTsSource.FromFolder, files: Option[IArray[String]]): IArray[InFile] =
4949
files.getOrElse(IArray.Empty).mapNotNone(file => LibraryResolver.file(fromFolder.folder, file))
5050

51-
def fromFilesGlobEntry(fromFolder: LibTsSource.FromFolder, globs: Option[IArray[String]]): IArray[InFile] = {
52-
val baseDirectory = fromFolder.folder.path
53-
val files = globs.fold(os.walk(baseDirectory))(GlobWalker.walkFiles(baseDirectory, _)).map(InFile(_))
54-
IArray.fromTraversable(files)
55-
}
56-
5751
def fromModuleDeclaration(
5852
fromFolder: LibTsSource.FromFolder,
5953
files: Option[Map[String, String]],
@@ -80,13 +74,8 @@ object LibTsSource {
8074
fromTypingsJson(f, f.packageJsonOpt.flatMap(_.parsedTypings)),
8175
).flatten
8276

83-
val mainTypings =
84-
if (fromTypings.nonEmpty) fromTypings
85-
else fromModuleDeclaration(f, f.packageJsonOpt.flatMap(_.parsedModules))
86-
87-
val filesTypings = fromFilesGlobEntry(f, f.packageJsonOpt.flatMap(_.files))
88-
89-
(mainTypings ++ filesTypings).distinct
77+
if (fromTypings.nonEmpty) fromTypings
78+
else fromModuleDeclaration(f, f.packageJsonOpt.flatMap(_.parsedModules))
9079
}
9180
}
9281
}

importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package importer
33

44
import com.olvind.logging.{Formatter, Logger}
55
import org.scalablytyped.converter.Selection
6+
import org.scalablytyped.converter.internal.importer.Phase1ReadTypescript.fromFilesGlobEntry
67
import org.scalablytyped.converter.internal.maps._
78
import org.scalablytyped.converter.internal.phases.{GetDeps, IsCircular, Phase, PhaseRes}
89
import org.scalablytyped.converter.internal.ts.TsTreeScope.LoopDetector
@@ -57,7 +58,8 @@ class Phase1ReadTypescript(
5758
f.shortenedFiles
5859
case f: LibTsSource.FromFolder =>
5960
/* There are often whole trees parallel to what is specified in `typings` (or similar). This ignores some of them. */
60-
val bound = f.shortenedFiles.map(_.folder).distinct
61+
val filesTypings = fromFilesGlobEntry(f, f.packageJsonOpt.flatMap(_.files))
62+
val bound = (f.shortenedFiles ++ filesTypings).map(_.folder)
6163
val boundOrParent = if (bound.isEmpty) IArray(f.folder) else bound
6264
boundOrParent.flatMap(PathsFromTsLibSource.filesFrom).distinct
6365
}
@@ -342,4 +344,10 @@ object Phase1ReadTypescript {
342344
T.VarToNamespace // after ExtractClasses
343345
).visitTsParsedFile(scope.caching),
344346
)
347+
348+
private def fromFilesGlobEntry(fromFolder: LibTsSource.FromFolder, globs: Option[IArray[String]]): IArray[InFile] = {
349+
val baseDirectory = fromFolder.folder.path
350+
val files = globs.fold(os.walk(baseDirectory))(GlobWalker.walkFiles(baseDirectory, _)).map(InFile(_))
351+
IArray.fromTraversable(files)
352+
}
345353
}

tests/stripe/check-3/s/stripe-js/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
organization := "org.scalablytyped"
22
name := "stripe-js"
3-
version := "4.1.0-e39ecd"
3+
version := "4.1.0-f7b2da"
44
scalaVersion := "3.3.1"
55
enablePlugins(ScalaJSPlugin)
66
libraryDependencies ++= Seq(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package typings.stripeJs
2+
3+
import typings.stripeJs.distStripeJsStripeMod.Stripe
4+
import typings.stripeJs.distStripeJsStripeMod.StripeConstructor
5+
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
6+
import org.scalablytyped.runtime.StObject
7+
import scala.scalajs.js
8+
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}
9+
10+
object distMod {
11+
12+
@JSImport("stripe-js/dist", JSImport.Namespace)
13+
@js.native
14+
val ^ : js.Any = js.native
15+
16+
inline def loadStripe(publishableKey: String): js.Promise[Stripe | Null] = ^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any]).asInstanceOf[js.Promise[Stripe | Null]]
17+
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]]
18+
19+
object global {
20+
21+
trait Window extends StObject {
22+
23+
// Stripe.js must be loaded directly from https://js.stripe.com/v3, which
24+
// places a `Stripe` object on the window
25+
var Stripe: js.UndefOr[StripeConstructor] = js.undefined
26+
}
27+
object Window {
28+
29+
inline def apply(): Window = {
30+
val __obj = js.Dynamic.literal()
31+
__obj.asInstanceOf[Window]
32+
}
33+
34+
@scala.inline
35+
implicit open class MutableBuilder[Self <: Window] (val x: Self) extends AnyVal {
36+
37+
inline def setStripe(value: (/* publishableKey */ String, /* options */ js.UndefOr[StripeConstructorOptions]) => Stripe): Self = StObject.set(x, "Stripe", js.Any.fromFunction2(value))
38+
39+
inline def setStripeUndefined: Self = StObject.set(x, "Stripe", js.undefined)
40+
}
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package typings.stripeJs
2+
3+
import typings.stripeJs.anon.SetLoadParameters
4+
import typings.stripeJs.distStripeJsStripeMod.Stripe
5+
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
6+
import org.scalablytyped.runtime.StObject
7+
import scala.scalajs.js
8+
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}
9+
10+
object distPureMod {
11+
12+
@JSImport("stripe-js/dist/pure", "loadStripe")
13+
@js.native
14+
val loadStripe: (js.Function2[
15+
/* publishableKey */ String,
16+
/* options */ js.UndefOr[StripeConstructorOptions],
17+
js.Promise[Stripe | Null]
18+
]) & SetLoadParameters = js.native
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package typings.stripeJs
2+
3+
import typings.stripeJs.distStripeJsStripeMod.Stripe
4+
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
5+
import org.scalablytyped.runtime.StObject
6+
import scala.scalajs.js
7+
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}
8+
9+
object distSharedMod {
10+
11+
@JSImport("stripe-js/dist/shared", JSImport.Namespace)
12+
@js.native
13+
val ^ : js.Any = js.native
14+
15+
inline def loadStripe(publishableKey: String): js.Promise[Stripe | Null] = ^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any]).asInstanceOf[js.Promise[Stripe | Null]]
16+
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]]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package typings.stripeJs
2+
3+
import org.scalablytyped.runtime.StObject
4+
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}
6+
7+
object distStripeJsStripeMod {
8+
9+
trait Stripe extends StObject {
10+
11+
def foo(): Unit
12+
}
13+
object Stripe {
14+
15+
inline def apply(foo: () => Unit): Stripe = {
16+
val __obj = js.Dynamic.literal(foo = js.Any.fromFunction0(foo))
17+
__obj.asInstanceOf[Stripe]
18+
}
19+
20+
@scala.inline
21+
implicit open class MutableBuilder[Self <: Stripe] (val x: Self) extends AnyVal {
22+
23+
inline def setFoo(value: () => Unit): Self = StObject.set(x, "foo", js.Any.fromFunction0(value))
24+
}
25+
}
26+
27+
type StripeConstructor = js.Function2[
28+
/* publishableKey */ String,
29+
/* options */ js.UndefOr[StripeConstructorOptions],
30+
Stripe
31+
]
32+
33+
trait StripeConstructorOptions extends StObject {
34+
35+
/**
36+
* Override your account's [API version](https://stripe.com/docs/api/versioning).
37+
*/
38+
var apiVersion: js.UndefOr[String] = js.undefined
39+
40+
/**
41+
* Opt-in to prerelease Stripe.js features by passing `betas` when instantiating a `Stripe` object.
42+
*
43+
* Supported values for the `betas` option can be found in integration guides for prerelease features.
44+
* Most users of Stripe.js do not pass this option.
45+
*/
46+
var betas: js.UndefOr[js.Array[String]] = js.undefined
47+
48+
/**
49+
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) used to globally configure localization in Stripe.js.
50+
* Setting the locale here will localize error strings for all Stripe.js methods.
51+
* 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).
52+
*
53+
* Supported values depend on which features you are using.
54+
* Checkout supports a slightly different set of locales than the rest of Stripe.js.
55+
* If you are planning on using Checkout, make sure to use a [value](#checkout_redirect_to_checkout-options-locale) that it supports.
56+
*/
57+
var locale: js.UndefOr[String] = js.undefined
58+
59+
/**
60+
* For usage with [Connect](https://stripe.com/docs/connect) only.
61+
* Specifying a connected account ID (e.g., `acct_24BFMpJ1svR5A89k`) allows you to perform actions on behalf of that account.
62+
*/
63+
var stripeAccount: js.UndefOr[String] = js.undefined
64+
}
65+
object StripeConstructorOptions {
66+
67+
inline def apply(): StripeConstructorOptions = {
68+
val __obj = js.Dynamic.literal()
69+
__obj.asInstanceOf[StripeConstructorOptions]
70+
}
71+
72+
@scala.inline
73+
implicit open class MutableBuilder[Self <: StripeConstructorOptions] (val x: Self) extends AnyVal {
74+
75+
inline def setApiVersion(value: String): Self = StObject.set(x, "apiVersion", value.asInstanceOf[js.Any])
76+
77+
inline def setApiVersionUndefined: Self = StObject.set(x, "apiVersion", js.undefined)
78+
79+
inline def setBetas(value: js.Array[String]): Self = StObject.set(x, "betas", value.asInstanceOf[js.Any])
80+
81+
inline def setBetasUndefined: Self = StObject.set(x, "betas", js.undefined)
82+
83+
inline def setBetasVarargs(value: String*): Self = StObject.set(x, "betas", js.Array(value*))
84+
85+
inline def setLocale(value: String): Self = StObject.set(x, "locale", value.asInstanceOf[js.Any])
86+
87+
inline def setLocaleUndefined: Self = StObject.set(x, "locale", js.undefined)
88+
89+
inline def setStripeAccount(value: String): Self = StObject.set(x, "stripeAccount", value.asInstanceOf[js.Any])
90+
91+
inline def setStripeAccountUndefined: Self = StObject.set(x, "stripeAccount", js.undefined)
92+
}
93+
}
94+
}

tests/stripe/check-3/s/stripe-js/src/main/scala/typings/stripeJs/mod.scala

+3-90
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package typings.stripeJs
22

3-
import typings.stripeJs.anon.SetLoadParameters
3+
import typings.stripeJs.distStripeJsStripeMod.Stripe
4+
import typings.stripeJs.distStripeJsStripeMod.StripeConstructor
5+
import typings.stripeJs.distStripeJsStripeMod.StripeConstructorOptions
46
import org.scalablytyped.runtime.StObject
57
import scala.scalajs.js
68
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}
@@ -11,98 +13,9 @@ object mod {
1113
@js.native
1214
val ^ : js.Any = js.native
1315

14-
@JSImport("stripe-js", "loadStripe")
15-
@js.native
16-
val loadStripe: (/* import warning: importer.ImportType#apply Failed type conversion: typeof _loadStripe */ js.Any) & SetLoadParameters = js.native
1716
inline def loadStripe(publishableKey: String): js.Promise[Stripe | Null] = ^.asInstanceOf[js.Dynamic].applyDynamic("loadStripe")(publishableKey.asInstanceOf[js.Any]).asInstanceOf[js.Promise[Stripe | Null]]
1817
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]]
1918

20-
trait Stripe extends StObject {
21-
22-
def foo(): Unit
23-
}
24-
object Stripe {
25-
26-
inline def apply(foo: () => Unit): Stripe = {
27-
val __obj = js.Dynamic.literal(foo = js.Any.fromFunction0(foo))
28-
__obj.asInstanceOf[Stripe]
29-
}
30-
31-
@scala.inline
32-
implicit open class MutableBuilder[Self <: Stripe] (val x: Self) extends AnyVal {
33-
34-
inline def setFoo(value: () => Unit): Self = StObject.set(x, "foo", js.Any.fromFunction0(value))
35-
}
36-
}
37-
38-
type StripeConstructor = js.Function2[
39-
/* publishableKey */ String,
40-
/* options */ js.UndefOr[StripeConstructorOptions],
41-
Stripe
42-
]
43-
44-
trait StripeConstructorOptions extends StObject {
45-
46-
/**
47-
* Override your account's [API version](https://stripe.com/docs/api/versioning).
48-
*/
49-
var apiVersion: js.UndefOr[String] = js.undefined
50-
51-
/**
52-
* Opt-in to prerelease Stripe.js features by passing `betas` when instantiating a `Stripe` object.
53-
*
54-
* Supported values for the `betas` option can be found in integration guides for prerelease features.
55-
* Most users of Stripe.js do not pass this option.
56-
*/
57-
var betas: js.UndefOr[js.Array[String]] = js.undefined
58-
59-
/**
60-
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) used to globally configure localization in Stripe.js.
61-
* Setting the locale here will localize error strings for all Stripe.js methods.
62-
* 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).
63-
*
64-
* Supported values depend on which features you are using.
65-
* Checkout supports a slightly different set of locales than the rest of Stripe.js.
66-
* If you are planning on using Checkout, make sure to use a [value](#checkout_redirect_to_checkout-options-locale) that it supports.
67-
*/
68-
var locale: js.UndefOr[String] = js.undefined
69-
70-
/**
71-
* For usage with [Connect](https://stripe.com/docs/connect) only.
72-
* Specifying a connected account ID (e.g., `acct_24BFMpJ1svR5A89k`) allows you to perform actions on behalf of that account.
73-
*/
74-
var stripeAccount: js.UndefOr[String] = js.undefined
75-
}
76-
object StripeConstructorOptions {
77-
78-
inline def apply(): StripeConstructorOptions = {
79-
val __obj = js.Dynamic.literal()
80-
__obj.asInstanceOf[StripeConstructorOptions]
81-
}
82-
83-
@scala.inline
84-
implicit open class MutableBuilder[Self <: StripeConstructorOptions] (val x: Self) extends AnyVal {
85-
86-
inline def setApiVersion(value: String): Self = StObject.set(x, "apiVersion", value.asInstanceOf[js.Any])
87-
88-
inline def setApiVersionUndefined: Self = StObject.set(x, "apiVersion", js.undefined)
89-
90-
inline def setBetas(value: js.Array[String]): Self = StObject.set(x, "betas", value.asInstanceOf[js.Any])
91-
92-
inline def setBetasUndefined: Self = StObject.set(x, "betas", js.undefined)
93-
94-
inline def setBetasVarargs(value: String*): Self = StObject.set(x, "betas", js.Array(value*))
95-
96-
inline def setLocale(value: String): Self = StObject.set(x, "locale", value.asInstanceOf[js.Any])
97-
98-
inline def setLocaleUndefined: Self = StObject.set(x, "locale", js.undefined)
99-
100-
inline def setStripeAccount(value: String): Self = StObject.set(x, "stripeAccount", value.asInstanceOf[js.Any])
101-
102-
inline def setStripeAccountUndefined: Self = StObject.set(x, "stripeAccount", js.undefined)
103-
}
104-
}
105-
10619
object global {
10720

10821
trait Window extends StObject {

0 commit comments

Comments
 (0)