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

Feature: build and nits #3

Merged
merged 17 commits into from
Nov 11, 2020
Merged

Feature: build and nits #3

merged 17 commits into from
Nov 11, 2020

Conversation

thatkookooguy
Copy link
Member

@thatkookooguy thatkookooguy commented Nov 11, 2020

Should release versions to npm once this commit is in (this will commit the github action as well)

If this pull request is too big, I can split it up into a couple of pull requests if you want.

TL;DR (I explained my changes in the description of each commit):

  • changed the readme to the kibibit template
  • added details to the readme (still need to add the shields after the first release)
  • changed testing system to jest for consistency with other kibibit projects
  • fixed some little nits like file names
  • added all-contributors to show contributions in the readme

added all contributors and a readme starter to have a decent place as a homepage for this repo.
The readme follows the kibibit readme template.

changed license date to 2020 instead of 2019
almost the same behavior and jest has some extra features.

Also, this is more uniform with the testing tools we use with other repos so should be easier to understand when contributing between repos
Changed the name assignment to take the name from the constructor.

This should make it so that whenever an error extends KbError, the name will be initialized by the super call.

This will be simpler and make sure it not depends on people forgetting to do this.name = '...' :-)

https://javascript.info/custom-errors#breadcrumb-2:~:text=Now%20custom%20errors%20are%20much%20shorter%2C,%3D%20...%22%20line%20in%20the%20constructor.
- Removed some type checks. For example: We're not actually testing the message 'type', so it can be something else than a string. for example, passing an array is totally acceptable as a message.

- Added some extra checks for 'should be extendable'
locally, and as a github action
didn't add a github action for this one. maybe later we'll add this:
https://github.com/wagoid/commitlint-github-action
also removed the contributors shields since it doesn't fit the format
@@ -5,6 +5,6 @@ module.exports = class kbError extends Error {
*/
constructor(message) {
super(message);
this.name = 'kbError';
this.name = this.constructor.name;
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

The problem with this approach is when things get uglified and you lose the name.
I have no problem with this change as we're currently not uglifying, but we need to keep this in mind.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good Point!

But right now, I think this doesn't support browser as-is since it doesn't support RequireJS (because of the module.export = part).

Even so, What you're worried about is easily fixable imo.

  1. we can always just use it as you intended when requiring on client-side, setting the name in the extended class
  2. Most minification\uglification libraries have support for this kind of exclusions.
    You can just not minify class names. That might be too project-wide but it's an option :-)
       module.exports = {
         entry: './kb-error.js',
         output: {
           filename: 'kb-error.min.js',
           path: path.resolve(__dirname, 'dist'),
         },
         optimization: {
           minimize: true,
           minimizer: [ new TerserPlugin({
             terserOptions: {
               mangle: {
                 keep_classnames: true
               }
             }
           }) ],
         }
       };

But then again, using:

class FooError extends kbError {
      constructor(message) {
        super(message);
      }
    }

should work without modification (node.js for example)

and:

class FooError extends kbError {
      constructor(message) {
        super(message);
        this.name = 'FooError';
      }
    }

should work fine in the browser with this implementation

@@ -5,6 +5,6 @@ module.exports = class kbError extends Error {
*/
constructor(message) {
super(message);
this.name = 'kbError';
this.name = this.constructor.name;
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this approach is when things get uglified and you lose the name.
I have no problem with this change as we're currently not uglifying, but we need to keep this in mind.

@thatkookooguy thatkookooguy merged commit da08c8c into master Nov 11, 2020
@thatkookooguy thatkookooguy deleted the feature/build-and-nits branch November 11, 2020 14:51
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.

None yet

2 participants