diff --git a/README.md b/README.md index 28ea3a3d13..be9f5202cf 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,6 @@ webExt.cmd.sign({ userAgentString: 'YOUR-CUSTOM-USERAGENT', apiKey, apiSecret, - amoBaseUrl: 'https://addons.mozilla.org/api/v5/', sourceDir: ..., channel: 'unlisted', ... diff --git a/src/cmd/sign.js b/src/cmd/sign.js index 1effd157aa..10c4296a84 100644 --- a/src/cmd/sign.js +++ b/src/cmd/sign.js @@ -3,6 +3,7 @@ import path from 'path'; import defaultBuilder from './build.js'; import { isErrorWithCode, UsageError, WebExtError } from '../errors.js'; import { prepareArtifactsDir } from '../util/artifacts.js'; +import { AMO_BASE_URL } from '../util/constants.js'; import { createLogger } from '../util/logger.js'; import getValidatedManifest, { getManifestId } from '../util/manifest.js'; import { @@ -20,7 +21,7 @@ export const uploadUuidFile = '.amo-upload-uuid'; export default function sign( { - amoBaseUrl, + amoBaseUrl = AMO_BASE_URL, apiKey, apiProxy, apiSecret, diff --git a/src/program.js b/src/program.js index d76263a3c4..d401d51549 100644 --- a/src/program.js +++ b/src/program.js @@ -20,6 +20,7 @@ import { loadJSConfigFile as defaultLoadJSConfigFile, applyConfigToArgv as defaultApplyConfigToArgv, } from './config.js'; +import { AMO_BASE_URL } from './util/constants.js'; const log = createLogger(import.meta.url); const envPrefix = 'WEB_EXT'; @@ -27,7 +28,7 @@ const envPrefix = 'WEB_EXT'; // at build time by scripts/babel-plugin-inline-environment-variables.cjs). const defaultGlobalEnv = process.env.WEBEXT_BUILD_ENV || 'development'; -export const AMO_BASE_URL = 'https://addons.mozilla.org/api/v5/'; +export { AMO_BASE_URL }; /* * The command line program. diff --git a/src/util/constants.js b/src/util/constants.js new file mode 100644 index 0000000000..fbcacaaa3b --- /dev/null +++ b/src/util/constants.js @@ -0,0 +1,5 @@ +// Shared constants that both the command line interface and the commands +// themselves need. Keeping them here avoids importing the CLI program (and +// its dependencies) from a command module. + +export const AMO_BASE_URL = 'https://addons.mozilla.org/api/v5/'; diff --git a/tests/unit/test-cmd/test.sign.js b/tests/unit/test-cmd/test.sign.js index 21b6d4deae..900c93693f 100644 --- a/tests/unit/test-cmd/test.sign.js +++ b/tests/unit/test-cmd/test.sign.js @@ -115,6 +115,17 @@ describe('sign', () => { }, )); + it('defaults the AMO base URL when it is not passed in', () => + withTempDir(async (tmpDir) => { + const stubs = getStubs(); + const signingConfig = { ...stubs.signingConfig }; + delete signingConfig.amoBaseUrl; + await sign(tmpDir, { ...stubs, signingConfig }); + sinon.assert.calledWithMatch(stubs.signingOptions.submitAddon, { + amoBaseUrl: AMO_BASE_URL, + }); + })); + it('requires a channel for submission API', () => withTempDir(async (tmpDir) => { const stubs = getStubs();