diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c437d5..9261c214 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.1 + +* [Fix a regression w/ plugins like tsconfig-paths-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/260) + ## v1.1.0 * [Add new custom resolution options](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/250) diff --git a/package.json b/package.json index 4dced347..d7075a37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fork-ts-checker-webpack-plugin", - "version": "1.1.0", + "version": "1.1.1", "description": "Runs typescript type checker and linter on separate process.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/CompilerHost.ts b/src/CompilerHost.ts index 47288bd5..f0bbc0e7 100644 --- a/src/CompilerHost.ts +++ b/src/CompilerHost.ts @@ -2,11 +2,7 @@ import * as ts from 'typescript'; // Imported for types alone import { LinkedList } from './LinkedList'; import { VueProgram } from './VueProgram'; -import { - ResolveModuleName, - ResolveTypeReferenceDirective, - makeResolutionFunctions -} from './resolution'; +import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution'; interface DirectoryWatchDelaySlot { events: { fileName: string }[]; @@ -56,8 +52,21 @@ export class CompilerHost private compilationStarted = false; - private readonly resolveModuleName: ResolveModuleName; - private readonly resolveTypeReferenceDirective: ResolveTypeReferenceDirective; + public resolveModuleNames: + | (( + moduleNames: string[], + containingFile: string, + reusedNames?: string[] | undefined, + redirectedReference?: ts.ResolvedProjectReference | undefined + ) => (ts.ResolvedModule | undefined)[]) + | undefined; + public resolveTypeReferenceDirectives: + | (( + typeReferenceDirectiveNames: string[], + containingFile: string, + redirectedReference?: ts.ResolvedProjectReference | undefined + ) => (ts.ResolvedTypeReferenceDirective | undefined)[]) + | undefined; constructor( private typescript: typeof ts, @@ -86,16 +95,39 @@ export class CompilerHost this.configFileName = this.tsHost.configFileName; this.optionsToExtend = this.tsHost.optionsToExtend || {}; - const { - resolveModuleName, - resolveTypeReferenceDirective - } = makeResolutionFunctions( - userResolveModuleName, - userResolveTypeReferenceDirective - ); + if (userResolveModuleName) { + this.resolveModuleNames = ( + moduleNames: string[], + containingFile: string + ) => { + return moduleNames.map(moduleName => { + return userResolveModuleName( + this.typescript, + moduleName, + containingFile, + this.optionsToExtend, + this + ).resolvedModule; + }); + }; + } - this.resolveModuleName = resolveModuleName; - this.resolveTypeReferenceDirective = resolveTypeReferenceDirective; + if (userResolveTypeReferenceDirective) { + this.resolveTypeReferenceDirectives = ( + typeDirectiveNames: string[], + containingFile: string + ) => { + return typeDirectiveNames.map(typeDirectiveName => { + return userResolveTypeReferenceDirective( + this.typescript, + typeDirectiveName, + containingFile, + this.optionsToExtend, + this + ).resolvedTypeReferenceDirective; + }); + }; + } } public async processChanges(): Promise<{ @@ -367,33 +399,6 @@ export class CompilerHost this.afterCompile(); } - public resolveModuleNames(moduleNames: string[], containingFile: string) { - return moduleNames.map(moduleName => { - return this.resolveModuleName( - this.typescript, - moduleName, - containingFile, - this.optionsToExtend, - this - ).resolvedModule; - }); - } - - public resolveTypeReferenceDirectives( - typeDirectiveNames: string[], - containingFile: string - ) { - return typeDirectiveNames.map(typeDirectiveName => { - return this.resolveTypeReferenceDirective( - this.typescript, - typeDirectiveName, - containingFile, - this.optionsToExtend, - this - ).resolvedTypeReferenceDirective; - }); - } - // the functions below are use internally by typescript. we cannot use non-emitting version of incremental watching API // because it is // - much slower for some reason, diff --git a/test/integration/helpers.js b/test/integration/helpers.js index 115fe408..705bdba3 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -23,7 +23,8 @@ exports.createVueCompiler = function(options) { resolve: { extensions: ['.ts', '.js', '.vue', '.json'], alias: { - '@': path.resolve(__dirname, './vue/src') + '@': path.resolve(__dirname, './vue/src'), + surprise: './src/index.ts' } }, module: { diff --git a/test/integration/index.spec.js b/test/integration/index.spec.js index 19490e64..0d33e082 100644 --- a/test/integration/index.spec.js +++ b/test/integration/index.spec.js @@ -35,6 +35,8 @@ function makeCommonTests(useTypescriptIncrementalApi) { return compiler.webpack; } + const skipIfIncremental = useTypescriptIncrementalApi ? it.skip : it; + /** * Implicitly check whether killService was called by checking that * the service property was set to undefined. @@ -132,6 +134,21 @@ function makeCommonTests(useTypescriptIncrementalApi) { }); }); + skipIfIncremental('should support custom resolution w/ "paths"', function( + callback + ) { + var compiler = createCompiler({ + tsconfig: 'tsconfig-weird-resolutions-with-paths.json', + resolveModuleNameModule: `${__dirname}/project/weirdResolver.js`, + resolveTypeReferenceDirectiveModule: `${__dirname}/project/weirdResolver.js` + }); + + compiler.run(function(err, stats) { + expect(stats.compilation.errors.length).to.be.eq(0); + callback(); + }); + }); + it('should fix linting errors with tslintAutofix flag set to true', function(callback) { const fileName = 'lintingError1'; helpers.testLintAutoFixTest( diff --git a/test/integration/project/src/pathResolutions.ts b/test/integration/project/src/pathResolutions.ts new file mode 100644 index 00000000..328c3a21 --- /dev/null +++ b/test/integration/project/src/pathResolutions.ts @@ -0,0 +1 @@ +import 'surprise'; diff --git a/test/integration/project/tsconfig-weird-resolutions-with-paths.json b/test/integration/project/tsconfig-weird-resolutions-with-paths.json new file mode 100644 index 00000000..9c3fc1b3 --- /dev/null +++ b/test/integration/project/tsconfig-weird-resolutions-with-paths.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "lib": ["es2016"], + "paths": { + "surprise": "./index.ts" + } + }, + "include": [ + "src/pathResolutions.ts", + "src/weirdResolutions.ts" + ] +} diff --git a/test/integration/project/tsconfig.json b/test/integration/project/tsconfig.json index e37f5727..676cd763 100644 --- a/test/integration/project/tsconfig.json +++ b/test/integration/project/tsconfig.json @@ -3,6 +3,7 @@ "lib": ["es2016"], }, "exclude": [ + "src/pathResolutions.ts", "src/weirdResolutions.ts" ] }