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

Commit

Permalink
feat(*): read .d.ts files from tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Panferov committed Aug 14, 2015
1 parent b1fe74c commit d4025d3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
tscommand
npm-debug.log
.awcache
2 changes: 0 additions & 2 deletions examples/tsx/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="./typings/react.d.ts" />

import * as React from 'react';

class Component extends React.Component<{ text: string }, void> {
Expand Down
2 changes: 2 additions & 0 deletions examples/tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
27 changes: 27 additions & 0 deletions examples/tsx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
8 changes: 2 additions & 6 deletions examples/tsx/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
]
},
Expand Down
1 change: 0 additions & 1 deletion src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class FileAnalyzer {

this.dependencies.clearDependencies(fileName);


let flow = this.state.hasFile(fileName) ?
Promise.resolve(false) :
this.state.readFileAndUpdate(fileName);
Expand Down
1 change: 1 addition & 0 deletions src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ICompilerOptions extends ts.CompilerOptions {
usePrecompiledFiles?: boolean;
useCache?: boolean;
cacheDirectory?: string;
files?: any;
}

export interface IOutputFile extends ts.OutputFile {
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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(<any>options.target, tsImpl);
}
Expand All @@ -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');
}
Expand Down

0 comments on commit d4025d3

Please sign in to comment.