Skip to content

Commit

Permalink
Build(schematics): Update TypeScript to 3.4.x and RxJS to 6.5.x
Browse files Browse the repository at this point in the history
Fixes #1788
  • Loading branch information
ksgaurang committed May 4, 2019
1 parent 63e4926 commit e03a2a8
Show file tree
Hide file tree
Showing 31 changed files with 972 additions and 663 deletions.
9 changes: 5 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "213dcf7e72f3acd4d1e369b7a356f3e5d9560f380bd655b13b7c0ea425d7c419",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.27.9/rules_nodejs-0.27.9.tar.gz"],
sha256 = "3a3efbf223f6de733475602844ad3a8faa02abda25ab8cfe1d1ed0db134887cf",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.27.12/rules_nodejs-0.27.12.tar.gz"],
)

http_archive(
Expand All @@ -38,7 +38,8 @@ check_bazel_version(minimum_bazel_version = "0.24.0")

node_repositories(
node_version = "10.9.0",
yarn_version = "1.9.2",
package_json = ["//:package.json"],
yarn_version = "1.12.1",
)

yarn_install(
Expand All @@ -61,7 +62,7 @@ browser_repositories(
firefox = True,
)

load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace")
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")

ts_setup_workspace()

Expand Down
22 changes: 13 additions & 9 deletions modules/data/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ describe('Data ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down Expand Up @@ -98,29 +102,29 @@ describe('Data ng-add Schematic', () => {
expect(content).toMatch(/EntityDataModuleWithoutEffects\n/);
});

describe('Migration of angular-ngrx-data', () => {
it('should remove angular-ngrx-data from package.json', () => {
describe('Migration of ngrx-data', () => {
it('should remove ngrx-data from package.json', () => {
const options = { ...defaultOptions, migrateNgrxData: true };

const packageJsonBefore = JSON.parse(
appTree.readContent('/package.json')
);
packageJsonBefore['dependencies']['angular-ngrx-data'] = '1.0.0';
packageJsonBefore['dependencies']['ngrx-data'] = '1.0.0';
appTree.overwrite(
'/package.json',
JSON.stringify(packageJsonBefore, null, 2)
);

expect(
JSON.parse(appTree.readContent('/package.json'))['dependencies'][
'angular-ngrx-data'
'ngrx-data'
]
).toBeDefined();

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const packageJson = JSON.parse(tree.readContent('/package.json'));

expect(packageJson.dependencies['angular-ngrx-data']).not.toBeDefined();
expect(packageJson.dependencies['ngrx-data']).not.toBeDefined();
});

it('should rename NgrxDataModule', () => {
Expand Down Expand Up @@ -260,7 +264,7 @@ describe('Data ng-add Schematic', () => {
NgrxDataModuleConfig,
Pluralizer
} from 'ngrx-data';
const customConfig: NgrxDataModuleConfig = {
root: 'api', // default root path to the server's web api
timeout: 3000, // request timeout
Expand Down Expand Up @@ -291,7 +295,7 @@ describe('Data ng-add Schematic', () => {
EntityDataModuleConfig,
Pluralizer
} from '@ngrx/data';
const customConfig: EntityDataModuleConfig = {
root: 'api', // default root path to the server's web api
timeout: 3000, // request timeout
Expand Down
4 changes: 2 additions & 2 deletions modules/data/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ function removeAngularNgRxDataFromPackageJson() {
const sourceText = host.read('package.json')!.toString('utf-8');
const json = JSON.parse(sourceText);

if (json['dependencies'] && json['dependencies']['angular-ngrx-data']) {
delete json['dependencies']['angular-ngrx-data'];
if (json['dependencies'] && json['dependencies']['ngrx-data']) {
delete json['dependencies']['ngrx-data'];
}

host.overwrite('package.json', JSON.stringify(json, null, 2));
Expand Down
2 changes: 1 addition & 1 deletion modules/data/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"migrateNgrxData": {
"type": "boolean",
"default": false,
"description": "Migrate from angular-ngrx-data, will rename modules.",
"description": "Migrate from ngrx-data, will rename modules.",
"alias": "migrate"
}
},
Expand Down
3 changes: 2 additions & 1 deletion modules/data/spec/utils/default-pluralizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ describe('DefaultPluralizer', () => {
TestBed.configureTestingModule({
providers: [{ provide: Pluralizer, useClass: DefaultPluralizer }],
});

pluralizer = TestBed.get(Pluralizer);
});
describe('without plural names', () => {
it('should turn "Hero" to "Heros" because no plural names map', () => {
pluralizer = TestBed.get(Pluralizer);
// No map so 'Hero' gets default pluralization
expect(pluralizer.pluralize('Hero')).toBe('Heros');
});
Expand Down
8 changes: 6 additions & 2 deletions modules/effects/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ describe('Effect ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/entity/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ describe('Entity ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/router-store/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ describe('Router Store ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
1 change: 1 addition & 0 deletions modules/schematics-core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ts_library(
deps = [
"@npm//@angular-devkit/core",
"@npm//@angular-devkit/schematics",
"@npm//rxjs",
"@npm//typescript",
],
)
57 changes: 28 additions & 29 deletions modules/schematics-core/testing/create-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
UnitTestTree,
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import { concatMap } from 'rxjs/operators';
import { Observable } from 'rxjs';

export const defaultWorkspaceOptions = {
name: 'workspace',
Expand All @@ -20,13 +22,6 @@ export const defaultAppOptions = {
skipTests: false,
};

const defaultModuleOptions = {
name: 'foo',
spec: true,
module: undefined,
flat: false,
};

const defaultLibOptions = {
name: 'baz',
};
Expand All @@ -40,28 +35,32 @@ export function getTestProjectPath(

export function createWorkspace(
schematicRunner: SchematicTestRunner,
appTree: UnitTestTree,
workspaceOptions = defaultWorkspaceOptions,
appOptions = defaultAppOptions,
libOptions = defaultLibOptions
) {
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'workspace',
workspaceOptions
);
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'application',
appOptions,
appTree
);
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'library',
libOptions,
appTree
);

return appTree;
): Observable<UnitTestTree> {
return schematicRunner
.runExternalSchematicAsync(
'@schematics/angular',
'workspace',
workspaceOptions
)
.pipe(
concatMap(tree =>
schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'application',
appOptions,
tree
)
),
concatMap(tree =>
schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'library',
libOptions,
tree
)
)
);
}
8 changes: 6 additions & 2 deletions modules/schematics/src/action/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ describe('Action Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create an action to specified project if provided', () => {
Expand Down
18 changes: 12 additions & 6 deletions modules/schematics/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ describe('CLI Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create a class by the angular/cli', () => {
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('class', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/foo.ts`);

expect(content).toMatch(/export class Foo/);
schematicRunner
.runSchematicAsync('class', options, appTree)
.subscribe(tree => {
const content = tree.readContent(`${projectPath}/src/app/foo.ts`);
expect(content).toMatch(/export class Foo/);
});
});
});
Loading

0 comments on commit e03a2a8

Please sign in to comment.