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

version check for compiled bundles #720

Closed
nkovacs opened this issue May 12, 2017 · 6 comments
Closed

version check for compiled bundles #720

nkovacs opened this issue May 12, 2017 · 6 comments

Comments

@nkovacs
Copy link
Contributor

nkovacs commented May 12, 2017

#719 and most likely any fix for #705 would make existing runtime bundles incompatible with 1.3.0's runtime code. If you update your npm packages, but forget to rebuild the bundle, your code will break.

I don't know how likely this is, but to be safe, my idea is to add a version number to the compiled bundle, and warn the user if the version number is incompatible.

This version number would be an integer, which is incremented whenever there's a breaking change. If the version number is missing, it'll default to 0, and so also cause a warning.

What do you think?

@rxaviers
Copy link
Member

I think it's a great idea. Ideally the used version number can be deduced from package.json's version.

@nkovacs
Copy link
Contributor Author

nkovacs commented May 12, 2017

So, every new minor version would be incompatible?

@rxaviers
Copy link
Member

rxaviers commented May 12, 2017

I would explore something in this line:

  • Globalize could expose its own version via Globalize.version attribute.
  • The compiled bundle could have an init check that asserts Globalize.version is within a certain range. We need to use a very lightweight approach here.
  • Globalize-compiler should be able to generate the init checker based on its peer dependency definition on globalize.

We need to explore ideas.

@nkovacs
Copy link
Contributor Author

nkovacs commented May 12, 2017

My original idea was to just have a simple integer, and the runtime check would be a ===. This is simpler than a semver check.
This integer would be defined in globalize.js, e.g. Globalize.runtimeVersion, the compiler would read it and generate something like this (hard-coding the integer into the bundle):

Globalize._checkRuntimeVersion(12);

_checkRuntimeVersion could be as simple as:

function(bundleVersion) {
    if (bundleVersion !== Globalize.runtimeVersion) {
        console.warn('Version mismatch etc.');
    }
}

Globalize.runtimeVersion could be generated automatically when building globalize.js, e.g. major*100+minor, or it could be handled manually, when you know that you broke compatibility.

Unfortunately, existing bundles (that don't have the _checkRuntimeVersion call) wouldn't be checked with this solution.

Edit: The compiler needs to be passed Globalize.runtimeVersion somehow. It only gets the formatter and parser functions. compileExtracts can get it, but compile can be called by third party code directly.

nkovacs added a commit to nkovacs/globalize-compiler that referenced this issue Jul 4, 2017
Generated bundle will throw an error if used with incompatible
globalize-runtime.

Refs globalizejs/globalize#720
nkovacs added a commit to nkovacs/globalize that referenced this issue Jul 4, 2017
@rxaviers
Copy link
Member

Closing this issue, because #719 (comment) was solved using an approach that doesn't require this.

@rxaviers
Copy link
Member

Thanks!

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

No branches or pull requests

2 participants