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: export static GoogleAuth #249

Merged
merged 2 commits into from
Jan 15, 2018
Merged

feat: export static GoogleAuth #249

merged 2 commits into from
Jan 15, 2018

Conversation

JustinBeckwith
Copy link
Contributor

Addresses #4

@JustinBeckwith JustinBeckwith requested review from ofrobots and a team January 12, 2018 06:50
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 12, 2018
@JustinBeckwith
Copy link
Contributor Author

My initial approach here was to try using es6 default exports:

export default new GoogleAuth();

However - given the lack of compat between CommonJS and es6 modules, consumers would have to use this syntax:

const auth = require('google-auth-library').default;

That doesn't feel terribly discoverable, and isn't much better from what we have today. Webpack works around this, but apparently TypeScript isn't really planning on muddying the waters:
microsoft/TypeScript#2719

Instead, I ended up taking the named export approach. I export both the GoogleAuth class, AND an auth object with a single instance. It means consumers using Node 6 and above can do this:

const {auth} = require('google-auth-library');
auth.getApplicationDefault()...

The module.exports and exports = syntax aren't terribly es6 compatible, and would have caused a whole other set of issues.

This seems like a fair compromise, but I'm looking for opinions :)

@JustinBeckwith
Copy link
Contributor Author

@ofrobots and @MylesBorins, would love to hear your thoughts too :)

Copy link
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, I ended up taking the named export approach.

This the right way to go at this point; given uncertainty about how ES6 interop is going to be settled. Regardless, default exports are banned by the style guide.

LGTM w/ nit.

src/index.ts Outdated
@@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {GoogleAuth} from './auth/googleauth';

export {Compute} from './auth/computeclient';
export {GoogleAuth} from './auth/googleauth';

This comment was marked as spam.

@JustinBeckwith JustinBeckwith merged commit 014ce0b into googleapis:master Jan 15, 2018
@JustinBeckwith JustinBeckwith mentioned this pull request Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants