diff --git a/packages/one-version/CHANGELOG.md b/packages/one-version/CHANGELOG.md index c489855..33f3f91 100644 --- a/packages/one-version/CHANGELOG.md +++ b/packages/one-version/CHANGELOG.md @@ -1,8 +1,12 @@ ### Unreleased: +### [0.1.0] - May 15th, 2024 + - Update description in package.json - Remove unnecessary devDependencies - Update readme +- Add implementation +- Add tests ### [0.0.1] - May 14th, 2024 diff --git a/packages/one-version/__fixtures__/bun-configured/bun.lockb b/packages/one-version/__fixtures__/bun-configured/bun.lockb new file mode 100755 index 0000000..53bbd2e Binary files /dev/null and b/packages/one-version/__fixtures__/bun-configured/bun.lockb differ diff --git a/packages/one-version/__fixtures__/bun-configured/libs/pkg-a/package.json b/packages/one-version/__fixtures__/bun-configured/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/bun-configured/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/bun-configured/libs/pkg-b/package.json b/packages/one-version/__fixtures__/bun-configured/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/bun-configured/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/bun-configured/libs/pkg-c/package.json b/packages/one-version/__fixtures__/bun-configured/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/bun-configured/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/bun-configured/one-version.config.jsonc b/packages/one-version/__fixtures__/bun-configured/one-version.config.jsonc new file mode 100644 index 0000000..9cdc6f8 --- /dev/null +++ b/packages/one-version/__fixtures__/bun-configured/one-version.config.jsonc @@ -0,0 +1,9 @@ +{ + "packageManager": "bun", + "overrides": { + "typescript": { + "^5.4": ["pkg-b"], + "^5": ["pkg-a"] + } + } +} diff --git a/packages/one-version/__fixtures__/bun-configured/package.json b/packages/one-version/__fixtures__/bun-configured/package.json new file mode 100644 index 0000000..b591ff9 --- /dev/null +++ b/packages/one-version/__fixtures__/bun-configured/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ] +} diff --git a/packages/one-version/__fixtures__/bun/bun.lockb b/packages/one-version/__fixtures__/bun/bun.lockb new file mode 100755 index 0000000..53bbd2e Binary files /dev/null and b/packages/one-version/__fixtures__/bun/bun.lockb differ diff --git a/packages/one-version/__fixtures__/bun/libs/pkg-a/package.json b/packages/one-version/__fixtures__/bun/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/bun/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/bun/libs/pkg-b/package.json b/packages/one-version/__fixtures__/bun/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/bun/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/bun/libs/pkg-c/package.json b/packages/one-version/__fixtures__/bun/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/bun/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/bun/package.json b/packages/one-version/__fixtures__/bun/package.json new file mode 100644 index 0000000..b591ff9 --- /dev/null +++ b/packages/one-version/__fixtures__/bun/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ] +} diff --git a/packages/one-version/__fixtures__/missing/libs/pkg-a/package.json b/packages/one-version/__fixtures__/missing/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/missing/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/missing/libs/pkg-b/package.json b/packages/one-version/__fixtures__/missing/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/missing/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/missing/libs/pkg-c/package.json b/packages/one-version/__fixtures__/missing/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/missing/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/missing/package.json b/packages/one-version/__fixtures__/missing/package.json new file mode 100644 index 0000000..b591ff9 --- /dev/null +++ b/packages/one-version/__fixtures__/missing/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ] +} diff --git a/packages/one-version/__fixtures__/npm/libs/pkg-a/package.json b/packages/one-version/__fixtures__/npm/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/npm/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/npm/libs/pkg-b/package.json b/packages/one-version/__fixtures__/npm/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/npm/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/npm/libs/pkg-c/package.json b/packages/one-version/__fixtures__/npm/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/npm/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/npm/package-lock.json b/packages/one-version/__fixtures__/npm/package-lock.json new file mode 100644 index 0000000..5c504e7 --- /dev/null +++ b/packages/one-version/__fixtures__/npm/package-lock.json @@ -0,0 +1,114 @@ +{ + "name": "npm", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "workspaces": [ + "libs/*" + ] + }, + "libs/pkg-a": { + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "devDependencies": { + "typescript": "^5" + } + }, + "libs/pkg-b": { + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "devDependencies": { + "typescript": "^5.4" + } + }, + "libs/pkg-c": { + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "devDependencies": { + "typescript": "5.4.5" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, + "node_modules/pkg-a": { + "resolved": "libs/pkg-a", + "link": true + }, + "node_modules/pkg-b": { + "resolved": "libs/pkg-b", + "link": true + }, + "node_modules/pkg-c": { + "resolved": "libs/pkg-c", + "link": true + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" + }, + "peerDependencies": { + "react": "^18.3.1" + } + }, + "node_modules/scheduler": { + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "dependencies": { + "loose-envify": "^1.1.0" + } + }, + "node_modules/typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/packages/one-version/__fixtures__/npm/package.json b/packages/one-version/__fixtures__/npm/package.json new file mode 100644 index 0000000..861dfa9 --- /dev/null +++ b/packages/one-version/__fixtures__/npm/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ], + "packageManager": "npm@10.7.0" +} diff --git a/packages/one-version/__fixtures__/pnpm/libs/pkg-a/package.json b/packages/one-version/__fixtures__/pnpm/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/pnpm/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/pnpm/libs/pkg-b/package.json b/packages/one-version/__fixtures__/pnpm/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/pnpm/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/pnpm/libs/pkg-c/package.json b/packages/one-version/__fixtures__/pnpm/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/pnpm/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/pnpm/package.json b/packages/one-version/__fixtures__/pnpm/package.json new file mode 100644 index 0000000..d1fe4fb --- /dev/null +++ b/packages/one-version/__fixtures__/pnpm/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ], + "packageManager": "pnpm@9.1.1" +} diff --git a/packages/one-version/__fixtures__/pnpm/pnpm-lock.yaml b/packages/one-version/__fixtures__/pnpm/pnpm-lock.yaml new file mode 100644 index 0000000..534a22b --- /dev/null +++ b/packages/one-version/__fixtures__/pnpm/pnpm-lock.yaml @@ -0,0 +1,98 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: {} + + libs/pkg-a: + dependencies: + react: + specifier: 18.3.1 + version: 18.3.1 + react-dom: + specifier: 18.3.1 + version: 18.3.1(react@18.3.1) + devDependencies: + typescript: + specifier: ^5 + version: 5.4.5 + + libs/pkg-b: + dependencies: + react: + specifier: 18.3.1 + version: 18.3.1 + react-dom: + specifier: 18.3.1 + version: 18.3.1(react@18.3.1) + devDependencies: + typescript: + specifier: ^5.4 + version: 5.4.5 + + libs/pkg-c: + dependencies: + react: + specifier: 18.3.1 + version: 18.3.1 + react-dom: + specifier: 18.3.1 + version: 18.3.1(react@18.3.1) + devDependencies: + typescript: + specifier: 5.4.5 + version: 5.4.5 + +packages: + + js-tokens@4.0.0: + resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} + + loose-envify@1.4.0: + resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} + hasBin: true + + react-dom@18.3.1: + resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==} + peerDependencies: + react: ^18.3.1 + + react@18.3.1: + resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} + engines: {node: '>=0.10.0'} + + scheduler@0.23.2: + resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} + + typescript@5.4.5: + resolution: {integrity: sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==} + engines: {node: '>=14.17'} + hasBin: true + +snapshots: + + js-tokens@4.0.0: {} + + loose-envify@1.4.0: + dependencies: + js-tokens: 4.0.0 + + react-dom@18.3.1(react@18.3.1): + dependencies: + loose-envify: 1.4.0 + react: 18.3.1 + scheduler: 0.23.2 + + react@18.3.1: + dependencies: + loose-envify: 1.4.0 + + scheduler@0.23.2: + dependencies: + loose-envify: 1.4.0 + + typescript@5.4.5: {} diff --git a/packages/one-version/__fixtures__/pnpm/pnpm-workspace.yaml b/packages/one-version/__fixtures__/pnpm/pnpm-workspace.yaml new file mode 100644 index 0000000..7170370 --- /dev/null +++ b/packages/one-version/__fixtures__/pnpm/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - 'libs/*' diff --git a/packages/one-version/__fixtures__/template-monorepo/libs/pkg-a/package.json b/packages/one-version/__fixtures__/template-monorepo/libs/pkg-a/package.json index a9facbc..7f19605 100644 --- a/packages/one-version/__fixtures__/template-monorepo/libs/pkg-a/package.json +++ b/packages/one-version/__fixtures__/template-monorepo/libs/pkg-a/package.json @@ -1,8 +1,14 @@ { "name": "pkg-a", + "version": "0.0.0", "dependencies": { - "a": "1.0.0", - "b": "2.3.1", - "c": "^3" + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" } } diff --git a/packages/one-version/__fixtures__/template-monorepo/libs/pkg-b/package.json b/packages/one-version/__fixtures__/template-monorepo/libs/pkg-b/package.json index 118b05c..3a854a1 100644 --- a/packages/one-version/__fixtures__/template-monorepo/libs/pkg-b/package.json +++ b/packages/one-version/__fixtures__/template-monorepo/libs/pkg-b/package.json @@ -1,8 +1,14 @@ { "name": "pkg-b", + "version": "0.0.0", "dependencies": { - "a": "1.0.0", - "b": "1.2.3", - "c": "^3" + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" } } diff --git a/packages/one-version/__fixtures__/template-monorepo/libs/pkg-c/package.json b/packages/one-version/__fixtures__/template-monorepo/libs/pkg-c/package.json index 460674a..336776b 100644 --- a/packages/one-version/__fixtures__/template-monorepo/libs/pkg-c/package.json +++ b/packages/one-version/__fixtures__/template-monorepo/libs/pkg-c/package.json @@ -1,8 +1,14 @@ { "name": "pkg-c", + "version": "0.0.0", "dependencies": { - "a": "1.0.0", - "b": "2.1.3", - "c": "^3" + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" } } diff --git a/packages/one-version/__fixtures__/yarn-berry/.yarn/install-state.gz b/packages/one-version/__fixtures__/yarn-berry/.yarn/install-state.gz new file mode 100644 index 0000000..1ea01d1 Binary files /dev/null and b/packages/one-version/__fixtures__/yarn-berry/.yarn/install-state.gz differ diff --git a/packages/one-version/__fixtures__/yarn-berry/.yarnrc.yml b/packages/one-version/__fixtures__/yarn-berry/.yarnrc.yml new file mode 100644 index 0000000..7e4c877 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-berry/.yarnrc.yml @@ -0,0 +1 @@ +nodeLinker: 'node-modules' diff --git a/packages/one-version/__fixtures__/yarn-berry/libs/pkg-a/package.json b/packages/one-version/__fixtures__/yarn-berry/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-berry/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/yarn-berry/libs/pkg-b/package.json b/packages/one-version/__fixtures__/yarn-berry/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-berry/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/yarn-berry/libs/pkg-c/package.json b/packages/one-version/__fixtures__/yarn-berry/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-berry/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/yarn-berry/package.json b/packages/one-version/__fixtures__/yarn-berry/package.json new file mode 100644 index 0000000..039f405 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-berry/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ], + "packageManager": "yarn@4.1.1" +} diff --git a/packages/one-version/__fixtures__/yarn-berry/yarn.lock b/packages/one-version/__fixtures__/yarn-berry/yarn.lock new file mode 100644 index 0000000..f6ba350 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-berry/yarn.lock @@ -0,0 +1,110 @@ +# This file is generated by running "yarn install" inside your project. +# Manual changes might be lost - proceed with caution! + +__metadata: + version: 8 + cacheKey: 10c0 + +"js-tokens@npm:^3.0.0 || ^4.0.0": + version: 4.0.0 + resolution: "js-tokens@npm:4.0.0" + checksum: 10c0/e248708d377aa058eacf2037b07ded847790e6de892bbad3dac0abba2e759cb9f121b00099a65195616badcb6eca8d14d975cb3e89eb1cfda644756402c8aeed + languageName: node + linkType: hard + +"loose-envify@npm:^1.1.0": + version: 1.4.0 + resolution: "loose-envify@npm:1.4.0" + dependencies: + js-tokens: "npm:^3.0.0 || ^4.0.0" + bin: + loose-envify: cli.js + checksum: 10c0/655d110220983c1a4b9c0c679a2e8016d4b67f6e9c7b5435ff5979ecdb20d0813f4dec0a08674fcbdd4846a3f07edbb50a36811fd37930b94aaa0d9daceb017e + languageName: node + linkType: hard + +"pkg-a@workspace:libs/pkg-a": + version: 0.0.0-use.local + resolution: "pkg-a@workspace:libs/pkg-a" + dependencies: + react: "npm:18.3.1" + react-dom: "npm:18.3.1" + typescript: "npm:^5" + languageName: unknown + linkType: soft + +"pkg-b@workspace:libs/pkg-b": + version: 0.0.0-use.local + resolution: "pkg-b@workspace:libs/pkg-b" + dependencies: + react: "npm:18.3.1" + react-dom: "npm:18.3.1" + typescript: "npm:^5.4" + languageName: unknown + linkType: soft + +"pkg-c@workspace:libs/pkg-c": + version: 0.0.0-use.local + resolution: "pkg-c@workspace:libs/pkg-c" + dependencies: + react: "npm:18.3.1" + react-dom: "npm:18.3.1" + typescript: "npm:5.4.5" + languageName: unknown + linkType: soft + +"react-dom@npm:18.3.1": + version: 18.3.1 + resolution: "react-dom@npm:18.3.1" + dependencies: + loose-envify: "npm:^1.1.0" + scheduler: "npm:^0.23.2" + peerDependencies: + react: ^18.3.1 + checksum: 10c0/a752496c1941f958f2e8ac56239172296fcddce1365ce45222d04a1947e0cc5547df3e8447f855a81d6d39f008d7c32eab43db3712077f09e3f67c4874973e85 + languageName: node + linkType: hard + +"react@npm:18.3.1": + version: 18.3.1 + resolution: "react@npm:18.3.1" + dependencies: + loose-envify: "npm:^1.1.0" + checksum: 10c0/283e8c5efcf37802c9d1ce767f302dd569dd97a70d9bb8c7be79a789b9902451e0d16334b05d73299b20f048cbc3c7d288bbbde10b701fa194e2089c237dbea3 + languageName: node + linkType: hard + +"root-workspace-0b6124@workspace:.": + version: 0.0.0-use.local + resolution: "root-workspace-0b6124@workspace:." + languageName: unknown + linkType: soft + +"scheduler@npm:^0.23.2": + version: 0.23.2 + resolution: "scheduler@npm:0.23.2" + dependencies: + loose-envify: "npm:^1.1.0" + checksum: 10c0/26383305e249651d4c58e6705d5f8425f153211aef95f15161c151f7b8de885f24751b377e4a0b3dd42cce09aad3f87a61dab7636859c0d89b7daf1a1e2a5c78 + languageName: node + linkType: hard + +"typescript@npm:5.4.5, typescript@npm:^5, typescript@npm:^5.4": + version: 5.4.5 + resolution: "typescript@npm:5.4.5" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10c0/2954022ada340fd3d6a9e2b8e534f65d57c92d5f3989a263754a78aba549f7e6529acc1921913560a4b816c46dce7df4a4d29f9f11a3dc0d4213bb76d043251e + languageName: node + linkType: hard + +"typescript@patch:typescript@npm%3A5.4.5#optional!builtin, typescript@patch:typescript@npm%3A^5#optional!builtin, typescript@patch:typescript@npm%3A^5.4#optional!builtin": + version: 5.4.5 + resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin::version=5.4.5&hash=5adc0c" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10c0/db2ad2a16ca829f50427eeb1da155e7a45e598eec7b086d8b4e8ba44e5a235f758e606d681c66992230d3fc3b8995865e5fd0b22a2c95486d0b3200f83072ec9 + languageName: node + linkType: hard diff --git a/packages/one-version/__fixtures__/yarn-classic/libs/pkg-a/package.json b/packages/one-version/__fixtures__/yarn-classic/libs/pkg-a/package.json new file mode 100644 index 0000000..7f19605 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-classic/libs/pkg-a/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-a", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5" + } +} diff --git a/packages/one-version/__fixtures__/yarn-classic/libs/pkg-b/package.json b/packages/one-version/__fixtures__/yarn-classic/libs/pkg-b/package.json new file mode 100644 index 0000000..3a854a1 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-classic/libs/pkg-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-b", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "^5.4" + } +} diff --git a/packages/one-version/__fixtures__/yarn-classic/libs/pkg-c/package.json b/packages/one-version/__fixtures__/yarn-classic/libs/pkg-c/package.json new file mode 100644 index 0000000..336776b --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-classic/libs/pkg-c/package.json @@ -0,0 +1,14 @@ +{ + "name": "pkg-c", + "version": "0.0.0", + "dependencies": { + "react": "18.3.1", + "react-dom": "18.3.1" + }, + "peerDependencies": { + "next": "14.3.0-canary.61" + }, + "devDependencies": { + "typescript": "5.4.5" + } +} diff --git a/packages/one-version/__fixtures__/yarn-classic/package.json b/packages/one-version/__fixtures__/yarn-classic/package.json new file mode 100644 index 0000000..22550f6 --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-classic/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "workspaces": [ + "libs/*" + ], + "packageManager": "yarn@1.22.4" +} diff --git a/packages/one-version/__fixtures__/yarn-classic/yarn.lock b/packages/one-version/__fixtures__/yarn-classic/yarn.lock new file mode 100644 index 0000000..e335a3c --- /dev/null +++ b/packages/one-version/__fixtures__/yarn-classic/yarn.lock @@ -0,0 +1,42 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"js-tokens@^3.0.0 || ^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== + +loose-envify@^1.1.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" + integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== + dependencies: + js-tokens "^3.0.0 || ^4.0.0" + +react-dom@18.3.1: + version "18.3.1" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4" + integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw== + dependencies: + loose-envify "^1.1.0" + scheduler "^0.23.2" + +react@18.3.1: + version "18.3.1" + resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891" + integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ== + dependencies: + loose-envify "^1.1.0" + +scheduler@^0.23.2: + version "0.23.2" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.2.tgz#414ba64a3b282892e944cf2108ecc078d115cdc3" + integrity sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ== + dependencies: + loose-envify "^1.1.0" + +typescript@5.4.5, typescript@^5, typescript@^5.4: + version "5.4.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" + integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== diff --git a/packages/one-version/__tests__/one-version.test.mjs b/packages/one-version/__tests__/one-version.test.mjs index e8a4b71..8d4ffc8 100644 --- a/packages/one-version/__tests__/one-version.test.mjs +++ b/packages/one-version/__tests__/one-version.test.mjs @@ -1,10 +1,7 @@ import assert from "node:assert"; -import { exec as execCallback } from "node:child_process"; -import { promises as fsPromises } from "node:fs"; import path from "node:path"; -import { after, before, describe, test } from "node:test"; +import { describe, test } from "node:test"; import { fileURLToPath } from "node:url"; -import { promisify } from "node:util"; import { start } from "../one-version.mjs"; describe("one-version", () => { @@ -15,160 +12,180 @@ describe("one-version", () => { logs.push(args.join(" ")); }, }; - await start({ rootDirectory: process.cwd(), logger, args: ["help"] }); + let { statusCode } = await start({ rootDirectory: process.cwd(), logger, args: ["help"] }); + + assert.equal(statusCode, 0); assert.match(logs[0], /one-version/); }); -}); -let exec = promisify(execCallback); + test("bails on unknown commands", async () => { + let logs = []; + const logger = { + log: (...args) => { + logs.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: process.cwd(), logger, args: [] }); + + assert.equal(statusCode, 1); + + assert.match(logs[0], /Unknown command:/); + }); +}); let __filename = fileURLToPath(import.meta.url); let __dirname = path.dirname(__filename); describe("one-version integration tests", () => { - // setup - // copy the `__fixtures__/template-monorepo` into the following directories - // - `__fixtures__/npm` - // - `__fixtures__/pnpm` - // - `__fixtures__/yarn-classic` - // - `__fixtures__/yarn-berry` - // - `__fixtures__/bun` - // - `__fixtures__/missing` - before(async () => { - let fixturesDir = path.join(__dirname, "..", "__fixtures__"); - let templateDir = path.join(fixturesDir, "template-monorepo"); - let targetDirs = [ - "npm", - "pnpm", - "yarn-classic", - "yarn-berry", - "bun", - "missing", - ]; - - async function copyDirectory(src, dest) { - // Create the destination directory if it doesn't exist - await fsPromises.mkdir(dest, { recursive: true }); - - // Read all files and subdirectories from the source directory - let entries = await fsPromises.readdir(src, { withFileTypes: true }); - - // Copy each file and directory recursively - for (let entry of entries) { - let srcPath = path.join(src, entry.name); - let destPath = path.join(dest, entry.name); - - if (entry.isDirectory()) { - await copyDirectory(srcPath, destPath); - } else { - await fsPromises.copyFile(srcPath, destPath); - } - } - } - - let lockFile = { - npm: "package-lock.json", - pnpm: "pnpm-lock.yaml", - "yarn-classic": "yarn.lock", - "yarn-berry": "yarn.lock", - bun: "bun.lock", + test("bun", async () => { + const targetDir = path.join(__dirname, "..", "__fixtures__", "bun"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); - for (const dir of targetDirs) { - const targetDir = path.join(fixturesDir, dir); - try { - await copyDirectory(templateDir, targetDir); - if (dir !== "missing") { - await fsPromises.writeFile(lockFile[dir], ""); - } - if (dir === "yarn-berry") { - await fsPromises.writeFile(".yarnrc.yml", "nodeLinker: node-modules"); - } - if (dir === "pnpm") { - await fsPromises.writeFile("pnpm-workspace.yaml", "packages: ['libs/*']\n"); - } - } catch (err) { - throw err; - } - } - }); - - after(async () => { - const fixturesDir = path.join(__dirname, "..", "__fixtures__"); - const targetDirs = [ - "npm", - "pnpm", - "yarn-classic", - "yarn-berry", - "bun", - "missing", - ]; - - async function removeDirectory(dir) { - try { - await fsPromises.rm(dir, { recursive: true, force: true }); - } catch (err) { - throw err; - } - } - - for (const dir of targetDirs) { - const targetDir = path.join(fixturesDir, dir); - await removeDirectory(targetDir); - } + // should fail - mismatch of typescript dependencies + assert.equal(statusCode, 1); + assert.match(errors[0], /More than one version of dependencies found. See above output/); + // single log line with multiple new-lines + assert.match(logs[0], /One Version Rule Failure/); + assert.match(logs[0], /typescript/); }); test("npm", async () => { const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); - let exitStatus; - function exit(exitCode) { - exitStatus = exitCode; - } - await start({ rootDirectory: targetDir, logger: console, args: ["check"], exit }); - // let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); - // let versions = JSON.parse(stdout); - // assert.equal(versions.length, 1); - // assert.equal(versions[0].name, "one-version"); - }); - test("pnpm", async () => { - const targetDir = path.join(__dirname, "..", "__fixtures__", "pnpm"); - await start({ rootDirectory: targetDir, logger: console }); - // let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); - // let versions = JSON.parse(stdout); - // assert.equal(versions.length, 1); - // assert.equal(versions[0].name, "one-version"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); + + // should fail - mismatch of typescript dependencies + assert.equal(statusCode, 1); + assert.match(errors[0], /More than one version of dependencies found. See above output/); + // single log line with multiple new-lines + assert.match(logs[0], /One Version Rule Failure/); + assert.match(logs[0], /typescript/); }); + test("yarn-classic", async () => { - const targetDir = path.join(__dirname, "..", "__fixtures__", "yarn"); - await start({ rootDirectory: targetDir, logger: console }); - // let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); - // let versions = JSON.parse(stdout); - // assert.equal(versions.length, 1); - // assert.equal(versions[0].name, "one-version"); + const targetDir = path.join(__dirname, "..", "__fixtures__", "yarn-classic"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); + + // should fail - mismatch of typescript dependencies + assert.equal(statusCode, 1); + assert.match(errors[0], /More than one version of dependencies found. See above output/); + // single log line with multiple new-lines + assert.match(logs[0], /One Version Rule Failure/); + assert.match(logs[0], /typescript/); }); + test("yarn-berry", async () => { const targetDir = path.join(__dirname, "..", "__fixtures__", "yarn-berry"); - await start({ rootDirectory: targetDir, logger: console }); - // let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); - // let versions = JSON.parse(stdout); - // assert.equal(versions.length, 1); - // assert.equal(versions[0].name, "one-version"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); + + // should fail - mismatch of typescript dependencies + assert.equal(statusCode, 1); + assert.match(errors[0], /More than one version of dependencies found. See above output/); + // single log line with multiple new-lines + assert.match(logs[0], /One Version Rule Failure/); + assert.match(logs[0], /typescript/); }); - test("bun", async () => { - const targetDir = path.join(__dirname, "..", "__fixtures__", "bun"); - await start({ rootDirectory: targetDir, logger: console }); - // let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); - // let versions = JSON.parse(stdout); - // assert.equal(versions.length, 1); - // assert.equal(versions[0].name, "one-version"); + + test("pnpm", async () => { + const targetDir = path.join(__dirname, "..", "__fixtures__", "pnpm"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); + + // should fail - mismatch of typescript dependencies + assert.equal(statusCode, 1); + assert.match(errors[0], /More than one version of dependencies found. See above output/); + // single log line with multiple new-lines + assert.match(logs[0], /One Version Rule Failure/); + assert.match(logs[0], /typescript/); }); + test("missing", async () => { const targetDir = path.join(__dirname, "..", "__fixtures__", "missing"); - await start({ rootDirectory: targetDir, logger: console }); - // let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); - // let versions = JSON.parse(stdout); - // assert.equal(versions.length, 1); - // assert.equal(versions[0].name, "one-version"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); + + // should fail - mismatch of typescript dependencies + assert.equal(statusCode, 1); + assert.match(errors[0], /Could not infer package manager!/); + }); + + test("bun - configured and allowed", async () => { + const targetDir = path.join(__dirname, "..", "__fixtures__", "bun-configured"); + let logs = []; + let errors = []; + let logger = { + log(...args) { + logs.push(args.join(" ")); + }, + error(...args) { + errors.push(args.join(" ")); + }, + }; + let { statusCode } = await start({ rootDirectory: targetDir, logger, args: ["check"] }); + + // should pass - configured overrides for typescript dependency + assert.equal(statusCode, 0); + + assert.equal(errors.length, 0); + // single log line with multiple new-lines + assert.match(logs[0], /One Version Rule Success/); }); }); diff --git a/packages/one-version/one-version.mjs b/packages/one-version/one-version.mjs index f27c0db..cbac510 100644 --- a/packages/one-version/one-version.mjs +++ b/packages/one-version/one-version.mjs @@ -61,7 +61,6 @@ function inferPackageManager({ rootDirectory }) { if (existsSync(pathJoin(rootDirectory, "bun.lockb"))) { return "bun"; } - throw new Error("Could not infer package manager! Please specify one in the config file."); } // MARK: Get Workspaces @@ -78,7 +77,7 @@ function inferPackageManager({ rootDirectory }) { function getWorkspaces({ rootDirectory, packageManager }) { switch (packageManager) { case "pnpm": { - let stdout = exec("pnpm list -r --json --depth -1", { encoding: "utf8" }); + let stdout = exec("pnpm list -r --json --depth -1", { cwd: rootDirectory, encoding: "utf8" }).trim(); /** * @type {Array<{ * name: string; @@ -92,6 +91,14 @@ function getWorkspaces({ rootDirectory, packageManager }) { return workspaces; } case "yarn-classic": { + // Silent still prints out some character escape sequences at the beginning that `trim` / `trimStart` doesn't remove + // Passing `--json` changes the output to be a stringified object of: `log` and `data` + // where `data` is a stringified object of workspace names and their dependencies + let stdout = exec("yarn --silent --json workspaces info", { + cwd: rootDirectory, + encoding: "utf8", + }).trim(); + let output = JSON.parse(stdout); /** * @type {{ * [name: string]: { @@ -101,10 +108,7 @@ function getWorkspaces({ rootDirectory, packageManager }) { * } * }} */ - let stdout = exec("yarn --silent workspaces info", { - encoding: "utf8", - }); - let workspaces = JSON.parse(stdout); + let workspaces = JSON.parse(output.data); // Yarn Classic does not include the root package. let rootPackageJSONPath = path.join(rootDirectory, "package.json"); let rootPackageJSON = JSON.parse(readFileSync(rootPackageJSONPath, { encoding: "utf8" })); @@ -112,7 +116,7 @@ function getWorkspaces({ rootDirectory, packageManager }) { return [ { name: rootPackageJSON.name, - path: rootPackageJSONPath, + path: rootDirectory, }, ...Object.entries(workspaces).map(([name, { location }]) => ({ name, @@ -123,10 +127,11 @@ function getWorkspaces({ rootDirectory, packageManager }) { case "yarn-berry": { // http://ndjson.org/ let ndJSONWorkspaces = exec("yarn workspaces list --json", { + cwd: rootDirectory, encoding: "utf8", }); - if (ndJSONWorkspaces != "") { + if (ndJSONWorkspaces !== "") { /** * @type {Array<{ * name: string; @@ -247,7 +252,7 @@ function getDuplicateDependencies({ workspaceDependencies, overrides }) { { name: consumerName, dependencies, peerDependencies, devDependencies }, ) => { if (dependencies) { - Object.entries(dependencies).forEach(([packageName, version]) => { + for (let [packageName, version] of Object.entries(dependencies)) { let seenConsumers = acc[packageName]?.[version]?.direct || []; let versionConsumers = seenConsumers.concat(consumerName); acc[packageName] = { @@ -257,10 +262,10 @@ function getDuplicateDependencies({ workspaceDependencies, overrides }) { direct: versionConsumers, }, }; - }); + } } if (peerDependencies) { - Object.entries(peerDependencies).forEach(([packageName, version]) => { + for (let [packageName, version] of Object.entries(peerDependencies)) { let seenConsumers = acc[packageName]?.[version]?.peer || []; let versionConsumers = seenConsumers.concat(consumerName); acc[packageName] = { @@ -270,10 +275,10 @@ function getDuplicateDependencies({ workspaceDependencies, overrides }) { peer: versionConsumers, }, }; - }); + } } if (devDependencies) { - Object.entries(devDependencies).forEach(([packageName, version]) => { + for (let [packageName, version] of Object.entries(devDependencies)) { let seenConsumers = acc[packageName]?.[version]?.dev || []; let versionConsumers = seenConsumers.concat(consumerName); acc[packageName] = { @@ -283,7 +288,7 @@ function getDuplicateDependencies({ workspaceDependencies, overrides }) { dev: versionConsumers, }, }; - }); + } } return acc; }, {}); @@ -345,11 +350,8 @@ let DOUBLE_INDENT = SINGLE_INDENT * 2; * direct: mock-app-b */ function getVersionString(version, dependencyTypeStrings) { - return ( - version.padStart(SINGLE_INDENT + version.length) - + "\n" - + dependencyTypeStrings.join("\n") - ); + return `${version.padStart(SINGLE_INDENT + version.length)} +${dependencyTypeStrings.join("\n")}`; } /** @@ -359,7 +361,7 @@ function getVersionString(version, dependencyTypeStrings) { */ function getTypeString({ type, names }) { const padded = type.padStart(DOUBLE_INDENT + type.length); - return `${padded}: ` + names.join(", "); + return `${padded}: ${names.join(", ")}`; } function prettify(packages) { @@ -404,7 +406,14 @@ export async function start({ rootDirectory, logger, args, exit }) { case "check": { let initialConfig = loadConfig({ rootDirectory }); if (!initialConfig.packageManager) { - initialConfig.packageManager = inferPackageManager({ rootDirectory }); + let inferredPackageManager = inferPackageManager({ rootDirectory }); + if (typeof inferredPackageManager !== "string") { + logger.error("Could not infer package manager! Please specify one in the config file."); + return Promise.resolve({ + statusCode: 1, + }); + } + initialConfig.packageManager = inferredPackageManager; } debug("Initial config", JSON.stringify(initialConfig, null, 2)); let workspaces = getWorkspaces({ rootDirectory, packageManager: initialConfig.packageManager }); diff --git a/packages/one-version/package.json b/packages/one-version/package.json index c0c5e5a..be29a62 100644 --- a/packages/one-version/package.json +++ b/packages/one-version/package.json @@ -1,10 +1,17 @@ { "name": "one-version", - "version": "0.0.1", + "version": "0.1.0", "description": "A strict dependency conformance tool for (mono)repos!", "bin": { "one-version": "./bin/index.mjs" }, + "files": [ + "bin", + "one-version.mjs", + "utils", + "README.md", + "CHANGELOG.md" + ], "type": "module", "devDependencies": { "@biomejs/biome": "1.6.3",