Skip to content

Commit

Permalink
fix getProjectRootPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Nov 6, 2017
1 parent f615422 commit e92a5ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"npm-run-all": "^4.1.1",
"rimraf": "^2.6.1",
"tslint": "^5.7.0",
"typescript": "^2.5.2"
"typescript": "^2.6.1"
},
"peerDependencies": {
"graphql": "^0.10.2",
Expand Down
12 changes: 10 additions & 2 deletions src/schema-manager/file-schema-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FileSchemaManager extends SchemaManager {
getSchema() {
if (!this._schemaPath || typeof this._schemaPath !== 'string') return;
try {
const resolvedSchmaPath = this.getAbsoluteSchemaPath(this._info.project.getProjectRootPath(), this._schemaPath);
const resolvedSchmaPath = this.getAbsoluteSchemaPath(this._getProjectRootPath(this._info), this._schemaPath);
this.log('Read schema from ' + resolvedSchmaPath);
const isExists = this._info.languageServiceHost.fileExists(resolvedSchmaPath);
if (!isExists) return;
Expand All @@ -37,7 +37,7 @@ export class FileSchemaManager extends SchemaManager {

startWatch(interval: number = 100) {
try {
const resolvedSchmaPath = this.getAbsoluteSchemaPath(this._info.project.getProjectRootPath(), this._schemaPath);
const resolvedSchmaPath = this.getAbsoluteSchemaPath(this._getProjectRootPath(this._info), this._schemaPath);
this._watcher = this._info.serverHost.watchFile(resolvedSchmaPath, () => {
this._log('Change schema file.');
this.emitChange();
Expand All @@ -53,6 +53,14 @@ export class FileSchemaManager extends SchemaManager {
if (this._watcher) this._watcher.close();
}

private _getProjectRootPath(info: ts.server.PluginCreateInfo) {
const { project } = info;
if (typeof (project as any).getProjectRootPath === 'function') {
return (project as any).getProjectRootPath();
}
return path.dirname(project.getProjectName());
}

private _log(msg: string) {
this._info.project.projectService.logger.info(`[ts-graphql-plugin] ${msg}`);
}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2951,9 +2951,9 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"

typescript@^2.5.2:
version "2.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.2.tgz#038a95f7d9bbb420b1bf35ba31d4c5c1dd3ffe34"
typescript@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.1.tgz#ef39cdea27abac0b500242d6726ab90e0c846631"

uid-number@^0.0.6:
version "0.0.6"
Expand Down

0 comments on commit e92a5ec

Please sign in to comment.