From d4025d3006e7f56c00936cb7ba9885ed408d1a3f Mon Sep 17 00:00:00 2001 From: Stanislav Panferov Date: Fri, 14 Aug 2015 09:22:02 +0300 Subject: [PATCH] feat(*): read `.d.ts` files from `tsconfig.json` --- .gitignore | 1 + examples/tsx/index.tsx | 2 -- examples/tsx/package.json | 2 ++ examples/tsx/tsconfig.json | 27 +++++++++++++++++++++++++++ examples/tsx/webpack.config.js | 8 ++------ src/deps.ts | 1 - src/host.ts | 1 + src/index.ts | 15 +++++++++++++-- 8 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 examples/tsx/tsconfig.json diff --git a/.gitignore b/.gitignore index c78d44e..8e767fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules dist tscommand npm-debug.log +.awcache diff --git a/examples/tsx/index.tsx b/examples/tsx/index.tsx index 953e90c..dd7b039 100644 --- a/examples/tsx/index.tsx +++ b/examples/tsx/index.tsx @@ -1,5 +1,3 @@ -/// - import * as React from 'react'; class Component extends React.Component<{ text: string }, void> { diff --git a/examples/tsx/package.json b/examples/tsx/package.json index f38676f..fd3c0e6 100644 --- a/examples/tsx/package.json +++ b/examples/tsx/package.json @@ -10,11 +10,13 @@ "license": "MIT", "dependencies": {}, "devDependencies": { + "babel": "^5.8.21", "babel-core": "^5.6.20", "babel-loader": "^5.3.1", "html-webpack-plugin": "^1.6.0", "node-libs-browser": "^0.5.2", "react": "^0.13.3", + "typescript": "^1.6.0-dev.20150813", "webpack": "^1.10.1", "webpack-dev-server": "^1.10.1" } diff --git a/examples/tsx/tsconfig.json b/examples/tsx/tsconfig.json new file mode 100644 index 0000000..9fdfcc3 --- /dev/null +++ b/examples/tsx/tsconfig.json @@ -0,0 +1,27 @@ +{ + "version": "1.5.0-beta", + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "isolatedModules": false, + "jsx": "react", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "declaration": false, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "preserveConstEnums": true, + "suppressImplicitAnyIndexErrors": true + }, + "compileOnSave": false, + "filesGlob": [ + "./**/*.ts", + "./**/*.tsx", + "!./node_modules/**/*" + ], + "files": [ + "./typings/react.d.ts", + "./index.tsx" + ] +} diff --git a/examples/tsx/webpack.config.js b/examples/tsx/webpack.config.js index 157ff35..670f7f1 100644 --- a/examples/tsx/webpack.config.js +++ b/examples/tsx/webpack.config.js @@ -8,12 +8,8 @@ module.exports = { module: { loaders: [ { - test: /\.tsx$/, - loader: 'babel-loader!awesome-typescript-loader?compiler=ntypescript&module=common&jsx=react' - }, - { - test: /\.ts$/, - loader: 'awesome-typescript-loader?compiler=ntypescript&module=common' + test: /\.tsx?$/, + loader: '../../dist/index.js?+useCache&+useBabel&module=common&jsx=preserve' } ] }, diff --git a/src/deps.ts b/src/deps.ts index bc948d1..d7cdf40 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -74,7 +74,6 @@ export class FileAnalyzer { this.dependencies.clearDependencies(fileName); - let flow = this.state.hasFile(fileName) ? Promise.resolve(false) : this.state.readFileAndUpdate(fileName); diff --git a/src/host.ts b/src/host.ts index 7b5d8cc..1329d8f 100644 --- a/src/host.ts +++ b/src/host.ts @@ -42,6 +42,7 @@ export interface ICompilerOptions extends ts.CompilerOptions { usePrecompiledFiles?: boolean; useCache?: boolean; cacheDirectory?: string; + files?: any; } export interface IOutputFile extends ts.OutputFile { diff --git a/src/index.ts b/src/index.ts index 84d5947..1c89388 100644 --- a/src/index.ts +++ b/src/index.ts @@ -139,6 +139,7 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa try { tsImpl = require(compilerName); } catch (e) { + console.error(e) console.error(COMPILER_ERROR); process.exit(1); } @@ -163,6 +164,8 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa let configFileName = tsImpl.findConfigFile(options.tsconfig || process.cwd()); let configFile = null; + + let tsConfigFiles = []; if (configFileName) { configFile = tsImpl.readConfigFile(configFileName); if (configFile.error) { @@ -171,6 +174,7 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa if (configFile.config) { _.extend(options, configFile.config.compilerOptions); _.extend(options, configFile.config.awesomeTypescriptLoaderOptions); + tsConfigFiles = configFile.config.files || tsConfigFiles; } } @@ -229,6 +233,15 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa options.externals = []; } + if (configFileName) { + let configFilePath = path.dirname(configFileName); + options.externals = options.externals.concat( + tsConfigFiles + .filter(file => /\.d\.ts$/.test(file)) + .map(file => path.resolve(configFilePath, file)) + ) + } + if (options.target) { options.target = helpers.parseOptionTarget(options.target, tsImpl); } @@ -245,8 +258,6 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa let cacheIdentifier = null; if (options.useCache) { - console.log(webpack.query); - if (!options.cacheDirectory) { options.cacheDirectory = path.join(process.cwd(), '.awcache'); }