File tree 10 files changed +158
-1
lines changed
test/execution-tests/2.1.4_babel-allowJsImportTypes
10 files changed +158
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,8 @@ function resolveModuleName(
152
152
isExternalLibraryImport : tsResolution . resolvedModule . isExternalLibraryImport
153
153
} ;
154
154
if ( resolutionResult ! ) {
155
- if ( resolutionResult ! . resolvedFileName === tsResolutionResult . resolvedFileName ) {
155
+ if ( resolutionResult ! . resolvedFileName === tsResolutionResult . resolvedFileName ||
156
+ / n o d e _ m o d u l e s ( \\ | \/ ) .* \. d \. t s $ / . test ( tsResolutionResult . resolvedFileName ) ) {
156
157
resolutionResult ! . isExternalLibraryImport = tsResolutionResult . isExternalLibraryImport ;
157
158
}
158
159
} else {
Original file line number Diff line number Diff line change
1
+ This test confirms that you can import typings from an npm module when ` allowJs ` is true. See details [ #586 ] ( https://github.com/TypeStrong/ts-loader/issues/586 ) .
2
+
3
+ This test is roughly based on https://github.com/bsouthga/ts-loader-types-error-example
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-var, strict */
2
+ 'use strict' ;
3
+ var webpackConfig = require ( './webpack.config.js' ) ;
4
+
5
+ module . exports = function ( config ) {
6
+ // Documentation: https://karma-runner.github.io/0.13/config/configuration-file.html
7
+ config . set ( {
8
+ browsers : [ 'PhantomJS' ] ,
9
+
10
+ files : [
11
+ // This ensures we have the es6 shims in place and then loads all the tests
12
+ 'main.js'
13
+ ] ,
14
+
15
+ port : 9876 ,
16
+
17
+ frameworks : [ 'jasmine' ] ,
18
+
19
+ logLevel : config . LOG_INFO , //config.LOG_DEBUG
20
+
21
+ preprocessors : {
22
+ 'main.js' : [ 'webpack' , 'sourcemap' ]
23
+ } ,
24
+
25
+ webpack : {
26
+ devtool : 'inline-source-map' ,
27
+ module : webpackConfig . module ,
28
+ resolve : webpackConfig . resolve ,
29
+
30
+ // for test harness purposes only, you would not need this in a normal project
31
+ resolveLoader : webpackConfig . resolveLoader
32
+ } ,
33
+
34
+ webpackMiddleware : {
35
+ quiet : true ,
36
+ stats : {
37
+ colors : true
38
+ }
39
+ } ,
40
+
41
+ // reporter options
42
+ mochaReporter : {
43
+ colors : {
44
+ success : 'bgGreen' ,
45
+ info : 'cyan' ,
46
+ warning : 'bgBlue' ,
47
+ error : 'bgRed'
48
+ }
49
+ }
50
+ } ) ;
51
+ } ;
Original file line number Diff line number Diff line change
1
+ import 'babel-polyfill' ;
2
+
3
+ const testsContext = require . context ( './' , true , / \. t e s t s \. j s $ / ) ;
4
+ testsContext . keys ( ) . forEach ( testsContext ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " allow-js-import-types" ,
3
+ "version" : " 1.0.0" ,
4
+ "main" : " index.js" ,
5
+ "devDependencies" : {
6
+ "babel" : " ^6.0.0" ,
7
+ "babel-core" : " ^6.0.0" ,
8
+ "babel-loader" : " ^7.0.0" ,
9
+ "babel-preset-es2015" : " ^6.0.0" ,
10
+ "jasmine-core" : " ^2.3.4"
11
+ },
12
+ "dependencies" : {
13
+ "babel-polyfill" : " ^6.0.0" ,
14
+ "event-rank" : " ^0.0.10"
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ import EventRank from './imported' ;
2
+
3
+ export function getEventRank ( ) {
4
+ return EventRank ;
5
+ }
Original file line number Diff line number Diff line change
1
+ import { EventRank } from 'event-rank' ;
2
+
3
+ export default EventRank ;
Original file line number Diff line number Diff line change
1
+ var entry = require ( '../src/entry' ) ;
2
+
3
+ describe ( "entry" , function ( ) {
4
+ it ( "getEventRank produces something" , function ( ) {
5
+ var EventRank = entry . getEventRank ( ) ;
6
+ expect ( EventRank ) . not . toBeUndefined ( ) ;
7
+ } ) ;
8
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "compilerOptions" : {
3
+ "allowJs" : true ,
4
+ "module" : " es2015" ,
5
+ "moduleResolution" : " node" ,
6
+ "noEmitOnError" : true ,
7
+ "noImplicitAny" : false ,
8
+ "sourceMap" : true ,
9
+ "target" : " es2015"
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-var, strict, prefer-arrow-callback */
2
+ 'use strict' ;
3
+
4
+ var path = require ( 'path' ) ;
5
+ var webpack = require ( 'webpack' ) ;
6
+
7
+ var babelOptions = {
8
+ "presets" : [
9
+ [
10
+ "es2015" ,
11
+ {
12
+ "modules" : false
13
+ }
14
+ ]
15
+ ]
16
+ } ;
17
+
18
+ module . exports = {
19
+ entry : './src/entry.js' ,
20
+ output : {
21
+ filename : 'bundle.js'
22
+ } ,
23
+ module : {
24
+ rules : [ {
25
+ test : / \. t s ( x ? ) $ / ,
26
+ exclude : / n o d e _ m o d u l e s / ,
27
+ use : [
28
+ {
29
+ loader : 'babel-loader' ,
30
+ options : babelOptions
31
+ } ,
32
+ {
33
+ loader : 'ts-loader' ,
34
+ options : { entryFileIsJs : true }
35
+ }
36
+ ]
37
+ } , {
38
+ test : / \. j s $ / ,
39
+ exclude : / n o d e _ m o d u l e s / ,
40
+ use : [
41
+ {
42
+ loader : 'babel-loader' ,
43
+ options : babelOptions
44
+ }
45
+ ]
46
+ } ]
47
+ } ,
48
+ resolve : {
49
+ // Add `.ts` and `.tsx` as a resolvable extension.
50
+ extensions : [ '.ts' , '.tsx' , '.js' ]
51
+ } ,
52
+ } ;
53
+
54
+ // for test harness purposes only, you would not need this in a normal project
55
+ module . exports . resolveLoader = { alias : { 'ts-loader' : path . join ( __dirname , "../../../index.js" ) } }
You can’t perform that action at this time.
0 commit comments