Skip to content

Commit

Permalink
Merge pull request #163 from ScalablyTyped/split-hierarchies
Browse files Browse the repository at this point in the history
Hack to support libraries with split lib/es directories
  • Loading branch information
oyvindberg authored Jun 4, 2020
2 parents 019be3b + 0ac69dc commit fb98fcc
Show file tree
Hide file tree
Showing 23 changed files with 275 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ object LibraryResolver {
)
}

IArray.fromOptions(shortened, Some(longName))
val ret = IArray.fromOptions(shortened, Some(longName))

/* some libraries contain multiple directory trees with type definitions, and refer to just one of them through
* `typings` in package.json for instance.
*
* Remarkably it can reach into one of the other trees even if the current tree has everything needed.
* This resolves the most common case, and fixes antd 4 in particular */
val inParallelDirectory = ret.collect {
case TsIdentModule(scopeOpt, fragments) if fragments.contains("lib") =>
TsIdentModule(scopeOpt, fragments.map { case "lib" => "es"; case other => other })
case TsIdentModule(scopeOpt, fragments) if fragments.contains("es") =>
TsIdentModule(scopeOpt, fragments.map { case "es" => "lib"; case other => other })
}

ret ++ inParallelDirectory
}

def file(folder: InFolder, fragment: String): Option[InFile] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImporterTest extends AnyFunSuite with ImporterHarness with ParallelTestExe
test("firebase-admin")(assertImportsOk("firebase-admin", pedantic = true, update = update))
test("properties")(assertImportsOk("properties", pedantic = true, update = update))
test("keyof")(assertImportsOk("keyof", pedantic = true, update = update))
test("antd")(assertImportsOk("antd", pedantic = true, update = update))

test("material-ui-slinky")(
assertImportsOk("material-ui", pedantic = true, update = update, flavour = Slinky),
Expand Down
12 changes: 12 additions & 0 deletions tests/antd/check/a/antd/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
organization := "org.scalablytyped"
name := "antd"
version := "4.3.1-f3593d"
scalaVersion := "2.13.2"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.olvind" %%% "scalablytyped-runtime" % "2.1.0")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-g:notailcalls", "-language:implicitConversions", "-language:higherKinds", "-language:existentials")
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
bintrayRepository := "ScalablyTyped"
resolvers += Resolver.bintrayRepo("oyvindberg", "ScalablyTyped")
1 change: 1 addition & 0 deletions tests/antd/check/a/antd/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.10
2 changes: 2 additions & 0 deletions tests/antd/check/a/antd/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.1.0")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
16 changes: 16 additions & 0 deletions tests/antd/check/a/antd/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# Scala.js typings for antd

Typings are for version 4.3.1



## 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.


16 changes: 16 additions & 0 deletions tests/antd/check/a/antd/src/main/resources/NPM_DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compile-dependencies" : [
{
"antd" : "4.3.1"
}
],
"test-dependencies" : [
{
"antd" : "4.3.1"
}
],
"compile-devDependencies" : [
],
"test-devDependencies" : [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package typings.antd

import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation._

/* 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("antd", JSImport.Namespace)
@js.native
object antdRequire extends js.Object

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package typings.antd.mod

import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation._

/* Inlined parent std.Omit<rc-field-form.rc-field-form/es/Form.FormProps, 'form'> */
@js.native
trait FormProps extends js.Object {
var name: js.UndefOr[String] = js.native
var prefixCls: js.UndefOr[String] = js.native
}

object FormProps {
@scala.inline
def apply(): FormProps = {
val __obj = js.Dynamic.literal()
__obj.asInstanceOf[FormProps]
}
@scala.inline
implicit class FormPropsOps[Self <: FormProps] (val x: Self) extends AnyVal {
@scala.inline
def duplicate: Self = (js.Dynamic.global.Object.assign(js.Dynamic.literal(), x)).asInstanceOf[Self]
@scala.inline
def combineWith[Other <: js.Any](other: Other): Self with Other = (js.Dynamic.global.Object.assign(js.Dynamic.literal(), x, other.asInstanceOf[js.Any])).asInstanceOf[Self with Other]
@scala.inline
def set(key: String, value: js.Any): Self = {
x.asInstanceOf[js.Dynamic].updateDynamic(key)(value)
x
}
@scala.inline
def setName(value: String): Self = this.set("name", value.asInstanceOf[js.Any])
@scala.inline
def deleteName: Self = this.set("name", js.undefined)
@scala.inline
def setPrefixCls(value: String): Self = this.set("prefixCls", value.asInstanceOf[js.Any])
@scala.inline
def deletePrefixCls: Self = this.set("prefixCls", js.undefined)
}

}

12 changes: 12 additions & 0 deletions tests/antd/check/r/rc-field-form/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
organization := "org.scalablytyped"
name := "rc-field-form"
version := "1.4.4-5a0521"
scalaVersion := "2.13.2"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.olvind" %%% "scalablytyped-runtime" % "2.1.0")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-g:notailcalls", "-language:implicitConversions", "-language:higherKinds", "-language:existentials")
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
bintrayRepository := "ScalablyTyped"
resolvers += Resolver.bintrayRepo("oyvindberg", "ScalablyTyped")
1 change: 1 addition & 0 deletions tests/antd/check/r/rc-field-form/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.10
2 changes: 2 additions & 0 deletions tests/antd/check/r/rc-field-form/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.1.0")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
16 changes: 16 additions & 0 deletions tests/antd/check/r/rc-field-form/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# Scala.js typings for rc-field-form

Typings are for version 1.4.4



## 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,16 @@
{
"compile-dependencies" : [
{
"rc-field-form" : "1.4.4"
}
],
"test-dependencies" : [
{
"rc-field-form" : "1.4.4"
}
],
"compile-devDependencies" : [
],
"test-devDependencies" : [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package typings.rcFieldForm.mod

import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation._

@js.native
trait FormProps extends js.Object {
var name: js.UndefOr[String] = js.native
}

object FormProps {
@scala.inline
def apply(): FormProps = {
val __obj = js.Dynamic.literal()
__obj.asInstanceOf[FormProps]
}
@scala.inline
implicit class FormPropsOps[Self <: FormProps] (val x: Self) extends AnyVal {
@scala.inline
def duplicate: Self = (js.Dynamic.global.Object.assign(js.Dynamic.literal(), x)).asInstanceOf[Self]
@scala.inline
def combineWith[Other <: js.Any](other: Other): Self with Other = (js.Dynamic.global.Object.assign(js.Dynamic.literal(), x, other.asInstanceOf[js.Any])).asInstanceOf[Self with Other]
@scala.inline
def set(key: String, value: js.Any): Self = {
x.asInstanceOf[js.Dynamic].updateDynamic(key)(value)
x
}
@scala.inline
def setName(value: String): Self = this.set("name", value.asInstanceOf[js.Any])
@scala.inline
def deleteName: Self = this.set("name", js.undefined)
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package typings.rcFieldForm

import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation._

/* 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("rc-field-form", JSImport.Namespace)
@js.native
object rcFieldFormRequire extends js.Object

5 changes: 5 additions & 0 deletions tests/antd/in/antd/lib/form/Form.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FormProps as RcFormProps } from 'rc-field-form/lib/Form';

export interface FormProps extends Omit<RcFormProps, 'form'> {
prefixCls?: string;
}
18 changes: 18 additions & 0 deletions tests/antd/in/antd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "antd",
"version": "4.3.1",
"description": "An enterprise-class UI design language and React components implementation",
"files": [
"dist",
"lib",
"es"
],
"main": "lib/index.js",
"module": "es/index.js",
"unpkg": "dist/antd.min.js",
"typings": "lib/index.d.ts",
"title": "Ant Design",
"dependencies": {
"rc-field-form": "^1.4.4"
}
}
3 changes: 3 additions & 0 deletions tests/antd/in/rc-field-form/es/Form.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FormProps {
name?: string;
}
1 change: 1 addition & 0 deletions tests/antd/in/rc-field-form/es/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { FormProps } from './Form';
15 changes: 15 additions & 0 deletions tests/antd/in/rc-field-form/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "rc-field-form",
"version": "1.4.4",
"description": "React Form Component",
"typings": "es/index.d.ts",
"files": [
"lib",
"es",
"dist",
"assets/*.css"
],
"license": "MIT",
"main": "./lib/index",
"module": "./es/index"
}
18 changes: 18 additions & 0 deletions tests/antd/in/stdlib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference no-default-lib="true"/>

/**
* From T, pick a set of properties whose keys are in the union K
*/
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};

/**
* Exclude from T those types that are assignable to U
*/
type Exclude<T, U> = T extends U ? never : T;

/**
* Construct a type with the properties of T except for those in type K.
*/
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
4 changes: 3 additions & 1 deletion tests/augment-module/in/stdlib.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference no-default-lib="true"/>

type Partial<T> = T;
interface Array<T> {}
interface ArrayLike<T> {}
interface ArrayLike<T> {}

0 comments on commit fb98fcc

Please sign in to comment.