-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
There was a problem hiding this 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 && |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) => |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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! :)
@kaylieEB yes |
- 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
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 |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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...
@kwelch I'll probably merge the PR but it'll still be here! 😄 |
@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. |
@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 |
@@ -1,13 +1,13 @@ | |||
{ | |||
"name": "brite-rest", | |||
"name": "eventbrite", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no spread?
There was a problem hiding this comment.
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
Thanks @benmvp! That is an amazing explanation. |
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Was having issues with
lodash
including everything just forisPlainObject
so I rewrote the code to no longer need it. In the future if we do needlodash
we should uselodash-es
(lodash exported as ES modules).Also changing the package name to be just
eventbrite
instead ofbrite-rest
.Fixes #11