Skip to content

Commit d8a7348

Browse files
gunchabasarat
authored andcommitted
Allow using baseUrl, paths and rootDirs options in tsconfig,json (#996)
* allow baseUrl, paths, rootDirs in tsconfig files Add the above as valid tsconfig.json properties. Note: this change does not necessarily make these properties functional, it simply allows them to be passed to the transpiler. `baseUrl` and `paths` seem to work. `rootDirs` has not been verified and might not be functioning (at least on cur. typescript@next). TODO: this does not yet deeply validate the paths and rootDirs properties. * Upgrade ntypescript to 1.201607050909.1 * Convert baseUrl and rootDirs options to absolute paths * Fix a few type errors introduced by ntypescript upgrade * Remove outdated comment
1 parent 8a4a68c commit d8a7348

File tree

10 files changed

+53
-18
lines changed

10 files changed

+53
-18
lines changed

dist/main/lang/fixmyts/quickFixes/typeAssertPropertyAccessToAny.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ var TypeAssertPropertyAccessToAny = (function () {
1919
var parent = info.positionNode.parent;
2020
if (parent.kind == ts.SyntaxKind.PropertyAccessExpression) {
2121
var propertyAccess = parent;
22+
var idx = propertyAccess.getChildren().indexOf(info.positionNode);
23+
var prev = propertyAccess.getChildAt(idx - 2);
2224
var start = propertyAccess.getStart();
23-
var end = propertyAccess.dotToken.getStart();
25+
var end = prev.getEnd();
2426
var oldText = propertyAccess.getText().substr(0, end - start);
2527
var refactoring = {
2628
filePath: info.filePath,

dist/main/lang/fixmyts/quickFixes/typeAssertPropertyAccessToType.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ var TypeAssertPropertyAccessToType = (function () {
1919
var parent = info.positionNode.parent;
2020
if (parent.kind == ts.SyntaxKind.PropertyAccessExpression) {
2121
var propertyAccess = parent;
22+
var idx = propertyAccess.getChildren().indexOf(info.positionNode);
23+
var prev = propertyAccess.getChildAt(idx - 2);
2224
var start = propertyAccess.getStart();
23-
var end = propertyAccess.dotToken.getStart();
25+
var end = prev.getEnd();
2426
var oldText = propertyAccess.getText().substr(0, end - start);
2527
var refactoring = {
2628
filePath: info.filePath,

dist/main/tsconfig/simpleValidator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
exports.types = {
33
string: 'string',
44
boolean: 'boolean',
5-
number: 'number'
5+
number: 'number',
6+
object: 'object'
67
};
78
var SimpleValidator = (function () {
89
function SimpleValidator(validationInfo) {

dist/main/tsconfig/tsconfig.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var compilerOptionsValidation = {
2727
mapRoot: { type: types.string },
2828
module: { type: types.string, validValues: ['commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'] },
2929
moduleResolution: { type: types.string, validValues: ['classic', 'node'] },
30+
baseUrl: { type: types.string },
31+
paths: { type: types.object },
32+
rootDirs: { type: types.object },
3033
newLine: { type: types.string },
3134
noEmit: { type: types.boolean },
3235
noEmitHelpers: { type: types.boolean },
@@ -167,6 +170,14 @@ function rawToTsCompilerOptions(jsonOptions, projectDir) {
167170
if (compilerOptions.outFile !== undefined) {
168171
compilerOptions.outFile = path.resolve(projectDir, compilerOptions.outFile);
169172
}
173+
if (compilerOptions.baseUrl !== undefined) {
174+
compilerOptions.baseUrl = path.resolve(projectDir, compilerOptions.baseUrl);
175+
}
176+
if (compilerOptions.rootDirs !== undefined && Array.isArray(compilerOptions.rootDirs)) {
177+
compilerOptions.rootDirs = compilerOptions.rootDirs.map(function (dir) {
178+
return path.resolve(projectDir, dir);
179+
});
180+
}
170181
return compilerOptions;
171182
}
172183
function tsToRawCompilerOptions(compilerOptions) {

lib/main/lang/fixmyts/quickFixes/typeAssertPropertyAccessToAny.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ export class TypeAssertPropertyAccessToAny implements QuickFix {
1919
}
2020

2121
provideFix(info: QuickFixQueryInformation): Refactoring[] {
22-
/**
23-
* We want the largest property access expressing `a.b.c` starting at the identifer `c`
24-
* Since this gets tokenized as `a.b` `.` `c` so its just the parent :)
25-
*/
2622
let parent = info.positionNode.parent;
2723
if (parent.kind == ts.SyntaxKind.PropertyAccessExpression) {
2824
let propertyAccess = <ts.PropertyAccessExpression>parent;
25+
26+
// Find the previous identifier skipping over the DotToken
27+
let idx = propertyAccess.getChildren().indexOf(info.positionNode)
28+
let prev = propertyAccess.getChildAt(idx-2);
29+
2930
let start = propertyAccess.getStart();
30-
let end = propertyAccess.dotToken.getStart();
31+
let end = prev.getEnd();
3132

3233
let oldText = propertyAccess.getText().substr(0, end - start);
3334

lib/main/lang/fixmyts/quickFixes/typeAssertPropertyAccessToType.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ export class TypeAssertPropertyAccessToType implements QuickFix {
1919
}
2020

2121
provideFix(info: QuickFixQueryInformation): Refactoring[] {
22-
/**
23-
* We want the largest property access expressing `a.b.c` starting at the identifer `c`
24-
* Since this gets tokenized as `a.b` `.` `c` so its just the parent :)
25-
*/
2622
let parent = info.positionNode.parent;
2723
if (parent.kind == ts.SyntaxKind.PropertyAccessExpression) {
2824
let propertyAccess = <ts.PropertyAccessExpression>parent;
25+
26+
// Find the previous identifier skipping over the DotToken
27+
let idx = propertyAccess.getChildren().indexOf(info.positionNode)
28+
let prev = propertyAccess.getChildAt(idx-2);
29+
2930
let start = propertyAccess.getStart();
30-
let end = propertyAccess.dotToken.getStart();
31+
let end = prev.getEnd();
3132

3233
let oldText = propertyAccess.getText().substr(0, end - start);
3334

lib/main/tsconfig/simpleValidator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/// Not useful for user input validation
2-
// But great for simple config validation
2+
// But great for simple config validation
33
// works only by "n" valid options
44

55
export var types = {
66
string: 'string',
77
boolean: 'boolean',
8-
number: 'number'
8+
number: 'number',
9+
object: 'object'
910
}
1011

1112
export interface ValidationInfo {
@@ -41,7 +42,7 @@ export class SimpleValidator {
4142
else {
4243
errors.extraKeys.push(`Unknown Option: ${k}`)
4344
}
44-
}
45+
}
4546
// Do validation
4647
else {
4748
var validationInfo = this.validationInfo[k];

lib/main/tsconfig/tsconfig.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ interface CompilerOptions {
4040
mapRoot?: string; // Optionally Specifies the location where debugger should locate map files after deployment
4141
module?: string;
4242
moduleResolution?: string;
43+
baseUrl?: string;
44+
paths?: { [pattern: string]: string[] };
45+
rootDirs?: string[];
4346
newLine?: string;
4447
noEmit?: boolean;
4548
noEmitHelpers?: boolean;
@@ -97,6 +100,9 @@ var compilerOptionsValidation: simpleValidator.ValidationInfo = {
97100
mapRoot: { type: types.string },
98101
module: { type: types.string, validValues: ['commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'] },
99102
moduleResolution: { type: types.string, validValues: ['classic', 'node'] },
103+
baseUrl: { type: types.string },
104+
paths: { type: types.object },
105+
rootDirs: { type: types.object },
100106
newLine: { type: types.string },
101107
noEmit: { type: types.boolean },
102108
noEmitHelpers: { type: types.boolean },
@@ -336,6 +342,16 @@ function rawToTsCompilerOptions(jsonOptions: CompilerOptions, projectDir: string
336342
compilerOptions.outFile = path.resolve(projectDir, compilerOptions.outFile);
337343
}
338344

345+
if (compilerOptions.baseUrl !== undefined) {
346+
compilerOptions.baseUrl = path.resolve(projectDir, compilerOptions.baseUrl);
347+
}
348+
349+
if (compilerOptions.rootDirs !== undefined && Array.isArray(compilerOptions.rootDirs)) {
350+
compilerOptions.rootDirs = compilerOptions.rootDirs.map(function(dir) {
351+
return path.resolve(projectDir, dir)
352+
});
353+
}
354+
339355
return compilerOptions;
340356
}
341357

lib/typings/d3/d3.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ declare module D3 {
835835
* to compare, and should return either a negative, positive, or zero value to indicate
836836
* their relative order.
837837
*/
838-
sort(comparator?: (a: T, b: T) => number): _Selection<T>;
838+
sort(comparator?: (a: T, b: T) => number): this;
839839

840840
/**
841841
* Re-inserts elements into the document such that the document order matches the selection

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"immutable": "^3.7.3",
6767
"json2dts": "0.0.1",
6868
"mkdirp": "^0.5.0",
69-
"ntypescript": "1.201604232306.1",
69+
"ntypescript": "1.201607050909.1",
7070
"react": "^0.13.3",
7171
"season": "^5.1.4",
7272
"tsconfig": "^2.2.0",

0 commit comments

Comments
 (0)