Skip to content
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

Add ${targetPlatform} placeholder for plugin downloads #12410

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions dev-packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,35 @@

## Outline

- [**Description**](#description)
- [**Getting Started**](#getting-started)
- [**Configure**](#configure)
- [**Application Properties**](#application-properties)
- [**Default Preferences**](#default-preferences)
- [**Default Theme**](#default-theme)
- [**Build Target**](#build-target)
- [**Electron Frontend Application Config**](#electron-frontend-application-config)
- [**Using Latest Builds**](#using-latest-builds)
- [**Building**](#building)
- [**Build**](#build)
- [**Watch**](#watch)
- [**Clean**](#clean)
- [**Rebuilding Native Modules**](#rebuilding-native-modules)
- [**Running**](#running)
- [**Debugging**](#debugging)
- [**Testing**](#testing)
- [**Enabling Tests**](#enabling-tests)
- [**Writing Tests**](#writing-tests)
- [**Running Tests**](#running-tests)
- [**Configuring Tests**](#configuring-tests)
- [**Inspecting Tests**](#inspecting-tests)
- [**Reporting Test Coverage**](#reporting-test-coverage)
- [**Downloading Plugins**](#downloading-plugins)
- [**Autogenerated Application**](#autogenerated-application)
- [Outline](#outline)
- [Description](#description)
- [Getting Started](#getting-started)
- [Configure](#configure)
- [Application Properties](#application-properties)
- [Default Preferences](#default-preferences)
- [Default Theme](#default-theme)
- [Build Target](#build-target)
- [Electron Frontend Application Config](#electron-frontend-application-config)
- [Using Latest Builds](#using-latest-builds)
- [Building](#building)
- [Build](#build)
- [Watch](#watch)
- [Clean](#clean)
- [Rebuilding Native Modules](#rebuilding-native-modules)
- [Running](#running)
- [Debugging](#debugging)
- [Testing](#testing)
- [Enabling Tests](#enabling-tests)
- [Writing Tests](#writing-tests)
- [Running Tests](#running-tests)
- [Configuring Tests](#configuring-tests)
- [Inspecting Tests](#inspecting-tests)
- [Reporting Test Coverage](#reporting-test-coverage)
- [Downloading Plugins](#downloading-plugins)
- [Autogenerated Application](#autogenerated-application)
- [Additional Information](#additional-information)
- [License](#license)
- [Trademark](#trademark)

## Description

Expand Down Expand Up @@ -301,7 +305,7 @@ The `@theia/cli` package provides a utility for applications to define and downl

theia download:plugins

This utility works by declaring in the `package.json` a location to store downloaded plugins, as well defining each plugin the application wishes to download.
This utility works by declaring in the `package.json` a location to store downloaded plugins, as well as defining each plugin the application wishes to download.

The property `theiaPluginsDir` describes the location of which to download plugins (relative to the `package.json`), for example:

Expand All @@ -317,8 +321,11 @@ The property `theiaPlugins` describes the list of plugins to download, for examp
"vscode-builtin-extension-pack": "https://open-vsx.org/api/eclipse-theia/builtin-extension-pack/1.50.0/file/eclipse-theia.builtin-extension-pack-1.50.0.vsix",
"vscode-editorconfig": "https://open-vsx.org/api/EditorConfig/EditorConfig/0.14.4/file/EditorConfig.EditorConfig-0.14.4.vsix",
"vscode-eslint": "https://open-vsx.org/api/dbaeumer/vscode-eslint/2.1.1/file/dbaeumer.vscode-eslint-2.1.1.vsix",
"rust-analyzer": "https://open-vsx.org/api/rust-lang/rust-analyzer/${targetPlatform}/0.4.1473/file/rust-lang.rust-analyzer-0.4.1473@${targetPlatform}.vsix"
}
```
As seen in the `rust-analyzer` entry we can use placeholders in the URLs. Supported placeholders are:
- The `${targetPlatform}` Placeholder, which resolves to a string like `win32-x64` describing the local system and architecture. This is useful for adding non-universal plugins.

Please note that in order to use `extensionPacks` properly you should use `namespace.name` as the `id` you give extensions so that when resolving the pack we do not re-download an existing plugin under a different name.

Expand Down
1 change: 1 addition & 0 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"chai": "^4.2.0",
"chalk": "4.0.0",
"decompress": "^4.2.1",
"escape-string-regexp": "4.0.0",
"glob": "^8.0.3",
"limiter": "^2.1.0",
"log-update": "^4.0.0",
Expand Down
13 changes: 12 additions & 1 deletion dev-packages/cli/src/download-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { NodeRequestService } from '@theia/request/lib/node-request-service';
import { DEFAULT_SUPPORTED_API_VERSION } from '@theia/application-package/lib/api';
import { RequestContext } from '@theia/request';
import { RateLimiter } from 'limiter';
import escapeStringRegexp = require('escape-string-regexp');

temp.track();

Expand Down Expand Up @@ -145,7 +146,7 @@ export default async function downloadPlugins(options: DownloadPluginsOptions =
// This will include both "normal" plugins as well as "extension packs".
const pluginsToDownload = Object.entries(pck.theiaPlugins)
.filter((entry: [string, unknown]): entry is [string, string] => typeof entry[1] === 'string')
.map(([pluginId, url]) => ({ id: pluginId, downloadUrl: url }));
.map(([pluginId, url]) => ({ id: pluginId, downloadUrl: resolveDownloadUrlPlaceholders(url) }));
await downloader(pluginsToDownload);

const handleDependencyList = async (dependencies: Array<string | string[]>) => {
Expand Down Expand Up @@ -195,6 +196,16 @@ export default async function downloadPlugins(options: DownloadPluginsOptions =
}
}

const placeholders: Record<string, string> = {
targetPlatform: `${process.platform}-${process.arch}`
};
function resolveDownloadUrlPlaceholders(url: string): string {
for (const [name, value] of Object.entries(placeholders)) {
url = url.replace(new RegExp(escapeStringRegexp(`\${${name}}`), 'g'), value);
}
return url;
}

/**
* Downloads a plugin, will make multiple attempts before actually failing.
* @param failures reference to an array storing all failures.
Expand Down