Reputation: 4656
I have two packages "app" and "lib". "app" depends on "lib" with the workspace protocol as below
{
"dependencies": {
"lib": "workspaces:*"
}
}
I know that when I execute "pnpm -r publish" the version part can be replaced with the real one, for example "lib": "^1.0.0"
.
But in my case, I don't want to publish "app" package, just copy source code and run it something like node app/index.js
. This means I cannot use "pnpm publish".
Is it possible to manually trigger the workspace replacement manually?
Upvotes: 2
Views: 872
Reputation: 4656
OK after dig into the source code of pnpm
I found a solution. Thanks to the monorepo pnpm
provided :)
pnpm add -wD @pnpm/exportable-manifest @pnpm/read-project-manifest
scripts/create-exportable-manifest.ts
, copy the content below.import { createExportableManifest } from "@pnpm/exportable-manifest";
import { readProjectManifestOnly } from "@pnpm/read-project-manifest";
import { writeFile } from "fs/promises";
(async () => {
const projectDir = "packages/app"; // folder of "package.json" to be translated
const distDir = "packages/app/dist"; // folder to save the translated one
const manifest = await readProjectManifestOnly(projectDir);
const exportable = await createExportableManifest(projectDir, manifest);
await writeFile(`${distDir}/package.json`, JSON.stringify(exportable, undefined, 2));
})().then(() => { }).catch(console.error);
{
"scripts": {
// ...
"build": "pnpm -r build && ts-node scripts/create-exportable-manifest.ts"
}
}
distDir
which should be translated.Hope this helps,
Upvotes: 2