tsconfig
Advanced tools
Comparing version 4.0.0 to 5.0.0
import Promise = require('any-promise'); | ||
export interface CompilerOptions { | ||
[key: string]: any; | ||
export interface LoadResult { | ||
path?: string; | ||
config?: any; | ||
} | ||
export interface TSConfig { | ||
compilerOptions?: CompilerOptions; | ||
files?: string[]; | ||
include?: string[]; | ||
exclude?: string[]; | ||
[key: string]: any; | ||
} | ||
export declare function resolve(cwd: string, filename?: string): Promise<string | void>; | ||
@@ -16,6 +10,6 @@ export declare function resolveSync(cwd: string, filename?: string): string | void; | ||
export declare function findSync(dir: string): string | void; | ||
export declare function load(cwd: string, filename?: string): Promise<TSConfig>; | ||
export declare function loadSync(cwd: string, filename?: string): TSConfig; | ||
export declare function readFile(filename: string): Promise<TSConfig>; | ||
export declare function readFileSync(filename: string): TSConfig; | ||
export declare function load(cwd: string, filename?: string): Promise<LoadResult>; | ||
export declare function loadSync(cwd: string, filename?: string): LoadResult; | ||
export declare function readFile(filename: string): Promise<any>; | ||
export declare function readFileSync(filename: string): any; | ||
export declare function parse(contents: string, filename: string): any; |
@@ -84,3 +84,8 @@ "use strict"; | ||
.then(function (path) { | ||
return path == null ? Promise.resolve({}) : readFile(path); | ||
if (path == null) { | ||
return Promise.resolve({ | ||
config: {} | ||
}); | ||
} | ||
return readFile(path).then(function (config) { return ({ config: config, path: path }); }); | ||
}); | ||
@@ -91,3 +96,9 @@ } | ||
var path = resolveSync(cwd, filename); | ||
return path == null ? {} : readFileSync(path); | ||
if (path == null) { | ||
return { | ||
config: {} | ||
}; | ||
} | ||
var config = readFileSync(path); | ||
return { path: path, config: config }; | ||
} | ||
@@ -94,0 +105,0 @@ exports.loadSync = loadSync; |
@@ -10,32 +10,35 @@ "use strict"; | ||
{ | ||
path: [TEST_DIR, 'invalidfile'], | ||
args: [TEST_DIR, 'invalidfile'], | ||
error: "Unexpected token 's' at 1:1 in " + path_1.join(TEST_DIR, 'invalidfile/tsconfig.json') + "\nsome random string\n^" | ||
}, | ||
{ | ||
path: [TEST_DIR, 'missing'], | ||
args: [TEST_DIR, 'missing'], | ||
error: 'Cannot find a tsconfig.json file at the specified directory: missing' | ||
}, | ||
{ | ||
path: [TEST_DIR, 'missing/foobar'], | ||
args: [TEST_DIR, 'missing/foobar'], | ||
error: 'The specified path does not exist: missing/foobar' | ||
}, | ||
{ | ||
path: ['/'], | ||
result: {} | ||
args: ['/'], | ||
config: {} | ||
}, | ||
{ | ||
path: [TEST_DIR, 'empty'], | ||
result: {} | ||
args: [TEST_DIR, 'empty'], | ||
config: {}, | ||
path: path_1.join(TEST_DIR, 'empty/tsconfig.json') | ||
}, | ||
{ | ||
path: [TEST_DIR, 'empty/tsconfig.json'], | ||
result: {} | ||
args: [TEST_DIR, 'empty/tsconfig.json'], | ||
config: {}, | ||
path: path_1.join(TEST_DIR, 'empty/tsconfig.json') | ||
}, | ||
{ | ||
path: [path_1.join(TEST_DIR, 'find/up/config')], | ||
result: {} | ||
args: [path_1.join(TEST_DIR, 'find/up/config')], | ||
config: {}, | ||
path: path_1.join(TEST_DIR, 'find/tsconfig.json') | ||
}, | ||
{ | ||
path: [TEST_DIR, 'valid'], | ||
result: { | ||
args: [TEST_DIR, 'valid'], | ||
config: { | ||
compilerOptions: { | ||
@@ -53,7 +56,7 @@ module: 'commonjs', | ||
}, | ||
filename: path_1.join(__dirname, '../tests/valid/tsconfig.json') | ||
path: path_1.join(TEST_DIR, 'valid/tsconfig.json') | ||
}, | ||
{ | ||
path: [TEST_DIR, 'bom'], | ||
result: { | ||
args: [TEST_DIR, 'bom'], | ||
config: { | ||
compilerOptions: { | ||
@@ -71,7 +74,7 @@ module: 'commonjs', | ||
}, | ||
filename: path_1.join(__dirname, '../tests/bom/tsconfig.json') | ||
path: path_1.join(TEST_DIR, 'bom/tsconfig.json') | ||
}, | ||
{ | ||
path: [path_1.join(TEST_DIR, 'cwd')], | ||
result: { | ||
args: [path_1.join(TEST_DIR, 'cwd')], | ||
config: { | ||
compilerOptions: { | ||
@@ -86,3 +89,3 @@ module: 'commonjs', | ||
}, | ||
filename: path_1.join(__dirname, '../tests/cwd/tsconfig.json') | ||
path: path_1.join(TEST_DIR, 'cwd/tsconfig.json') | ||
} | ||
@@ -92,7 +95,7 @@ ]; | ||
tests.forEach(function (test) { | ||
describe(util_1.inspect(test.path), function () { | ||
describe(util_1.inspect(test.args), function () { | ||
it('should try to find config', function () { | ||
var result; | ||
try { | ||
result = tsconfig.loadSync(test.path[0], test.path[1]); | ||
result = tsconfig.loadSync(test.args[0], test.args[1]); | ||
} | ||
@@ -103,7 +106,8 @@ catch (err) { | ||
} | ||
chai_1.expect(result).to.deep.equal(test.result); | ||
chai_1.expect(result.path).to.equal(test.path); | ||
chai_1.expect(result.config).to.deep.equal(test.config); | ||
}); | ||
if (test.filename) { | ||
if (test.path) { | ||
it('should resolve filename', function () { | ||
chai_1.expect(tsconfig.resolveSync(test.path[0], test.path[1])).to.equal(test.filename); | ||
chai_1.expect(tsconfig.resolveSync(test.args[0], test.args[1])).to.equal(test.path); | ||
}); | ||
@@ -116,11 +120,18 @@ } | ||
tests.forEach(function (test) { | ||
describe(util_1.inspect(test.path), function () { | ||
describe(util_1.inspect(test.args), function () { | ||
it('should try to find config', function () { | ||
return tsconfig.load(test.path[0], test.path[1]) | ||
.then(function (config) { return chai_1.expect(config).to.deep.equal(test.result); }, function (error) { return chai_1.expect(error.message).to.equal(test.error); }); | ||
return tsconfig.load(test.args[0], test.args[1]) | ||
.then(function (result) { | ||
chai_1.expect(result.path).to.equal(test.path); | ||
chai_1.expect(result.config).to.deep.equal(test.config); | ||
}, function (error) { | ||
chai_1.expect(error.message).to.equal(test.error); | ||
}); | ||
}); | ||
if (test.filename) { | ||
if (test.path) { | ||
it('should resolve filename', function () { | ||
return tsconfig.resolve(test.path[0], test.path[1]) | ||
.then(function (filename) { return chai_1.expect(filename).to.equal(test.filename); }); | ||
return tsconfig.resolve(test.args[0], test.args[1]) | ||
.then(function (filename) { | ||
chai_1.expect(filename).to.equal(test.path); | ||
}); | ||
}); | ||
@@ -127,0 +138,0 @@ } |
{ | ||
"name": "tsconfig", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Resole and parse `tsconfig.json`, replicating to TypeScript's behaviour", | ||
@@ -5,0 +5,0 @@ "main": "dist/tsconfig.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22254
314
0