revert: fix(ivy): ngcc - resolve main
property paths correctly (#31509)
This reverts commit 103a5b42ec
.
This commit is contained in:
@ -5,8 +5,11 @@
|
||||
* 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 {AbsoluteFsPath, FileSystem, absoluteFrom, dirname, isRoot, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {PathMappings, isRelativePath, resolveFileWithPostfixes} from '../utils';
|
||||
import {PathMappings, isRelativePath} from '../utils';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is a very cut-down implementation of the TypeScript module resolution strategy.
|
||||
@ -69,8 +72,8 @@ export class ModuleResolver {
|
||||
* If neither of these files exist then the method returns `null`.
|
||||
*/
|
||||
private resolveAsRelativePath(moduleName: string, fromPath: AbsoluteFsPath): ResolvedModule|null {
|
||||
const resolvedPath = resolveFileWithPostfixes(
|
||||
this.fs, resolve(dirname(fromPath), moduleName), this.relativeExtensions);
|
||||
const resolvedPath =
|
||||
this.resolvePath(resolve(dirname(fromPath), moduleName), this.relativeExtensions);
|
||||
return resolvedPath && new ResolvedRelativeModule(resolvedPath);
|
||||
}
|
||||
|
||||
@ -130,6 +133,20 @@ export class ModuleResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to resolve a `path` to a file by appending the provided `postFixes`
|
||||
* to the `path` and checking if the file exists on disk.
|
||||
* @returns An absolute path to the first matching existing file, or `null` if none exist.
|
||||
*/
|
||||
private resolvePath(path: AbsoluteFsPath, postFixes: string[]): AbsoluteFsPath|null {
|
||||
for (const postFix of postFixes) {
|
||||
const testPath = absoluteFrom(path + postFix);
|
||||
if (this.fs.exists(testPath)) {
|
||||
return testPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we consider the given path as an entry-point to a package?
|
||||
|
@ -6,15 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, PathSegment} from '../../../src/ngtsc/file_system';
|
||||
import {getImportsOfUmdModule, parseStatementForUmdModule} from '../host/umd_host';
|
||||
import {resolveFileWithPostfixes} from '../utils';
|
||||
|
||||
import {DependencyHost, DependencyInfo} from './dependency_host';
|
||||
import {ModuleResolver, ResolvedDeepImport, ResolvedRelativeModule} from './module_resolver';
|
||||
|
||||
|
||||
/**
|
||||
* Helper functions for computing dependencies.
|
||||
*/
|
||||
@ -54,20 +50,15 @@ export class UmdDependencyHost implements DependencyHost {
|
||||
private recursivelyFindDependencies(
|
||||
file: AbsoluteFsPath, dependencies: Set<AbsoluteFsPath>, missing: Set<string>,
|
||||
deepImports: Set<string>, alreadySeen: Set<AbsoluteFsPath>): void {
|
||||
const resolvedFile = resolveFileWithPostfixes(this.fs, file, ['', '.js', '/index.js']);
|
||||
if (resolvedFile === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fromContents = this.fs.readFile(resolvedFile);
|
||||
const fromContents = this.fs.readFile(file);
|
||||
if (!this.hasRequireCalls(fromContents)) {
|
||||
// Avoid parsing the source file as there are no require calls.
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the source into a TypeScript AST and then walk it looking for imports and re-exports.
|
||||
const sf = ts.createSourceFile(
|
||||
resolvedFile, fromContents, ts.ScriptTarget.ES2015, false, ts.ScriptKind.JS);
|
||||
const sf =
|
||||
ts.createSourceFile(file, fromContents, ts.ScriptTarget.ES2015, false, ts.ScriptKind.JS);
|
||||
if (sf.statements.length !== 1) {
|
||||
return;
|
||||
}
|
||||
@ -79,7 +70,7 @@ export class UmdDependencyHost implements DependencyHost {
|
||||
}
|
||||
|
||||
umdImports.forEach(umdImport => {
|
||||
const resolvedModule = this.moduleResolver.resolveModuleImport(umdImport.path, resolvedFile);
|
||||
const resolvedModule = this.moduleResolver.resolveModuleImport(umdImport.path, file);
|
||||
if (resolvedModule) {
|
||||
if (resolvedModule instanceof ResolvedRelativeModule) {
|
||||
const internalDependency = resolvedModule.modulePath;
|
||||
|
@ -11,7 +11,6 @@ import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, FileSystem, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {parseStatementForUmdModule} from '../host/umd_host';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {resolveFileWithPostfixes} from '../utils';
|
||||
import {NgccConfiguration, NgccEntryPointConfig} from './configuration';
|
||||
|
||||
/**
|
||||
@ -168,12 +167,8 @@ function loadEntryPointPackage(
|
||||
}
|
||||
|
||||
function isUmdModule(fs: FileSystem, sourceFilePath: AbsoluteFsPath): boolean {
|
||||
const resolvedPath = resolveFileWithPostfixes(fs, sourceFilePath, ['', '.js', '/index.js']);
|
||||
if (resolvedPath === null) {
|
||||
return false;
|
||||
}
|
||||
const sourceFile =
|
||||
ts.createSourceFile(sourceFilePath, fs.readFile(resolvedPath), ts.ScriptTarget.ES5);
|
||||
ts.createSourceFile(sourceFilePath, fs.readFile(sourceFilePath), ts.ScriptTarget.ES5);
|
||||
return sourceFile.statements.length > 0 &&
|
||||
parseStatementForUmdModule(sourceFile.statements[0]) !== null;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom} from '../../src/ngtsc/file_system';
|
||||
|
||||
export function getOriginalSymbol(checker: ts.TypeChecker): (symbol: ts.Symbol) => ts.Symbol {
|
||||
return function(symbol: ts.Symbol) {
|
||||
@ -66,19 +65,3 @@ export type PathMappings = {
|
||||
export function isRelativePath(path: string): boolean {
|
||||
return /^\/|^\.\.?($|\/)/.test(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to resolve a `path` to a file by appending the provided `postFixes`
|
||||
* to the `path` and checking if the file exists on disk.
|
||||
* @returns An absolute path to the first matching existing file, or `null` if none exist.
|
||||
*/
|
||||
export function resolveFileWithPostfixes(
|
||||
fs: FileSystem, path: AbsoluteFsPath, postFixes: string[]): AbsoluteFsPath|null {
|
||||
for (const postFix of postFixes) {
|
||||
const testPath = absoluteFrom(path + postFix);
|
||||
if (fs.exists(testPath) && fs.stat(testPath).isFile()) {
|
||||
return testPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user