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

chore(build): Add esm, cjs, umd & dist build targets #14

Merged
merged 6 commits into from
Mar 29, 2018

Conversation

benmvp
Copy link
Contributor

@benmvp benmvp commented Mar 28, 2018

Added Gulp in order to create build targets for ECMAScript modules (ESM), CommonJS (cjs), Universal Modules (UMD), and dist bundles. This should hopefully be the final step before actually doing an inaugural release.

  • ESM - used by modern dependency systems like Webpack or Rollup that can do tree-shaking optimizations
  • CJS - used primarily by Node for resolving dependencies
  • Dist bundle - used by legacy dependency systems like requireJS
  • UMD - Can't think of a good use case where you'd use UMD over the previous 3, but adding it for now for completeness. May get removed in later releases

Was having issues with lodash including everything just for isPlainObject so I rewrote the code to no longer need it. In the future if we do need lodash we should use lodash-es (lodash exported as ES modules).

Also changing the package name to be just eventbrite instead of brite-rest.

Fixes #11

Copy link
Contributor

@kaylie-alexa kaylie-alexa left a comment

Choose a reason for hiding this comment

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

looks good, minor comments -- have lib and dist already been added to .gitignore?

src/request.ts Outdated
isPlainObject(responseData['error_detail']) &&
isPlainObject(responseData['error_detail']['ARGUMENTS_ERROR']);
!!(
responseData &&
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to check this with typescript right? i assume you'd get a warning otherwise since responseData is required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I don't need to check the existence of responseData because of TypeScript, but I do need to check the existence of of the sub properties since they are the response from the server. Will fix!

package.json Outdated
"prebuild:dist": "rm -rf dist",
"prebuild:lib:cjs": "rm -rf lib/cjs",
"prebuild:lib:esm": "rm -rf lib/esm",
"prebuild:lib:umd": "rm -rf lib/umd",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm tempted to say that we should combine all the lib into one build:lib -- what would be the use case of wanting to build in one lib format but not the other? The time to build would be relatively incremental

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you're probably right. I'll think on it. I don't like the script explosion, but they're definitely gonna be separate in gulp. The kinda sucky part is that the declarations are also put in lib/ so I can't just delete the whole lib/ folder

gulpfile.js Outdated
// do the appropriate babel transpile (this is a copy from package.json)
.pipe(babel(_getBabelConfig(format)));

const _genUmd = (minify = false) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

could we do ({minify = false}) instead? Boolean flags make it hard to follow below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure thing

.pipe(
replace(
"process.env.NODE_ENV",
JSON.stringify(minify ? "production" : "development")
Copy link
Contributor

Choose a reason for hiding this comment

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

actually instead you could set the parameter to environment = 'development' and then do process.env.NODE_ENV || environment right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! I totally forgot to add the conditional minification!

    .pipe(uglify())
    .pipe(rename({ extname: ".min.js" }))

I know that's not what you meant, but thanks for catching! :)

@benmvp
Copy link
Contributor Author

benmvp commented Mar 29, 2018

benmvp added 2 commits March 29, 2018 08:50
- Add missing minified UMD
- Remove unnecessary check from `hasArgumentsError`
- Clean up build NPM scripts to just have one since we'll likely only call one and we can still call `gulp` directly if needed
@kwelch
Copy link
Contributor

kwelch commented Mar 29, 2018

I have little gulp and no rollup experience. I will continue to peak at it throughout the day.

gulpfile.js Outdated

// Minify the code if that option is specified. `null` will get filtered out
// below
minify ? rollupUglify() : null
Copy link
Contributor

Choose a reason for hiding this comment

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

can you do minify && rollupUglify()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like that would work...

@benmvp
Copy link
Contributor Author

benmvp commented Mar 29, 2018

@kwelch I'll probably merge the PR but it'll still be here! 😄

@kwelch-eb
Copy link
Contributor

@benmvp I see no reason not to merge, I mostly want to learn more about it. I would love to hear why gulp? I would have expected rollup to handle all of these cases.

@benmvp
Copy link
Contributor Author

benmvp commented Mar 29, 2018

@kwelch from my investigations Rollup is much like Webpack in that it's really good at taking all of the dependencies and creating a single bundle. Not so good at transpiling and generating target module formats for individual files, like we want for ESM, CJS & UMD.

That's where Gulp comes in. It's much better at taking a bunch of files and processing them all sorts of ways and outputting new versions of them in an efficient/parallel way.

So I guess when you break it down, Rollup is like reduce and Gulp is like map. 😂

@@ -1,13 +1,13 @@
{
"name": "brite-rest",
"name": "eventbrite",

Choose a reason for hiding this comment

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

why not something like eventbrite-sdk-javascript

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Barrett wanted eventbrite. Having javascript in the name is pretty redundant considering it's a node module. And sdk is pretty much implied?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought brite-rest was pretty funny. that being said my first attempt to import it I tried it as eventbrite

];

const _getBabelConfig = format => ({
babelrc: false,

Choose a reason for hiding this comment

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

is there too much dev stuff in there that we couldnt reuse it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think there's some sort of bug inheriting it here in gulp. I was trying to override the dev stuff and it just wasn't working, particularly the modules: false which we need for ESM


// Seamless integration between Rollup and Babel
rollupBabel(
Object.assign(

Choose a reason for hiding this comment

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

no spread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cuz this is just running in Node, so didn't wanna assume Node > 8.X. Ideally folks can run the build on Node 6 as well. See: https://github.com/eventbrite/eventbrite-sdk-javascript/blob/master/.travis.yml#L2-L5

@kwelch-eb
Copy link
Contributor

Thanks @benmvp! That is an amazing explanation.

@BenAtEventbrite BenAtEventbrite merged commit 6250f55 into eventbrite:master Mar 29, 2018
@BenAtEventbrite BenAtEventbrite added this to the Alpha milestone Apr 5, 2018
@ebtravis
Copy link
Collaborator

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants