Skip to content

Commit af7b2cc

Browse files
feat(component-store): add ng-add and ng-update schematics (#2598)
Closes #2569
1 parent 60cd5cc commit af7b2cc

34 files changed

+2373
-9
lines changed

angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@
579579
"commands": [
580580
{
581581
"command": "ng run component-store:build-package"
582+
},
583+
{
584+
"command": "yarn tsc -p modules/component-store/tsconfig.schematics.json"
582585
}
583586
]
584587
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("//tools:defaults.bzl", "pkg_npm", "ts_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ts_library(
6+
name = "migrations",
7+
srcs = glob(
8+
[
9+
"**/*.ts",
10+
],
11+
exclude = [
12+
"**/testing/*.ts",
13+
"**/*.spec.ts",
14+
],
15+
),
16+
module_name = "@ngrx/component-store/migrations",
17+
deps = [
18+
"//modules/component-store/schematics-core",
19+
"@npm//@angular-devkit/schematics",
20+
],
21+
)
22+
23+
pkg_npm(
24+
name = "npm_package",
25+
srcs = [
26+
":migration.json",
27+
],
28+
deps = [
29+
":migrations",
30+
],
31+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"schematics": {}
4+
}

modules/component-store/package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,18 @@
2525
"@angular/core": "^10.0.0",
2626
"rxjs": "^6.5.3"
2727
},
28-
"sideEffects": false
28+
"sideEffects": false,
29+
"ng-update": {
30+
"packageGroup": [
31+
"@ngrx/store",
32+
"@ngrx/effects",
33+
"@ngrx/entity",
34+
"@ngrx/router-store",
35+
"@ngrx/data",
36+
"@ngrx/schematics",
37+
"@ngrx/store-devtools",
38+
"@ngrx/component-store"
39+
],
40+
"migrations": "./migrations/migration.json"
41+
}
2942
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import {
2+
dasherize,
3+
decamelize,
4+
camelize,
5+
classify,
6+
underscore,
7+
group,
8+
capitalize,
9+
featurePath,
10+
pluralize,
11+
} from './utility/strings';
12+
13+
export { isIvyEnabled } from './utility/angular-utils';
14+
15+
export {
16+
findNodes,
17+
getSourceNodes,
18+
getDecoratorMetadata,
19+
getContentOfKeyLiteral,
20+
insertAfterLastOccurrence,
21+
insertImport,
22+
addBootstrapToModule,
23+
addDeclarationToModule,
24+
addExportToModule,
25+
addImportToModule,
26+
addProviderToModule,
27+
replaceImport,
28+
containsProperty,
29+
} from './utility/ast-utils';
30+
31+
export {
32+
Host,
33+
Change,
34+
NoopChange,
35+
InsertChange,
36+
RemoveChange,
37+
ReplaceChange,
38+
createReplaceChange,
39+
createChangeRecorder,
40+
commitChanges,
41+
} from './utility/change';
42+
43+
export { AppConfig, getWorkspace, getWorkspacePath } from './utility/config';
44+
45+
export {
46+
findModule,
47+
findModuleFromOptions,
48+
buildRelativePath,
49+
ModuleOptions,
50+
} from './utility/find-module';
51+
52+
export { findPropertyInAstObject } from './utility/json-utilts';
53+
54+
export {
55+
addReducerToState,
56+
addReducerToStateInterface,
57+
addReducerImportToNgModule,
58+
addReducerToActionReducerMap,
59+
omit,
60+
} from './utility/ngrx-utils';
61+
62+
export { getProjectPath, getProject, isLib } from './utility/project';
63+
64+
export const stringUtils = {
65+
dasherize,
66+
decamelize,
67+
camelize,
68+
classify,
69+
underscore,
70+
group,
71+
capitalize,
72+
featurePath,
73+
pluralize,
74+
};
75+
76+
export { updatePackage } from './utility/update';
77+
78+
export { parseName } from './utility/parse-name';
79+
80+
export { addPackageToPackageJson } from './utility/package';
81+
82+
export { platformVersion } from './utility/libs-version';
83+
84+
export {
85+
visitTSSourceFiles,
86+
visitNgModuleImports,
87+
visitNgModuleExports,
88+
visitComponents,
89+
visitDecorator,
90+
visitNgModules,
91+
visitTemplates,
92+
} from './utility/visitors';
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {
2+
JsonParseMode,
3+
dirname,
4+
normalize,
5+
parseJsonAst,
6+
resolve,
7+
} from '@angular-devkit/core';
8+
import { Tree } from '@angular-devkit/schematics';
9+
import { findPropertyInAstObject } from './json-utilts';
10+
11+
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-9/utils.ts
12+
export function isIvyEnabled(tree: Tree, tsConfigPath: string): boolean {
13+
// In version 9, Ivy is turned on by default
14+
// Ivy is opted out only when 'enableIvy' is set to false.
15+
16+
const buffer = tree.read(tsConfigPath);
17+
if (!buffer) {
18+
return true;
19+
}
20+
21+
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose);
22+
23+
if (tsCfgAst.kind !== 'object') {
24+
return true;
25+
}
26+
27+
const ngCompilerOptions = findPropertyInAstObject(
28+
tsCfgAst,
29+
'angularCompilerOptions'
30+
);
31+
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') {
32+
const enableIvy = findPropertyInAstObject(ngCompilerOptions, 'enableIvy');
33+
34+
if (enableIvy) {
35+
return !!enableIvy.value;
36+
}
37+
}
38+
39+
const configExtends = findPropertyInAstObject(tsCfgAst, 'extends');
40+
if (configExtends && configExtends.kind === 'string') {
41+
const extendedTsConfigPath = resolve(
42+
dirname(normalize(tsConfigPath)),
43+
normalize(configExtends.value)
44+
);
45+
46+
return isIvyEnabled(tree, extendedTsConfigPath);
47+
}
48+
49+
return true;
50+
}

0 commit comments

Comments
 (0)