Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(compiler): make .ngsummary.json files idempotent (#21448)
Fixes: #21432

PR Close #21448
  • Loading branch information
chuckjaz authored and alexeagle committed Jan 11, 2018
1 parent 6be9c04 commit e64b1e9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/compiler-cli/src/transformers/compiler_host.ts
Expand Up @@ -488,6 +488,10 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
return assert(this.context.readFile(filePath));
}

getOutputName(filePath: string): string {
return path.relative(this.getCurrentDirectory(), filePath);
}

private hasBundleIndex(filePath: string): boolean {
const checkBundleIndex = (directory: string): boolean => {
let result = this.flatModuleIndexCache.get(directory);
Expand Down
9 changes: 8 additions & 1 deletion packages/compiler/src/aot/static_symbol_resolver.ts
Expand Up @@ -39,6 +39,12 @@ export interface StaticSymbolResolverHost {
* `path/to/containingFile.ts` containing `import {...} from 'module-name'`.
*/
moduleNameToFileName(moduleName: string, containingFile?: string): string|null;

/**
* Get a file suitable for display to the user that should be relative to the project directory
* or the current directory.
*/
getOutputName(filePath: string): string;
}

const SUPPORTED_SCHEMA_VERSION = 4;
Expand Down Expand Up @@ -382,7 +388,8 @@ export class StaticSymbolResolver {
// .ts or .d.ts, append `.ts'. Also, if it is in `node_modules`, trim the `node_module`
// location as it is not important to finding the file.
_originalFileMemo =
topLevelPath.replace(/((\.ts)|(\.d\.ts)|)$/, '.ts').replace(/^.*node_modules[/\\]/, '');
this.host.getOutputName(topLevelPath.replace(/((\.ts)|(\.d\.ts)|)$/, '.ts')
.replace(/^.*node_modules[/\\]/, ''));
}
return _originalFileMemo;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/test/aot/static_symbol_resolver_spec.ts
Expand Up @@ -496,6 +496,8 @@ export class MockStaticSymbolResolverHost implements StaticSymbolResolverHost {

getMetadataFor(moduleId: string): any { return this._getMetadataFor(moduleId); }

getOutputName(filePath: string): string { return filePath; }

private _getMetadataFor(filePath: string): any {
if (this.data[filePath] && filePath.match(TS_EXT)) {
const text = this.data[filePath];
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/test/aot/test_util.ts
Expand Up @@ -386,6 +386,8 @@ export class MockAotCompilerHost implements AotCompilerHost {
return resolved ? resolved.resolvedFileName : null;
}

getOutputName(filePath: string) { return filePath; }

resourceNameToFileName(resourceName: string, containingFile: string) {
// Note: we convert package paths into relative paths to be compatible with the the
// previous implementation of UrlResolver.
Expand Down
2 changes: 2 additions & 0 deletions packages/language-service/src/reflector_host.ts
Expand Up @@ -76,4 +76,6 @@ export class ReflectorHost implements StaticSymbolResolverHost {
.resolvedModule;
return resolved ? resolved.resolvedFileName : null;
}

getOutputName(filePath: string) { return filePath; }
}

1 comment on commit e64b1e9

@alexeagle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a hermeticity test like they made for forge, somewhere?

Please sign in to comment.