From 2e6f98030254527c9031c6ee1339fb1ab22b4d91 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Wed, 6 Dec 2023 18:27:03 +0000 Subject: [PATCH] fix getPackages for pnpm globs --- package.json | 1 - pnpm-lock.yaml | 27 ++++++++++++++++++++++++--- src/interdep.ts | 48 ++++++++++++++++++++++++------------------------ 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 8030f30..b6e9eae 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "cli-highlight": "^2.1.11", "execa": "^4.0.3", "fs-extra": "^10.0.0", - "globby": "^11.0.3", "js-yaml": "^4.1.0", "latest-version": "^5.0.0", "parse-github-repo-url": "^1.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7be2136..61040e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ dependencies: fs-extra: specifier: ^10.0.0 version: 10.1.0 - globby: - specifier: ^11.0.3 - version: 11.1.0 js-yaml: specifier: ^4.1.0 version: 4.1.0 @@ -408,10 +405,12 @@ packages: dependencies: '@nodelib/fs.stat': 2.0.5 run-parallel: 1.2.0 + dev: true /@nodelib/fs.stat@2.0.5: resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} engines: {node: '>= 8'} + dev: true /@nodelib/fs.walk@1.2.8: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} @@ -419,6 +418,7 @@ packages: dependencies: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 + dev: true /@npmcli/fs@1.1.1: resolution: {integrity: sha512-8KG5RD0GVP4ydEzRn/I4BNDuxDtqVbOdm8675T49OIG/NGhaK0pjPX7ZcDlvKYbA+ulvVK3ztfcF4uBdOxuJbQ==} @@ -1047,6 +1047,7 @@ packages: /array-union@2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} + dev: true /assert-never@1.2.1: resolution: {integrity: sha512-TaTivMB6pYI1kXwrFlEhLeGfOqoDNdTxjCdwRfFFkEA30Eu+k48W34nlok2EYWJfFFzqaEmichdNM7th6M5HNw==} @@ -1092,6 +1093,7 @@ packages: engines: {node: '>=8'} dependencies: fill-range: 7.0.1 + dev: true /builtin-modules@3.3.0: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} @@ -1326,6 +1328,7 @@ packages: engines: {node: '>=8'} dependencies: path-type: 4.0.0 + dev: true /doctrine@3.0.0: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} @@ -1647,6 +1650,7 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 + dev: true /fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -1660,6 +1664,7 @@ packages: resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} dependencies: reusify: 1.0.4 + dev: true /file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} @@ -1673,6 +1678,7 @@ packages: engines: {node: '>=8'} dependencies: to-regex-range: 5.0.1 + dev: true /find-up@5.0.0: resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} @@ -1776,6 +1782,7 @@ packages: engines: {node: '>= 6'} dependencies: is-glob: 4.0.3 + dev: true /glob-parent@6.0.2: resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==} @@ -1823,6 +1830,7 @@ packages: ignore: 5.3.0 merge2: 1.4.1 slash: 3.0.0 + dev: true /got@9.6.0: resolution: {integrity: sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==} @@ -1941,6 +1949,7 @@ packages: /ignore@5.3.0: resolution: {integrity: sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==} engines: {node: '>= 4'} + dev: true /import-fresh@3.3.0: resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==} @@ -2007,6 +2016,7 @@ packages: /is-extglob@2.1.1: resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} engines: {node: '>=0.10.0'} + dev: true /is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} @@ -2018,6 +2028,7 @@ packages: engines: {node: '>=0.10.0'} dependencies: is-extglob: 2.1.1 + dev: true /is-inside-container@1.0.0: resolution: {integrity: sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==} @@ -2034,6 +2045,7 @@ packages: /is-number@7.0.0: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} + dev: true /is-path-inside@3.0.3: resolution: {integrity: sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==} @@ -2228,6 +2240,7 @@ packages: /merge2@1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} + dev: true /micromatch@4.0.5: resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} @@ -2235,6 +2248,7 @@ packages: dependencies: braces: 3.0.2 picomatch: 2.3.1 + dev: true /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} @@ -2600,6 +2614,7 @@ packages: /path-type@4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} + dev: true /pathe@1.1.1: resolution: {integrity: sha512-d+RQGp0MAYTIaDBIMmOfMwz3E+LOZnxx1HZd5R18mmCZY0QBlK0LDZfPc8FW8Ed2DlvsuE6PRjroDY+wg4+j/Q==} @@ -2616,6 +2631,7 @@ packages: /picomatch@2.3.1: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + dev: true /pkg-types@1.0.3: resolution: {integrity: sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==} @@ -2707,6 +2723,7 @@ packages: /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} + dev: true /rc@1.2.8: resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==} @@ -2773,6 +2790,7 @@ packages: /reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + dev: true /rimraf@3.0.2: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} @@ -2811,6 +2829,7 @@ packages: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: queue-microtask: 1.2.3 + dev: true /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -2854,6 +2873,7 @@ packages: /slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} + dev: true /smart-buffer@4.2.0: resolution: {integrity: sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==} @@ -3054,6 +3074,7 @@ packages: engines: {node: '>=8.0'} dependencies: is-number: 7.0.0 + dev: true /tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} diff --git a/src/interdep.ts b/src/interdep.ts index a1fe0f3..5513db3 100644 --- a/src/interdep.ts +++ b/src/interdep.ts @@ -1,10 +1,8 @@ -import glob from 'globby'; -import { resolve, relative } from 'path'; +import { resolve, relative, join } from 'path'; import fsExtra from 'fs-extra'; -import yaml from 'js-yaml'; import execa from 'execa'; -const { readFileSync, readJSONSync, existsSync } = fsExtra; +const { readJSONSync, existsSync } = fsExtra; export type Range = `workspace:${string}`; export interface PkgEntry { @@ -12,10 +10,10 @@ export interface PkgEntry { pkgJSONPath: string; isDependencyOf: Map; isPeerDependencyOf: Map; + pkg: any; } -export function publishedInterPackageDeps(): Map { - const rootDir = './'; +export function getPackages(rootDir: string): Map { const packages: Map = new Map(); function loadPackage(packagePath: string) { @@ -23,19 +21,18 @@ export function publishedInterPackageDeps(): Map { if (pkg.private) { return; } - pkgJSONS.set(pkg.name, pkg); + packages.set(pkg.name, { version: pkg.version, pkgJSONPath: `./${relative('.', packagePath)}`, isDependencyOf: new Map(), isPeerDependencyOf: new Map(), + pkg, }); } - const pkgJSONS: Map = new Map(); - - if (!existsSync('./pnpm-workspace.yaml')) { - const result = execa.sync('npm', ['query', '.workspace']); + if (!existsSync(join(rootDir, './pnpm-workspace.yaml'))) { + const result = execa.sync('npm', ['query', '.workspace'], { cwd: rootDir }); const resultParsed = JSON.parse(result.stdout); const locations = resultParsed.map((i: any) => i.location); @@ -43,22 +40,25 @@ export function publishedInterPackageDeps(): Map { loadPackage(resolve(location, 'package.json')); } - loadPackage('./package.json'); + loadPackage(join(rootDir, './package.json')); } else { - for (const pattern of ( - yaml.load(readFileSync('./pnpm-workspace.yaml', 'utf8')) as any - ).packages) { - for (const dir of glob.sync(pattern, { - cwd: rootDir, - expandDirectories: false, - onlyDirectories: true, - })) { - loadPackage(resolve(rootDir, dir, 'package.json')); - } - } + const result = execa.sync(`pnpm`, ['m', 'ls', '--json', '--depth=-1'], { + cwd: rootDir, + }); + const workspaceJson = JSON.parse(result.stdout); + + workspaceJson + .filter((item: any) => item.name && item.path) + .forEach((item: any) => loadPackage(join(item.path, 'package.json'))); } + return packages; +} + +export function publishedInterPackageDeps(): Map { + const packages = getPackages('./'); - for (const [consumerName, consumerPkgJSON] of pkgJSONS) { + for (const [consumerName, packageDefinition] of packages) { + const consumerPkgJSON = packageDefinition.pkg; // no devDeps because changes to devDeps shouldn't ever force us to // release for (const section of ['dependencies', 'peerDependencies'] as const) {