fix(sign): Defaulted amoBaseUrl when signing from the Node API - #3833
Open
MaxFreedomPollard wants to merge 1 commit into
Open
MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
The documented default for amoBaseUrl only existed as a yargs default in the CLI option table, so it was applied on the command line and nowhere else. Calling webExt.cmd.sign() from Node without that option passed undefined down to signAddon(), which rejected it with "Invalid AMO API base URL: undefined". The constant now lives in src/util/constants.js, program.js imports and re-exports it so existing imports keep working, and src/cmd/sign.js uses it as the parameter default. The README example for webExt.cmd.sign() no longer passes amoBaseUrl, because it is no longer needed there. Fixes mozilla#3164
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3164.
Calling
webExt.cmd.sign({apiKey, apiSecret, artifactsDir, channel, sourceDir})from Node fails withInvalid AMO API base URL: undefined. The default only exists as a yargs default in the CLI option table (src/program.js:527), so it is applied on the command line and nowhere else. src/cmd/sign.js:23 destructuresamoBaseUrlwith no default, andsignAddonrejects a missing value at src/util/submit-addon.js:500-503. The reporter hit this moving from 7.x to 8.x and worked around it by hardcodingamoBaseUrl: 'https://addons.mozilla.org/api/v5/', which pins them to an API version web-ext is meant to manage for them.This moves the constant into a new dependency-free module, src/util/constants.js. src/program.js imports it and re-exports it, so
import { AMO_BASE_URL } from './program.js'keeps working for existing callers and tests, and the CLI option table is untouched. src/cmd/sign.js imports it from the new module rather than from src/program.js, so a Node API caller does not pull yargs and the rest of the CLI in behind it. No command module imports src/program.js today, and src/cmd/index.js loads commands lazily for the same start-up reason (#1302).One scope note:
signAddon()in src/util/submit-addon.js still takesamoBaseUrlexplicitly. It is public API, since package.json exports./util/submit-addon, so this is a real choice rather than an oversight. I kept the change to the entry point the issue reports, but signAddon() can get the same default here if you would rather have it in one place.The new test is "defaults the AMO base URL when it is not passed in" in tests/unit/test-cmd/test.sign.js.
getStubs()always suppliesamoBaseUrl, so the test copies the stub config, deletes that key, and asserts thatsubmitAddonwas called with the default. Reverting the one line in src/cmd/sign.js makes it fail withamoBaseUrl: undefined. The README example forwebExt.cmd.sign()also drops the hardcodedamoBaseUrl; thesignAddon()example below it keeps it, because that entry point still needs it.Unit tests, eslint and prettier pass locally.