forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler-cli): add i18n parameters to tsconfig
You can now add parameters to your tsconfig that will be used when you don't provide cli parameters. It works with ng-xi18n and ngc. Since they both use some parameters with a similar name, those options in tsconfig can have a slightly different name compared to the cli parameters. Closes angular#16232 Fixes angular#16235
- Loading branch information
Showing
7 changed files
with
144 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {ɵReflectionCapabilities, ɵreflector} from '@angular/core'; | ||
import * as tsc from '@angular/tsc-wrapped'; | ||
import {makeTempDir} from '@angular/tsc-wrapped/test/test_support'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as ts from 'typescript'; | ||
|
||
import {main} from '../src/main'; | ||
|
||
|
||
describe('codegen', () => { | ||
let basePath: string; | ||
let write: (fileName: string, content: string) => void; | ||
|
||
beforeEach(() => { | ||
basePath = makeTempDir(); | ||
write = (fileName: string, content: string) => { | ||
fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'}); | ||
}; | ||
const nodeModulesPath = path.resolve(basePath, 'node_modules'); | ||
fs.mkdirSync(nodeModulesPath); | ||
fs.symlinkSync(path.resolve(__dirname, '..', '..'), path.resolve(nodeModulesPath, '@angular')); | ||
}); | ||
|
||
// Restore reflector since AoT compiler will update it with a new static reflector | ||
afterEach(() => { ɵreflector.updateCapabilities(new ɵReflectionCapabilities()); }); | ||
|
||
it('should use i18n params without error', (done) => { | ||
write('tsconfig.json', `{ | ||
"compilerOptions": { | ||
"experimentalDecorators": true, | ||
"types": [], | ||
"outDir": "built", | ||
"declaration": true, | ||
"module": "es2015", | ||
"moduleResolution": "node" | ||
}, | ||
"angularCompilerOptions": { | ||
"annotateForClosureCompiler": true, | ||
"missingTranslation": "error", | ||
"foo": "bar" | ||
}, | ||
"files": ["test.ts"] | ||
}`); | ||
|
||
write('test.ts', `const A = 1;`); | ||
|
||
spyOn(console, 'error').and.callThrough(); | ||
|
||
const codegen = jasmine | ||
.createSpy( | ||
'codegenSpy', | ||
(ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, | ||
program: ts.Program, host: ts.CompilerHost) => { | ||
expect(ngOptions.missingTranslation).toBe('error'); | ||
expect(ngOptions.i18nFormat).toBeUndefined(); | ||
expect(ngOptions.locale).toBeUndefined(); | ||
expect((<any>ngOptions).foo).toEqual('bar'); | ||
|
||
expect(cliOptions.missingTranslation).toBe('ignore'); | ||
expect(cliOptions.i18nFormat).toBeNull(); | ||
expect(cliOptions.locale).toBeNull(); | ||
expect((<any>cliOptions).foo).toBeUndefined(); | ||
|
||
return Promise.resolve(); | ||
}) | ||
.and.callThrough(); | ||
|
||
main({p: basePath, missingTranslation: 'ignore', foo: 'bar'}, console.error, codegen) | ||
.then(() => { | ||
expect(console.error).not.toHaveBeenCalled(); | ||
expect(codegen).toHaveBeenCalled(); | ||
done(); | ||
}) | ||
.catch(e => done.fail(e)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters