-
Notifications
You must be signed in to change notification settings - Fork 114
feat(install-dynamic-plugins): add ref:// plugin reference resolution #4110
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
nickboldt
merged 1 commit into
redhat-developer:main
from
jonkoops:ref-plugin-resolution
Jul 30, 2026
Merged
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions
5
workspaces/install-dynamic-plugins/.changeset/ref-plugin-resolution.md
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,5 @@ | ||
| --- | ||
| '@red-hat-developer-hub/cli-module-install-dynamic-plugins': minor | ||
| --- | ||
|
|
||
| Add `ref://` plugin reference resolution to simplify plugin configuration |
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
145 changes: 145 additions & 0 deletions
145
workspaces/install-dynamic-plugins/packages/install-dynamic-plugins/src/plugin-name.test.ts
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,145 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import { extractPluginName } from './plugin-name'; | ||
|
|
||
| describe('extractPluginName', () => { | ||
| const cases: [string, string | null][] = [ | ||
| // OCI — digest | ||
| [ | ||
| 'oci://quay.io/rhdh/backstage-plugin-foo@sha256:abc123', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // OCI — tag | ||
| ['oci://quay.io/rhdh/backstage-plugin-bar:v1.0.0', 'backstage-plugin-bar'], | ||
| // OCI — latest tag | ||
| ['oci://quay.io/rhdh/backstage-plugin-bar:latest', 'backstage-plugin-bar'], | ||
| // OCI — registry with port, no tag | ||
| ['oci://localhost:5000/path/my-plugin', 'my-plugin'], | ||
| // OCI — registry with port and tag | ||
| ['oci://localhost:5000/path/my-plugin:v1.0.0', 'my-plugin'], | ||
| // OCI — IP address registry with port | ||
| ['oci://10.0.0.1:5000/repo/plugin:tag', 'plugin'], | ||
| // OCI — with !plugin-path suffix | ||
| [ | ||
| 'oci://quay.io/rhdh/backstage-plugin-foo@sha256:abc123!plugin-path', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // OCI — with !plugin-path with slashes | ||
| [ | ||
| 'oci://quay.io/rhdh/backstage-plugin-foo:v1.0!path/to/plugin', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // OCI — with {{inherit}} tag | ||
| [ | ||
| 'oci://quay.io/rhdh/backstage-plugin-foo:{{inherit}}', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // OCI — with {{inherit}} tag and !path | ||
| [ | ||
| 'oci://quay.io/rhdh/backstage-plugin-foo:{{inherit}}!some-path', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // OCI — deep paths (multiple segments) | ||
| [ | ||
| 'oci://quay.io/org/sub/backstage-plugin-foo@sha256:abc123', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // OCI — single path segment | ||
| ['oci://quay.io/backstage-plugin-foo:v1.0', 'backstage-plugin-foo'], | ||
| // OCI — registry-only URL returns null | ||
| ['oci://localhost:5000', null], | ||
| // OCI — trailing slash returns null | ||
| ['oci://localhost:5000/', null], | ||
| // OCI — host-only returns null | ||
| ['oci://quay.io', null], | ||
| // OCI — bare scheme returns null | ||
| ['oci://', null], | ||
| // OCI — malformed URL returns null | ||
| ['oci://[invalid', null], | ||
| // OCI — empty image name returns null | ||
| ['oci://quay.io/rhdh/:v1.0', null], | ||
|
|
||
| // HTTP(S) — .tgz with version | ||
| [ | ||
| 'https://example.com/plugins/backstage-plugin-foo-1.0.0.tgz', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // HTTP(S) — .tar.gz with version | ||
| ['https://example.com/path/my-plugin-2.3.4.tar.gz', 'my-plugin'], | ||
| // HTTP(S) — http:// URL | ||
| [ | ||
| 'http://registry.example.com/backstage-plugin-bar-0.1.0.tgz', | ||
| 'backstage-plugin-bar', | ||
| ], | ||
| // HTTP(S) — with query string (stripped by URL) | ||
| [ | ||
| 'https://example.com/plugins/backstage-plugin-foo-1.0.0.tgz?token=abc', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // HTTP(S) — no archive extension (version still stripped) | ||
| [ | ||
| 'https://example.com/plugins/backstage-plugin-foo-1.0.0', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // HTTP(S) — no version suffix (name returned as-is) | ||
| [ | ||
| 'https://example.com/plugins/backstage-plugin-foo.tgz', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // HTTP(S) — .tar.gz without version | ||
| [ | ||
| 'https://example.com/plugins/backstage-plugin-foo.tar.gz', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // HTTP(S) — no path returns null | ||
| ['https://example.com', null], | ||
| // HTTP(S) — trailing slash returns null | ||
| ['https://example.com/', null], | ||
| // HTTP(S) — bare scheme returns null | ||
| ['https://', null], | ||
| // HTTP(S) — pre-release version | ||
| [ | ||
| 'https://example.com/plugins/backstage-plugin-foo-1.0.0-beta.1.tgz', | ||
| 'backstage-plugin-foo', | ||
| ], | ||
| // HTTP(S) — plugin name containing digits | ||
| [ | ||
| 'https://example.com/plugins/plugin-3scale-backend-1.2.3.tgz', | ||
| 'plugin-3scale-backend', | ||
| ], | ||
|
|
||
| // Local path — deep | ||
| [ | ||
| './dynamic-plugins/dist/backstage-plugin-techdocs', | ||
| 'backstage-plugin-techdocs', | ||
| ], | ||
| // Local path — shallow | ||
| ['./plugin-foo', 'plugin-foo'], | ||
| // Local path — trailing slash | ||
| ['./foo/', 'foo'], | ||
| // Local path — bare prefix | ||
| ['./', '.'], | ||
|
|
||
| // Unknown formats return null | ||
| ['@backstage/plugin-catalog', null], | ||
| ['some-package', null], | ||
| ['', null], | ||
| ]; | ||
|
|
||
| it.each(cases)('parses %s -> %s', (input, expected) => { | ||
| expect(extractPluginName(input)).toBe(expected); | ||
| }); | ||
| }); |
72 changes: 72 additions & 0 deletions
72
workspaces/install-dynamic-plugins/packages/install-dynamic-plugins/src/plugin-name.ts
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,72 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import { basename } from 'node:path'; | ||
| import { isHttpUrl, isLocalPath, isOciUrl } from './protocols'; | ||
|
|
||
| /** | ||
| * Extract the human-readable plugin name from a package URL. | ||
| * | ||
| * Supports OCI (`oci://`), HTTP(S) (`.tgz`/`.tar.gz` archives), and | ||
| * local (`./`) paths. Returns `null` for unrecognized formats. | ||
|
nickboldt marked this conversation as resolved.
|
||
| */ | ||
| export function extractPluginName(pkg: string): string | null { | ||
| if (isOciUrl(pkg)) return ociName(pkg); | ||
| if (isHttpUrl(pkg)) return httpName(pkg); | ||
| if (isLocalPath(pkg)) return basename(pkg); | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Extract the plugin name from an OCI URL by stripping the plugin path | ||
| * (`!` suffix), digest, and tag. | ||
| * | ||
| * @example | ||
| * ociName('oci://quay.io/rhdh/backstage-plugin-foo@sha256:abc123') // 'backstage-plugin-foo' | ||
| * ociName('oci://quay.io/rhdh/backstage-plugin-foo:v1.0!path') // 'backstage-plugin-foo' | ||
| * ociName('oci://localhost:5000/path/my-plugin:v1.0.0') // 'my-plugin' | ||
| */ | ||
| function ociName(pkg: string): string | null { | ||
| const withoutBang = pkg.split('!').at(0) as string; | ||
|
|
||
| if (!URL.canParse(withoutBang)) return null; | ||
|
|
||
| const segment = basename(new URL(withoutBang).pathname); | ||
| if (!segment) return null; | ||
|
|
||
| const beforeDigest = segment.split('@').at(0) as string; | ||
| const name = beforeDigest.split(':').at(0) as string; | ||
|
|
||
| return name || null; | ||
| } | ||
|
|
||
| /** | ||
| * Extract the plugin name from an HTTP(S) URL by stripping the archive | ||
| * extension and version suffix. | ||
| * | ||
| * @example | ||
| * httpName('https://example.com/backstage-plugin-foo-1.0.0.tgz') // 'backstage-plugin-foo' | ||
| * httpName('https://example.com/plugin-3scale-backend-1.2.3.tar.gz') // 'plugin-3scale-backend' | ||
| * httpName('https://example.com/backstage-plugin-foo.tgz') // 'backstage-plugin-foo' | ||
| */ | ||
| function httpName(pkg: string): string | null { | ||
| if (!URL.canParse(pkg)) return null; | ||
|
|
||
| const name = basename(new URL(pkg).pathname) | ||
| .replace(/\.(tar\.gz|tgz)$/, '') | ||
| .replace(/(.*)-\d.*$/, '$1'); | ||
|
Check warning on line 69 in workspaces/install-dynamic-plugins/packages/install-dynamic-plugins/src/plugin-name.ts
|
||
|
|
||
| return name || null; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.