Skip to content

Commit

Permalink
refactor(schematics): use context logger, match devkit rxjs version
Browse files Browse the repository at this point in the history
  • Loading branch information
damyanpetev committed Mar 1, 2021
1 parent 8e47fd2 commit 743b428
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"name": "Launch Test",
"program": "${workspaceFolder}/spec/jasmine-runner.js",
"preLaunchTask": "build",
"outFiles": [ "${workspaceRoot}/lib/**/*.js",
"outFiles": [ "${workspaceRoot}/packages/**/*.js",
"${workspaceRoot}/spec/**/*.js" ]
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"jasmine-spec-reporter": "~5.0.0",
"lite-server": "^2.4.0",
"nyc": "^13.1.0",
"rxjs": "6.5.4",
"rxjs": "6.6.3",
"source-map-support": "^0.5.4",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ng-schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@igniteui/angular-templates": "~11.1.710",
"@igniteui/cli-core": "~7.1.0",
"@schematics/angular": "^11.0.0",
"rxjs": "6.5.3"
"rxjs": "6.6.3"
},
"devDependencies": {
"@types/jasmine": "3.3.9",
Expand Down
10 changes: 4 additions & 6 deletions packages/ng-schematics/src/cli-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DependencyNotFoundException } from "@angular-devkit/core";
import { yellow } from "@angular-devkit/core/src/terminal";
import { chain, FileDoesNotExistException, Rule, Tree } from "@angular-devkit/schematics";
import { chain, FileDoesNotExistException, Rule, SchematicContext, Tree } from "@angular-devkit/schematics";
import { NPM_PACKAGE, resolveIgxPackage } from "@igniteui/angular-templates";
import { addTypography, TypeScriptFileUpdate } from "@igniteui/cli-core";
import { createCliConfig } from "../utils/cli-config";
Expand Down Expand Up @@ -32,7 +31,7 @@ function getDependencyVersion(pkg: string, tree: Tree): string {
}

function displayVersionMismatch(): Rule {
return (tree: Tree) => {
return (tree: Tree, context: SchematicContext) => {
const igxPackage = resolveIgxPackage(NPM_PACKAGE);
const pkgJson = JSON.parse(tree.read(`/node_modules/${igxPackage}/package.json`)!.toString());
const ngKey = "@angular/core";
Expand All @@ -43,10 +42,9 @@ function displayVersionMismatch(): Rule {
const ngCommonVer = pkgJson.peerDependencies[ngCommonKey];

if (ngCoreProjVer < ngCoreVer || ngCommonProjVer < ngCommonVer) {
// tslint:disable-next-line:no-console
console.warn(yellow(`
context.logger.warn(`
WARNING Version mismatch detected - ${igxPackage} is built against a newer version of @angular/core (${ngCoreVer}).
Running 'ng update' will prevent potential version conflicts.\n`));
Running 'ng update' will prevent potential version conflicts.\n`);
}
};
}
Expand Down
13 changes: 8 additions & 5 deletions packages/ng-schematics/src/cli-config/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,22 @@ export class AppModule {
});

it("should properly display the dependency mismatch warning", async () => {
spyOn(console, "warn");
const warns: string[] = [];
runner.logger.subscribe(entry => {
if (entry.level === "warn") {
warns.push(entry.message);
}
});
await runner.runSchematicAsync("cli-config", {}, tree).toPromise();
let pattern = new RegExp(`WARNING Version mismatch detected - ${NPM_PACKAGE}`);
// tslint:disable-next-line:no-console
expect(console.warn).toHaveBeenCalledWith(jasmine.stringMatching(pattern));
expect(warns).toContain(jasmine.stringMatching(pattern));

resetTree();
createIgPkgJson(FEED_PACKAGE);
populatePkgJson(FEED_PACKAGE);
pattern = new RegExp(`WARNING Version mismatch detected - ${FEED_PACKAGE}`);

await runner.runSchematicAsync("cli-config", {}, tree).toPromise();
// tslint:disable-next-line:no-console
expect(console.warn).toHaveBeenCalledWith(jasmine.stringMatching(pattern));
expect(warns).toContain(jasmine.stringMatching(pattern));
});
});
14 changes: 7 additions & 7 deletions packages/ng-schematics/src/ng-new/index_spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SchematicContext, Tree } from "@angular-devkit/schematics";
import { NodePackageTaskOptions } from "@angular-devkit/schematics/tasks/node-package/options";
import { NodePackageTaskOptions } from "@angular-devkit/schematics/tasks/package-manager/options";
import { RepositoryInitializerTaskOptions } from "@angular-devkit/schematics/tasks/repo-init/options";
import { RunSchematicTaskOptions } from "@angular-devkit/schematics/tasks/run-schematic/options";
import { SchematicTestRunner, UnitTestTree } from "@angular-devkit/schematics/testing";
Expand Down Expand Up @@ -67,11 +67,11 @@ describe("Schematics ng-new", () => {
expect(e.exists(`${workingDirectory}/.gitignore`)).toBeTruthy();
const taskOptions = runner.tasks.map(task => task.options);
const expectedInstall: NodePackageTaskOptions = {
workingDirectory,
command: "install",
packageManager: undefined,
quiet: true,
workingDirectory,
packageName: undefined,
quiet: true
packageManager: undefined
};
const expectedInit: RepositoryInitializerTaskOptions = {
workingDirectory,
Expand Down Expand Up @@ -135,11 +135,11 @@ describe("Schematics ng-new", () => {
expect(e.exists(`${workingDirectory}/.gitignore`)).toBeTruthy();
const taskOptions = runner.tasks.map(task => task.options);
const expectedInstall: NodePackageTaskOptions = {
workingDirectory,
command: "install",
packageManager: undefined,
quiet: true,
workingDirectory,
packageName: undefined,
quiet: true
packageManager: undefined
};
const expectedInit: RepositoryInitializerTaskOptions = {
workingDirectory,
Expand Down
14 changes: 0 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5739,20 +5739,6 @@ rx@4.1.0:
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"
integrity sha1-pfE/957zt0D+MKqAP7CfmIBdR4I=

rxjs@6.5.3:
version "6.5.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.3.tgz#510e26317f4db91a7eb1de77d9dd9ba0a4899a3a"
integrity sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==
dependencies:
tslib "^1.9.0"

rxjs@6.5.4:
version "6.5.4"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.4.tgz#e0777fe0d184cec7872df147f303572d414e211c"
integrity sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==
dependencies:
tslib "^1.9.0"

rxjs@6.6.3:
version "6.6.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552"
Expand Down

0 comments on commit 743b428

Please sign in to comment.