-
Notifications
You must be signed in to change notification settings - Fork 70
pnpm: "catalog:" is not supported #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you so much for reporting this! have you tried |
I used |
I will have a look, thanks! |
Hmm, do you have any reproduction or a repo? I want to see what kind of workspace pkg.pr.new should adapt to. |
The code is not public but here's how the relevant files look. pnpm-workspace.yaml
packages/core {
"name": "",
"version": "0.28.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"style": "dist/index.css",
"dependencies": {
"@baseline-ui/core": "workspace:*",
"@baseline-ui/utils": "workspace:*",
"@react-aria/interactions": "catalog:",
"@react-aria/utils": "catalog:",
"@react-spring/web": "^9.7.4",
},
"peerDependencies": {
"react": "^17.0.2 || ^18.0.0",
"react-dom": "^17.0.2 || ^18.0.0"
},
}
I was able to resolve this by running a script that replaces all occurences of #!/usr/bin/env ts-node
import { pick } from "lodash";
import fs from "node:fs/promises";
import path from "node:path";
import yaml from "yaml";
// This script removes the catalog from the dependencies of the packages in the monorepo.
// Temporary workaround for https://github.com/stackblitz-labs/pkg.pr.new/issues/204
void (async function () {
const pnpmWorkspace = await fs.readFile(
path.resolve(__dirname, "./pnpm-workspace.yaml"),
);
const catalog = yaml.parse(pnpmWorkspace.toString("utf8")).catalog;
const packagesName = await fs.readdir(path.resolve(__dirname, "./packages"));
const packages = packagesName.map((dir) =>
path.resolve(__dirname, `./packages/${dir}`),
);
for (const package_ of packages) {
const packageJson = await fs.readFile(
path.resolve(package_, "package.json"),
);
const packageJsonObj = JSON.parse(packageJson.toString("utf8"));
const dependencies = packageJsonObj.dependencies || {};
packageJsonObj.dependencies = {
...dependencies,
...pick(catalog, Object.keys(dependencies)),
};
const devDependencies = packageJsonObj.devDependencies || {};
packageJsonObj.devDependencies = {
...devDependencies,
...pick(catalog, Object.keys(devDependencies)),
};
await fs.writeFile(
path.resolve(package_, "package.json"),
JSON.stringify(packageJsonObj, null, 2),
);
}
})(); |
I can confirm this is also an issue in UnoCSS - see unocss/unocss#4122 for description and reproduction. We are also using the |
Interesting, now I'm thinking, how does pnpm handles catalogs? Does it handle catalogs in Since pkg.pr.new uses cc @zkochan out of curiosity! |
The docs indicate both |
Oh nice catch, yea, since we use pnpm pack, it should be handled but there might be a bug there? I think it'd be good to reproduce without pkg.pr.new and see if it's an actual bug in pnpm itself. |
Based on the following comment, using `pnpm` should resolve the workspace:*protocol correctly. Let's try it. stackblitz-labs/pkg.pr.new#204 (comment)
@ritz078 can you please confirm that using We also have an in-house patch to replace all |
here is our full script that includes a import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from "node:path";
import readYamlFile from 'read-yaml-file';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
let pnpmCatalog;
async function fixPackageJsonCatalogEntries(packageJsonPath) {
if (!pnpmCatalog) {
const pnpmWorkspaceYaml = await readYamlFile(path.resolve(__dirname, "../pnpm-workspace.yaml"));
pnpmCatalog = pnpmWorkspaceYaml.catalog;
}
const packageJsonRaw = await fs.promises.readFile(packageJsonPath, 'utf8');
const packageJsonObj = JSON.parse(packageJsonRaw);
for (const depObjKey of ['dependencies', 'devDependencies', 'peerDependencies']) {
const depObj = packageJsonObj[depObjKey];
if (!depObj) continue;
for (const depName of Object.keys(depObj)) {
if (depObj[depName] === 'catalog:') {
const catalogVersion = pnpmCatalog[depName];
if (!catalogVersion) throw new Error('Missing pnpm catalog version for ' + depName);
depObj[depName] = catalogVersion;
} else if (depObj[depName].startsWith('catalog:')) {
throw new Error('multiple named catalogs not supported');
}
}
}
await fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJsonObj, null, 2));
}
let err;
try {
const workspacePackagesInfoRaw = execSync('pnpm m ls --json --depth=-1');
const workspacePackagesInfo = JSON.parse(workspacePackagesInfoRaw);
// generate summary of changed (publishable) modules according to changesets
// only has option to output to a file
execSync('pnpm exec changeset status --output=changesets-summary.json');
const changeSetsSummaryRaw = fs.readFileSync('./changesets-summary.json', 'utf8');
const changeSetsSummary = JSON.parse(changeSetsSummaryRaw);
// console.log(changeSetsSummary);
if (!changeSetsSummary.releases.length) {
console.log('No preview packages to release!');
process.exit(0);
}
const releasePackagePaths = changeSetsSummary.releases
.filter((r) => r.newVersion !== r.oldVersion)
.map((r) => workspacePackagesInfo.find((p) => p.name === r.name))
.map((p) => p.path);
// Temporary workaround for https://github.com/stackblitz-labs/pkg.pr.new/issues/204
console.log('replacing pnpm `catalog:*` deps');
for (const releasePackagePath of releasePackagePaths) {
await fixPackageJsonCatalogEntries(path.join(releasePackagePath, 'package.json'))
}
const publishResult = execSync(`pnpm dlx pkg-pr-new publish --compact --pnpm ${releasePackagePaths.join(' ')}`);
console.log('published preview packages!')
console.log(publishResult);
} catch (_err) {
err = _err;
console.error('preview release failed');
console.error(_err);
}
fs.unlinkSync('./changesets-summary.json');
process.exit(err ? 1 : 0); |
a while ago, i heard it was working well with catalogs using the --pnpm flag! but thank you so much for the workaround, i appreciate! |
Works for me when I added the Edit: Here's the exact command I'm using pnpx pkg-pr-new publish --compact --pnpm './packages/*' |
same here. By the way, make sure to place the --pnpm flag after the publish argument, or else it won't work (took me a good few hours to notice that 😂). |
thank you so much y'all! i was worried about this issue. let's close it then. |
Replace custom publishConfig expansion and manual build step with the built-in --pnpm flag in pkg-pr-new, simplifying the workflow and reducing potential errors. stackblitz-labs/pkg.pr.new#204
The catalog: protocol is a new feature that is not supported by this app yet. https://pnpm.io/catalogs
The text was updated successfully, but these errors were encountered: