Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit d4025d3

Browse files
author
Stanislav Panferov
committed
feat(*): read .d.ts files from tsconfig.json
1 parent b1fe74c commit d4025d3

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
dist
44
tscommand
55
npm-debug.log
6+
.awcache

examples/tsx/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="./typings/react.d.ts" />
2-
31
import * as React from 'react';
42

53
class Component extends React.Component<{ text: string }, void> {

examples/tsx/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"license": "MIT",
1111
"dependencies": {},
1212
"devDependencies": {
13+
"babel": "^5.8.21",
1314
"babel-core": "^5.6.20",
1415
"babel-loader": "^5.3.1",
1516
"html-webpack-plugin": "^1.6.0",
1617
"node-libs-browser": "^0.5.2",
1718
"react": "^0.13.3",
19+
"typescript": "^1.6.0-dev.20150813",
1820
"webpack": "^1.10.1",
1921
"webpack-dev-server": "^1.10.1"
2022
}

examples/tsx/tsconfig.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "1.5.0-beta",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"module": "commonjs",
6+
"isolatedModules": false,
7+
"jsx": "react",
8+
"experimentalDecorators": true,
9+
"emitDecoratorMetadata": true,
10+
"declaration": false,
11+
"noImplicitAny": false,
12+
"removeComments": true,
13+
"noLib": false,
14+
"preserveConstEnums": true,
15+
"suppressImplicitAnyIndexErrors": true
16+
},
17+
"compileOnSave": false,
18+
"filesGlob": [
19+
"./**/*.ts",
20+
"./**/*.tsx",
21+
"!./node_modules/**/*"
22+
],
23+
"files": [
24+
"./typings/react.d.ts",
25+
"./index.tsx"
26+
]
27+
}

examples/tsx/webpack.config.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ module.exports = {
88
module: {
99
loaders: [
1010
{
11-
test: /\.tsx$/,
12-
loader: 'babel-loader!awesome-typescript-loader?compiler=ntypescript&module=common&jsx=react'
13-
},
14-
{
15-
test: /\.ts$/,
16-
loader: 'awesome-typescript-loader?compiler=ntypescript&module=common'
11+
test: /\.tsx?$/,
12+
loader: '../../dist/index.js?+useCache&+useBabel&module=common&jsx=preserve'
1713
}
1814
]
1915
},

src/deps.ts

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export class FileAnalyzer {
7474

7575
this.dependencies.clearDependencies(fileName);
7676

77-
7877
let flow = this.state.hasFile(fileName) ?
7978
Promise.resolve(false) :
8079
this.state.readFileAndUpdate(fileName);

src/host.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface ICompilerOptions extends ts.CompilerOptions {
4242
usePrecompiledFiles?: boolean;
4343
useCache?: boolean;
4444
cacheDirectory?: string;
45+
files?: any;
4546
}
4647

4748
export interface IOutputFile extends ts.OutputFile {

src/index.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa
139139
try {
140140
tsImpl = require(compilerName);
141141
} catch (e) {
142+
console.error(e)
142143
console.error(COMPILER_ERROR);
143144
process.exit(1);
144145
}
@@ -163,6 +164,8 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa
163164

164165
let configFileName = tsImpl.findConfigFile(options.tsconfig || process.cwd());
165166
let configFile = null;
167+
168+
let tsConfigFiles = [];
166169
if (configFileName) {
167170
configFile = tsImpl.readConfigFile(configFileName);
168171
if (configFile.error) {
@@ -171,6 +174,7 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa
171174
if (configFile.config) {
172175
_.extend(options, configFile.config.compilerOptions);
173176
_.extend(options, configFile.config.awesomeTypescriptLoaderOptions);
177+
tsConfigFiles = configFile.config.files || tsConfigFiles;
174178
}
175179
}
176180

@@ -229,6 +233,15 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa
229233
options.externals = [];
230234
}
231235

236+
if (configFileName) {
237+
let configFilePath = path.dirname(configFileName);
238+
options.externals = options.externals.concat(
239+
tsConfigFiles
240+
.filter(file => /\.d\.ts$/.test(file))
241+
.map(file => path.resolve(configFilePath, file))
242+
)
243+
}
244+
232245
if (options.target) {
233246
options.target = helpers.parseOptionTarget(<any>options.target, tsImpl);
234247
}
@@ -245,8 +258,6 @@ function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceNa
245258

246259
let cacheIdentifier = null;
247260
if (options.useCache) {
248-
console.log(webpack.query);
249-
250261
if (!options.cacheDirectory) {
251262
options.cacheDirectory = path.join(process.cwd(), '.awcache');
252263
}

0 commit comments

Comments
 (0)