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

Export VERSION information #794

Merged
merged 4 commits into from Nov 9, 2020
Merged

Conversation

pgcalixto
Copy link
Contributor

@pgcalixto pgcalixto commented Oct 3, 2020

This is an attempt to resolve #747 and #799.

Closes #800.

I've read the contribution guide, but I do not know it there is anything to update in the documentation regarding the exports.

As pointed out by @networkimprov, it is a good practice to tell the
package version by exporting a constant or having a comment to
indicate it. Therefere, the version info is exported now.

Resolves moment#747.
@jsf-clabot
Copy link

jsf-clabot commented Oct 3, 2020

CLA assistant check
All committers have signed the CLA.

@pgcalixto
Copy link
Contributor Author

@networkimprov it was needed to read the version from package.json (src/luxon.js, line 1).

I tried running without it first, but got error messages telling me to install plugin-json.

@GillesDebunne
Copy link
Collaborator

This seems fair.
Is it an 'official' way of exporting the VERSION? Can anyone reference some major libs that do it this way?

@pgcalixto
Copy link
Contributor Author

pgcalixto commented Oct 4, 2020

@GillesDebunne, I retrieved the version from package.json because I've used this procedure to retrieve the package's name and version in some projects I worked in (both little personal projects and some bigger closed source projects for companies).
Also, this procedure of using require("package.json") to obtain the package's information seems to be present in a lot of code on GitHub: https://github.com/search?q=%22require(%27package.json%27)%22&type=Code

I tried to identify some major libs that also do this, but I had little success. I inspected code from some libs as lodash, moment, axios, request, chalk, fs-extra, etc.
While some of them do not export the version, the ones that do seem to do it manually.

We could think of a way to the same procedure as Moment's: first we would manually write the version export (1.25.0), and for the future releases, we run a task to bump it when.
While this loses some of the automation compared to the way I did, it still seems to work fine, as long as the bump_version task is always run when creating new releases.

I will try to look for more examples on how to do this and bring some references.

@pgcalixto
Copy link
Contributor Author

How is the version bumped on Luxon (such as the commit below)? Is it manual?

345b1cd

@GillesDebunne
Copy link
Collaborator

Indeed, updating the version from package.json as part of a release script seems appropriate (scripts/tag already reads it).

@pgcalixto
Copy link
Contributor Author

I quite didn't get your suggestion, @GillesDebunne. How do you think we should proceed?

@networkimprov
Copy link

networkimprov commented Oct 5, 2020

Vue includes a version in its package.json: vuejs/vue@ec78fc8b which is visible at runtime as Vue.version

EDIT: I'm not familiar with its build process, but found this: https://github.com/vuejs/vue-next/pull/254/commits

@pgcalixto
Copy link
Contributor Author

Thank you for the reference, @networkimprov!
Both Vue and Vue-next uses require('package.json').version indeed:

React also seems to read the version from package.json:

This was referenced Oct 7, 2020
This reverts commit 972e157.

@GillesDebunne and I agreed on a different approach, which is based
on a hardcoded VERSION export, while maintaining a logic to ensure
that the VERSION variable matches the package version.

See moment#800 (comment).
For a less bold approach, the exported VERSION variable is now
hardcoded. Meanwhile, the `scripts/tag` script was improved to
ensure that all versions match.

See moment#800 (comment).

Resolves moment#747 and resolves moment#799.
@pgcalixto
Copy link
Contributor Author

I update the code in this PR to an agreed approach discussed in #800.

Copy link
Collaborator

@GillesDebunne GillesDebunne left a comment

Choose a reason for hiding this comment

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

What about moving this code in a specific script? It does not seems to belong to tag.

Or maybe check versions at the beginning of release since the entire process should be stopped in case of version mismatch (which is not the case here)

scripts/tag Outdated
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PACKAGE_LOCK_VERSION=$(node -p "require('./package-lock.json').version")
EXPORTED_VERSION=$(grep -oP "(?<=const VERSION = \").*(?=\";)" ./src/luxon.js)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure grep will work on Windows for instance, but that may not be an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it too, but all these scripts have #!/usr/bin/env bash in the beginning, reinforcing the idea to run them on Bash, which afaik always has grep, even in Bash for Windows.

(also, the syntax of the scripts have other details that would only allow them to be run on Bash)

Move the version validation to a dedicated script, so that it can
be called both from release and tag scripts, which are scripts that
should validate the version before proceeding.
@pgcalixto
Copy link
Contributor Author

What about moving this code in a specific script? It does not seems to belong to tag.

Or maybe check versions at the beginning of release since the entire process should be stopped in case of version mismatch (which is not the case here)

I moved it to a dedicated script, and called it in the beginning of both release and tag scripts.

@icambron icambron merged commit 343978d into moment:master Nov 9, 2020
@icambron
Copy link
Member

icambron commented Nov 9, 2020

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

Successfully merging this pull request may close these issues.

Add a version const (or at least a comment)
5 participants