Skip to content

Commit

Permalink
fix(@angular-devkit/build-ng-packagr): update builder
Browse files Browse the repository at this point in the history
Followup to comments in angular/devkit#444
  • Loading branch information
filipesilva authored and hansl committed Jun 6, 2018
1 parent e5271e4 commit 21f728e
Show file tree
Hide file tree
Showing 36 changed files with 80 additions and 6,922 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"mini-css-extract-plugin": "~0.2.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.0",
"ng-packagr": "^2.1.0",
"ng-packagr": "^2.2.0",
"node-sass": "^4.7.2",
"opn": "^5.1.0",
"parse5": "^4.0.0",
Expand Down
10 changes: 6 additions & 4 deletions packages/angular_devkit/build_ng_packagr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"dependencies": {
"@angular-devkit/architect": "0.0.0",
"@angular-devkit/core": "0.0.0",
"rxjs": "0.0.0",
"resolve": "0.0.0",
"ng-packagr": "0.0.0"
"resolve": "^1.5.0",
"rxjs": "^5.5.6"
},
"peerDependencies": {
"ng-packagr": "^2.2.0"
}
}
}
32 changes: 21 additions & 11 deletions packages/angular_devkit/build_ng_packagr/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
* found in the LICENSE file at https://angular.io/license
*/

import { BuildEvent, Builder, BuilderContext, Target } from '@angular-devkit/architect';
import { getSystemPath } from '@angular-devkit/core';
import {
BuildEvent,
Builder,
BuilderConfiguration,
BuilderContext,
} from '@angular-devkit/architect';
import { getSystemPath, normalize, resolve } from '@angular-devkit/core';
import * as ngPackagr from 'ng-packagr';
import { resolve as resolvePath } from 'path';
import { Observable } from 'rxjs/Observable';

// XX: blatantly copy-pasted from 'require-project-module.ts'
const resolve = require('resolve');
// 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) {
const resolve = require('resolve');

return require(resolve.sync(moduleName, { basedir: root }));
}

Expand All @@ -27,22 +33,26 @@ export class NgPackagrBuilder implements Builder<NgPackagrBuilderOptions> {

constructor(public context: BuilderContext) { }

run(target: Target<NgPackagrBuilderOptions>): Observable<BuildEvent> {
const root = getSystemPath(target.root);
const options = target.options;
run(builderConfig: BuilderConfiguration<NgPackagrBuilderOptions>): Observable<BuildEvent> {
const root = this.context.workspace.root;
const options = builderConfig.options;

if (!options.project) {
throw new Error('A "project" must be specified to build a library\'s npm package.');
}

return new Observable(obs => {
const projectNgPackagr = requireProjectModule(root, 'ng-packagr') as typeof ngPackagr;
const packageJsonPath = resolvePath(root, options.project);
const projectNgPackagr = requireProjectModule(
getSystemPath(root), 'ng-packagr') as typeof ngPackagr;
const packageJsonPath = getSystemPath(resolve(root, normalize(options.project)));

projectNgPackagr.ngPackagr()
.forProject(packageJsonPath)
.build()
.then(() => obs.complete())
.then(() => {
obs.next({ success: true });
obs.complete();
})
.catch((e) => obs.error(e));
});
}
Expand Down
53 changes: 0 additions & 53 deletions packages/angular_devkit/build_ng_packagr/src/build/index_spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { Architect, TargetSpecifier } from '@angular-devkit/architect';
import { experimental, join, normalize } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import { concatMap, tap } from 'rxjs/operators';


describe('NgPackagr Builder', () => {
it('works', (done) => {
const workspaceFile = normalize('angular.json');
const devkitRoot = normalize((global as any)._DevKitRoot); // tslint:disable-line:no-any
const workspaceRoot = join(devkitRoot,
'tests/@angular_devkit/build_ng_packagr/ng-packaged/');

// TODO: move TestProjectHost from build-webpack to architect, or somewhere else, where it
// can be imported from.
const host = new NodeJsSyncHost();
const workspace = new experimental.workspace.Workspace(workspaceRoot, host);
const targetSpec: TargetSpecifier = { project: 'lib', target: 'build' };

return workspace.loadWorkspaceFromHost(workspaceFile).pipe(
concatMap(ws => new Architect(ws).loadArchitect()),
concatMap(arch => arch.run(arch.getBuilderConfiguration(targetSpec))),
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
).subscribe(undefined, done.fail, done);
}, 30000);
});

This file was deleted.

13 changes: 0 additions & 13 deletions tests/@angular_devkit/build_ng_packagr/ng-packaged/.editorconfig

This file was deleted.

27 changes: 0 additions & 27 deletions tests/@angular_devkit/build_ng_packagr/ng-packaged/README.md

This file was deleted.

18 changes: 18 additions & 0 deletions tests/@angular_devkit/build_ng_packagr/ng-packaged/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "../../../../packages/angular_devkit/core/src/workspace/workspace-schema.json",
"version": 1,
"projects": {
"lib": {
"root": "projects/lib",
"projectType": "library",
"architect": {
"build": {
"builder": "../../../../packages/angular_devkit/build_ng_packagr:build",
"options": {
"project": "projects/lib/package.json"
}
}
}
}
}
}

This file was deleted.

11 changes: 0 additions & 11 deletions tests/@angular_devkit/build_ng_packagr/ng-packaged/e2e/app.po.ts

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions tests/@angular_devkit/build_ng_packagr/ng-packaged/karma.conf.js

This file was deleted.

Loading

0 comments on commit 21f728e

Please sign in to comment.