constructor()

in projenrc/upgrade-dependencies.ts [92:139]


  constructor(project: javascript.NodeProject, options: UpgradeDependenciesOptions = {}) {
    super(project);

    this._project = project;
    this.options = options;
    this.pullRequestTitle = options.pullRequestTitle ?? 'upgrade dependencies';
    this.gitIdentity = options.workflowOptions?.gitIdentity ?? DEFAULT_GITHUB_ACTIONS_USER;
    this.permissions = {
      contents: github.workflows.JobPermission.READ,
      ...options.workflowOptions?.permissions,
    };
    this.postBuildSteps = [];
    this.containerOptions = options.workflowOptions?.container;
    project.addDevDeps('npm-check-updates@^16');

    this.postUpgradeTask =
      project.tasks.tryFind('post-upgrade') ??
      project.tasks.addTask('post-upgrade', {
        description: 'Runs after upgrading dependencies',
      });

    this.upgradeTask = project.addTask(options.taskName ?? 'upgrade', {
      // this task should not run in CI mode because its designed to
      // update package.json and lock files.
      env: { CI: '0' },
      description: this.pullRequestTitle,
      steps: { toJSON: () => this.renderTaskSteps() } as any,
    });
    this.upgradeTask.lock(); // this task is a lazy value, so make it readonly

    if (this.upgradeTask && project.github && (options.workflow ?? true)) {
      if (options.workflowOptions?.branches) {
        for (const branch of options.workflowOptions.branches) {
          this.workflows.push(this.createWorkflow(this.upgradeTask, project.github, branch));
        }
      } else if (release.Release.of(project)) {
        const rel = release.Release.of(project)!;
        rel._forEachBranch((branch: string) => {
          this.workflows.push(this.createWorkflow(this.upgradeTask, project.github!, branch));
        });
      } else {
        // represents the default repository branch.
        // just like not specifying anything.
        const defaultBranch = undefined;
        this.workflows.push(this.createWorkflow(this.upgradeTask, project.github, defaultBranch));
      }
    }
  }