feat(ivy): able to compile @angular/core with ngtsc (#24677)
@angular/core is unique in that it defines the Angular decorators (@Component, @Directive, etc). Ordinarily ngtsc looks for imports from @angular/core in order to identify these decorators. Clearly within core itself, this strategy doesn't work. Instead, a special constant ITS_JUST_ANGULAR is declared within a known file in @angular/core. If ngtsc sees this constant it knows core is being compiled and can ignore the imports when evaluating decorators. Additionally, when compiling decorators ngtsc will often write an import to @angular/core for needed symbols. However @angular/core cannot import itself. This change creates a module within core to export all the symbols needed to compile it and adds intelligence within ngtsc to write relative imports to that module, instead of absolute imports to @angular/core. PR Close #24677
This commit is contained in:

committed by
Miško Hevery

parent
c57b491778
commit
104d30507a
@ -9,4 +9,7 @@ ts_library(
|
||||
"src/**/*.ts",
|
||||
]),
|
||||
module_name = "@angular/compiler-cli/src/ngtsc/util",
|
||||
deps = [
|
||||
"//packages:types",
|
||||
],
|
||||
)
|
||||
|
26
packages/compiler-cli/src/ngtsc/util/src/path.ts
Normal file
26
packages/compiler-cli/src/ngtsc/util/src/path.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 'path';
|
||||
|
||||
const TS_DTS_EXTENSION = /(\.d)?\.ts$/;
|
||||
|
||||
export function relativePathBetween(from: string, to: string): string|null {
|
||||
let relative = path.posix.relative(path.dirname(from), to).replace(TS_DTS_EXTENSION, '');
|
||||
|
||||
if (relative === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// path.relative() does not include the leading './'.
|
||||
if (!relative.startsWith('.')) {
|
||||
relative = `./${relative}`;
|
||||
}
|
||||
|
||||
return relative;
|
||||
}
|
Reference in New Issue
Block a user