private renderTaskSteps()

in projenrc/upgrade-dependencies.ts [149:216]


  private renderTaskSteps(): TaskStep[] {
    // exclude depedencies that has already version pinned (fully or with patch version) by Projen with ncu (but not package manager upgrade)
    // Getting only unique values through set
    const ncuExcludes = [
      ...new Set(
        this.project.deps.all
          .filter(
            (dep) =>
              dep.name === 'typescript' ||
              (dep.version && dep.version[0] !== '^' && dep.type !== DependencyType.OVERRIDE),
          )
          .map((dep) => dep.name),
      ),
    ];
    // TypeScript is minor-pinned in this project...
    const hasTypescript = ncuExcludes.includes('typescript');

    const ncuIncludes = this.options.include?.filter((item) => !ncuExcludes.includes(item));

    const includeLength = this.options.include?.length ?? 0;
    const ncuIncludesLength = ncuIncludes?.length ?? 0;

    // If all explicit includes already have version pinned, don't add task.
    // Note that without explicit includes task gets added
    if (includeLength > 0 && ncuIncludesLength === 0) {
      return [{ exec: 'echo No dependencies to upgrade.' }];
    }

    const steps = new Array<TaskStep>();

    // update npm-check-updates before everything else, in case there is a bug
    // in it or one of its dependencies. This will make upgrade workflows
    // slightly more stable and resilient to upstream changes.
    steps.push({
      exec: this.renderUpgradePackagesCommand(['npm-check-updates']),
    });

    for (const dep of ['dev', 'optional', 'peer', 'prod', 'bundle']) {
      const ncuCommand = ['npm-check-updates', '--dep', dep, '--upgrade', '--target=minor'];
      // Don't add includes and excludes same time
      if (ncuIncludes) {
        ncuCommand.push(`--filter='${ncuIncludes.join(',')}'`);
      } else if (ncuExcludes.length > 0) {
        ncuCommand.push(`--reject='${ncuExcludes.join(',')}'`);
      }

      steps.push({ exec: ncuCommand.join(' ') });
    }
    if (hasTypescript) {
      const ncuCommand = ['npm-check-updates', '--upgrade', '--target=patch', '--filter=typescript'];
      steps.push({ exec: ncuCommand.join(' ') });
    }

    // run "yarn/npm install" to update the lockfile and install any deps (such as projen)
    steps.push({ exec: this._project.package.installAndUpdateLockfileCommand });

    // run upgrade command to upgrade transitive deps as well
    steps.push({
      exec: this.renderUpgradePackagesCommand(this.options.include),
    });

    // run "projen" to give projen a chance to update dependencies (it will also run "yarn install")
    steps.push({ exec: this._project.projenCommand });

    steps.push({ spawn: this.postUpgradeTask.name });

    return steps;
  }