feat(compiler-cli): add parameters to ngc main needed by bazel rules (#17885)
This commit is contained in:

committed by
Jason Aden

parent
0ede642cb9
commit
c1474f33be
@ -9,6 +9,7 @@
|
||||
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/ngc';
|
||||
|
||||
@ -40,6 +41,7 @@ describe('ngc command-line', () => {
|
||||
write('tsconfig-base.json', `{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"types": [],
|
||||
"outDir": "built",
|
||||
"declaration": true,
|
||||
@ -72,6 +74,28 @@ describe('ngc command-line', () => {
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it('should be able to be called without a config file by passing options explicitly', () => {
|
||||
write('test.ts', 'export const A = 1;');
|
||||
|
||||
const mockConsole = {error: (s: string) => {}};
|
||||
|
||||
spyOn(mockConsole, 'error');
|
||||
|
||||
const result = main(
|
||||
['-p', basePath], mockConsole.error, [path.join(basePath, 'test.ts')], {
|
||||
experimentalDecorators: true,
|
||||
skipLibCheck: true,
|
||||
types: [],
|
||||
outDir: path.join(basePath, 'built'),
|
||||
declaration: true,
|
||||
module: ts.ModuleKind.ES2015,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
},
|
||||
{});
|
||||
expect(mockConsole.error).not.toHaveBeenCalled();
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it('should not print the stack trace if user input file does not exist', () => {
|
||||
writeConfig(`{
|
||||
"extends": "./tsconfig-base.json",
|
||||
@ -365,6 +389,61 @@ describe('ngc command-line', () => {
|
||||
shouldExist('index.metadata.json');
|
||||
});
|
||||
|
||||
it('should be able to build a flat module passing explicit options', () => {
|
||||
write('public-api.ts', `
|
||||
export * from './src/flat.component';
|
||||
export * from './src/flat.module';`);
|
||||
write('src/flat.component.html', '<div>flat module component</div>');
|
||||
write('src/flat.component.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'flat-comp',
|
||||
templateUrl: 'flat.component.html',
|
||||
})
|
||||
export class FlatComponent {
|
||||
}`);
|
||||
write('src/flat.module.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
import {FlatComponent} from './flat.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
FlatComponent,
|
||||
],
|
||||
exports: [
|
||||
FlatComponent,
|
||||
]
|
||||
})
|
||||
export class FlatModule {
|
||||
}`);
|
||||
|
||||
const exitCode = main(
|
||||
['-p', path.join(basePath, 'tsconfig.json')], undefined,
|
||||
[path.join(basePath, 'public-api.ts')], {
|
||||
target: ts.ScriptTarget.ES5,
|
||||
experimentalDecorators: true,
|
||||
noImplicitAny: true,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
rootDir: basePath,
|
||||
declaration: true,
|
||||
lib: ['lib.es2015.d.ts', 'lib.dom.d.ts'],
|
||||
baseUrl: basePath,
|
||||
outDir: path.join(basePath, 'built'),
|
||||
typeRoots: [path.join(basePath, 'node_modules/@types')]
|
||||
},
|
||||
{
|
||||
genDir: 'ng',
|
||||
flatModuleId: 'flat_module',
|
||||
flatModuleOutFile: 'index.js',
|
||||
skipTemplateCodegen: true
|
||||
});
|
||||
expect(exitCode).toEqual(0);
|
||||
shouldExist('index.js');
|
||||
shouldExist('index.metadata.json');
|
||||
});
|
||||
|
||||
describe('with a third-party library', () => {
|
||||
const writeGenConfig = (skipCodegen: boolean) => {
|
||||
writeConfig(`{
|
||||
|
Reference in New Issue
Block a user