-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@schematics/angular): remove dependency on tsickle (#15603)
With this change we remove the requirement to add tsickle as a dependency when having a workspace library. Since the CTOR downlevel transformer which was previously provided via tsickle is now in ng-packagr version 5.5.1+ We migrate existing libraries to remove the need for tsickle.
- Loading branch information
1 parent
643ff77
commit 745670f
Showing
8 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/schematics/angular/migrations/update-9/remove-tsickle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @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 { JsonParseMode, parseJsonAst } from '@angular-devkit/core'; | ||
import { Rule, Tree } from '@angular-devkit/schematics'; | ||
import { removePackageJsonDependency } from '../../utility/dependencies'; | ||
import { findPropertyInAstObject, removePropertyInAstObject } from '../../utility/json-utils'; | ||
import { Builders } from '../../utility/workspace-models'; | ||
import { getAllOptions, getTargets, getWorkspace } from './utils'; | ||
|
||
/** | ||
* Remove tsickle from libraries | ||
*/ | ||
export function removeTsickle(): Rule { | ||
return (tree: Tree) => { | ||
removePackageJsonDependency(tree, 'tsickle'); | ||
|
||
const workspace = getWorkspace(tree); | ||
|
||
for (const { target } of getTargets(workspace, 'build', Builders.NgPackagr)) { | ||
for (const options of getAllOptions(target)) { | ||
const tsConfigOption = findPropertyInAstObject(options, 'tsConfig'); | ||
if (!tsConfigOption || tsConfigOption.kind !== 'string') { | ||
continue; | ||
} | ||
|
||
const tsConfigContent = tree.read(tsConfigOption.value); | ||
if (!tsConfigContent) { | ||
continue; | ||
} | ||
|
||
const tsConfigAst = parseJsonAst(tsConfigContent.toString(), JsonParseMode.Loose); | ||
if (!tsConfigAst || tsConfigAst.kind !== 'object') { | ||
continue; | ||
} | ||
|
||
const ngCompilerOptions = findPropertyInAstObject(tsConfigAst, 'angularCompilerOptions'); | ||
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') { | ||
// remove annotateForClosureCompiler option | ||
const recorder = tree.beginUpdate(tsConfigOption.value); | ||
removePropertyInAstObject(recorder, ngCompilerOptions, 'annotateForClosureCompiler'); | ||
tree.commitUpdate(recorder); | ||
} | ||
} | ||
} | ||
|
||
return tree; | ||
}; | ||
} |
84 changes: 84 additions & 0 deletions
84
packages/schematics/angular/migrations/update-9/remove-tsickle_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* @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 { EmptyTree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
|
||
// tslint:disable:no-big-function | ||
describe('Migration to version 9', () => { | ||
describe('Remove tsickle and annotateForClosureCompiler', () => { | ||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
|
||
beforeEach(async () => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
tree = await schematicRunner | ||
.runExternalSchematicAsync( | ||
require.resolve('../../collection.json'), | ||
'workspace', | ||
{ | ||
name: 'migration-test', | ||
version: '1.2.3', | ||
directory: '.', | ||
}, | ||
tree, | ||
) | ||
.toPromise(); | ||
tree = await schematicRunner | ||
.runExternalSchematicAsync( | ||
require.resolve('../../collection.json'), | ||
'library', | ||
{ | ||
name: 'migration-lib', | ||
}, | ||
tree, | ||
) | ||
.toPromise(); | ||
}); | ||
|
||
it(`should remove 'annotateForClosureCompiler' from library tsconfig`, async () => { | ||
const libTsConfig = 'migration-lib/tsconfig.lib.json'; | ||
|
||
const tsconfig = { | ||
compilerOptions: {}, | ||
angularCompilerOptions: { | ||
enableIvy: false, | ||
skipTemplateCodegen: true, | ||
annotateForClosureCompiler: true, | ||
}, | ||
}; | ||
|
||
tree.overwrite(libTsConfig, JSON.stringify(tsconfig, undefined, 2)); | ||
|
||
const tree2 = await schematicRunner.runSchematicAsync('migration-09', {}, tree.branch()).toPromise(); | ||
const { angularCompilerOptions } = JSON.parse(tree2.readContent(libTsConfig)); | ||
expect(angularCompilerOptions).toEqual({ enableIvy: false, skipTemplateCodegen: true }); | ||
}); | ||
|
||
it('should remove all dependencies on tsickle', async () => { | ||
const packageJson = { | ||
dependencies: { | ||
'tsickle': '0.0.0', | ||
}, | ||
devDependencies: { | ||
'tsickle': '0.0.0', | ||
}, | ||
}; | ||
|
||
tree.overwrite('/package.json', JSON.stringify(packageJson, undefined, 2)); | ||
const tree2 = await schematicRunner.runSchematicAsync('migration-09', {}, tree.branch()).toPromise(); | ||
const { dependencies, devDependencies } = JSON.parse(tree2.readContent('/package.json')); | ||
expect(dependencies['tsickle']).toBeUndefined(); | ||
expect(devDependencies['tsickle']).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters