Skip to content

Commit 4f91e9e

Browse files
feat: Add ng update support to ngrx packages (#1053)
Also adds a `schematics-core` and `migrations` build to each package
1 parent 92c13fd commit 4f91e9e

File tree

122 files changed

+12391
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+12391
-267
lines changed

.circleci/config.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,20 @@ jobs:
5454
# Install the dependencies from NPM, using the node and yarn binaries managed by Bazel
5555
- run: bazel run @yarn//:yarn
5656

57-
# Copy shared schematics-core into schematics/src directory
58-
- run: yarn copy:schematics
59-
6057
# Build and Test
6158
# Use bazel query so that we explicitly ask for all buildable targets to
6259
# be built even though we run `bazel test`
6360
# See https://github.com/bazelbuild/bazel/issues/4257
6461
- run: bazel query --output=label //... | xargs bazel test
6562

6663
test:
67-
<<: *run_in_ngcontainer
64+
docker:
65+
- image: circleci/node:latest-browsers
6866
steps:
6967
- checkout
7068
- restore_cache:
7169
key: *cache_key
7270
- run: yarn
73-
- run: yarn copy:schematics
7471
- run: yarn run ci
7572
- run: yarn run example:build:prod
7673
- run: yarn run example:test --watch=false
@@ -89,7 +86,6 @@ jobs:
8986
- restore_cache:
9087
key: *cache_key
9188
- run: yarn
92-
- run: yarn copy:schematics
9389
- run: yarn run build
9490
- run: yarn run deploy:builds
9591

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ tmp
7171

7272
example-dist/
7373

74-
schematics-core
75-
!modules/schematics-core
76-
*.tgz
74+
*.tgz
75+
modules/*/schematics-core/testing
76+
!modules/schematics-core/testing

build/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Config {
99
scope: string;
1010
}
1111

12-
const modulesDir = './modules/';
12+
export const modulesDir = './modules/';
1313
export const packages: PackageDescription[] = fs
1414
.readdirSync(modulesDir)
1515
.filter(path => {

build/copy-schematics-core.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as tasks from './tasks';
2+
import { createBuilder } from './util';
3+
import { packages } from './config';
4+
5+
const copySchematics = createBuilder([
6+
['Copy Schematics Core Files', tasks.copySchematicsCore],
7+
]);
8+
9+
copySchematics({
10+
scope: '@ngrx',
11+
packages,
12+
}).catch(err => {
13+
console.error(err);
14+
process.exit(1);
15+
});

build/tasks.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1-
import { Config } from './config';
1+
import { Config, modulesDir } from './config';
22
import * as util from './util';
3+
import * as fs from 'fs';
4+
import { ncp } from 'ncp';
5+
6+
/**
7+
*
8+
* Copies the schematics-core package into any package that provides
9+
* schematics or migrations
10+
*/
11+
export async function copySchematicsCore(config: Config) {
12+
(ncp as any).limit = 1;
13+
for (let pkg of util.getTopLevelPackages(config)) {
14+
const packageJson = fs
15+
.readFileSync(`${modulesDir}${pkg}/package.json`)
16+
.toString('utf-8');
17+
const pkgConfig = JSON.parse(packageJson);
18+
19+
if (pkgConfig.schematics || pkgConfig['ng-update'].migrations) {
20+
ncp(
21+
`${modulesDir}/schematics-core`,
22+
`${modulesDir}/${pkg}/schematics-core`,
23+
function(err: any) {
24+
if (err) {
25+
return console.error(err);
26+
}
27+
}
28+
);
29+
}
30+
}
31+
}
332

433
/**
534
* Deploy build artifacts to repos

modules/effects/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ ng_package(
2323
"//modules/effects/testing:package.json",
2424
],
2525
entry_point = "modules/effects/index.js",
26+
packages = [
27+
"//modules/effects/migrations:npm_package",
28+
"//modules/effects/schematics-core:npm_package",
29+
],
2630
deps = [
2731
":effects",
2832
"//modules/effects/testing",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Tree } from '@angular-devkit/schematics';
2+
import {
3+
SchematicTestRunner,
4+
UnitTestTree,
5+
} from '@angular-devkit/schematics/testing';
6+
import * as path from 'path';
7+
import {
8+
createPackageJson,
9+
packagePath,
10+
} from '../../../schematics-core/testing/create-package';
11+
import {
12+
upgradeVersion,
13+
versionPrefixes,
14+
} from '../../../schematics-core/testing/update';
15+
16+
const collectionPath = path.join(__dirname, '../migration.json');
17+
18+
describe('Effects Migration 6_0_0', () => {
19+
let appTree;
20+
const pkgName = 'effects';
21+
22+
versionPrefixes.forEach(prefix => {
23+
it(`should install version ${prefix}6.0.0`, () => {
24+
appTree = new UnitTestTree(Tree.empty());
25+
const runner = new SchematicTestRunner('schematics', collectionPath);
26+
const tree = createPackageJson(prefix, pkgName, appTree);
27+
28+
const newTree = runner.runSchematic(
29+
`ngrx-${pkgName}-migration-01`,
30+
{},
31+
tree
32+
);
33+
const pkg = JSON.parse(newTree.readContent(packagePath));
34+
expect(pkg.dependencies[`@ngrx/${pkgName}`]).toBe(
35+
`${prefix}${upgradeVersion}`
36+
);
37+
});
38+
});
39+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Rule } from '@angular-devkit/schematics';
2+
import { updatePackage } from '@ngrx/effects/schematics-core';
3+
4+
export default function(): Rule {
5+
return updatePackage('effects');
6+
}

modules/effects/migrations/BUILD

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
load("//tools:defaults.bzl", "npm_package")
5+
6+
ts_library(
7+
name = "migrations",
8+
srcs = glob(
9+
[
10+
"**/*.ts",
11+
],
12+
exclude = [
13+
"**/testing/*.ts",
14+
"**/*.spec.ts",
15+
],
16+
),
17+
module_name = "@ngrx/effects/migrations",
18+
deps = [
19+
"//modules/effects/schematics-core",
20+
],
21+
)
22+
23+
npm_package(
24+
name = "npm_package",
25+
srcs = [
26+
":migration.json",
27+
],
28+
deps = [
29+
":migrations",
30+
],
31+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema":
3+
"../../../node_modules/@angular-devkit/schematics/collection-schema.json",
4+
"schematics": {
5+
"ngrx-effects-migration-01": {
6+
"description": "The road to v6",
7+
"version": "5.2",
8+
"factory": "./6_0_0/index"
9+
}
10+
}
11+
}

modules/effects/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"rxjs": "RXJS_VERSION"
1919
},
2020
"ng-update": {
21-
"packageGroup": "NG_UPDATE_PACKAGE_GROUP"
21+
"packageGroup": "NG_UPDATE_PACKAGE_GROUP",
22+
"migrations": "NG_UPDATE_MIGRATIONS"
2223
},
2324
"sideEffects": false
2425
}

modules/effects/schematics-core/BUILD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
load("//tools:defaults.bzl", "npm_package")
5+
6+
ts_library(
7+
name = "schematics-core",
8+
srcs = glob(
9+
[
10+
"**/*.ts",
11+
],
12+
exclude = [
13+
"**/testing/**/*.ts",
14+
"**/*spec.ts",
15+
],
16+
),
17+
module_name = "@ngrx/effects/schematics-core",
18+
)
19+
20+
npm_package(
21+
name = "npm_package",
22+
srcs = [],
23+
deps = [
24+
":schematics-core",
25+
],
26+
)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
dasherize,
3+
decamelize,
4+
camelize,
5+
classify,
6+
underscore,
7+
group,
8+
capitalize,
9+
featurePath,
10+
} from './utility/strings';
11+
12+
export {
13+
findNodes,
14+
getSourceNodes,
15+
getDecoratorMetadata,
16+
getContentOfKeyLiteral,
17+
insertAfterLastOccurrence,
18+
addBootstrapToModule,
19+
addDeclarationToModule,
20+
addExportToModule,
21+
addImportToModule,
22+
addProviderToModule,
23+
} from './utility/ast-utils';
24+
25+
export {
26+
Host,
27+
Change,
28+
NoopChange,
29+
InsertChange,
30+
RemoveChange,
31+
ReplaceChange,
32+
} from './utility/change';
33+
34+
export {
35+
AppConfig,
36+
CliConfig,
37+
getAppFromConfig,
38+
getConfig,
39+
getWorkspace,
40+
getWorkspacePath,
41+
} from './utility/config';
42+
43+
export {
44+
findModule,
45+
findModuleFromOptions,
46+
buildRelativePath,
47+
ModuleOptions,
48+
} from './utility/find-module';
49+
50+
export {
51+
addReducerToState,
52+
addReducerToStateInferface,
53+
addReducerImportToNgModule,
54+
addReducerToActionReducerMap,
55+
omit,
56+
} from './utility/ngrx-utils';
57+
58+
export { getProjectPath } from './utility/project';
59+
export { insertImport } from './utility/route-utils';
60+
61+
export const stringUtils = {
62+
dasherize,
63+
decamelize,
64+
camelize,
65+
classify,
66+
underscore,
67+
group,
68+
capitalize,
69+
featurePath,
70+
};
71+
72+
export { updatePackage } from './utility/update';

0 commit comments

Comments
 (0)