-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): export reducer directly when Ivy is enabled (#2440)
- Loading branch information
1 parent
fdee3d8
commit b68fa67
Showing
30 changed files
with
773 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
JsonParseMode, | ||
dirname, | ||
normalize, | ||
parseJsonAst, | ||
resolve, | ||
} from '@angular-devkit/core'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { findPropertyInAstObject } from './json-utilts'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-9/utils.ts | ||
export function isIvyEnabled(tree: Tree, tsConfigPath: string): boolean { | ||
// In version 9, Ivy is turned on by default | ||
// Ivy is opted out only when 'enableIvy' is set to false. | ||
|
||
const buffer = tree.read(tsConfigPath); | ||
if (!buffer) { | ||
return true; | ||
} | ||
|
||
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); | ||
|
||
if (tsCfgAst.kind !== 'object') { | ||
return true; | ||
} | ||
|
||
const ngCompilerOptions = findPropertyInAstObject( | ||
tsCfgAst, | ||
'angularCompilerOptions' | ||
); | ||
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') { | ||
const enableIvy = findPropertyInAstObject(ngCompilerOptions, 'enableIvy'); | ||
|
||
if (enableIvy) { | ||
return !!enableIvy.value; | ||
} | ||
} | ||
|
||
const configExtends = findPropertyInAstObject(tsCfgAst, 'extends'); | ||
if (configExtends && configExtends.kind === 'string') { | ||
const extendedTsConfigPath = resolve( | ||
dirname(normalize(tsConfigPath)), | ||
normalize(configExtends.value) | ||
); | ||
|
||
return isIvyEnabled(tree, extendedTsConfigPath); | ||
} | ||
|
||
return true; | ||
} |
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,16 @@ | ||
import { JsonAstNode, JsonAstObject } from '@angular-devkit/core'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/utility/json-utils.ts | ||
export function findPropertyInAstObject( | ||
node: JsonAstObject, | ||
propertyName: string | ||
): JsonAstNode | null { | ||
let maybeNode: JsonAstNode | null = null; | ||
for (const property of node.properties) { | ||
if (property.key.value == propertyName) { | ||
maybeNode = property.value; | ||
} | ||
} | ||
|
||
return maybeNode; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
JsonParseMode, | ||
dirname, | ||
normalize, | ||
parseJsonAst, | ||
resolve, | ||
} from '@angular-devkit/core'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { findPropertyInAstObject } from './json-utilts'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-9/utils.ts | ||
export function isIvyEnabled(tree: Tree, tsConfigPath: string): boolean { | ||
// In version 9, Ivy is turned on by default | ||
// Ivy is opted out only when 'enableIvy' is set to false. | ||
|
||
const buffer = tree.read(tsConfigPath); | ||
if (!buffer) { | ||
return true; | ||
} | ||
|
||
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); | ||
|
||
if (tsCfgAst.kind !== 'object') { | ||
return true; | ||
} | ||
|
||
const ngCompilerOptions = findPropertyInAstObject( | ||
tsCfgAst, | ||
'angularCompilerOptions' | ||
); | ||
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') { | ||
const enableIvy = findPropertyInAstObject(ngCompilerOptions, 'enableIvy'); | ||
|
||
if (enableIvy) { | ||
return !!enableIvy.value; | ||
} | ||
} | ||
|
||
const configExtends = findPropertyInAstObject(tsCfgAst, 'extends'); | ||
if (configExtends && configExtends.kind === 'string') { | ||
const extendedTsConfigPath = resolve( | ||
dirname(normalize(tsConfigPath)), | ||
normalize(configExtends.value) | ||
); | ||
|
||
return isIvyEnabled(tree, extendedTsConfigPath); | ||
} | ||
|
||
return true; | ||
} |
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,16 @@ | ||
import { JsonAstNode, JsonAstObject } from '@angular-devkit/core'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/utility/json-utils.ts | ||
export function findPropertyInAstObject( | ||
node: JsonAstObject, | ||
propertyName: string | ||
): JsonAstNode | null { | ||
let maybeNode: JsonAstNode | null = null; | ||
for (const property of node.properties) { | ||
if (property.key.value == propertyName) { | ||
maybeNode = property.value; | ||
} | ||
} | ||
|
||
return maybeNode; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
JsonParseMode, | ||
dirname, | ||
normalize, | ||
parseJsonAst, | ||
resolve, | ||
} from '@angular-devkit/core'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { findPropertyInAstObject } from './json-utilts'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-9/utils.ts | ||
export function isIvyEnabled(tree: Tree, tsConfigPath: string): boolean { | ||
// In version 9, Ivy is turned on by default | ||
// Ivy is opted out only when 'enableIvy' is set to false. | ||
|
||
const buffer = tree.read(tsConfigPath); | ||
if (!buffer) { | ||
return true; | ||
} | ||
|
||
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); | ||
|
||
if (tsCfgAst.kind !== 'object') { | ||
return true; | ||
} | ||
|
||
const ngCompilerOptions = findPropertyInAstObject( | ||
tsCfgAst, | ||
'angularCompilerOptions' | ||
); | ||
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') { | ||
const enableIvy = findPropertyInAstObject(ngCompilerOptions, 'enableIvy'); | ||
|
||
if (enableIvy) { | ||
return !!enableIvy.value; | ||
} | ||
} | ||
|
||
const configExtends = findPropertyInAstObject(tsCfgAst, 'extends'); | ||
if (configExtends && configExtends.kind === 'string') { | ||
const extendedTsConfigPath = resolve( | ||
dirname(normalize(tsConfigPath)), | ||
normalize(configExtends.value) | ||
); | ||
|
||
return isIvyEnabled(tree, extendedTsConfigPath); | ||
} | ||
|
||
return true; | ||
} |
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,16 @@ | ||
import { JsonAstNode, JsonAstObject } from '@angular-devkit/core'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/utility/json-utils.ts | ||
export function findPropertyInAstObject( | ||
node: JsonAstObject, | ||
propertyName: string | ||
): JsonAstNode | null { | ||
let maybeNode: JsonAstNode | null = null; | ||
for (const property of node.properties) { | ||
if (property.key.value == propertyName) { | ||
maybeNode = property.value; | ||
} | ||
} | ||
|
||
return maybeNode; | ||
} |
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
50 changes: 50 additions & 0 deletions
50
modules/router-store/schematics-core/utility/angular-utils.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,50 @@ | ||
import { | ||
JsonParseMode, | ||
dirname, | ||
normalize, | ||
parseJsonAst, | ||
resolve, | ||
} from '@angular-devkit/core'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { findPropertyInAstObject } from './json-utilts'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-9/utils.ts | ||
export function isIvyEnabled(tree: Tree, tsConfigPath: string): boolean { | ||
// In version 9, Ivy is turned on by default | ||
// Ivy is opted out only when 'enableIvy' is set to false. | ||
|
||
const buffer = tree.read(tsConfigPath); | ||
if (!buffer) { | ||
return true; | ||
} | ||
|
||
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); | ||
|
||
if (tsCfgAst.kind !== 'object') { | ||
return true; | ||
} | ||
|
||
const ngCompilerOptions = findPropertyInAstObject( | ||
tsCfgAst, | ||
'angularCompilerOptions' | ||
); | ||
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') { | ||
const enableIvy = findPropertyInAstObject(ngCompilerOptions, 'enableIvy'); | ||
|
||
if (enableIvy) { | ||
return !!enableIvy.value; | ||
} | ||
} | ||
|
||
const configExtends = findPropertyInAstObject(tsCfgAst, 'extends'); | ||
if (configExtends && configExtends.kind === 'string') { | ||
const extendedTsConfigPath = resolve( | ||
dirname(normalize(tsConfigPath)), | ||
normalize(configExtends.value) | ||
); | ||
|
||
return isIvyEnabled(tree, extendedTsConfigPath); | ||
} | ||
|
||
return true; | ||
} |
16 changes: 16 additions & 0 deletions
16
modules/router-store/schematics-core/utility/json-utilts.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,16 @@ | ||
import { JsonAstNode, JsonAstObject } from '@angular-devkit/core'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/utility/json-utils.ts | ||
export function findPropertyInAstObject( | ||
node: JsonAstObject, | ||
propertyName: string | ||
): JsonAstNode | null { | ||
let maybeNode: JsonAstNode | null = null; | ||
for (const property of node.properties) { | ||
if (property.key.value == propertyName) { | ||
maybeNode = property.value; | ||
} | ||
} | ||
|
||
return maybeNode; | ||
} |
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
Oops, something went wrong.