-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactored ext:install to use the latest extension metadata. #5997
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8d993df
Added cascading of latest approved version to latest version when ins…
apascal07 caf805d
Changed output of extension version info.
apascal07 4ce8fc6
Formatting, added more metadata, and cleaned up TODOs.
apascal07 3ce0c95
Formatting and extra notices.
apascal07 1ef2992
Added even more metadata.
apascal07 160eb51
Formatting.
apascal07 5558760
Fixing tests.
apascal07 f4a6231
Merge branch 'master' into ap-latest-version
apascal07 e3e7065
Added display of extension resources.
apascal07 d8fcfb4
Added link to Extensions Hub.
apascal07 83abfb0
Added displaying of events.
apascal07 89bd3d4
Formatting.
apascal07 8aa5f18
Formatting.
apascal07 2f26e26
Version bug.
apascal07 7190227
Added displaying of secrets and task queues.
apascal07 79d21d1
Added displaying of external services.
apascal07 f07fe5e
Fixed resolveVersion() + tests.
apascal07 6fb7722
Added tests for displayExtensionInfo().
apascal07 7e6fcb9
Merge branch 'master' into ap-latest-version
apascal07 66edd99
Update CHANGELOG.md
apascal07 1e3d2e2
Update CHANGELOG.md
apascal07 286685f
Update CHANGELOG.md
apascal07 6d0c1a9
Better messaging and parameterizing.
apascal07 6ce2d53
Merge branch 'master' into ap-latest-version
apascal07 01c68e3
Update displayExtensionInfo.ts
apascal07 dad2289
Update displayExtensionInfo.spec.ts
apascal07 9b9f959
Merge branch 'master' into ap-latest-version
apascal07 376e595
Update CHANGELOG.md
apascal07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Refactored `ext:install` to use the latest extension metadata. (#5997) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| import * as clc from "colorette"; | ||
| import { marked } from "marked"; | ||
| import * as semver from "semver"; | ||
| import * as TerminalRenderer from "marked-terminal"; | ||
|
|
||
| import { displayExtInfo } from "../extensions/displayExtensionInfo"; | ||
| import { displayExtensionVersionInfo } from "../extensions/displayExtensionInfo"; | ||
| import * as askUserForEventsConfig from "../extensions/askUserForEventsConfig"; | ||
| import { checkMinRequiredVersion } from "../checkMinRequiredVersion"; | ||
| import { Command } from "../command"; | ||
| import { FirebaseError } from "../error"; | ||
| import { logger } from "../logger"; | ||
| import { getProjectId, needProjectId } from "../projectUtils"; | ||
| import * as extensionsApi from "../extensions/extensionsApi"; | ||
| import { ExtensionVersion, ExtensionSource } from "../extensions/types"; | ||
|
|
@@ -17,13 +19,11 @@ import { | |
| createSourceFromLocation, | ||
| ensureExtensionsApiEnabled, | ||
| logPrefix, | ||
| promptForOfficialExtension, | ||
| promptForValidInstanceId, | ||
| diagnoseAndFixProject, | ||
| isUrlPath, | ||
| isLocalPath, | ||
| canonicalizeRefInput, | ||
| } from "../extensions/extensionsHelper"; | ||
| import { resolveVersion } from "../deploy/extensions/planner"; | ||
| import { getRandomString } from "../extensions/utils"; | ||
| import { requirePermissions } from "../requirePermissions"; | ||
| import * as utils from "../utils"; | ||
|
|
@@ -40,7 +40,7 @@ marked.setOptions({ | |
| /** | ||
| * Command for installing an extension | ||
| */ | ||
| export const command = new Command("ext:install [extensionName]") | ||
| export const command = new Command("ext:install [extensionRef]") | ||
| .description( | ||
| "add an uploaded extension to firebase.json if [publisherId/extensionId] is provided;" + | ||
| "or, add a local extension if [localPath] is provided" | ||
|
|
@@ -51,67 +51,80 @@ export const command = new Command("ext:install [extensionName]") | |
| .before(ensureExtensionsApiEnabled) | ||
| .before(checkMinRequiredVersion, "extMinVersion") | ||
| .before(diagnoseAndFixProject) | ||
| .action(async (extensionName: string, options: Options) => { | ||
| const projectId = getProjectId(options); | ||
| // TODO(b/230598656): Clean up paramsEnvPath after v11 launch. | ||
| const paramsEnvPath = ""; | ||
| let learnMore = false; | ||
| if (!extensionName) { | ||
| if (options.interactive) { | ||
| learnMore = true; | ||
| extensionName = await promptForOfficialExtension( | ||
| "Which official extension do you wish to install?\n" + | ||
| " Select an extension, then press Enter to learn more." | ||
| ); | ||
| } else { | ||
| throw new FirebaseError( | ||
| `Unable to find published extension '${clc.bold(extensionName)}'. ` + | ||
| `Run ${clc.bold( | ||
| "firebase ext:install -i" | ||
| )} to select from the list of all available published extensions.` | ||
| ); | ||
| } | ||
| } | ||
| let source; | ||
| let extensionVersion; | ||
|
|
||
| // TODO(b/220900194): Remove when deprecating old install flow. | ||
| // --local doesn't support urlPath so this will become dead codepath. | ||
| if (isUrlPath(extensionName)) { | ||
| throw new FirebaseError( | ||
| `Installing with a source url is no longer supported in the CLI. Please use Firebase Console instead.` | ||
| ); | ||
| } | ||
| .action(async (extensionRef: string, options: Options) => { | ||
| if (options.local) { | ||
| utils.logLabeledWarning( | ||
| logPrefix, | ||
| "As of [email protected], the `--local` flag is no longer required, as it is the default behavior." | ||
| ); | ||
| } | ||
|
|
||
| if (!extensionRef) { | ||
| throw new FirebaseError( | ||
| "Extension ref is required to install. To see a full list of available extensions, go to Extensions Hub (https://extensions.dev/extensions)." | ||
| ); | ||
| } | ||
| let source: ExtensionSource | undefined; | ||
| let extensionVersion: ExtensionVersion | undefined; | ||
| const projectId = getProjectId(options); | ||
| // If the user types in a local path (prefixed with ~/, ../, or ./), install from local source. | ||
| // Otherwise, treat the input as an extension reference and proceed with reference-based installation. | ||
| if (isLocalPath(extensionName)) { | ||
| if (isLocalPath(extensionRef)) { | ||
| // TODO(b/228444119): Create source should happen at deploy time. | ||
| // Should parse spec locally so we don't need project ID. | ||
| source = await createSourceFromLocation(needProjectId({ projectId }), extensionName); | ||
| await displayExtInfo(extensionName, "", source.spec); | ||
| source = await createSourceFromLocation(needProjectId({ projectId }), extensionRef); | ||
| await displayExtensionVersionInfo({ spec: source.spec }); | ||
| void trackGA4("extension_added_to_manifest", { | ||
| published: "local", | ||
| interactive: options.nonInteractive ? "false" : "true", | ||
| }); | ||
| } else { | ||
| extensionName = await canonicalizeRefInput(extensionName); | ||
| extensionVersion = await extensionsApi.getExtensionVersion(extensionName); | ||
|
|
||
| const extension = await extensionsApi.getExtension(extensionRef); | ||
| const ref = refs.parse(extensionRef); | ||
| ref.version = await resolveVersion(ref, extension); | ||
| const extensionVersionRef = refs.toExtensionVersionRef(ref); | ||
| extensionVersion = await extensionsApi.getExtensionVersion(extensionVersionRef); | ||
| void trackGA4("extension_added_to_manifest", { | ||
| published: extensionVersion.listing?.state === "APPROVED" ? "published" : "uploaded", | ||
| interactive: options.nonInteractive ? "false" : "true", | ||
| }); | ||
| await infoExtensionVersion({ | ||
| extensionName, | ||
| await displayExtensionVersionInfo({ | ||
| spec: extensionVersion.spec, | ||
| extensionVersion, | ||
| latestApprovedVersion: extension.latestApprovedVersion, | ||
| latestVersion: extension.latestVersion, | ||
| }); | ||
| if (extensionVersion.state === "DEPRECATED") { | ||
| throw new FirebaseError( | ||
| `Extension version ${clc.bold( | ||
| extensionVersionRef | ||
| )} is deprecated and cannot be installed. To install the latest non-deprecated version, omit the version in the extension ref.` | ||
| ); | ||
| } | ||
| logger.info(); | ||
| // Check if selected version is older than the latest approved version, or the latest version only if there is no approved version. | ||
| if ( | ||
| (extension.latestApprovedVersion && | ||
| semver.gt(extension.latestApprovedVersion, extensionVersion.spec.version)) || | ||
| (!extension.latestApprovedVersion && | ||
| extension.latestVersion && | ||
| semver.gt(extension.latestVersion, extensionVersion.spec.version)) | ||
| ) { | ||
| const version = extension.latestApprovedVersion || extension.latestVersion; | ||
| logger.info( | ||
| `You are about to install extension version ${clc.bold( | ||
| extensionVersion.spec.version | ||
| )} which is older than the latest ${ | ||
| extension.latestApprovedVersion ? "accepted version" : "version" | ||
| } ${clc.bold(version!)}.` | ||
| ); | ||
| } | ||
| } | ||
| if (!source && !extensionVersion) { | ||
| throw new FirebaseError( | ||
| `Failed to parse ${clc.bold( | ||
| extensionRef | ||
| )} as an extension version or a path to a local extension. Please specify a valid reference.` | ||
| ); | ||
| } | ||
| if ( | ||
| !(await confirm({ | ||
|
|
@@ -122,33 +135,18 @@ export const command = new Command("ext:install [extensionName]") | |
| ) { | ||
| return; | ||
| } | ||
| if (!source && !extensionVersion) { | ||
| throw new FirebaseError( | ||
| "Could not find a source. Please specify a valid source to continue." | ||
| ); | ||
| } | ||
| const spec = source?.spec ?? extensionVersion?.spec; | ||
| if (!spec) { | ||
| throw new FirebaseError( | ||
| `Could not find the extension.yaml for extension '${clc.bold( | ||
| extensionName | ||
| extensionRef | ||
| )}'. Please make sure this is a valid extension and try again.` | ||
| ); | ||
| } | ||
| if (learnMore) { | ||
| utils.logLabeledBullet( | ||
| logPrefix, | ||
| `You selected: ${clc.bold(spec.displayName || "")}.\n` + | ||
| `${spec.description}\n` + | ||
| `View details: https://firebase.google.com/products/extensions/${spec.name}\n` | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| return installToManifest({ | ||
| paramsEnvPath, | ||
| projectId, | ||
| extensionName, | ||
| extensionRef, | ||
| source, | ||
| extVersion: extensionVersion, | ||
| nonInteractive: options.nonInteractive, | ||
|
|
@@ -164,18 +162,9 @@ export const command = new Command("ext:install [extensionName]") | |
| } | ||
| }); | ||
|
|
||
| async function infoExtensionVersion(args: { | ||
| extensionName: string; | ||
| extensionVersion: ExtensionVersion; | ||
| }): Promise<void> { | ||
| const ref = refs.parse(args.extensionName); | ||
| await displayExtInfo(args.extensionName, ref.publisherId, args.extensionVersion.spec, true); | ||
| } | ||
|
|
||
| interface InstallExtensionOptions { | ||
| paramsEnvPath?: string; | ||
| projectId?: string; | ||
| extensionName: string; | ||
| extensionRef: string; | ||
| source?: ExtensionSource; | ||
| extVersion?: ExtensionVersion; | ||
| nonInteractive: boolean; | ||
|
|
@@ -189,14 +178,13 @@ interface InstallExtensionOptions { | |
| * @param options | ||
| */ | ||
| async function installToManifest(options: InstallExtensionOptions): Promise<void> { | ||
| const { projectId, extensionName, extVersion, source, paramsEnvPath, nonInteractive, force } = | ||
| options; | ||
| const isLocalSource = isLocalPath(extensionName); | ||
| const { projectId, extensionRef, extVersion, source, nonInteractive, force } = options; | ||
| const isLocalSource = isLocalPath(extensionRef); | ||
|
|
||
| const spec = extVersion?.spec ?? source?.spec; | ||
| if (!spec) { | ||
| throw new FirebaseError( | ||
| `Could not find the extension.yaml for ${extensionName}. Please make sure this is a valid extension and try again.` | ||
| `Could not find the extension.yaml for ${extensionRef}. Please make sure this is a valid extension and try again.` | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -215,7 +203,6 @@ async function installToManifest(options: InstallExtensionOptions): Promise<void | |
| projectId, | ||
| paramSpecs: (spec.params ?? []).concat(spec.systemParams ?? []), | ||
| nonInteractive, | ||
| paramsEnvPath, | ||
| instanceId, | ||
| }); | ||
| const eventsConfig = spec.events | ||
|
|
@@ -237,7 +224,7 @@ async function installToManifest(options: InstallExtensionOptions): Promise<void | |
| { | ||
| instanceId, | ||
| ref: !isLocalSource ? ref : undefined, | ||
| localPath: isLocalSource ? extensionName : undefined, | ||
| localPath: isLocalSource ? extensionRef : undefined, | ||
| params: paramBindingOptions, | ||
| extensionSpec: spec, | ||
| }, | ||
|
|
||
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
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
Oops, something went wrong.
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.
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.
Are these
| undefinedneeded? I think it is usually only necessary if you are explicitly settingsource=undefinedThere 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.
Hmm, if I don't then
if (!source && !extensionVersion)complains about using them before initialization. Isn'tMyType | undefinedthe expanded version of an optional/nullable in TS?