Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*tl;dr: in Node, we were sending `User-Agent: Airtable.js/undefined`. This fixes that.* [This line](https://github.com/Airtable/airtable.js/blob/d9bf0f68f58ec82ffd63a206866229c61801a8c7/lib/run_action.js#L26) "computes" the user agent: ```js var userAgent = 'Airtable.js/' + process.env.npm_package_version; ``` This actually has _two_ code paths: 1. In the browser, [we transformed `process.env.npm_package_version`](https://github.com/Airtable/airtable.js/blob/d9bf0f68f58ec82ffd63a206866229c61801a8c7/gruntfile.js#L15-L18) into the real package version. As far as I know, this bug never manifests itself in browsers. 2. In Node, `process.env.npm_package_version` is a value [magically set by npm](https://docs.npmjs.com/misc/scripts#packagejson-vars). However, when I tested this with [a quick one-off script](https://gist.github.com/EvanHahn/e0f712798b1af53af4c2478bc72ab608), that value was `undefined`. This explains the bug. There are a number of ways to fix this problem: 1. Hard-code the version into the source code. While [this header is tested](https://github.com/Airtable/airtable.js/blob/d9bf0f68f58ec82ffd63a206866229c61801a8c7/test/base.test.js#L30), this approach would require manual changes, which could be brittle if you forget to run `npm test` before releasing. 2. Figure out why `process.env.npm_package_version` isn't being set and make sure it's set reliably. Documentation for these values is scant (it's unclear whether the value changes depending on the subpackage you're in or if it reflects the top-level package), and it didn't work even in my simple case, so I was inclined to steer clear of this. 3. Create a Node build in addition to a browser build. I felt like this solution was overkill, among its other issues. 4. Use `require('./package.json').version`. This works fine in Node, but increases the size of the browser build and includes unnecessary package info. (I've also had some issues requiring `package.json` in the browser in the past, though I can't remember what they were.) 5. Use `require('./package.json').version` in Node and `process.env.npm_package_version` in the browser. This is what I went with. `npm test` passes after this change.
- Loading branch information