Skip to content

WIP: typescript sys proxy #231

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

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
75ece48
wrap typescript.sys in a proxy for handling of different file extensions
phryneas Mar 10, 2019
03f56ab
working module resolution
phryneas Mar 16, 2019
cb5f6ac
fix for useTypescriptIncrementalApi: false
phryneas Mar 16, 2019
12e8537
make wrapTypeScript configurable from the outside, start vue integration
phryneas Mar 16, 2019
49c25be
identify vuex by extension, not by contents
phryneas Mar 16, 2019
8ebdb38
skip VueProgram tests since VueProgram was deleted
phryneas Mar 16, 2019
6fa928b
make vue tests run using useTypescriptIncrementalApi true and false
johnnyreilly Mar 17, 2019
f8d1827
wrap creation of compilerHosts - less code changes to master
phryneas Mar 17, 2019
35eed6d
add /* @fork-ts-checker-handle-file-as TS */ comment
phryneas Mar 22, 2019
2ee76fe
no special tsx extension handling required any more
phryneas Mar 22, 2019
5a6731a
make tests use checker from real spawned service - mock "forking"
phryneas Mar 22, 2019
b4f9f19
tests: differentiate between ApiIncrementalChecker and IncrementalChe…
phryneas Mar 22, 2019
5c49439
add one expected error to make sure the test works at all
phryneas Mar 22, 2019
6e24d41
show correct file name in diagnostics
phryneas Mar 22, 2019
aadda93
prevent mocked child_process from leaking into other tests
phryneas Mar 22, 2019
ab8168b
more targeted tests; identifying specific error types
johnnyreilly Apr 6, 2019
c02c26d
add worker-rpc for inter-process-communication (use signal-based mess…
phryneas Apr 14, 2019
d023cae
use rpc calls instead of signaling
phryneas Apr 14, 2019
7400414
Merge branch 'worker-rpc' into typescript-sys-proxy
phryneas Apr 14, 2019
9ab2870
tests now working correctly with spawned sub-processes
phryneas Apr 14, 2019
19fe8ec
take review feedback into account, remove unnecessary file
phryneas Apr 14, 2019
b381c3c
Merge branch 'master' into worker-rpc
phryneas Apr 14, 2019
502e154
remove obsolete unit test
phryneas Apr 15, 2019
eacb1de
fix missed rpc call for webpack 2/3
phryneas Apr 15, 2019
ed83aee
Merge branch 'worker-rpc' into typescript-sys-proxy
phryneas Apr 16, 2019
808afbd
fix for typescript 3.4
phryneas Apr 19, 2019
f5c871e
Merge commit 'bbbbfce41e8ae37716f8534e90588845f43d738f' into typescri…
phryneas Apr 20, 2019
e21d9dc
fix(tests): rework vue integration tests
phryneas Apr 20, 2019
745f4b5
instead of wrapping the typescript object, actually replace functions…
phryneas Apr 21, 2019
9db85d7
Revert commits for #260 and #250 to re-apply them manually after merging
phryneas Apr 27, 2019
4296c91
Merge branch 'beta' into typescript-sys-proxy
phryneas Apr 27, 2019
928b016
manually re-apply commits for #250 and #260
phryneas Apr 27, 2019
1fc6aa5
experimental: use fake fs
May 16, 2019
cfa4360
remove unneccessary code
May 16, 2019
30380a7
Merge branch 'master' into fake-fs
phryneas Jun 2, 2019
96fabb3
adjust new tests to wrapped virtual file names
phryneas Jun 2, 2019
cade139
centralize parsing config from env
phryneas Jun 2, 2019
8475b1d
remove mdx-specific code
phryneas Jun 2, 2019
c73112f
rewrite fakeExtensionFs
phryneas Jun 2, 2019
6a39983
remove debugging console logs
phryneas Jun 2, 2019
d17dcd4
handle watching & promisifying, add test
phryneas Jun 9, 2019
fc2d2b7
remove obsolete test
phryneas Jun 9, 2019
66f4381
try to make tests more resilient in the CI
phryneas Jun 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = {
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
testMatch: ['**/?(*.)+(spec).[tj]s?(x)']
testMatch: ['**/?(*.)+(spec).[tj]s?(x)'],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
Expand Down Expand Up @@ -181,7 +181,7 @@ module.exports = {
// verbose: null,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
watchPathIgnorePatterns: ['test/tmp']

// Whether to use watchman for file crawling
// watchman: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"chokidar": "^2.0.4",
"micromatch": "^3.1.10",
"minimatch": "^3.0.4",
"mock-require": "^3.0.3",
"semver": "^5.6.0",
"tapable": "^1.0.0",
"worker-rpc": "^0.1.0"
Expand Down Expand Up @@ -131,7 +132,6 @@
"jest": "^24.7.1",
"lint-staged": "^8.0.5",
"mock-fs": "^4.3.0",
"mock-require": "^3.0.2",
"prettier": "^1.14.3",
"rimraf": "^2.5.4",
"semantic-release": "^16.0.0-beta.18",
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
81 changes: 16 additions & 65 deletions src/CompilerHost.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// tslint:disable-next-line:no-implicit-dependencies
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 +50,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 @@ -96,43 +76,8 @@ export class CompilerHost
// do nothing
}
);

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 Expand Up @@ -263,6 +208,20 @@ export class CompilerHost
// do nothing
}

public resolveModuleNames(
moduleNames: string[],
containingFile: string,
reusedNames?: string[],
redirectedReference?: ts.ResolvedProjectReference
): (ts.ResolvedModule | undefined)[] {
return this.tsHost.resolveModuleNames!(
moduleNames,
containingFile,
reusedNames,
redirectedReference
);
}

public watchDirectory(
path: string,
callback: ts.DirectoryWatcherCallback,
Expand Down Expand Up @@ -316,15 +275,7 @@ export class CompilerHost
}

public readFile(path: string, encoding?: string) {
const content = this.tsHost.readFile(path, encoding);

// get typescript contents from Vue file
if (content && VueProgram.isVue(path)) {
const resolved = VueProgram.resolveScriptBlock(this.typescript, content);
return resolved.content;
}

return content;
return this.tsHost.readFile(path, encoding);
}

public directoryExists(path: string): boolean {
Expand Down
83 changes: 5 additions & 78 deletions src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ 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';
import { IncrementalCheckerInterface } from './IncrementalCheckerInterface';

Expand Down Expand Up @@ -63,12 +57,7 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
private watchPaths: string[],
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 checkSyntacticErrors: boolean = false
) {
this.hasFixedConfig = typeof this.linterConfigFile === 'string';
}
Expand Down Expand Up @@ -111,48 +100,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 @@ -207,9 +159,7 @@ export class IncrementalChecker implements IncrementalCheckerInterface {

public nextIteration() {
if (!this.watcher) {
const watchExtensions = this.vue
? ['.ts', '.tsx', '.vue']
: ['.ts', '.tsx'];
const watchExtensions = ['.ts', '.tsx'];
this.watcher = new FilesWatcher(this.watchPaths, watchExtensions);

// connect watcher with register
Expand Down Expand Up @@ -239,34 +189,13 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
}
}

this.program = this.vue ? this.loadVueProgram() : this.loadDefaultProgram();
this.program = this.loadDefaultProgram();

if (this.linterConfigFile) {
this.linter = this.createLinter(this.program!);
}
}

private loadVueProgram() {
this.programConfig =
this.programConfig ||
VueProgram.loadProgramConfig(
this.typescript,
this.programConfigFile,
this.compilerOptions
);

return VueProgram.createProgram(
this.typescript,
this.programConfig,
path.dirname(this.programConfigFile),
this.files,
this.watcher!,
this.program!,
this.resolveModuleName,
this.resolveTypeReferenceDirective
);
}

private loadDefaultProgram() {
this.programConfig =
this.programConfig ||
Expand All @@ -281,9 +210,7 @@ export class IncrementalChecker implements IncrementalCheckerInterface {
this.programConfig,
this.files,
this.watcher!,
this.program!,
this.resolveModuleName,
this.resolveTypeReferenceDirective
this.program!
);
}

Expand Down
Loading