Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compilerOptions option #173

Merged
merged 4 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ It helps to distinguish lints from typescript's diagnostics.
* **tsconfig** `string`:
Path to *tsconfig.json* file. Default: `path.resolve(compiler.options.context, './tsconfig.json')`.

* **compilerOptions** `string`:
ianschmitz marked this conversation as resolved.
Show resolved Hide resolved
Allows overriding TypeScript options. Should be specified in the same format as you would do for the `compilerOptions` property in tsconfig.json. Default: `{}`.

* **tslint** `string | true`:
Path to *tslint.json* file or `true`. If `true`, uses `path.resolve(compiler.options.context, './tslint.json')`. Default: `undefined`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the documented type of compilerOptions be object instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. Good catch! Was a late night for me yesterday 😛


Expand Down
21 changes: 17 additions & 4 deletions src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ConfigurationFile extends Configuration.IConfigurationFile {

export class IncrementalChecker {
programConfigFile: string;
compilerOptions: object;
linterConfigFile: string | false;
watchPaths: string[];
workNumber: number;
Expand All @@ -41,6 +42,7 @@ export class IncrementalChecker {

constructor(
programConfigFile: string,
compilerOptions: object,
linterConfigFile: string | false,
watchPaths: string[],
workNumber: number,
Expand All @@ -49,6 +51,7 @@ export class IncrementalChecker {
vue: boolean
) {
this.programConfigFile = programConfigFile;
this.compilerOptions = compilerOptions;
this.linterConfigFile = linterConfigFile;
this.watchPaths = watchPaths;
this.workNumber = workNumber || 0;
Expand All @@ -68,15 +71,19 @@ export class IncrementalChecker {
}));
}

static loadProgramConfig(configFile: string) {
return ts.parseJsonConfigFileContent(
static loadProgramConfig(configFile: string, compilerOptions: object) {
const parsed = ts.parseJsonConfigFileContent(
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
isolatedModules: false
}),
ts.sys,
path.dirname(configFile)
);

parsed.options = { ...parsed.options, ...compilerOptions };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we can use object spread as it won't work on node 6 (and fork-ts-checker supports node 6). https://node.green/#ES2018-features-object-rest-spread-properties-object-spread-properties

Can we switch to Object.assign please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript will compile it down to Object.assign for you as long as your target is correct. It's a little tough for me to check as I'm on my phone right now but will double check tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use assign elsewhere in code base I don't mind changing either way!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript will compile it down to Object.assign for you as long as your target is correct. It's a little tough for me to check as I'm on my phone right now but will double check tomorrow.

If that's the case then that's fine with me!


return parsed;
}

static loadLinterConfig(configFile: string): ConfigurationFile {
Expand Down Expand Up @@ -189,7 +196,10 @@ export class IncrementalChecker {
loadVueProgram() {
this.programConfig =
this.programConfig ||
VueProgram.loadProgramConfig(this.programConfigFile);
VueProgram.loadProgramConfig(
this.programConfigFile,
this.compilerOptions
);

return VueProgram.createProgram(
this.programConfig,
Expand All @@ -203,7 +213,10 @@ export class IncrementalChecker {
loadDefaultProgram() {
this.programConfig =
this.programConfig ||
IncrementalChecker.loadProgramConfig(this.programConfigFile);
IncrementalChecker.loadProgramConfig(
this.programConfigFile,
this.compilerOptions
);

return IncrementalChecker.createProgram(
this.programConfig,
Expand Down
3 changes: 2 additions & 1 deletion src/VueProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ResolvedScript {
}

export class VueProgram {
static loadProgramConfig(configFile: string) {
static loadProgramConfig(configFile: string, compilerOptions: object) {
const extraExtensions = ['vue'];

const parseConfigHost: ts.ParseConfigHost = {
Expand Down Expand Up @@ -40,6 +40,7 @@ export class VueProgram {
);

parsed.options.allowNonTsExtensions = true;
parsed.options = { ...parsed.options, ...compilerOptions };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we can use object spread as it won't work on node 6 (and fork-ts-checker supports node 6). https://node.green/#ES2018-features-object-rest-spread-properties-object-spread-properties

Can we switch to Object.assign please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again - fine with this staying as is if TypeScript transpiles us to glory! 😄


return parsed;
}
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface Logger {

interface Options {
tsconfig: string;
compilerOptions: object;
tslint: string | true;
watch: string | string[];
async: boolean;
Expand Down Expand Up @@ -71,6 +72,7 @@ class ForkTsCheckerWebpackPlugin {

options: Partial<Options>;
tsconfig: string;
compilerOptions: object;
tslint: string | true;
watch: string[];
ignoreDiagnostics: number[];
Expand Down Expand Up @@ -114,6 +116,10 @@ class ForkTsCheckerWebpackPlugin {
this.options = Object.assign({}, options);

this.tsconfig = options.tsconfig || './tsconfig.json';
this.compilerOptions =
typeof options.compilerOptions === 'object'
? options.compilerOptions
: {};
this.tslint = options.tslint
? options.tslint === true
? './tslint.json'
Expand Down Expand Up @@ -554,6 +560,7 @@ class ForkTsCheckerWebpackPlugin {
: ['--max-old-space-size=' + this.memoryLimit],
env: Object.assign({}, process.env, {
TSCONFIG: this.tsconfigPath,
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
TSLINT: this.tslintPath || '',
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
WORK_DIVISION: Math.max(1, this.workersNumber),
Expand Down
1 change: 1 addition & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NormalizedMessage } from './NormalizedMessage';

const checker = new IncrementalChecker(
process.env.TSCONFIG,
JSON.parse(process.env.COMPILER_OPTIONS),
process.env.TSLINT === '' ? false : process.env.TSLINT,
process.env.WATCH === '' ? [] : process.env.WATCH.split('|'),
parseInt(process.env.WORK_NUMBER, 10),
Expand Down
1 change: 1 addition & 0 deletions test/integration/vue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('[INTEGRATION] vue', function() {

checker = new IncrementalChecker(
plugin.tsconfigPath,
{},
plugin.tslintPath || false,
[compiler.context],
ForkTsCheckerWebpackPlugin.ONE_CPU,
Expand Down