11import fs from "fs-extra" ;
22import * as path from "path" ;
3- import { getOptions , OptionObject } from "loader-utils" ;
4- import validateOptions = require( "schema-utils" ) ;
5- import tsickle = require( "tsickle" ) ;
3+ import { validate } from "schema-utils" ;
4+ import * as tsickle from "tsickle" ;
65import ts from "typescript" ;
76import { EOL } from "os" ;
8- import webpack = require ( "webpack" ) ;
7+ import webpack from "webpack" ;
98import { fixCode , fixExtern } from "./fix-output" ;
109import { jsToTS , tsToJS } from "./path-utils" ;
11- import { TcpSocketConnectOpts } from "net " ;
10+ import { JSONSchema7 } from "json-schema " ;
1211
1312const LOADER_NAME = "tsickle-loader" ;
1413const DEFAULT_EXTERN_DIR = "dist/externs" ;
1514const EXTERNS_FILE_NAME = "externs.js" ;
1615const DEFAULT_CONFIG_FILE = "tsconfig.json" ;
1716
18- const optionsSchema = {
17+ const optionsSchema : JSONSchema7 = {
1918 type : "object" ,
2019 properties : {
2120 tsconfig : {
@@ -34,16 +33,16 @@ const optionsSchema = {
3433 }
3534} ;
3635
37- interface RealOptions extends OptionObject {
36+ interface RealOptions {
3837 externDir : string ;
3938 tsconfig : string ;
4039 externFile : string ;
4140 compilerConfig : ReturnType < typeof ts . parseJsonConfigFileContent > ;
4241}
4342
44- const setup = ( loaderCTX : webpack . loader . LoaderContext ) : RealOptions => {
45- const options = getOptions ( loaderCTX ) ;
46- validateOptions ( optionsSchema , options , LOADER_NAME ) ;
43+ const setup = ( loaderCTX : LoaderCTX ) : RealOptions => {
44+ const options = loaderCTX . getOptions ( ) ;
45+ validate ( optionsSchema , options , { name : LOADER_NAME } ) ;
4746
4847 const externDir =
4948 options . externDir != null ? options . externDir : DEFAULT_EXTERN_DIR ;
@@ -78,7 +77,7 @@ const setup = (loaderCTX: webpack.loader.LoaderContext): RealOptions => {
7877 } ;
7978} ;
8079
81- type LoaderCTX = webpack . loader . LoaderContext ;
80+ type LoaderCTX = webpack . LoaderContext < RealOptions > ;
8281
8382const handleDiagnostics = (
8483 ctx : LoaderCTX ,
@@ -92,13 +91,13 @@ const handleDiagnostics = (
9291 ) ;
9392
9493 if ( type === "error" ) {
95- ctx . emitError ( Error ( formatted ) ) ;
94+ ctx . emitError ( new Error ( formatted ) ) ;
9695 } else {
97- ctx . emitWarning ( formatted ) ;
96+ ctx . emitWarning ( new Error ( formatted ) ) ;
9897 }
9998} ;
10099
101- const tsickleLoader : webpack . loader . Loader = function (
100+ const tsickleLoader = function (
102101 this : LoaderCTX ,
103102 _source : string | Buffer
104103) {
@@ -131,15 +130,16 @@ const tsickleLoader: webpack.loader.Loader = function(
131130 pathToModuleName : ( name : string ) => name ,
132131 fileNameToModuleId : ( name : string ) => name ,
133132 options : { } , // TODO: set possible options here
134- es5Mode : true ,
135133 moduleResolutionHost : compilerHost ,
136134 googmodule : false ,
137135 transformDecorators : true ,
138136 transformTypesToClosure : true ,
139137 typeBlackListPaths : new Set ( ) ,
140138 untyped : false ,
141139 logWarning : warning =>
142- handleDiagnostics ( this , [ warning ] , diagnosticsHost , "warning" )
140+ handleDiagnostics ( this , [ warning ] , diagnosticsHost , "warning" ) ,
141+ generateExtraSuppressions : true ,
142+ rootDirsRelative : ( f : string ) => f ,
143143 } ;
144144
145145 const jsFiles = new Map < string , string > ( ) ;
0 commit comments