constructor()

in packages/monorepo/src/projects/typescript/monorepo-ts.ts [165:354]


  constructor(options: MonorepoTsProjectOptions) {
    const defaultReleaseBranch = options.defaultReleaseBranch ?? "main";
    super({
      ...options,
      github: options.github ?? false,
      package: options.package ?? false,
      projenCommand: options.packageManager
        ? NodePackageUtils.command.projen(options.packageManager)
        : undefined,
      prettier: options.prettier ?? true,
      projenrcTs: true,
      release: options.release ?? false,
      jest: options.jest ?? false,
      sampleCode: false, // root should never have sample code,
      gitignore: [".tmp", ...(options.gitignore ?? [])],
      defaultReleaseBranch,
      eslintOptions: options.eslintOptions ?? {
        dirs: ["."],
        ignorePatterns: ["packages/**/*.*"],
      },
      tsconfig: options.tsconfig ?? {
        compilerOptions: {
          rootDir: ".",
        },
        include: ["**/*.ts", ".projenrc.ts"],
      },
      peerDeps: ["nx@^19", ...(options.peerDeps || [])],
      devDeps: ["nx@^19", "@aws/pdk@^0", ...(options.devDeps || [])],
      deps: [
        "aws-cdk-lib",
        "cdk-nag",
        "@aws-cdk/aws-cognito-identitypool-alpha@latest",
        ...(options.deps || []),
      ],
      projenVersion: options.projenVersion ?? DEFAULT_PROJEN_VERSION,
    });

    this.projenVersion = options.projenVersion ?? DEFAULT_PROJEN_VERSION;

    this.nxConfigurator = new NxConfigurator(this, {
      defaultReleaseBranch,
      licenseOptions: options.licenseOptions,
    });
    this._options = options;

    // engines
    this.package.addEngine("node", ">=16");
    this.package.setScript(
      "install:ci",
      !this.ejected
        ? NodePackageUtils.command.exec(
            this.package.packageManager,
            "projen install:ci"
          )
        : "scripts/run-task install:ci"
    );

    switch (this.package.packageManager) {
      case NodePackageManager.BUN: {
        this.package.addEngine("bun", ">=1");
        break;
      }
      case NodePackageManager.PNPM: {
        // https://pnpm.io/package_json
        // https://github.com/pnpm/pnpm/releases/tag/v8.0.0
        this.package.addEngine("pnpm", ">=8 <9");
        break;
      }
      case NodePackageManager.YARN_CLASSIC:
      case NodePackageManager.YARN: {
        this.package.addEngine("yarn", ">=1 <2");
        break;
      }
      case NodePackageManager.YARN_BERRY:
      case NodePackageManager.YARN2: {
        this.package.addEngine("yarn", ">=2");
        // Yarn Berry cannot call yarn exec without an install first! Use NPX instead.
        this.package.setScript(
          "install:ci",
          !this.ejected
            ? NodePackageUtils.command.exec(
                NodePackageManager.NPM,
                "projen install:ci"
              )
            : "scripts/run-task install:ci"
        );
        this.package.setScript(
          "install",
          !this.ejected
            ? NodePackageUtils.command.exec(
                NodePackageManager.NPM,
                "projen install"
              )
            : "scripts/run-task install"
        );
        this.gitignore.addPatterns(
          ".yarn/*",
          ".pnp.cjs",
          "!.yarn/releases",
          "!.yarn/plugins"
        );
        break;
      }
      case NodePackageManager.NPM: {
        // Allow older versions of peer deps to resolv compatibility issues
        this.tasks.tryFind("install")?.reset("npm install --legacy-peer-deps");
        this.tasks.tryFind("install:ci")?.reset("npm ci --legacy-peer-deps");
        break;
      }
    }

    this.workspaceConfig = options.workspaceConfig;
    this.workspacePackages = options.workspaceConfig?.additionalPackages ?? [];

    // Never publish a monorepo root package.
    this.package.addField("private", true);

    // Add alias task for "projen" to synthesize workspace
    !this.ejected &&
      this.package.setScript(
        "synth-workspace",
        NodePackageUtils.command.projen(this.package.packageManager)
      );

    // Map tasks to nx run-many
    if (options.scripts == null || options.scripts.build == null) {
      this.nxConfigurator._overrideNxBuildTask(
        this.buildTask,
        { target: "build" },
        { force: true }
      );
    }
    if (options.scripts == null || options.scripts["pre-compile"] == null) {
      this.nxConfigurator._overrideNxBuildTask(this.preCompileTask, {
        target: "pre-compile",
      });
    }
    if (options.scripts == null || options.scripts.compile == null) {
      this.nxConfigurator._overrideNxBuildTask(this.compileTask, {
        target: "compile",
      });
    }
    if (options.scripts == null || options.scripts["post-compile"] == null) {
      this.nxConfigurator._overrideNxBuildTask(this.postCompileTask, {
        target: "post-compile",
      });
    }
    if (options.scripts == null || options.scripts.test == null) {
      this.nxConfigurator._overrideNxBuildTask(this.testTask, {
        target: "test",
      });
    }
    if (options.scripts == null || options.scripts.eslint == null) {
      // The Projenrc component of TypeScriptProject resets the eslint task as part of preSynthesize which would undo
      // our changes, so we disable further resets.
      this.nxConfigurator._overrideNxBuildTask(
        this.eslint?.eslintTask,
        { target: "eslint" },
        { disableReset: true }
      );
    }
    if (options.scripts == null || options.scripts.package == null) {
      this.nxConfigurator._overrideNxBuildTask(this.packageTask, {
        target: "package",
      });
    }
    if (options.scripts == null || options.scripts.prepare == null) {
      this.nxConfigurator._overrideNxBuildTask("prepare", {
        target: "prepare",
      });
    }
    if (options.scripts == null || options.scripts.watch == null) {
      this.nxConfigurator._overrideNxBuildTask(this.watchTask, {
        target: "watch",
        noBail: false,
        ignoreCycles: true,
        skipCache: true,
        outputStyle: "stream",
      });
    }

    this.package.addPackageResolutions(
      "@types/babel__traverse@7.18.2",
      "wrap-ansi@^7.0.0"
    );

    if (this.package.packageManager !== NodePackageManager.BUN) {
      this.package.addPackageResolutions("@zkochan/js-yaml@npm:js-yaml@4.1.0");
    }
  }