Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lib.externals support. #57

Merged
merged 1 commit into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion integration/sample_core/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$schema": "../../ng-package.schema.json",
"lib": {
"entryFile": "public_api.ts"
"entryFile": "public_api.ts",
"externals": {
"rxjs/operator/map": "Rx.Observable.prototype"
}
}
}
11 changes: 6 additions & 5 deletions integration/sample_core/src/angular.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import 'rxjs/add/operator/map';
import { map } from 'rxjs/operator/map';

@Injectable()
export class AngularService {

private _subject: Subject<any> = new ReplaySubject<any>(1);

constructor(
private http: Http
) {}

public foo(): Observable<string> {

return this.http.get('/foo/bar')
.map((res: Response) => `${res.ok}`);
return map.call(
this.http.get('/foo/bar'),
(res: Response) => `${res.ok}`
);
}

public get bar(): Observable<any> {
Expand Down
11 changes: 7 additions & 4 deletions lib/model/ng-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ export class NgPackage {
if (!ngPackageJson.src) this.ngPackageJson.src = '.';
if (!ngPackageJson.dest) this.ngPackageJson.dest = 'dist';
if (!ngPackageJson.workingDirectory) this.ngPackageJson.workingDirectory = '.ng_build';
if (ngPackageJson.lib) {
if (!ngPackageJson.lib.entryFile) this.ngPackageJson.lib.entryFile = 'src/public_api.ts';
//if (!ngPackageJson.lib.flatModuleFile) this.ngPackageJson.lib.flatModuleFile = 'index';
}
if (!ngPackageJson.lib) this.ngPackageJson.lib = {};
if (!ngPackageJson.lib.entryFile) this.ngPackageJson.lib.entryFile = 'src/public_api.ts';
//if (!ngPackageJson.lib.flatModuleFile) this.ngPackageJson.lib.flatModuleFile = 'index';
}

public get dest(): string {
Expand All @@ -39,6 +38,10 @@ export class NgPackage {
return path.basename(this.ngPackageJson.lib.flatModuleFile || this.meta.name || 'index');
}

public get libExternals(): Object {
return this.ngPackageJson.lib.externals || {};
}

/** Package meta information */
public get meta(): { name: string, scope?: string } {
// split into name and scope (`@<scope>/<name>`)
Expand Down
6 changes: 4 additions & 2 deletions lib/ng-packagr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export const ngPackage = (opts: NgPackagrCliArguments): Promise<any> => {
moduleName: ngPkg.meta.name,
entry: es2015EntryFile,
format: 'es',
dest: `${ngPkg.workingDirectory}/${ngPkg.artefacts.es2015}`
dest: `${ngPkg.workingDirectory}/${ngPkg.artefacts.es2015}`,
externals: ngPkg.libExternals
})
// XX ... rollup generates relative paths in sourcemaps. It would be nice to re-locate source map files
// so that `@scope/name/foo/bar.ts` shows up as path in the browser...
Expand All @@ -85,7 +86,8 @@ export const ngPackage = (opts: NgPackagrCliArguments): Promise<any> => {
moduleName: ngPkg.meta.name,
entry: `${ngPkg.workingDirectory}/${ngPkg.artefacts.module}`,
format: 'umd',
dest: `${ngPkg.workingDirectory}/${ngPkg.artefacts.main}`
dest: `${ngPkg.workingDirectory}/${ngPkg.artefacts.main}`,
externals: ngPkg.libExternals
})
.then(() => remapSourcemap(`${ngPkg.workingDirectory}/${ngPkg.artefacts.main}`))
)
Expand Down
6 changes: 4 additions & 2 deletions lib/steps/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface RollupOptions {
moduleName: string,
entry: string,
format: string,
dest: string
dest: string,
externals: Object,
}

/**
Expand Down Expand Up @@ -161,7 +162,8 @@ export const rollup = (opts: RollupOptions) => {
'rxjs/add/operator/windowWhen': 'Rx.Observable.prototype',
'rxjs/add/operator/withLatestFrom': 'Rx.Observable.prototype',
'rxjs/add/operator/zipAll': 'Rx.Observable.prototype',
'rxjs/add/operator/zipProto': 'Rx.Observable.prototype'
'rxjs/add/operator/zipProto': 'Rx.Observable.prototype',
...opts.externals,
};

let bundleOptions = {
Expand Down