Skip to content

Commit

Permalink
feat(core): when initializing the Configuration, check if the plugi…
Browse files Browse the repository at this point in the history
…n exists and try to fetch the missing plugins
  • Loading branch information
jj811208 committed Sep 29, 2022
1 parent c26001a commit 1c5c3a0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {WorkspaceFetcher}
import {WorkspaceResolver} from './WorkspaceResolver';
import * as folderUtils from './folderUtils';
import * as formatUtils from './formatUtils';
import * as httpUtils from './httpUtils';
import * as miscUtils from './miscUtils';
import * as nodeUtils from './nodeUtils';
import * as semverUtils from './semverUtils';
Expand Down Expand Up @@ -1130,8 +1131,23 @@ export class Configuration {
const userProvidedPath = typeof userPluginEntry !== `string`
? userPluginEntry.path
: userPluginEntry;
const userProvidedSpec = userPluginEntry?.spec ?? ``;

const pluginPath = ppath.resolve(cwd, npath.toPortablePath(userProvidedPath));
if (!await xfs.existsPromise(pluginPath)) {
if (!userProvidedSpec.match(/^https?:/)) {
const prettyPluginName = formatUtils.pretty(configuration, ppath.basename(pluginPath, `.cjs`), formatUtils.Type.NAME);
const prettyGitIgnore = formatUtils.pretty(configuration, `.gitignore`, formatUtils.Type.NAME) ;
const prettyYarnrc = formatUtils.pretty(configuration, configuration.values.get(`rcFilename`), formatUtils.Type.NAME) ;
const prettyUrl = formatUtils.pretty(configuration, `https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored`, formatUtils.Type.URL) ;
throw new UsageError(`Failed to get ${prettyPluginName} plugin, please try to delete the plugin from ${prettyYarnrc} and reinstall it, the error usually occurs because ${prettyGitIgnore} is incorrect, please check ${prettyUrl} to set the correct ${prettyGitIgnore}`);
}

const pluginBuffer = await httpUtils.get(userProvidedSpec, {configuration});
await xfs.mkdirPromise(ppath.dirname(pluginPath), {recursive: true});
await xfs.writeFilePromise(pluginPath, pluginBuffer);
}

await importPlugin(pluginPath, path);
}
}
Expand Down

0 comments on commit 1c5c3a0

Please sign in to comment.