Skip to content

Commit

Permalink
fix getPackages for pnpm globs
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Dec 6, 2023
1 parent db4ad86 commit 2e6f980
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 24 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions src/interdep.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
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 {
version: string;
pkgJSONPath: string;
isDependencyOf: Map<string, Range>;
isPeerDependencyOf: Map<string, Range>;
pkg: any;
}

export function publishedInterPackageDeps(): Map<string, PkgEntry> {
const rootDir = './';
export function getPackages(rootDir: string): Map<string, PkgEntry> {
const packages: Map<string, PkgEntry> = new Map();

function loadPackage(packagePath: string) {
const pkg = readJSONSync(packagePath);
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<string, any> = 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);

for (const location of locations) {
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<string, PkgEntry> {
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) {
Expand Down

0 comments on commit 2e6f980

Please sign in to comment.