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

Feat: resolutions overrides #1304

Merged
merged 1 commit into from
Dec 18, 2023
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
1 change: 1 addition & 0 deletions packages/core/src/configs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type NpmPackageFile = {
dependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
resolutions?: Record<string, string>;
author?: string;
license?: string;
description?: string;
Expand Down
25 changes: 19 additions & 6 deletions packages/core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { installPackageDependencies } from '../projects/npm';
import { OverridesOptions, ResolveOptions } from '../system/types';
import { ConfigFileOverrides, ConfigFilePlugin, ConfigFilePlugins } from '../schema/configFiles/types';
import { NpmPackageFile } from '../configs/types';
import { getContext } from '../context/provider';

const _getPluginScope = (plugin: RenativeConfigPlugin | string): RnvPluginScope => {
if (typeof plugin === 'string') {
Expand Down Expand Up @@ -151,6 +152,18 @@ const _getMergedPlugin = (
return mergedPlugin;
};

const _applyPackageDependency = (deps: Record<string, string>, key: string, version: string) => {
const ctx = getContext();
const { resolutions } = ctx.files.project.package;
const res = resolutions?.[key];
if (res) {
logInfo(`Found resolutions override for ${key}@${res}`);
deps[key] = res;
} else {
deps[key] = version;
}
};

export const configurePlugins = async (c: RnvContext) => {
logTask('configurePlugins');

Expand Down Expand Up @@ -201,7 +214,7 @@ ${ovMsg}`
);

hasPackageChanged = true;
newDeps[k] = plugin.version;
_applyPackageDependency(newDeps, k, plugin.version);
}
}
} else if (devDependencies && devDependencies[k]) {
Expand All @@ -217,7 +230,7 @@ ${ovMsg}`
)}) and plugins.json: v(${chalk().red(plugin.version)}). ${ovMsg}`
);
hasPackageChanged = true;
newDevDeps[k] = plugin.version;
_applyPackageDependency(newDevDeps, k, plugin.version);
}
}
} else if (plugin.disabled !== true && plugin.disableNpm !== true) {
Expand All @@ -229,7 +242,7 @@ ${ovMsg}`

hasPackageChanged = true;
if (plugin.version) {
newDeps[k] = plugin.version;
_applyPackageDependency(newDeps, k, plugin.version);
}
}
}
Expand All @@ -247,7 +260,7 @@ ${ovMsg}`
} else if (!dependencies[npmKey]) {
logInfo(`Plugin ${chalk().white(k)} requires npm dependency ${chalk().white(npmKey)}. ${ovMsg}`);
if (npmDep) {
newDeps[npmKey] = npmDep;
_applyPackageDependency(newDeps, npmKey, npmDep);
hasPackageChanged = true;
}
} else if (dependencies[npmKey] !== npmDep) {
Expand All @@ -257,7 +270,7 @@ ${ovMsg}`
)}) => (${chalk().green(npmDep)}) .${ovMsg}`
);
if (npmDep) {
newDeps[npmKey] = npmDep;
_applyPackageDependency(newDeps, npmKey, npmDep);
hasPackageChanged = true;
}
}
Expand Down Expand Up @@ -486,7 +499,7 @@ export const loadPluginTemplates = async (c: RnvContext) => {
const plugin = getMergedPlugin(c, dep);
if (plugin?.version) {
hasPackageChanged = true;
dependencies[dep] = plugin.version;
_applyPackageDependency(dependencies, dep, plugin.version);
} else {
// Unresolved Plugin
}
Expand Down