Code Monkey home page Code Monkey logo

sbt-typescript's Introduction

sbt-typescript

Build Status

This sbt plugin compiles the Typescript code in your Play application to javascript fit for consumption by your average browser and device.

Getting started

The easiest way to get started is to use the demo projects for Angular2 or React. You can create the Angular2 application locally by running sbt new joost-de-vries/play-angular-typescript.g8. For the React application that's sbt new joost-de-vries/play-reactjs-typescript.g8

Configuring

Create a tsconfig.json file in the root of your project with the required compiler options. The following tsc compiler options are managed by sbt-typescript so setting them in tsconfig.json has no effect: outDir, rootDirs, paths, baseUrl, typeRoots.
If you use the stage compile mode the outFile option is also managed by sbt-typescript.
To be able to view the original Typescript code from your browser when developing add the following to tsconfig.json

"compilerOptions": {
    "sourceMap": true,
    "mapRoot": "/assets",
    "sourceRoot": "/assets",

Add the following line to your project\plugins.sbt:

addSbtPlugin("name.de-vries" % "sbt-typescript" % "2.6.2")

If your project is not a Play application you will have to enable sbt-web in build.sbt:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

There are several Javascript engines you can use for the build. The fastest is NodeJs. So make sure you have a recent NodeJs installed and add to build.sbt

JsEngineKeys.engineType := JsEngineKeys.EngineType.Node

NPM libraries are used as standard sbt dependencies (jar files). Add your typescript libraries as dependencies as follows. If the library doesn't include typescript definitions add them too.

resolvers += Resolver.bintrayRepo("webjars","maven")
libraryDependencies ++= Seq(
    "org.webjars.npm" % "react" % "15.4.0",
    "org.webjars.npm" % "types__react" % "15.0.34"
)

These NPM dependencies are resolved through Webjars. Check whether the versions of the NPM packages you need are available there. If not you can add them yourself. Since we added the webjars resolver they'll be available immediately. Otherwise you'd have to wait a while before being able to use them. NB NPM package names like @angular/code and @types/react are a bit different in webjars: angular__react and types__react. Add the following to build.sbt to resolve against those npms.

resolveFromWebjarsNodeModulesDir := true

To lint your Typescript code add sbt-tslint to your project and create a tslint.json file with the linting rules.

To test your Typescript code add an sbt plugin for a JS testframework. For instance sbt-jasmine or sbt-mocha. You can override tsc configurations for your test code. To do that create a file tsconfig.test.json and add to build.sbt

(projectTestFile in typescript) := Some("tsconfig.test.json")

Any settings in that file will override those in tsconfig.json for the compilation of test code.

Configuring an IDE

The typescript version of your project can be found in project/target/node-modules/webjars/typescript Configure your IDE to use that and point it to the tsconfig.json.

Compiling directly through tsc

Sometimes it can be helpful to compile your project directly through the Typescript compiler without sbt-typescript in between to check whether a problem is an sbt-typescript problem. To do that you can run

project/target/node-modules/webjars/typescript/bin/tsc -p . -w

Make sure to set the executable bit if necessary. For this kind of compilation to work you have to fill in the settings in tsconfig.json that sbt-typescript normally manages. See the Angular2 demo project for an example.

Compiling to a single js file

You can develop using individual javascript files when running sbt ~run in Play and have your whole typescript application concatenated into a single javascript output file for your stage environment without changes to your sources. To do that you have to add a -DtsCompileMode=stage parameter to the sbt task in your CI that creates the stage app. So for Play that will often be sbt stage -DtsCompileMode=stage.

import modules without type information

If you are importing modules for which you don't have the typings you can ignore the TS2307 can not find module error:

tsCodesToIgnore := List(canNotFindModule)

release notes

v2.6.2

  • typescript version upgrade
  • upgrade to sbt-web 1.4.3
  • webjars-locator 0.35

v2.6.1

  • upgrade typescript to v2.6.1

v2.5.2-1

  • cross build to sbt 0.13.6 and 1.0.1. alpha release

v2.5.2

  • upgrade to ts 2.5.2
  • fixes issue with test tsconfig overrides

v2.4.1-2

  • upgrade to sbt-js-engine 1.2.1 and sbt-web 1.4.1
  • add correct typeRoots values to tsconfig.json for resolution of @types type def dependencies

v2.4.1-1

  • allow for overrides of the tsconfig.json for test code

v2.4.1

  • upgrade to ts npm 2.4.1

v2.3.2

  • upgrade to ts npm 2.3.2

v2.3.1

  • upgrade to ts 2.3 final: npm 2.3.1
  • sbt-typescript follows the typescript version

v0.3.0-beta.11

v0.3.0-beta.10

v0.4.0-alfa.1

  • supports multi project builds. Uses sbt-web webModules for js deps resolution instead of nodeModules. Hence the alfa moniker to see whether f.i. @types resolution still works.

v0.3.0-beta.9

  • fixes compilation of test assets

v0.3.0-beta.8-1

  • allows configuring outfile with a path
  • makes compile errors 1 based instead of 0 based

v0.3.0-beta.8

  • upgrades to typescript 2.1 (npm 2.1.4)

v0.3.0-beta.7

  • upgrades to typescript 2.1 RC (npm 2.1.1)
  • resolves webjar @types type definitions

v0.3.0-beta.6

  • upgrades to typescript 2.0.6

v0.3.0-beta.5

  • solves an issue (#9) where RxJs would cause a nullpointer.
  • uses typescript 2.0.3

v0.3.0-beta.4

  • solves an issue (#9) where RxJs would be extracted to the wrong directory.

v0.3.0-beta.3

  • uses typescript 2.0 RC (npm 2.0.2)

v0.3.0-beta.2

  • uses typescript 2.0 beta (npm 2.0.0)

v0.3.0SNAPSHOT

  • uses standard typescript functionality to resolve against webjars. Instead of the previous custom rolled module resolution extension.
  • uses a snapshot of the upcoming typescript 2.0
  • add output assertion options

v0.2.7

  • adds convenience task for setting up tsc compilation

v0.2.6

  • fixes jstaskfailure error

v0.2.5

  • allows for developing using individual javascript files and using a single javascript file in production

v0.2.4

  • upgrades to typescript 1.8.10

v0.2.3

  • upgrades to typescript 1.8.7
  • adds support for tests in typescript

v0.2.2

  • upgrades to typescript 1.8.2
  • improves output of single outfile
  • fixes a nasty bug in module resolution. This is essential for angular2 applications.
  • gives feedback on faulty compiler options.

status

The plugin is young. Currently it is mostly tested against EngineType.Node and Angular2 applications with npm style dependencies.
There are some other features I'm planning to implement.

history

I started this plugin because the features I mentioned above were missing in the existing plugins.
And since I'd like Play and sbt(-web) to be kickass build tools for Typescript and Angular2 applications, and I wanted to give back to the open source community, I thought I'd implement it myself.. But not by writing javascript if I could just as well write Typescript...
Kudos to Brendan Arp for his javascript tsc driver to get me started. And also to all of the other plugins mentioned here. Open source is an amazing tool for collective learning. Just imagine those poor programmers in the 1970s with only IBM manuals to provide them with information.

sbt-typescript's People

Contributors

camilosampedro avatar joost-de-vries avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sbt-typescript's Issues

Wrong unpacked folder name of webjars (rxjs)

Hello,

i dont know where to address this issue. It can be a problem in webjar or in sbt-web as well. In my project with angular2 and your typescript compiler plugin (great work btw.!) the webjar of RxJs is unpacked in a wrong folder name in the target output folder (see picture). The Typescript Compiler and my IDE throw errors if i try to import Rxjs classes like Observable. I looked into the webjar but didnt see any problems with it. I dont know why this folder name is created. "Ben Lesh" is only in the package.json file specially in the author and contributor tag.

image

java version < 8 not supported?

[info] java.lang.UnsupportedClassVersionError: name/devries/sbt/typescript/JsonCleaner : Unsupported major.minor version 52.0
[info]  at java.lang.ClassLoader.defineClass1(Native Method)
[info]  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
[info]  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[info]  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[info]  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[info]  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[info]  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[info]  at java.security.AccessController.doPrivileged(Native Method)
[info]  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[info]  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[info]  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[info]  at name.devries.sbt.typescript.SbtTypescript$$anonfun$parseTsConfig$1.removeComments$1(SbtTypescript.scala:176)
[info]  at name.devries.sbt.typescript.SbtTypescript$$anonfun$parseTsConfig$1.parseJson$1(SbtTypescript.scala:182)
[info]  at name.devries.sbt.typescript.SbtTypescript$$anonfun$parseTsConfig$1.apply(SbtTypescript.scala:187)
[info]  at name.devries.sbt.typescript.SbtTypescript$$anonfun$parseTsConfig$1.apply(SbtTypescript.scala:173)
[info]  at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[info]  at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
[info]  at sbt.std.Transform$$anon$4.work(System.scala:63)
[info]  at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
[info]  at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
[info]  at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
[info]  at sbt.Execute.work(Execute.scala:237)
[info]  at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
[info]  at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
[info]  at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
[info]  at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[info]  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[info]  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[info]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[info]  at java.lang.Thread.run(Thread.java:745)
[info] [error] (web-assets:typescript::jstaskJsOptions) java.lang.UnsupportedClassVersionError: name/devries/sbt/typescript/JsonCleaner : Unsupported major.minor version 52.0

Failed compilation with dependencies containing typescript files

Hello!

I am currently working on a project where we have injected your plugin to compile our typescript files.
Everything was working fine until I had to use a dependency (angular2-jwt, angular2-material or any dependency with some ts files) which contains typescript files. The problem is that those files are getting compiled even though they are not included in rootDir and included in the excluded folders.

When compiling we get the following mistake :
TS6059 File 'path/to/file' is not under 'rootDir' 'rootDir/path'. 'rootDir' is expected to contain all source files.
As a consequence, my ts files are not compiled and they appear as empty folders (with a js extension though). The rootDir compiler option is definitely the key to it but I can't seem to find any solution after a long week of research and tries. Is there already a workaround the fact that rootDir is an ignored compiler option? If not is it a work in progress or can I do anything about it?

About our project, we are using the Play 2.5.4, Scala 2.11.8 and are using the latest versions available on webjars for angular2 (basically the webjars you are using in play-angular2-typescript).

If you consider that this is not an issue on your side, can you contact me at [email protected] ?
And thanks already for your plugins they are truly helpful.

TypeScript not being compiled.

Forgive me if I misunderstand how this plugin is supposed to work.

When I sbt run or change the TS files and reload in the browser, the compilation doesn't seem to run. That is, my ts files are not compiled to js files.

If I run tsc from the root of my project, however, the ts files are compiled and everything works.

Is the plugin supposed to run the compiler automatically or do I have to run tsc manually?

I think I have configured the plugin as directed by the README.

plugins.sbt

addSbtPlugin("name.de-vries" % "sbt-typescript" % "2.3.2")

tsconfig.json in root dir

{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"mapRoot": "/assets",
"sourceRoot": "/assets",
"baseUrl": ".",
"paths": {
"": [
"
",
"target/web/node-modules/main/webjars/*"
]
},
"strict":true,
"noUnusedLocals":true,
"noUnusedParameters": true,
"lib": ["es6", "dom"]
},
"exclude": [
"node_modules",
"project/target",
"typings/main",
"typings/main.d.ts",
"typings/browser",
"target/web"
]
}

tsc installed

==> tsc -v
Version 2.3.3

Legacy Play 2.4.0 app

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")

I'm running on a macOS Sierra rig.

sbt/TrackLevel

I seem to be getting this error when using this plugin with play framework and activator.

Error
java.lang.NoClassDefFoundError: sbt/TrackLevel

plugins.bat
addSbtPlugin("name.de-vries" % "sbt-typescript" % "0.3.0-beta.7")

sbt version
0.13.13

If I change out the plugin with ArpNetworking/sbt-typescript for instance I can get a successful build.
Any ideas as to the cause of this?

This happens with a fresh clone of the play-angular2-typescript as well as a custom structure.

Object has no method 'convertCompilerOptionsFromJson'

I encounter the following error for all examples you provide (in this case play-angular-typescript):

com.typesafe.sbt.jse.SbtJsTask$JsTaskFailure: 
/home/richard/src/play-angular2-typescript/target/typescript/typescript.js:191
        return ts.convertCompilerOptionsFromJson(unparsedCompilerOptions, sbtO
                  ^
TypeError: Object #<Object> has no method 'convertCompilerOptionsFromJson'
    at toCompilerOptions (/home/richard/src/play-angular2-typescript/target/typescript/typescript.js:191:19)
    at compile (/home/richard/src/play-angular2-typescript/target/typescript/typescript.js:152:14)
    at Object.<anonymous> (/home/richard/src/play-angular2-typescript/target/typescript/typescript.js:146:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

    at com.typesafe.sbt.jse.SbtJsTask$$anonfun$com$typesafe$sbt$jse$SbtJsTask$$executeJsOnEngine$1.apply(SbtJsTask.scala:195)
    at com.typesafe.sbt.jse.SbtJsTask$$anonfun$com$typesafe$sbt$jse$SbtJsTask$$executeJsOnEngine$1.apply(SbtJsTask.scala:167)
    at scala.util.Success$$anonfun$map$1.apply(Try.scala:206)
    at scala.util.Try$.apply(Try.scala:161)
    at scala.util.Success.map(Try.scala:206)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at scala.concurrent.impl.ExecutionContextImpl$$anon$3.exec(ExecutionContextImpl.scala:107)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

Compilation fails the first time, succeeds the second

I'm using this great plugin in a Play app. We have this strange behavior that on a first compilation pass, tsc can't find most imports. On a second pass, however, everything works.

Just checked out this repo and I get the same behavior when building the example. I'm using setupTscCompilation. First time I get:

[error] tsconfig.json:0: TS6053 File '/Users/bertvh/Qmino/Development/github/sbt-typescript/example/typings/browser.d.ts' not found.
[error] /Users/bertvh/Qmino/Development/github/sbt-typescript/example/target/web/node-modules/main/webjars/angular2/platform/browser.d.ts:76: TS2304 Cannot find name 'Promise'.
[error] export declare function bootstrap(appComponentType: Type, customProviders?: Array<any>): Promise<ComponentRef>;
[error]                                                                                          ^
[error] /Users/bertvh/Qmino/Development/github/sbt-typescript/example/target/web/node-modules/main/webjars/angular2/src/core/application_ref.d.ts:82: TS2304 Cannot find name 'Promise'.
[error]     abstract asyncApplication(bindingFn: (zone: NgZone) => Promise<Array<Type | Provider | any[]>>, providers?: Array<Type | Provider | any[]>): Promise<ApplicationRef>;
[error]                                                            ^
[error] /Users/bertvh/Qmino/Development/github/sbt-typescript/example/target/web/node-modules/main/webjars/angular2/src/core/application_ref.d.ts:82: TS2304 Cannot find name 'Promise'.
[error]     abstract asyncApplication(bindingFn: (zone: NgZone) => Promise<Array<Type | Provider | any[]>>, providers?: Array<Type | Provider | any[]>): Promise<ApplicationRef>;
[error]                                                                                                                                                  ^
[error] /Users/bertvh/Qmino/Development/github/sbt-typescript/example/target/web/node-modules/main/webjars/angular2/src/core/application_ref.d.ts:95: TS2304 Cannot find name 'Promise'.
[error]     asyncApplication(bindingFn: (zone: NgZone) => Promise<Array<Type | Provider | any[]>>, additionalProviders?: Array<Type | Provider | any[]>): Promise<ApplicationRef>;
[error]                                                   ^
[error] 65 errors found
[error] (web-assets:typescript) com.typesafe.sbt.web.CompileProblemsException

At this point, the node_modules directory in target contains everything that I would expect.

Second run, everything works:

[info] Webjars copied to ./node_modules
[success] Total time: 8 s, completed Aug 2, 2016 11:30:34 AM

Any ideas?

Intellij does not resolve angular2 (or other) webjar libs

Hi,

We're currently struggling keeping our gulp based angular2 project sane, so I very much appreciate how your webjar approach simplifies things.

I do seem to have trouble telling my IDE where to find the angular2 webjar files for autocompletion etc., is it possible to configure this in any way?

I realize this is not an issue against the sbt-typescript project, but I'm wondering if there's a solution to this.

Many thanks!

Keep paths specified in tsconfig.json

Hi, I am trying to use two root dirs for my TypeScript code in a Play application (app/assets/javascripts and app/assets/test) so that modules defined in the second dir were able to use modules defined in the first. This seems to work with plain tsconfig.json+tsc but not with sbt-typescript plugin.

Here is my tsconfig.json:

{
    "compilerOptions": {
        "baseUrl": "app/assets",
        "paths": {
            "*": [
                "javascripts/*",
                "test/*"
            ]
        },
        "rootDirs": [
            "app/assets/javascripts",
            "app/assets/test"
        ],
        "typeRoots": ["node_modules" ],
        "types": ["jquery", "requirejs", "qunit"],
        "allowJs": true,
        "target": "es5",
        "module": "amd",
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "strictNullChecks": true
    },
    "include": [
        "**/*.ts"
    ],
    "exclude": [ "project/**" ]
}

It works just fine if compiled with plain tsc. However, when sbt-typescript is involved, it builds rootDirs on its own and I get Compilation error[TS2307 Cannot find module 'module/sitting/inside/javascripts'.]

Any ideas how to get it working with the current sbt-typescript or maybe fix the plugin so that it didn't ignore rootDirs from tsconfig.json ?

Bower support (for angular + polymer)?

Just something I want to drop here... I'd like to use a Polymer component inside my angular2 app. The thing is that Polymer is distributed through Bower, while Angular uses npm.

I can install some of the Polymer packages as Bower Webjars, but some of them don't seem to work properly (You can't use gotoNode for a node which does not represent the same Module as the one represented by this node) or dependencies aren't resolved.

Any suggestions / experiences / ideas ?

Enable to import Lodash In my project

Hey, in my build.sbt, I do have :

"org.webjars.npm" % "types__lodash" % "4.14.30",
"org.webjars.npm" % "lodash" % "4.17.2",

I haven't set anything regarding types in my tsconfig.json.
However, I do have used a folder used typings/browser.d.ts
where I set
///<reference path="./../target/web/web-modules/main/webjars/lib/types__lodash/lodash/index.d.ts"/>
and in my built.sbt, I have set the following :
typingsFile := Some(baseDirectory.value / "typings" / "browser.d.ts")

It seems to work fine, but I am pretty sure that's not the right way to do it. Did I miss anything here ?

Inability to configure `rootDir` is causing issues with using TypeScript across sub-projects in Play.

I've created an example of the problem I'm about to describe at objectmastery/rootdir-error-example for you to try.

I have a Play Framework project structure where I have a main project and a sub project. In both of these projects are .ts files, and the main project .ts files reference the sub project .ts files.

Since I cannot control how sbt-typescript specifies the rootDir, and the rootDir appears to be bound to sourceDirectory in Assets, an error will occur when I try to compile the main project.

TypeScript will first detect that the referenced .ts files in the sub project are located outside of the `rootDir specified.

TypeScript shows a warning about this and also "fixes" the rootDir to refer to the root of both the main and sub projects (since that would be the commonality between the files referenced).

sbt-typescript then falls over, since it cannot find its way around the outDir due to it assuming the folder structure would match sourceDirectory in Assets and TypeScript outputting a different folder structure.

At the moment, I'm working around this problem with a modified version of the plugin where the rootDir is never specified or overridden (and I find the output files based in part on the explicitly or implicitly defined rootDir), but I don't think that's necessarily the correct answer. I think either only set the rootDir if it isn't already set, or have some ability to turn off the overriding functionality?

Thoughts?

Plugin tries to compile dependencies

Hi,

I'm trying to modify play-angular2-typescript to use akka-http but I'm stuck on one problem. When i run stage task a lot of errors show up from angular sources.

Have you got any idea what can be wrong? Here are my tsconfig.json, and build.sbt, if it can help.

{
  /* the configuration of the typescript compiler. See docs https://github.com/Microsoft/TypeScript/wiki/Compiler-Options
  The settings outDir and rootDir are managed by sbt-typescript.
  */
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    /* the following two settings are required for angular2 annotations to work*/
    "emitDecoratorMetadata": true,
    "experimentalDecorators":true,
    /* for reading your ts source while debugging from a browser */
    "sourceMap": true,
    "mapRoot": "/assets",
    "sourceRoot": "/assets",
    "rootDirs": ["src/main/assets","src/test/assets"],
    "baseUrl": ".",
    "paths": {
      "*": [
        "*",
        "target/web/node-modules/main/webjars/*"
      ]
    },
    /* noImplicitAny when you want your typescript to be fully typed */
    "noImplicitAny":true,
    "noFallthroughCasesInSwitch":true,
    "noImplicitReturns":true,
    "noImplicitThis":true,
    // "strictNullChecks":true, doesn't work yet with @angular RC4
    "outDir": "./target/ts",
    "lib": ["es6", "dom"]
  },
  /* the information below is not used by sbt-typescript. but you can use it if you want to run tsc -p .*/
  "exclude": [
    "node_modules",
    "project/target",
    "typings/main",
    "typings/main.d.ts",
    "typings/browser",
    "target/web"
  ]
}
name := """akka-http-angular2-typescript"""
version := "0.1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(SbtWeb)

scalaVersion := "2.11.8"
incOptions := incOptions.value.withNameHashing(true)
updateOptions := updateOptions.value.withCachedResolution(cachedResoluton = true)

lazy val akkaVersion = "2.4.6"
/** Note that all webjars dependencies are marked as "provided". This is to avoid them be added to the runtime class path. Just for efficiency. It's not needed.
  * If they weren't marked as provided, they would be added to the runtime class path with the "META-INF/resources/webjars" path prefix. But since the SBT-Web's "webJarsNodeModules" task adds copies of them with the mentioned prefix and module version striped, which is more convenient, we can discard the originals. */
val ngVersion="2.0.0-rc.6"
libraryDependencies ++= Seq(
  // binding logback as the underlying logging framework for SLF4J
  "ch.qos.logback" % "logback-classic" % "1.1.7",

  //akka
  "com.typesafe.akka" %% "akka-actor" % akkaVersion,
  "com.typesafe.akka" %% "akka-stream" % akkaVersion,
  "com.typesafe.akka" %% "akka-http-core" % akkaVersion,
  "com.typesafe.akka" %% "akka-http-experimental" % akkaVersion,
  "com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
  "de.heikoseeberger" %% "akka-http-json4s" % "1.9.0",
  "org.json4s" %% "json4s-native" % "3.4.0",

  //slick
  "com.typesafe.slick" %% "slick" % "3.1.1",
  //"org.slf4j" % "slf4j-nop" % "1.6.4",
  "io.strongtyped" %% "active-slick" % "0.3.4",
  "org.apache.derby" % "derby" % "10.12.1.1",

  //@angular
  "org.webjars.npm" % "angular__common" % ngVersion,
  "org.webjars.npm" % "angular__compiler" % ngVersion,
  "org.webjars.npm" % "angular__core" % ngVersion,
  "org.webjars.npm" % "angular__http" % ngVersion,
  "org.webjars.npm" % "angular__platform-browser-dynamic" % ngVersion,
  "org.webjars.npm" % "angular__platform-browser" % "2.0.0-rc.5",
  "org.webjars.npm" % "angular__router" % "3.0.0-rc.2",
  "org.webjars.npm" % "systemjs" % "0.19.31",
  "org.webjars.npm" % "todomvc-common" % "1.0.2",
  "org.webjars.npm" % "rxjs" % "5.0.0-beta.9",
  "org.webjars.npm" % "es6-promise" % "3.1.2",
  "org.webjars.npm" % "es6-shim" % "0.35.1",
  "org.webjars.npm" % "reflect-metadata" % "0.1.3",
  "org.webjars.npm" % "zone.js" % "0.6.12",
  "org.webjars.npm" % "core-js" % "2.4.0",
  "org.webjars.npm" % "symbol-observable" % "1.0.1",

  "org.webjars.npm" % "typescript" % "2.0.0-dev.20160707",

  //tslint dependency
  "org.webjars.npm" % "tslint-eslint-rules" % "1.2.0",
  "org.webjars.npm" % "codelyzer" % "0.0.25",
  "org.webjars.npm" % "types__jasmine" % "2.2.26-alpha" % "test",

  "org.webjars" % "webjars-locator" % "0.32"

)
dependencyOverrides += "org.webjars.npm" % "minimatch" % "3.0.0"

// the typescript typing information is by convention in the typings directory
// It provides ES6 implementations. This is required when compiling to ES5.
typingsFile := Some(baseDirectory.value / "typings" / "index.d.ts")

// use the webjars npm directory (target/web/node_modules ) for resolution of module imports of @angular/core etc
resolveFromWebjarsNodeModulesDir := true

// use the combined tslint and eslint rules plus ng2 lint rules
(rulesDirectories in tslint) := Some(List(tslintEslintRulesDir.value, ng2LintRulesDir.value))

// If true, sources from the project's base directory are included as main sources.
sourcesInBase := false


// adds, to the runtime classpath, the directories where the webjars are extracted (with META-INF and version stripped).
(managedClasspath in Runtime) ++= WebKeys.nodeModuleDirectories.in(Assets).value
(managedClasspath in Runtime) += WebKeys.webJarsDirectory.in(Assets).value
(managedClasspath in Runtime) += WebKeys.public.in(Assets).value


// run the application in a separate JVM (instead of using the same than SBT)
fork in run := true

enablePlugins(JavaServerAppPackaging)
(managedClasspath in Runtime) += (packageBin in Assets).value

And the error from sbt:

[info] Compiling 24 Scala sources to /home/wpitula/Projects/plandget/target/scala-2.11/classes...
[info] Typescript linting on 9 source(s)
[info] Typescript compiling on 9 source(s)
model contains 62 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /home/wpitula/Projects/plandget/target/scala-2.11/akka-http-angular2-typescript_2.11-0.1.0-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[error] /home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/platform-browser/core_private.d.ts:7: TS2305 Module '"/home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/core/index"' has no exported member 'core_private_types'.
[error] import { core_private as r, core_private_types as t } from '@angular/core';
[error] ^
[error] /home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/platform-browser/src/browser.d.ts:0: TS2305 Module '"/home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/core/index"' has no exported member 'ExceptionHandler'.
[error] import { ExceptionHandler, PlatformRef } from '@angular/core';
[error] ^
[error] /home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/platform-browser/src/browser/location/browser_platform_location.d.ts:7: TS2305 Module '"/home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/common/index"' has no exported member 'UrlChangeListener'.
[error] import { PlatformLocation, UrlChangeListener } from '@angular/common';
[error] ^
[error] /home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/platform-browser/src/security/dom_sanitization_service.d.ts:7: TS2305 Module '"/home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/core/index"' has no exported member 'SanitizationService'.
[error] import { SanitizationService, SecurityContext } from '@angular/core';
[error] ^
[error] /home/wpitula/Projects/plandget/target/web/node-modules/main/webjars/@angular/platform-browser/src/web_workers/shared/client_message_broker.d.ts:31: TS2314 Generic type 'Type' requires 1 type argument(s).
[error] abstract runOnService(args: UiArguments, returnType: Type): Promise;
[error] ^
[error] 9 errors found
error com.typesafe.sbt.web.CompileProblemsException
[error] Total time: 5 s, completed Sep 2, 2016 8:42:45 AM

source maps not working in example project?

Hi,

I can't get the source maps to work properly in Chrome in my own project. Trying out the example project they don't appear to be working there either. Chrome can't locate the ts files at all and shows the breakpoints in the generated js files.

Kind regards,
Marc van Kempen.

TypeScript compilation fails in Trireme JS engine

When Node is not available, the compilation process falls back to the Rhino based Trireme engine. Somewhere between beta-6 and beta-9, the compilation stopped working. I get the error ReferenceError: "Promise" is not defined.

Relevant excerpt from build log:

[error] ReferenceError: "Promise" is not defined. (<...../project/target/typescript/typescript.js>#183)    at compile (<...../project/target/typescript/typescript.js>:183)
[error]     at <...../project/target/typescript/typescript.js>:152
[error]     at module.js:456
[error]     at module.js:474
[error]     at module.js:356
[error]     at module.js:312
[error]     at module.js:497
[error]     at startup (trireme.js:142)
[error]     at trireme.js:923
[info] 
com.typesafe.sbt.jse.SbtJsTask$JsTaskFailure: ReferenceError: "Promise" is not defined. (<...../project/target/typescript/typescript.js>#183)    at compile (<...../project/target/typescript/typescript.js>:183)
    at <...../project/target/typescript/typescript.js>:152
    at module.js:456
    at module.js:474
    at module.js:356
    at module.js:312
    at module.js:497
    at startup (trireme.js:142)
    at trireme.js:923

	at com.typesafe.sbt.jse.SbtJsTask$$anonfun$com$typesafe$sbt$jse$SbtJsTask$$executeJsOnEngine$1.apply(SbtJsTask.scala:215)
	at com.typesafe.sbt.jse.SbtJsTask$$anonfun$com$typesafe$sbt$jse$SbtJsTask$$executeJsOnEngine$1.apply(SbtJsTask.scala:187)
	at scala.util.Success$$anonfun$map$1.apply(Try.scala:206)
	at scala.util.Try$.apply(Try.scala:161)
	at scala.util.Success.map(Try.scala:206)
	at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
	at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
	at scala.concurrent.impl.ExecutionContextImpl$$anon$3.exec(ExecutionContextImpl.scala:107)
	at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
	at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
	at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
	at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
[error] (web-assets:typescript) com.typesafe.sbt.jse.SbtJsTask$JsTaskFailure: ReferenceError: "Promise" is not defined. (<...../project/target/typescript/typescript.js>#183)    at compile (<...../project/target/typescript/typescript.js>:183)
[error]     at <...../project/target/typescript/typescript.js>:152
[error]     at module.js:456
[error]     at module.js:474
[error]     at module.js:356
[error]     at module.js:312
[error]     at module.js:497
[error]     at startup (trireme.js:142)
[error]     at trireme.js:923

Thank you!

rootDir not including sources under app/assets when compiling tests

Say that we have the following directory structure, much like your play-angular2-typesscript project:

  • app/
    • assets/
      • app/
        • Dog.ts
  • test/
    • assets/
      • Dog.spec.ts

If, in Dog.ts we have:

export class Dog {
  name:string
}

and, in Dog.spec.ts we have:

import {Dog} from "../../app/assets/app/Dog"

describe("some test", ()=> {
  it("does a test"), ()=> {
    d:Dog = new Dog();
  }
});

I get the following error:

[error] tsconfig.json:0: TS6059 File '/projects/myapp/app/assets/app/models/Dog.ts' is not under 'rootDir' '/projects/myapp/test/assets'. 'rootDir' is expected to contain all source files.

Is there any way to have the app/assets/app directory included when compiling the TypeScript test files?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.