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

fix: update upgrade-dependencies to circumvent projen breaking changes #246

Merged
merged 1 commit into from
Aug 12, 2023
Merged
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
36 changes: 35 additions & 1 deletion projenrc/upgrade-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, DependencyType, github, javascript, release, Task, TaskStep } from 'projen';
import { DEFAULT_GITHUB_ACTIONS_USER } from 'projen/lib/github/constants';
import { NodePackageManager } from 'projen/lib/javascript';

const CREATE_PATCH_STEP_ID = 'create_patch';
const PATCH_CREATED_OUTPUT = 'patch_created';
Expand Down Expand Up @@ -189,7 +190,7 @@ export class UpgradeDependencies extends Component {
// in it or one of its dependencies. This will make upgrade workflows
// slightly more stable and resilient to upstream changes.
steps.push({
exec: this._project.package.renderUpgradePackagesCommand([], ['npm-check-updates']),
exec: this.renderUpgradePackagesCommand(['npm-check-updates']),
});

for (const dep of ['dev', 'optional', 'peer', 'prod', 'bundle']) {
Expand Down Expand Up @@ -330,6 +331,39 @@ export class UpgradeDependencies extends Component {
jobId: 'pr',
};
}

/**
* Render a package manager specific command to upgrade all requested dependencies.
*/
private renderUpgradePackagesCommand(include: string[]): string {
function upgradePackages(command: string) {
return () => {
return `${command} ${include.join(' ')}`;
};
}

const packageManager = this._project.package.packageManager;

let lazy;
switch (packageManager) {
case NodePackageManager.YARN:
case NodePackageManager.YARN2:
lazy = upgradePackages('yarn upgrade');
break;
case NodePackageManager.NPM:
lazy = upgradePackages('npm update');
break;
case NodePackageManager.PNPM:
lazy = upgradePackages('pnpm update');
break;
default:
throw new Error(`unexpected package manager ${packageManager}`);
}

// return a lazy function so that dependencies include ones that were
// added post project instantiation (i.e using project.addDeps)
return lazy as unknown as string;
}
}

interface Upgrade {
Expand Down