"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/ngtools/webpack/src/ngcc_processor.ts" between
angular-cli-11.0.1.tar.gz and angular-cli-11.0.2.tar.gz

About: Angular CLI is a command line interface for Angular.

ngcc_processor.ts  (angular-cli-11.0.1):ngcc_processor.ts  (angular-cli-11.0.2)
skipping to change at line 12 skipping to change at line 12
* @license * @license
* Copyright Google Inc. All Rights Reserved. * Copyright Google Inc. All Rights Reserved.
* *
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import { LogLevel, Logger, process as mainNgcc } from '@angular/compiler-cli/ngc c'; import { LogLevel, Logger, process as mainNgcc } from '@angular/compiler-cli/ngc c';
import { spawnSync } from 'child_process'; import { spawnSync } from 'child_process';
import { createHash } from 'crypto'; import { createHash } from 'crypto';
import { Resolver, ResolverFactory } from 'enhanced-resolve';
import { accessSync, constants, existsSync, mkdirSync, readFileSync, writeFileSy nc } from 'fs'; import { accessSync, constants, existsSync, mkdirSync, readFileSync, writeFileSy nc } from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import { InputFileSystem } from 'webpack';
import { time, timeEnd } from './benchmark'; import { time, timeEnd } from './benchmark';
// We cannot create a plugin for this, because NGTSC requires addition type // We cannot create a plugin for this, because NGTSC requires addition type
// information which ngcc creates when processing a package which was compiled w ith NGC. // information which ngcc creates when processing a package which was compiled w ith NGC.
// Example of such errors: // Example of such errors:
// ERROR in node_modules/@angular/platform-browser/platform-browser.d.ts(42,22): // ERROR in node_modules/@angular/platform-browser/platform-browser.d.ts(42,22):
// error TS-996002: Appears in the NgModule.imports of AppModule, // error TS-996002: Appears in the NgModule.imports of AppModule,
// but could not be resolved to an NgModule class // but could not be resolved to an NgModule class
// We now transform a package and it's typings when NGTSC is resolving a module. // We now transform a package and it's typings when NGTSC is resolving a module.
export class NgccProcessor { export class NgccProcessor {
private _processedModules = new Set<string>(); private _processedModules = new Set<string>();
private _logger: NgccLogger; private _logger: NgccLogger;
private _nodeModulesDirectory: string; private _nodeModulesDirectory: string;
private _resolver: Resolver;
constructor( constructor(
private readonly propertiesToConsider: string[], private readonly propertiesToConsider: string[],
private readonly fileWatchPurger: (path: string) => void,
private readonly compilationWarnings: (Error | string)[], private readonly compilationWarnings: (Error | string)[],
private readonly compilationErrors: (Error | string)[], private readonly compilationErrors: (Error | string)[],
private readonly basePath: string, private readonly basePath: string,
private readonly tsConfigPath: string, private readonly tsConfigPath: string,
private readonly inputFileSystem: InputFileSystem,
private readonly symlinks: boolean | undefined,
) { ) {
this._logger = new NgccLogger(this.compilationWarnings, this.compilationErro rs); this._logger = new NgccLogger(this.compilationWarnings, this.compilationErro rs);
this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath); this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath);
this._resolver = ResolverFactory.createResolver({
// NOTE: @types/webpack InputFileSystem is missing some methods
// tslint:disable-next-line: no-any
fileSystem: this.inputFileSystem as any,
extensions: ['.json'],
useSyncFileSystemCalls: true,
symlinks,
});
} }
/** Process the entire node modules tree. */ /** Process the entire node modules tree. */
process() { process() {
// Under Bazel when running in sandbox mode parts of the filesystem is read- only. // Under Bazel when running in sandbox mode parts of the filesystem is read- only.
if (process.env.BAZEL_TARGET) { if (process.env.BAZEL_TARGET) {
return; return;
} }
// Skip if node_modules are read-only // Skip if node_modules are read-only
skipping to change at line 194 skipping to change at line 207
propertiesToConsider: this.propertiesToConsider, propertiesToConsider: this.propertiesToConsider,
compileAllFormats: false, compileAllFormats: false,
createNewEntryPointFormats: true, createNewEntryPointFormats: true,
logger: this._logger, logger: this._logger,
tsConfigPath: this.tsConfigPath, tsConfigPath: this.tsConfigPath,
}); });
timeEnd(timeLabel); timeEnd(timeLabel);
// Purge this file from cache, since NGCC add new mainFields. Ex: module_ivy _ngcc // Purge this file from cache, since NGCC add new mainFields. Ex: module_ivy _ngcc
// which are unknown in the cached file. // which are unknown in the cached file.
this.fileWatchPurger(packageJsonPath); if (this.inputFileSystem.purge) {
// tslint:disable-next-line: no-any
(this.inputFileSystem.purge as any)(packageJsonPath);
}
this._processedModules.add(resolvedFileName); this._processedModules.add(resolvedFileName);
} }
invalidate(fileName: string) { invalidate(fileName: string) {
this._processedModules.delete(fileName); this._processedModules.delete(fileName);
} }
/** /**
* Try resolve a package.json file from the resolved .d.ts file. * Try resolve a package.json file from the resolved .d.ts file.
*/ */
private tryResolvePackage(moduleName: string, resolvedFileName: string): strin g | undefined { private tryResolvePackage(moduleName: string, resolvedFileName: string): strin g | undefined {
try { try {
// This is based on the logic in the NGCC compiler const resolvedPath = this._resolver.resolveSync({}, resolvedFileName, `${m
// tslint:disable-next-line:max-line-length oduleName}/package.json`);
// See: https://github.com/angular/angular/blob/b93c1dffa17e4e6900b3ab1b9e
554b6da92be0de/packages/compiler-cli/src/ngcc/src/packages/dependency_host.ts#L8 return resolvedPath || undefined;
5-L121
return require.resolve(`${moduleName}/package.json`, {
paths: [resolvedFileName],
});
} catch { } catch {
// if it fails this might be a deep import which doesn't have a package.js on
// Ex: @angular/compiler/src/i18n/i18n_ast/package.json // Ex: @angular/compiler/src/i18n/i18n_ast/package.json
// or local libraries which don't reside in node_modules // or local libraries which don't reside in node_modules
const packageJsonPath = path.resolve(resolvedFileName, '../package.json'); const packageJsonPath = path.resolve(resolvedFileName, '../package.json');
return existsSync(packageJsonPath) ? packageJsonPath : undefined; return existsSync(packageJsonPath) ? packageJsonPath : undefined;
} }
} }
private findNodeModulesDirectory(startPoint: string): string { private findNodeModulesDirectory(startPoint: string): string {
let current = startPoint; let current = startPoint;
 End of changes. 9 change blocks. 
11 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)