From 93ac21ccd048f2e96c511f41fca026f158d6959c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=E1=BA=A3i?= Date: Thu, 15 May 2025 16:16:22 +0700 Subject: [PATCH] refactor: add types to `installSome` and `installCase` (#9539) --------- Co-authored-by: Zoltan Kochan --- pkg-manager/core/src/install/index.ts | 49 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/pkg-manager/core/src/install/index.ts b/pkg-manager/core/src/install/index.ts index 04a08f5188..d82b6c5c04 100644 --- a/pkg-manager/core/src/install/index.ts +++ b/pkg-manager/core/src/install/index.ts @@ -474,13 +474,13 @@ export async function mutateModules ( case 'install': { await installCase({ ...projectOpts, - updatePackageManifest: (projectOpts as InstallDepsMutation).updatePackageManifest ?? (projectOpts as InstallDepsMutation).update, + updatePackageManifest: (projectOpts as InstallDepsMutation).updatePackageManifest ?? (projectOpts as InstallDepsMutation).update!, }) break } case 'installSome': { await installSome({ - ...projectOpts, + ...projectOpts as InstallSomeProject, updatePackageManifest: (projectOpts as InstallSomeDepsMutation).updatePackageManifest !== false, }) break @@ -489,7 +489,18 @@ export async function mutateModules ( } /* eslint-enable no-await-in-loop */ - async function installCase (project: any) { // eslint-disable-line + type InstallCaseProject = Pick + + async function installCase (project: InstallCaseProject) { const wantedDependencies = getWantedDependencies(project.manifest, { autoInstallPeers: opts.autoInstallPeers, includeDirect: opts.includeDirect, @@ -501,9 +512,9 @@ export async function mutateModules ( forgetResolutionsOfPrevWantedDeps(ctx.wantedLockfile.importers[project.id], wantedDependencies, _isWantedDepBareSpecifierSame) } if (opts.ignoreScripts && project.manifest?.scripts && - (project.manifest.scripts.preinstall || - project.manifest.scripts.install || - project.manifest.scripts.postinstall || + (project.manifest.scripts.preinstall != null || + project.manifest.scripts.install != null || + project.manifest.scripts.postinstall != null || project.manifest.scripts.prepare) ) { ctx.pendingBuilds.push(project.id) @@ -513,13 +524,29 @@ export async function mutateModules ( pruneDirectDependencies: false, ...project, wantedDependencies, - }) + } as ImporterToUpdate) } - async function installSome (project: any) { // eslint-disable-line + type InstallSomeProject = Pick & Pick + + async function installSome (project: InstallSomeProject) { const currentBareSpecifiers = opts.ignoreCurrentSpecifiers ? {} : getAllDependenciesFromManifest(project.manifest) - const optionalDependencies = project.targetDependenciesField ? {} : project.manifest.optionalDependencies || {} - const devDependencies = project.targetDependenciesField ? {} : project.manifest.devDependencies || {} + const optionalDependencies = project.targetDependenciesField ? {} : project.manifest.optionalDependencies ?? {} + const devDependencies = project.targetDependenciesField ? {} : project.manifest.devDependencies ?? {} if (preferredSpecs == null) { const manifests = [] for (const versions of ctx.workspacePackages.values()) { @@ -547,7 +574,7 @@ export async function mutateModules ( pruneDirectDependencies: false, ...project, wantedDependencies: wantedDeps.map(wantedDep => ({ ...wantedDep, isNew: !currentBareSpecifiers[wantedDep.alias], updateSpec: true, nodeExecPath: opts.nodeExecPath })), - }) + } as ImporterToUpdate) } // Unfortunately, the private lockfile may differ from the public one.