Skip to content

Commit

Permalink
fix(@ngtools/webpack): do not remove outDir from the configuration
Browse files Browse the repository at this point in the history
It would overwrite JavaScript files in the source directory. Even if its a virtual
compiler host, this is still a BAD THING and TypeScript complains.

Fixes angular/angular#21080
Might help with #8371
Fixes #8885
  • Loading branch information
hansl committed Dec 19, 2017
1 parent 8ca3de7 commit 0df9419
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ export class AngularCompilerPlugin implements Tapable {
this._compilerOptions = { ...config.options, ...options.compilerOptions };
this._basePath = config.options.basePath;

// Overwrite outDir so we can find generated files next to their .ts origin in compilerHost.
this._compilerOptions.outDir = '';

// Default plugin sourceMap to compiler options setting.
if (!options.hasOwnProperty('sourceMap')) {
options.sourceMap = this._compilerOptions.sourceMap || false;
Expand Down Expand Up @@ -793,8 +790,21 @@ export class AngularCompilerPlugin implements Tapable {
}
}

private _getOutputPathFromSourcePath(fileName: string) {
if (fileName.startsWith(this._basePath)) {
return fileName
.substr(this._basePath.length)
.replace(/^/, this._compilerOptions.outDir + '/')
.replace(/.ts$/, '.js');
} else if (path.isAbsolute(fileName)) {
return fileName;
} else {
return path.join(this._compilerOptions.outDir);
}
}

getCompiledFile(fileName: string) {
const outputFile = fileName.replace(/.ts$/, '.js');
const outputFile = this._getOutputPathFromSourcePath(fileName);
let outputText: string;
let sourceMap: string;
let errorDependencies: string[] = [];
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/tests/build/allow-js.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ng } from '../../utils/process';
import { copyProjectAsset } from '../../utils/assets';
import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
import { updateJsonFile } from '../../utils/project';


export default function () {
return Promise.resolve()
.then(() => writeMultipleFiles({
// Doesn't need to have content or be imported from anywhere.
'src/some-javascript.js': '',
}))
.then(() => updateJsonFile('tsconfig.json', json => {
json['compilerOptions']['allowJs'] = true;
}))
// We only test that the build passes.
.then(() => ng('build'))
}

0 comments on commit 0df9419

Please sign in to comment.