-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from serverless-heaven/329-packager-interface
Abstract packager into universal interface.
- Loading branch information
Showing
8 changed files
with
663 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
coverage | ||
examples | ||
tests | ||
*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
/** | ||
* Factory for supported packagers. | ||
* | ||
* All packagers must implement the following interface: | ||
* | ||
* interface Packager { | ||
* | ||
* static get lockfileName(): string; | ||
* static getProdDependencies(cwd: string, depth: number = 1, maxExecBufferSize = undefined): BbPromise<Object>; | ||
* static rebaseLockfile(pathToPackageRoot: string, lockfile: Object): void; | ||
* static install(cwd: string, maxExecBufferSize = undefined): BbPromise<void>; | ||
* static prune(cwd: string): BbPromise<void>; | ||
* | ||
* } | ||
*/ | ||
|
||
const _ = require('lodash'); | ||
const npm = require('./npm'); | ||
|
||
const registeredPackagers = { | ||
npm: npm | ||
}; | ||
|
||
/** | ||
* Factory method. | ||
* @this ServerlessWebpack - Active plugin instance | ||
* @param {string} packagerId - Well known packager id. | ||
* @returns {BbPromise<Packager>} - Promised packager to allow packagers be created asynchronously. | ||
*/ | ||
module.exports.get = function(packagerId) { | ||
if (!_.has(registeredPackagers, packagerId)) { | ||
const message = `Could not find packager '${packagerId}'`; | ||
this.serverless.cli.log(`ERROR: ${message}`); | ||
throw new this.serverless.classes.Error(message); | ||
} | ||
return registeredPackagers[packagerId]; | ||
}; |
Oops, something went wrong.