Skip to content

Commit

Permalink
Revert commits for TypeStrong#260 and TypeStrong#250 to re-apply them…
Browse files Browse the repository at this point in the history
… manually after merging

Revert "Enables custom resolver only if they're used in incremental mode (TypeStrong#260)"

This reverts commit 3990a13.

Revert "Adds support for custom resolvers to CompilerHost (TypeStrong#250) - fixes TypeStrong#181"

This reverts commit dfd8933.
  • Loading branch information
phryneas committed Apr 27, 2019
1 parent 4bde6f1 commit 9db85d7
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 348 deletions.
11 changes: 4 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# [1.2.0-beta.4](https://github.com/Realytics/fork-ts-checker-webpack-plugin/compare/v1.2.0-beta.3@beta...v1.2.0-beta.4@beta) (2019-04-23)


### Bug Fixes

* **tests:** fix linter tests that were doing nothing ([d078278](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/d078278))
* **tests:** linter tests - useTypescriptIncrementalApi usage ([e0020d6](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/e0020d6))

- **tests:** fix linter tests that were doing nothing ([d078278](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/d078278))
- **tests:** linter tests - useTypescriptIncrementalApi usage ([e0020d6](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/e0020d6))

### Features

* **apiincrementalchecker:** improve generation of diagnostics ([ae80e5f](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/ae80e5f)), closes [#257](https://github.com/Realytics/fork-ts-checker-webpack-plugin/issues/257)
- **apiincrementalchecker:** improve generation of diagnostics ([ae80e5f](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/ae80e5f)), closes [#257](https://github.com/Realytics/fork-ts-checker-webpack-plugin/issues/257)

# [1.2.0-beta.3](https://github.com/Realytics/fork-ts-checker-webpack-plugin/compare/v1.2.0-beta.2@beta...v1.2.0-beta.3@beta) (2019-04-22)


### Bug Fixes

* **tests:** rework vue integration tests ([5ad2568](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/5ad2568))
- **tests:** rework vue integration tests ([5ad2568](https://github.com/Realytics/fork-ts-checker-webpack-plugin/commit/5ad2568))

# [1.2.0-beta.2](https://github.com/Realytics/fork-ts-checker-webpack-plugin/compare/v1.2.0-beta.1@beta...v1.2.0-beta.2@beta) (2019-04-22)

Expand Down
9 changes: 2 additions & 7 deletions src/ApiIncrementalChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from './linterConfigHelpers';
import { NormalizedMessage } from './NormalizedMessage';
import { CompilerHost } from './CompilerHost';
import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution';
import { FsHelper } from './FsHelper';

export class ApiIncrementalChecker implements IncrementalCheckerInterface {
Expand Down Expand Up @@ -42,9 +41,7 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface {
private context: string,
private linterConfigFile: string | boolean,
private linterAutoFix: boolean,
checkSyntacticErrors: boolean,
resolveModuleName: ResolveModuleName | undefined,
resolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined
checkSyntacticErrors: boolean
) {
this.hasFixedConfig = typeof this.linterConfigFile === 'string';

Expand All @@ -54,9 +51,7 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface {
typescript,
programConfigFile,
compilerOptions,
checkSyntacticErrors,
resolveModuleName,
resolveTypeReferenceDirective
checkSyntacticErrors
);
}

Expand Down
55 changes: 1 addition & 54 deletions src/CompilerHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as ts from 'typescript'; // Imported for types alone
import { LinkedList } from './LinkedList';
import { VueProgram } from './VueProgram';
import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution';

interface DirectoryWatchDelaySlot {
events: { fileName: string }[];
Expand Down Expand Up @@ -52,29 +51,11 @@ export class CompilerHost

private compilationStarted = false;

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,
programConfigFile: string,
compilerOptions: ts.CompilerOptions,
checkSyntacticErrors: boolean,
userResolveModuleName?: ResolveModuleName,
userResolveTypeReferenceDirective?: ResolveTypeReferenceDirective
checkSyntacticErrors: boolean
) {
this.tsHost = typescript.createWatchCompilerHost(
programConfigFile,
Expand All @@ -94,40 +75,6 @@ export class CompilerHost

this.configFileName = this.tsHost.configFileName;
this.optionsToExtend = this.tsHost.optionsToExtend || {};

if (userResolveModuleName) {
this.resolveModuleNames = (
moduleNames: string[],
containingFile: string
) => {
return moduleNames.map(moduleName => {
return userResolveModuleName(
this.typescript,
moduleName,
containingFile,
this.optionsToExtend,
this
).resolvedModule;
});
};
}

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<{
Expand Down
58 changes: 4 additions & 54 deletions src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import {
import { WorkSet } from './WorkSet';
import { NormalizedMessage } from './NormalizedMessage';
import { CancellationToken } from './CancellationToken';
import {
ResolveModuleName,
ResolveTypeReferenceDirective,
makeResolutionFunctions
} from './resolution';
import * as minimatch from 'minimatch';
import { VueProgram } from './VueProgram';
import { FsHelper } from './FsHelper';
Expand Down Expand Up @@ -64,11 +59,7 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
private workNumber: number = 0,
private workDivision: number = 1,
private checkSyntacticErrors: boolean = false,
private vue: boolean = false,
private resolveModuleName: ResolveModuleName | undefined,
private resolveTypeReferenceDirective:
| ResolveTypeReferenceDirective
| undefined
private vue: boolean = false
) {
this.hasFixedConfig = typeof this.linterConfigFile === 'string';
}
Expand Down Expand Up @@ -111,48 +102,11 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
programConfig: ts.ParsedCommandLine,
files: FilesRegister,
watcher: FilesWatcher,
oldProgram: ts.Program,
userResolveModuleName: ResolveModuleName | undefined,
userResolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined
oldProgram: ts.Program
) {
const host = typescript.createCompilerHost(programConfig.options);
const realGetSourceFile = host.getSourceFile;

const {
resolveModuleName,
resolveTypeReferenceDirective
} = makeResolutionFunctions(
userResolveModuleName,
userResolveTypeReferenceDirective
);

host.resolveModuleNames = (moduleNames, containingFile) => {
return moduleNames.map(moduleName => {
return resolveModuleName(
typescript,
moduleName,
containingFile,
programConfig.options,
host
).resolvedModule;
});
};

host.resolveTypeReferenceDirectives = (
typeDirectiveNames,
containingFile
) => {
return typeDirectiveNames.map(typeDirectiveName => {
return resolveTypeReferenceDirective(
typescript,
typeDirectiveName,
containingFile,
programConfig.options,
host
).resolvedTypeReferenceDirective;
});
};

host.getSourceFile = (filePath, languageVersion, onError) => {
// first check if watcher is watching file - if not - check it's mtime
if (!watcher.isWatchingFile(filePath)) {
Expand Down Expand Up @@ -261,9 +215,7 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
path.dirname(this.programConfigFile),
this.files,
this.watcher!,
this.program!,
this.resolveModuleName,
this.resolveTypeReferenceDirective
this.program!
);
}

Expand All @@ -281,9 +233,7 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
this.programConfig,
this.files,
this.watcher!,
this.program!,
this.resolveModuleName,
this.resolveTypeReferenceDirective
this.program!
);
}

Expand Down
44 changes: 1 addition & 43 deletions src/VueProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import * as path from 'path';
import * as ts from 'typescript'; // import for types alone
import { FilesRegister } from './FilesRegister';
import { FilesWatcher } from './FilesWatcher';
import {
ResolveModuleName,
ResolveTypeReferenceDirective,
makeResolutionFunctions
} from './resolution';
// tslint:disable-next-line:no-implicit-dependencies
import * as vueCompiler from 'vue-template-compiler';

Expand Down Expand Up @@ -125,48 +120,11 @@ export class VueProgram {
basedir: string,
files: FilesRegister,
watcher: FilesWatcher,
oldProgram: ts.Program,
userResolveModuleName: ResolveModuleName | undefined,
userResolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined
oldProgram: ts.Program
) {
const host = typescript.createCompilerHost(programConfig.options);
const realGetSourceFile = host.getSourceFile;

const {
resolveModuleName,
resolveTypeReferenceDirective
} = makeResolutionFunctions(
userResolveModuleName,
userResolveTypeReferenceDirective
);

host.resolveModuleNames = (moduleNames, containingFile) => {
return moduleNames.map(moduleName => {
return resolveModuleName(
typescript,
moduleName,
containingFile,
programConfig.options,
host
).resolvedModule;
});
};

host.resolveTypeReferenceDirectives = (
typeDirectiveNames,
containingFile
) => {
return typeDirectiveNames.map(typeDirectiveName => {
return resolveTypeReferenceDirective(
typescript,
typeDirectiveName,
containingFile,
programConfig.options,
host
).resolvedTypeReferenceDirective;
});
};

// We need a host that can parse Vue SFCs (single file components).
host.getSourceFile = (filePath, languageVersion, onError) => {
// first check if watcher is watching file - if not - check it's mtime
Expand Down
52 changes: 15 additions & 37 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ interface Options {
vue: boolean;
useTypescriptIncrementalApi: boolean;
measureCompilationTime: boolean;
resolveModuleNameModule: string;
resolveTypeReferenceDirectiveModule: string;
}

/**
Expand Down Expand Up @@ -101,8 +99,6 @@ class ForkTsCheckerWebpackPlugin {
private colors: Chalk;
private formatter: Formatter;
private useTypescriptIncrementalApi: boolean;
private resolveModuleNameModule: string | undefined;
private resolveTypeReferenceDirectiveModule: string | undefined;

private tsconfigPath?: string;
private tslintPath?: string;
Expand Down Expand Up @@ -162,9 +158,6 @@ class ForkTsCheckerWebpackPlugin {
this.silent = options.silent === true; // default false
this.async = options.async !== false; // default true
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
this.resolveModuleNameModule = options.resolveModuleNameModule;
this.resolveTypeReferenceDirectiveModule =
options.resolveTypeReferenceDirectiveModule;
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
this.memoryLimit =
options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
Expand Down Expand Up @@ -576,50 +569,35 @@ class ForkTsCheckerWebpackPlugin {
}

private spawnService() {
const env: { [key: string]: string | undefined } = {
...process.env,
TYPESCRIPT_PATH: this.typescriptPath,
TSCONFIG: this.tsconfigPath,
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
TSLINT: this.tslintPath || (this.tslint ? 'true' : ''),
CONTEXT: this.compiler.options.context,
TSLINTAUTOFIX: String(this.tslintAutoFix),
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
WORK_DIVISION: String(Math.max(1, this.workersNumber)),
MEMORY_LIMIT: String(this.memoryLimit),
CHECK_SYNTACTIC_ERRORS: String(this.checkSyntacticErrors),
USE_INCREMENTAL_API: String(this.useTypescriptIncrementalApi === true),
VUE: String(this.vue)
};

if (typeof this.resolveModuleNameModule !== 'undefined') {
env.RESOLVE_MODULE_NAME = this.resolveModuleNameModule;
} else {
delete env.RESOLVE_MODULE_NAME;
}

if (typeof this.resolveTypeReferenceDirectiveModule !== 'undefined') {
env.RESOLVE_TYPE_REFERENCE_DIRECTIVE = this.resolveTypeReferenceDirectiveModule;
} else {
delete env.RESOLVE_TYPE_REFERENCE_DIRECTIVE;
}

this.service = childProcess.fork(
path.resolve(
__dirname,
this.workersNumber > 1 ? './cluster.js' : './service.js'
),
[],
{
env,
execArgv: (this.workersNumber > 1
? []
: ['--max-old-space-size=' + this.memoryLimit]
).concat(this.nodeArgs),
env: {
...process.env,
TYPESCRIPT_PATH: this.typescriptPath,
TSCONFIG: this.tsconfigPath,
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
TSLINT: this.tslintPath || (this.tslint ? 'true' : ''),
CONTEXT: this.compiler.options.context,
TSLINTAUTOFIX: this.tslintAutoFix,
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
WORK_DIVISION: Math.max(1, this.workersNumber),
MEMORY_LIMIT: this.memoryLimit,
CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors,
USE_INCREMENTAL_API: this.useTypescriptIncrementalApi === true,
VUE: this.vue
},
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
}
);

this.serviceRpc = new RpcProvider(message => this.service!.send(message));
this.service.on('message', message => this.serviceRpc!.dispatch(message));

Expand Down
Loading

0 comments on commit 9db85d7

Please sign in to comment.