Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.error(ng.formatDiagnostics(errors));
return false;
}
const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
const angularCompilerOptions: {[k: string]: unknown} = config['angularCompilerOptions'] || {};
// Allow Bazel users to control some of the bazel options.
// Since TypeScript's "extends" mechanism applies only to "compilerOptions"
// we have to repeat some of their logic to get the user's "angularCompilerOptions".
if (config['extends']) {
// Load the user's config file
// Note: this doesn't handle recursive extends so only a user's top level
// `angularCompilerOptions` will be considered. As this code is going to be
// removed with Ivy, the added complication of handling recursive extends
// is likely not needed.
let userConfigFile = resolveNormalizedPath(path.dirname(project), config['extends']);
if (!userConfigFile.endsWith('.json')) userConfigFile += '.json';
const {config: userConfig, error} = ts.readConfigFile(userConfigFile, ts.sys.readFile);
if (error) {
console.error(ng.formatDiagnostics([error]));
return false;
}
// All user angularCompilerOptions values that a user has control
// over should be collected here
if (userConfig.angularCompilerOptions) {
angularCompilerOptions['diagnostics'] =
angularCompilerOptions['diagnostics'] || userConfig.angularCompilerOptions.diagnostics;
angularCompilerOptions['trace'] =
angularCompilerOptions['trace'] || userConfig.angularCompilerOptions.trace;
angularCompilerOptions['disableExpressionLowering'] =
export function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
const [parsedOptions, errors] = parseTsconfig(project);
if (errors && errors.length) {
console.error(ng.formatDiagnostics(errors));
return false;
}
const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
const angularCompilerOptions: {[k: string]: unknown} = config['angularCompilerOptions'] || {};
// Allow Bazel users to control some of the bazel options.
// Since TypeScript's "extends" mechanism applies only to "compilerOptions"
// we have to repeat some of their logic to get the user's "angularCompilerOptions".
if (config['extends']) {
// Load the user's config file
// Note: this doesn't handle recursive extends so only a user's top level
// `angularCompilerOptions` will be considered. As this code is going to be
// removed with Ivy, the added complication of handling recursive extends
// is likely not needed.
export function runMain(
tsConfig: string, entryPoint: string, dtsBundleOut?: string, apiReviewFolder?: string,
acceptApiUpdates = false): 1|0 {
const [parsedConfig, errors] = parseTsconfig(tsConfig);
if (errors && errors.length) {
console.error(format('', errors));
return 1;
}
const pkgJson = path.resolve(path.dirname(entryPoint), 'package.json');
if (!fs.existsSync(pkgJson)) {
fs.writeFileSync(pkgJson, JSON.stringify({
'name': 'GENERATED-BY-BAZEL',
'version': '0.0.0',
'description': 'This is a dummy package.json as API Extractor always requires one.',
}));
}
// API extractor doesn't always support the version of TypeScript used in the repo
constructor(args: string[], inputs?: Record) {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
const [parsedOptions, errors] = parseTsconfig(project);
if (errors && errors.length) {
throw console.error(errors);
}
const { options: tsCompilerOpts, bazelOpts, files, config } = parsedOptions;
this.files = files;
this.bazelOpts = bazelOpts;
this.compilerOpts = {
...tsCompilerOpts,
...defaultCompilerOptions,
};
if (!this.bazelOpts.es5Mode) {
this.compilerOpts.annotateForClosureCompiler = true;
this.compilerOpts.annotationsAs = 'static fields';
}
// Look for foo.d.ts or foo.ts on disk
fileName = file + (ext || '');
}
}
return tsHost.fileExists(fileName);
};
function generatedFileModuleResolver(
moduleName: string, containingFile: string,
compilerOptions: ts.CompilerOptions): ts.ResolvedModuleWithFailedLookupLocations {
return ts.resolveModuleName(
moduleName, containingFile, compilerOptions, generatedFileModuleResolverHost);
}
if (!bazelHost) {
bazelHost = new CompilerHost(
files, compilerOpts, bazelOpts, tsHost, fileLoader, generatedFileModuleResolver);
}
// Also need to disable decorator downleveling in the BazelHost in Ivy mode.
if (isInIvyMode) {
bazelHost.transformDecorators = false;
}
// Prevent tsickle adding any types at all if we don't want closure compiler annotations.
if (compilerOpts.annotateForClosureCompiler) {
bazelHost.transformTypesToClosure = true;
bazelHost.transformDecorators = true;
}
const origBazelHostFileExist = bazelHost.fileExists;
bazelHost.fileExists = (fileName: string) => {
if (NGC_ASSETS.test(fileName)) {
// Note: We compile the content of node_modules with plain ngc command line.
const ALL_DEPS_COMPILED_WITH_BAZEL = false;
const NODE_MODULES = 'node_modules/';
export function main(args) {
if (runAsWorker(args)) {
runWorkerLoop(runOneBuild);
} else {
return runOneBuild(args) ? 0 : 1;
}
return 0;
}
/** The one FileCache instance used in this process. */
const fileCache = new FileCache(debug);
export function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
const [parsedOptions, errors] = parseTsconfig(project);
if (errors && errors.length) {
console.error(ng.formatDiagnostics(errors));
return false;
}
const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
const angularCompilerOptions: {[k: string]: unknown} = config['angularCompilerOptions'] || {};
// Allow Bazel users to control some of the bazel options.
// Since TypeScript's "extends" mechanism applies only to "compilerOptions"
export function runMain(
tsConfig: string, entryPoint: string, dtsBundleOut?: string, apiReviewFolder?: string,
acceptApiUpdates = false): 1|0 {
const [parsedConfig, errors] = parseTsconfig(tsConfig);
if (errors && errors.length) {
console.error(format('', errors));
return 1;
}
const pkgJson = path.resolve(path.dirname(entryPoint), 'package.json');
if (!fs.existsSync(pkgJson)) {
fs.writeFileSync(pkgJson, JSON.stringify({
'name': 'GENERATED-BY-BAZEL',
'version': '0.0.0',
'description': 'This is a dummy package.json as API Extractor always requires one.',
}));
}
// API extractor doesn't always support the version of TypeScript used in the repo
// example: at the moment it is not compatable with 3.2
// to use the internal TypeScript we shall not create a program but rather pass a parsed tsConfig.
warnings.forEach(warning => {
if (!this.options.suppressWarnings.includes(warning.code)) {
if (warning.code === 'missing-declaration') return;
// console.log(`You can suppress this warning by putting "${warning.code}" into your Svelte compiler options`);
log(warning.toString());
}
});
}
if (bazelOpts.maxCacheSizeMb !== undefined) {
const maxCacheSizeBytes = bazelOpts.maxCacheSizeMb * (1 << 20);
fileCache.setMaxCacheSize(maxCacheSizeBytes);
} else {
fileCache.resetMaxCacheSize();
}
if (inputs) {
fileLoader = new CachedFileLoader(fileCache);
// Resolve the inputs to absolute paths to match TypeScript internals
const resolvedInputs = new Map();
const inputKeys = Object.keys(inputs);
for (let i = 0; i < inputKeys.length; i++) {
const key = inputKeys[i];
resolvedInputs.set(resolveNormalizedPath(key), inputs[key]);
}
fileCache.updateCache(resolvedInputs);
} else {
fileLoader = new UncachedFileLoader();
}
if (!bazelOpts.es5Mode) {
compilerOpts.annotateForClosureCompiler = true;
compilerOpts.annotationsAs = 'static fields';
}
// Detect from compilerOpts whether the entrypoint is being invoked in Ivy mode.
const isInIvyMode = compilerOpts.enableIvy === 'ngtsc';
// Disable downleveling and Closure annotation if in Ivy mode.
if (isInIvyMode) {
files: string[],
expectedOuts: string[],
gatherDiagnostics?: (program: ng.Program) => ng.Diagnostics,
bazelHost?: CompilerHost,
}): {diagnostics: ng.Diagnostics, program: ng.Program} {
let fileLoader: FileLoader;
if (bazelOpts.maxCacheSizeMb !== undefined) {
const maxCacheSizeBytes = bazelOpts.maxCacheSizeMb * (1 << 20);
fileCache.setMaxCacheSize(maxCacheSizeBytes);
} else {
fileCache.resetMaxCacheSize();
}
if (inputs) {
fileLoader = new CachedFileLoader(fileCache);
// Resolve the inputs to absolute paths to match TypeScript internals
const resolvedInputs = new Map();
const inputKeys = Object.keys(inputs);
for (let i = 0; i < inputKeys.length; i++) {
const key = inputKeys[i];
resolvedInputs.set(resolveNormalizedPath(key), inputs[key]);
}
fileCache.updateCache(resolvedInputs);
} else {
fileLoader = new UncachedFileLoader();
}
if (!bazelOpts.es5Mode) {
compilerOpts.annotateForClosureCompiler = true;
compilerOpts.annotationsAs = 'static fields';
}