From 2ee0136ec27346bd3dc075ac050a37b42a4f582a Mon Sep 17 00:00:00 2001 From: Adrian Dimech Date: Tue, 17 Oct 2023 09:50:51 +1100 Subject: [PATCH] fix(monorepo): fix issues with monorepo-ts peer deps fix #601, #586 --- .../monorepo/src/projects/typescript/monorepo-ts.ts | 13 +++++++++---- packages/pdk/_scripts/exec-command.js | 4 ++-- .../type-safe-api-project.test.ts.snap | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/monorepo/src/projects/typescript/monorepo-ts.ts b/packages/monorepo/src/projects/typescript/monorepo-ts.ts index 3aac34f73..2d96fec8f 100644 --- a/packages/monorepo/src/projects/typescript/monorepo-ts.ts +++ b/packages/monorepo/src/projects/typescript/monorepo-ts.ts @@ -171,6 +171,9 @@ export class MonorepoTsProject }, include: ["**/*.ts", ".projenrc.ts"], }, + peerDeps: ["nx@^16", ...(options.peerDeps || [])], + devDeps: ["nx@^16", "@aws/pdk@^0", ...(options.devDeps || [])], + deps: ["aws-cdk-lib", "constructs", "cdk-nag", ...(options.deps || [])], }); this.nxConfigurator = new NxConfigurator(this, { @@ -201,6 +204,12 @@ export class MonorepoTsProject ); 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; @@ -272,10 +281,6 @@ export class MonorepoTsProject }); } - // Add dependency on nx 16 - this.addPeerDeps("nx@^16"); - this.addDevDeps("nx@^16", "@aws/pdk@^0"); - this.addDeps("aws-cdk-lib", "constructs", "cdk-nag"); // Needed as this can be bundled in @aws/pdk this.package.addPackageResolutions( "@types/babel__traverse@7.18.2", "wrap-ansi@^7.0.0", diff --git a/packages/pdk/_scripts/exec-command.js b/packages/pdk/_scripts/exec-command.js index 96796b620..653ce4bf7 100755 --- a/packages/pdk/_scripts/exec-command.js +++ b/packages/pdk/_scripts/exec-command.js @@ -27,8 +27,8 @@ const engines = JSON.parse( ).engines; if (engines) { - const pkgMgr = engines.pnpm ? "pnpm" : engines.yarn ? "yarn" : "npm"; - execa.commandSync(`${pkgMgr}${isSynth ? " projen" : ""} ${process.argv.join(" ")}`, { stdio: "inherit" }); + const pkgMgrCmd = engines.pnpm ? "pnpm" : engines.yarn ? "yarn" : "npm run"; + execa.commandSync(`${pkgMgrCmd}${isSynth ? " default" : ""} ${process.argv.join(" ")}`, { stdio: "inherit" }); } else { execa.commandSync(`npx projen ${process.argv.join(" ")}`, { stdio: "inherit"}); } diff --git a/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap b/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap index 06c4830ed..a85463edd 100644 --- a/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap +++ b/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap @@ -39615,7 +39615,7 @@ tsconfig.tsbuildinfo "name": "install", "steps": [ { - "exec": "npm install", + "exec": "npm install --legacy-peer-deps", }, ], }, @@ -39624,7 +39624,7 @@ tsconfig.tsbuildinfo "name": "install:ci", "steps": [ { - "exec": "npm ci", + "exec": "npm ci --legacy-peer-deps", }, ], },