refactor(ivy): ngcc - remove the last remnants of `path` and `canonical-path` (#29643)

The ngcc code now uses `AbsoluteFsPath` and `PathSegment` to do all its
path manipulation.

PR Close #29643
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:47:57 +01:00 committed by Andrew Kushnir
parent 20898f9f4f
commit 029a93963a
4 changed files with 7 additions and 10 deletions

View File

@ -6,9 +6,9 @@
* 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 * as path from 'canonical-path';
import * as yargs from 'yargs';
import {AbsoluteFsPath} from '../src/ngtsc/path';
import {mainNgcc} from './src/main';
import {ConsoleLogger, LogLevel} from './src/logging/console_logger';
@ -56,7 +56,7 @@ if (require.main === module) {
'The formats option (-f/--formats) has been removed. Consider the properties option (-p/--properties) instead.');
process.exit(1);
}
const baseSourcePath = path.resolve(options['s'] || './node_modules');
const baseSourcePath = AbsoluteFsPath.resolve(options['s'] || './node_modules');
const propertiesToConsider: string[] = options['p'];
const targetEntryPointPath = options['t'] ? options['t'] : undefined;
const compileAllFormats = !options['first-only'];

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ConstantPool} from '@angular/compiler';
import * as path from 'path';
import * as ts from 'typescript';
import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../src/ngtsc/annotations';
@ -57,7 +56,7 @@ class NgccResourceLoader implements ResourceLoader {
preload(): undefined|Promise<void> { throw new Error('Not implemented.'); }
load(url: string): string { return this.fs.readFile(AbsoluteFsPath.resolve(url)); }
resolve(url: string, containingFile: string): string {
return path.resolve(path.dirname(containingFile), url);
return AbsoluteFsPath.resolve(AbsoluteFsPath.dirname(AbsoluteFsPath.from(containingFile)), url);
}
}

View File

@ -7,7 +7,6 @@
*/
import {DepGraph} from 'dependency-graph';
import {resolve} from 'path';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {Logger} from '../logging/logger';
@ -171,7 +170,7 @@ function getEntryPointPath(entryPoint: EntryPoint): AbsoluteFsPath {
if (format === 'esm2015' || format === 'esm5') {
const formatPath = entryPoint.packageJson[property] !;
return AbsoluteFsPath.from(resolve(entryPoint.path, formatPath));
return AbsoluteFsPath.resolve(entryPoint.path, formatPath);
}
}
throw new Error(`There is no format with import statements in '${entryPoint.path}' entry-point.`);

View File

@ -9,7 +9,6 @@
import {AbsoluteFsPath} from '@angular/compiler-cli/src/ngtsc/path';
import {existsSync, readFileSync, readdirSync, statSync, writeFileSync} from 'fs';
import * as mockFs from 'mock-fs';
import {join} from 'path';
import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from '../../../test/runfile_helpers';
import {NodeJSFileSystem} from '../../src/file_system/node_js_file_system';
@ -142,8 +141,8 @@ describe('ngcc main()', () => {
function markPropertiesAsProcessed(packagePath: string, properties: EntryPointJsonProperty[]) {
const basePath = '/node_modules';
const targetPackageJsonPath = _(join(basePath, packagePath, 'package.json'));
const basePath = _('/node_modules');
const targetPackageJsonPath = AbsoluteFsPath.join(basePath, packagePath, 'package.json');
const targetPackage = loadPackage(packagePath);
const fs = new NodeJSFileSystem();
markAsProcessed(fs, targetPackage, targetPackageJsonPath, 'typings');
@ -386,7 +385,7 @@ function loadDirectory(directoryPath: string): Directory {
const directory: Directory = {};
readdirSync(directoryPath).forEach(item => {
const itemPath = join(directoryPath, item);
const itemPath = AbsoluteFsPath.resolve(directoryPath, item);
if (statSync(itemPath).isDirectory()) {
directory[item] = loadDirectory(itemPath);
} else {