-
Notifications
You must be signed in to change notification settings - Fork 96
Export package version #131
Export package version #131
Conversation
The ocagent (#128) requests the core library version as part of it's payload. This PR exposes the core lib version in a cleaner manner so that it can be easily consumed by the exporters. |
Fix the build? |
Yeah, I'm working on the fix for the tests now. |
I've tried to solve this in a way that keeps the overhead minimal (still one location to update the current version, namely the package.json) but also keeps the /cc @kjin I believe the node 6 failure is just environmental. It works locally for me on node 6. Can you rerun the that workflow to see if it fixes itself? Here are the failing logs:
|
* limitations under the License. | ||
*/ | ||
|
||
const pjson = require('../../package.json'); |
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.
Let's use the pjson
module which I believe recursively descends directories until it hits a package.json file. That way we don't need to copy it into the build
directory.
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.
My only concern with that is that pjson
uses the fs
node library, which means that core
would be node-only and wouldn't work in (for example) a browser context. Is that okay? My understanding architecturally was that core
should be environment agnostic, with other packages (opencensus-nodejs
) that are environment specific.
If that's not true, then yeah, something like pjson is a nice fit for this use case for sure and I could easily add that in.
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're right. In that case, to avoid the file copy would it be possible to use a try-catch to descend either 2 or 3 directories, or hardcode '../../../package.json'
instead? (I would prefer the former, but either works)
Exports the current package version from the root level. This allows users of this module to read the version of the library that has been loaded.
Tests were failing because the `package.json`'s relative location changes between compile and test time (from "../../package.json" during `compile` and "../../../package.json" during `test`). To resolve this, we now copy the package.json into the build directory after compililation is done, which keeps the relative location the same during compile, test, and deployment.
We do not need to handle two relative paths because both the packaged lib and test suite run through the /build directory, which means we can support a single path. The opencensus-exporter-ocagent has been updated to support the newly exported version.
4f462af
to
4212361
Compare
@isaikevych I've resurrected this older PR to get it cleaned up and pushed in. The main goal was to export the I've incorporated the feedback from @kjin above into the review, but also went ahead and updated the ocagent exporter code to use the new Let me know if you have any questions! |
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.
Thank you
Should this PR be merged? |
Exports the current package version from the root level. This allows
users of this module to read the version of the library that has been
loaded.