style(ngcc): reformat of ngcc after clang update (#36447)
PR Close #36447
This commit is contained in:

committed by
Kara Erickson

parent
bfa55162de
commit
74b7a8eaf5
@ -8,8 +8,9 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as os from 'os';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, join} from '../../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem, TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, join} from '../../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem, runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadStandardTestFiles, loadTestFiles} from '../../../test/helpers';
|
||||
import {getLockFilePath} from '../../src/locking/lock_file';
|
||||
import {mainNgcc} from '../../src/main';
|
||||
@ -19,6 +20,7 @@ import {EntryPointManifestFile} from '../../src/packages/entry_point_manifest';
|
||||
import {Transformer} from '../../src/packages/transformer';
|
||||
import {DirectPackageJsonUpdater, PackageJsonUpdater} from '../../src/writing/package_json_updater';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
import {compileIntoApf, compileIntoFlatEs5Package} from './util';
|
||||
|
||||
const testFiles = loadStandardTestFiles({fakeCore: false, rxjs: true});
|
||||
@ -145,7 +147,8 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
['esm5', 'esm2015'].forEach(target => {
|
||||
it(`should be able to process spread operator inside objects for ${target} format (imported helpers)`,
|
||||
it(`should be able to process spread operator inside objects for ${
|
||||
target} format (imported helpers)`,
|
||||
() => {
|
||||
compileIntoApf(
|
||||
'test-package', {
|
||||
@ -184,7 +187,8 @@ runInEachFileSystem(() => {
|
||||
expect(jsContents).toContain('ngcc0.ɵɵclassProp("a", true)("b", true)("c", false)');
|
||||
});
|
||||
|
||||
it(`should be able to process emitted spread operator inside objects for ${target} format (emitted helpers)`,
|
||||
it(`should be able to process emitted spread operator inside objects for ${
|
||||
target} format (emitted helpers)`,
|
||||
() => {
|
||||
compileIntoApf(
|
||||
'test-package', {
|
||||
@ -326,7 +330,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
const before = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||
const originalProp = /ɵprov[^;]+/.exec(before) ![0];
|
||||
const originalProp = /ɵprov[^;]+/.exec(before)![0];
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: 'test-package',
|
||||
@ -496,7 +500,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
describe('in async mode', () => {
|
||||
it('should run ngcc without errors for fesm2015', async() => {
|
||||
it('should run ngcc without errors for fesm2015', async () => {
|
||||
const promise = mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['fesm2015'],
|
||||
@ -507,7 +511,7 @@ runInEachFileSystem(() => {
|
||||
await promise;
|
||||
});
|
||||
|
||||
it('should reject, if some of the entry-points are unprocessable', async() => {
|
||||
it('should reject, if some of the entry-points are unprocessable', async () => {
|
||||
const createEntryPoint = (name: string, prop: EntryPointJsonProperty): TestFile[] => {
|
||||
return [
|
||||
{
|
||||
@ -541,7 +545,7 @@ runInEachFileSystem(() => {
|
||||
` - ${_('/dist/unprocessable-3')}`)));
|
||||
});
|
||||
|
||||
it('should reject, if an error happens during processing', async() => {
|
||||
it('should reject, if an error happens during processing', async () => {
|
||||
spyOn(Transformer.prototype, 'transform').and.throwError('Test error.');
|
||||
|
||||
const promise = mainNgcc({
|
||||
@ -651,7 +655,8 @@ runInEachFileSystem(() => {
|
||||
markPropertiesAsProcessed('@angular/common/http/testing', SUPPORTED_FORMAT_PROPERTIES);
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing', logger,
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.debug).toContain([
|
||||
'The target entry-point has already been processed'
|
||||
@ -665,7 +670,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
propertiesToConsider: ['fesm2015', 'esm5', 'esm2015'], logger,
|
||||
propertiesToConsider: ['fesm2015', 'esm5', 'esm2015'],
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.debug).not.toContain([
|
||||
'The target entry-point has already been processed'
|
||||
@ -682,7 +688,8 @@ runInEachFileSystem(() => {
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
propertiesToConsider: ['esm5', 'esm2015'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).not.toContain([
|
||||
@ -699,7 +706,8 @@ runInEachFileSystem(() => {
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
// Simulate a property that does not exist on the package.json and will be ignored.
|
||||
propertiesToConsider: ['missing', 'esm2015', 'esm5'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).toContain([
|
||||
@ -717,7 +725,8 @@ runInEachFileSystem(() => {
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
// Simulate a property that does not exist on the package.json and will be ignored.
|
||||
propertiesToConsider: ['missing', 'esm2015', 'esm5'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).toContain([
|
||||
@ -752,7 +761,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
// Now hack the files to look like it was processed by an outdated version of ngcc
|
||||
const packageJson = loadPackage('test-package', _('/node_modules'));
|
||||
packageJson.__processed_by_ivy_ngcc__ !.typings = '8.0.0';
|
||||
packageJson.__processed_by_ivy_ngcc__!.typings = '8.0.0';
|
||||
packageJson.main_ivy_ngcc = '__ivy_ngcc__/main.js';
|
||||
fs.writeFile(_('/node_modules/test-package/package.json'), JSON.stringify(packageJson));
|
||||
fs.writeFile(_('/node_modules/test-package/x.js'), 'processed content');
|
||||
@ -838,7 +847,8 @@ runInEachFileSystem(() => {
|
||||
// `fesm2015` and `es2015` map to the same file: `./fesm2015/common.js`
|
||||
mainNgcc({
|
||||
basePath: '/node_modules/@angular/common',
|
||||
propertiesToConsider: ['fesm2015'], logger,
|
||||
propertiesToConsider: ['fesm2015'],
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logs).not.toContain(['Skipping @angular/common : es2015 (already compiled).']);
|
||||
@ -851,7 +861,8 @@ runInEachFileSystem(() => {
|
||||
// Now, compiling `es2015` should be a no-op.
|
||||
mainNgcc({
|
||||
basePath: '/node_modules/@angular/common',
|
||||
propertiesToConsider: ['es2015'], logger,
|
||||
propertiesToConsider: ['es2015'],
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logs).toContain(['Skipping @angular/common : es2015 (already compiled).']);
|
||||
@ -997,21 +1008,21 @@ runInEachFileSystem(() => {
|
||||
expectNotToHaveProp(pkg, 'esm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm2015_ivy_ngcc');
|
||||
expectNotToHaveProp(pkg, 'fesm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__ !, 'fesm2015');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__!, 'fesm2015');
|
||||
|
||||
// Process `fesm5` and update `package.json`.
|
||||
pkg = processFormatAndUpdatePackageJson('fesm5');
|
||||
expectNotToHaveProp(pkg, 'esm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm2015_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__ !, 'fesm5');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__!, 'fesm5');
|
||||
|
||||
// Process `esm5` and update `package.json`.
|
||||
pkg = processFormatAndUpdatePackageJson('esm5');
|
||||
expectToHaveProp(pkg, 'esm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm2015_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__ !, 'esm5');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__!, 'esm5');
|
||||
|
||||
// Ensure the properties are in deterministic order (regardless of processing order).
|
||||
const pkgKeys = stringifyKeys(pkg);
|
||||
@ -1026,7 +1037,7 @@ runInEachFileSystem(() => {
|
||||
// For example:
|
||||
// - `fesm2015` <=> `es2015`
|
||||
// - `fesm5` <=> `module`
|
||||
expect(stringifyKeys(pkg.__processed_by_ivy_ngcc__ !))
|
||||
expect(stringifyKeys(pkg.__processed_by_ivy_ngcc__!))
|
||||
.toBe('|es2015|esm5|fesm2015|fesm5|module|typings|');
|
||||
|
||||
// Helpers
|
||||
@ -1034,7 +1045,8 @@ runInEachFileSystem(() => {
|
||||
expect(obj.hasOwnProperty(prop))
|
||||
.toBe(
|
||||
false,
|
||||
`Expected object not to have property '${prop}': ${JSON.stringify(obj, null, 2)}`);
|
||||
`Expected object not to have property '${prop}': ${
|
||||
JSON.stringify(obj, null, 2)}`);
|
||||
}
|
||||
|
||||
function expectToHaveProp(obj: object, prop: string) {
|
||||
@ -1053,7 +1065,9 @@ runInEachFileSystem(() => {
|
||||
return loadPackage('@angular/core');
|
||||
}
|
||||
|
||||
function stringifyKeys(obj: object) { return `|${Object.keys(obj).join('|')}|`; }
|
||||
function stringifyKeys(obj: object) {
|
||||
return `|${Object.keys(obj).join('|')}|`;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -1206,7 +1220,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['es2015'],
|
||||
errorOnFailedEntryPoint: false, logger,
|
||||
errorOnFailedEntryPoint: false,
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.error.length).toEqual(1);
|
||||
const message = logger.logs.error[0][0];
|
||||
@ -1236,7 +1251,8 @@ runInEachFileSystem(() => {
|
||||
const logger = new MockLogger();
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['esm2015'], logger,
|
||||
propertiesToConsider: ['esm2015'],
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.info).toContain(['Compiling @angular/common/http : esm2015 as esm2015']);
|
||||
});
|
||||
@ -1281,7 +1297,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/dist',
|
||||
propertiesToConsider: ['es2015'],
|
||||
tsConfigPath: _('/tsconfig.app.json'), logger
|
||||
tsConfigPath: _('/tsconfig.app.json'),
|
||||
logger
|
||||
});
|
||||
expect(loadPackage('local-package', _('/dist')).__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
@ -1316,7 +1333,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['es2015'],
|
||||
pathMappings: {paths: {'*': ['dist/*']}, baseUrl: '/'}, logger
|
||||
pathMappings: {paths: {'*': ['dist/*']}, baseUrl: '/'},
|
||||
logger
|
||||
});
|
||||
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
@ -1356,7 +1374,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/dist',
|
||||
propertiesToConsider: ['es2015'],
|
||||
tsConfigPath: null, logger,
|
||||
tsConfigPath: null,
|
||||
logger,
|
||||
});
|
||||
expect(loadPackage('local-package', _('/dist')).__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
@ -1821,7 +1840,7 @@ runInEachFileSystem(() => {
|
||||
expect(jsContents).toContain('exports.ɵngExportɵFooModuleɵFoo = ɵngcc1.Foo;');
|
||||
expect(dtsContents)
|
||||
.toContain(`export {Foo as ɵngExportɵFooModuleɵFoo} from './directive';`);
|
||||
expect(dtsContents.match(/ɵngExportɵFooModuleɵFoo/g) !.length).toBe(1);
|
||||
expect(dtsContents.match(/ɵngExportɵFooModuleɵFoo/g)!.length).toBe(1);
|
||||
expect(dtsContents).not.toContain(`ɵngExportɵFooModuleɵLocalDir`);
|
||||
});
|
||||
});
|
||||
|
@ -234,11 +234,21 @@ class MockCompilerHost implements ts.CompilerHost {
|
||||
this.fs.writeFile(this.fs.resolve(fileName), data);
|
||||
}
|
||||
|
||||
getCurrentDirectory(): string { return this.fs.pwd(); }
|
||||
getCanonicalFileName(fileName: string): string { return fileName; }
|
||||
useCaseSensitiveFileNames(): boolean { return true; }
|
||||
getNewLine(): string { return '\n'; }
|
||||
fileExists(fileName: string): boolean { return this.fs.exists(this.fs.resolve(fileName)); }
|
||||
getCurrentDirectory(): string {
|
||||
return this.fs.pwd();
|
||||
}
|
||||
getCanonicalFileName(fileName: string): string {
|
||||
return fileName;
|
||||
}
|
||||
useCaseSensitiveFileNames(): boolean {
|
||||
return true;
|
||||
}
|
||||
getNewLine(): string {
|
||||
return '\n';
|
||||
}
|
||||
fileExists(fileName: string): boolean {
|
||||
return this.fs.exists(this.fs.resolve(fileName));
|
||||
}
|
||||
readFile(fileName: string): string|undefined {
|
||||
const abs = this.fs.resolve(fileName);
|
||||
return this.fs.exists(abs) ? this.fs.readFile(abs) : undefined;
|
||||
|
Reference in New Issue
Block a user