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
Use lib library rather than xregexp-all.js #182
Conversation
Can you clarify "using webpack and browserify these days makes it dangerous to use dynamic packaging"? This seems to counter the whole idea behind packaging libs for others to digest. The umd signature should be adequate... You shouldn't need a separate Instead of |
There already is a separate I am just suggesting that the default export be a regular Node module and that anyone who is going to take the package and use it as a standalone browser script can use the browser version. |
Oh, and as for what I meant about the increasing problems with UMD, I work full-time building desktop JavaScript applications and as such I often have access to both window and global and UMD can get confused in those contexts. I previously worked with a project using AMD packaging which also fell apart because I had to namespace the AMD require which broke XRegExp because it refused to expose itself as an AMD module. Back then, I didn't bring up an issue because I was very new at web programming and was just getting my footing. But, tooling has come a long way now and the modern standard is to use a regular Node module for the export. This avoids all of those problems and other potential problems as well. |
Good point re: babel, however the src code here appears to all be es5. Not sure where babel fits into the pipeline, although I do see it in the prebuild package.json script. I haven't run across a scenario where a standard umd definition as provided by browserify (as used in xregexp) or webpack have troubles working inside other webpack builds. I've used xregexp in both webpack and in the browser directly and haven't noticed any problems. |
Oh, that warning looks like it's simply a matter of telling webpack to not parse this lib via noparse option (which will speed up your build anyway)... |
Yup, that sometimes works. But, xregexp is a small enough library that I just wanted to mention that it might be a good time to update the lib for modern packaging systems. Here is a comment from that same thread which makes the point better than I have. |
BTW, I absolutely love xregexp and use in it literally every application I make. But, because the packaging is a little out of date, I just wanted to present the idea to you all and a PR seemed to make more sense than just creating another issue. |
Me too. I can't take any credit for it, though; I just noticed your PR and thought I'd poke a bit to learn more :D |
lol, looks like we're re-creating that webpack conversation... that point clarifies it a bit, but I still wonder why you would want to parse all those lib files, regardless of wether they're precompiled or not. The library author packages the library. It doesn't need additional handling, just needs to be made available in your build; re-minifying seems unnecessary as does re-compiling. But I digress, my question would be, then, how are we leveraging babel here? The |
That's a great question. At the moment, it does look like everything would work perfectly from the src folder, but as I see it, it just makes sense to have Babel for future development. You want that build step so that anyone can write they JS without worrying about whether or not a feature is available in the different environments. The current babel config doesn't appear to actually do anything, but it's still a step worth having (in my opinion) for if anyone does need it at some point. |
Regarding Babel (since I introduced it to the build): The I think @rBurgett makes great points about the benefits of having package.json 👍 from me :) One concern I do have is that removing |
This seems fine to me. Thanks for the PR @rBurgett, and @kaidjohnson + @josephfrazier for the discussion.
Note that I'm very open to any changes that modernize or otherwise improve the build process, repo structure, etc. E.g. if you think that xregexp-all.js shouldn't be kept in sync in the repo, and instead only updated in a |
Just keeping it in sync after slevithan#182 was merged.
Just keeping it in sync after #182 was merged.
Oh, I was under the assumption that you were set on having Again, a downside of this approach is that |
@josephfrazier I'm down with all of that, including dropping support for bower and removing bower.json. I'm much less familiar than you guys with build/release tools though. Would you be okay with submitting the related configuration changes?
I'm not sure what this means. Can you clarify? |
Sure, for example: Another project I work on (and introduced XRegExp to) uses this mechanism to make .zip files (that the build process generates) available on each github release page. Here's the .travis.yml configuration, and here's a release page with the relevant files. We could do something similar with
Yeah, I'd be happy to put together a PR with the non-Travis changes (since they aren't really needed). If you decide you'd like the Travis changes as well, we can work on it then. |
Following up on slevithan#182 (comment), this change removes `lib/`, `xregexp-all.js`, and `bower.json` from the repository. It also adds a `prepublish` [script] that builds/tests the files before publishing to npm, to ensure they are included. You can run [npm pack] to see the `prepublish` script in action, then you can take a look at the generated tarball with `tar tvf xregexp-3.2.0.tgz` and verify that `lib/` and `xregexp-all.js` are still there. [script]: https://docs.npmjs.com/misc/scripts [npm pack]: https://docs.npmjs.com/cli/pack
After some thought on the issue, I'm not sure I fully agree with the idea of pointing "main" to src files. As an app architect, I don't want to have to compile all my third party library code on top of my own code in my builds; it's frankly more efficient, consistent, and reliable to concat independently maintained/tested packages than to re-compile code that you don't own. I know it's after the fact, and I'm not advocating for reversing the decision; it's definitely not a deal-breaker, but I thought I'd pick some brains of the folks on this thread to get more insight into how or why this is a better approach than using webpack's |
I think the idea is that bundlers default to assuming that |
Following up on #182 (comment), this change removes `lib/`, `xregexp-all.js`, and `bower.json` from the repository. It also adds a `prepublish` [script] that builds/tests the files before publishing to npm, to ensure they are included. You can run [npm pack] to see the `prepublish` script in action, then you can take a look at the generated tarball with `tar tvf xregexp-3.2.0.tgz` and verify that `lib/` and `xregexp-all.js` are still there. [script]: https://docs.npmjs.com/misc/scripts [npm pack]: https://docs.npmjs.com/cli/pack
The UMD definition provides the Node-style CommonJS wrapper you mention. I believe this argument is exactly why UMD became a thing, because it's flexible across bundler formats and agnostic to whether you use a browser, CommonJS, or AMD. Basically what you're asking application maintainers to do is bundle your code for you and you're assuming that they want to bundle your code using CommonJS. I get the sense that this is a regression in flexibility. I realize they can still require the pre-bundled option, but it seems like the other way around makes more sense: provide the Keep in mind, too, that we're not just talking bundling here. Our bundlers also minify for us, so you're asking application maintainers to not only bundle your code, but also minify it for you, adding some serious implications to bundle times for applications that work with a lot of libraries. To sum: I want to include your library in my bundle. I don't want to have to bundle and minify your library when I bundle my application. |
Hmm, has XRegExp ever been published in a minified format? Unless I'm mistaken, it's only ever been available unminified, so I think this is a separate issue. Otherwise, I'm interested to hear more about your build tooling and configuration. I'm not aware of a build tool that both relies on the package.json Could you shed some light on your process? I realize that this change (and then #187) is pretty big, and it would be nice to minimize build breakage however possible. |
So let's say the At the end of the day, though, it's not a huge difference either way, so I don't really want to continue bashing against it; if a library causes slowdowns during bundling or minification, the bundler config is there to allow flexibility. It's 5.5 in one hand and a half-dozen in the other -- close enough and they both work. Thanks for the insightful feedback and conversation and for maintaining this library! It's a very useful resource and we're happy to have included it within our application! |
Oh, I see now. If you've configured your bundler to assume everything in I definitely understand that increased build times are a pain. You might be able to improve them by doing incremental builds using e.g. webpack's watch mode. If you're using browserify, there are a variety of options available. Other build tools have similar arrangements, I'm sure. |
…e compiled files in the repo for the prepublish idea is nice but b0rks very badly when you work on the code and happen to not have a 100% working instance at some point. :-(( * .gitignore compiled files, build them on prepublish Following up on slevithan#182 (comment), this change removes `lib/`, `xregexp-all.js`, and `bower.json` from the repository. It also adds a `prepublish` [script] that builds/tests the files before publishing to npm, to ensure they are included. You can run [npm pack] to see the `prepublish` script in action, then you can take a look at the generated tarball with `tar tvf xregexp-3.2.0.tgz` and verify that `lib/` and `xregexp-all.js` are still there. [script]: https://docs.npmjs.com/misc/scripts [npm pack]: https://docs.npmjs.com/cli/pack
Just keeping it in sync after slevithan/xregexp#182 was merged.
Following up on slevithan/xregexp#182 (comment), this change removes `lib/`, `xregexp-all.js`, and `bower.json` from the repository. It also adds a `prepublish` [script] that builds/tests the files before publishing to npm, to ensure they are included. You can run [npm pack] to see the `prepublish` script in action, then you can take a look at the generated tarball with `tar tvf xregexp-3.2.0.tgz` and verify that `lib/` and `xregexp-all.js` are still there. [script]: https://docs.npmjs.com/misc/scripts [npm pack]: https://docs.npmjs.com/cli/pack
Just keeping it in sync after slevithan/xregexp#182 was merged.
Following up on slevithan/xregexp#182 (comment), this change removes `lib/`, `xregexp-all.js`, and `bower.json` from the repository. It also adds a `prepublish` [script] that builds/tests the files before publishing to npm, to ensure they are included. You can run [npm pack] to see the `prepublish` script in action, then you can take a look at the generated tarball with `tar tvf xregexp-3.2.0.tgz` and verify that `lib/` and `xregexp-all.js` are still there. [script]: https://docs.npmjs.com/misc/scripts [npm pack]: https://docs.npmjs.com/cli/pack
A few years ago, using a universal package declaration was sufficient so you could load a lib in either Node or the browser. But, using webpack and browserify these days makes it dangerous to use dynamic packaging. If you use the xregexp library with webpack right now, for example, it gives you a warning that you should not use compiled code. This is because each of our build processes make necessary changes to the code and if the lib uses traditional means of dynamically choosing how to expose itself, your users could potentially run into problems.
I don't know how you would want to handle it, but I would suggest that the default Node export needs to be a straight Node module which anyone can use with any build process without problem. Along with that, if someone really needs a standalone file to use in a browser, we could keep the xregexp-all.js for them. But, there are fewer and fewer people who use precompiled browser files anyway.
Every application developer has their own packaging process and this is an essential lib for application development in JavaScript.
Am I making my case well? Would you prefer to see it another way? I'm happy to keep using my own fork if you do not like the idea of changing your lib right now, but something will need to be done eventually since build processes have matured.
Thanks!