Skip to content

Commit

Permalink
feat(@angular-devkit/build-ng-packagr): add support for ng-packagr ve…
Browse files Browse the repository at this point in the history
…rsion 5
  • Loading branch information
alan-agius4 authored and mgechev committed Mar 27, 2019
1 parent e516a81 commit 952da42
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 292 deletions.
8 changes: 3 additions & 5 deletions packages/angular_devkit/build_ng_packagr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
"dependencies": {
"@angular-devkit/architect": "0.0.0",
"@angular-devkit/core": "0.0.0",
"rxjs": "6.4.0",
"semver": "6.0.0"
"rxjs": "6.4.0"
},
"peerDependencies": {
"ng-packagr": "^4.0.0"
"ng-packagr": "^4.0.0 || ^5.0.0"
},
"devDependencies": {
"@angular/compiler": "^8.0.0-beta.9",
"@angular/compiler-cli": "^8.0.0-beta.9",
"ng-packagr": "^4.0.0",
"tsickle": ">=0.34.0",
"ng-packagr": "^5.0.1",
"tslib": "^1.9.0"
}
}
36 changes: 0 additions & 36 deletions packages/angular_devkit/build_ng_packagr/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,18 @@ import * as fs from 'fs';
import * as ngPackagr from 'ng-packagr';
import { EMPTY, Observable } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import * as semver from 'semver';

const NEW_NG_PACKAGR_VERSION = '4.0.0-rc.3';

// TODO move this function to architect or somewhere else where it can be imported from.
// Blatantly copy-pasted from 'require-project-module.ts'.
function requireProjectModule(root: string, moduleName: string) {
return require(require.resolve(moduleName, { paths: [root] }));
}

function resolveProjectModule(root: string, moduleName: string) {
return require.resolve(moduleName, { paths: [root] });
}

export interface NgPackagrBuilderOptions {
project: string;
tsConfig?: string;
watch?: boolean;
}

function checkNgPackagrVersion(projectRoot: string): boolean {
let ngPackagrJsonPath;

try {
ngPackagrJsonPath = resolveProjectModule(projectRoot, 'ng-packagr/package.json');
} catch {
// ng-packagr is not installed
throw new Error(tags.stripIndent`
ng-packagr is not installed. Run \`npm install ng-packagr --save-dev\` and try again.
`);
}

const ngPackagrPackageJson = fs.readFileSync(ngPackagrJsonPath).toString();
const ngPackagrVersion = JSON.parse(ngPackagrPackageJson)['version'];

if (!semver.gte(ngPackagrVersion, NEW_NG_PACKAGR_VERSION)) {
throw new Error(tags.stripIndent`
The installed version of ng-packagr is ${ngPackagrVersion}. The watch feature
requires ng-packagr version to satisfy ${NEW_NG_PACKAGR_VERSION}.
Please upgrade your ng-packagr version.
`);
}

return true;
}

export class NgPackagrBuilder implements Builder<NgPackagrBuilderOptions> {

constructor(public context: BuilderContext) { }
Expand All @@ -89,8 +55,6 @@ export class NgPackagrBuilder implements Builder<NgPackagrBuilderOptions> {
}

if (options.watch) {
checkNgPackagrVersion(getSystemPath(root));

const ngPkgSubscription = ngPkgProject
.watch()
.pipe(
Expand Down
Loading

0 comments on commit 952da42

Please sign in to comment.