diff --git a/index.js b/index.js index c8f519de..07670035 100644 --- a/index.js +++ b/index.js @@ -77,6 +77,7 @@ module.exports = { if (options.pnpm) { tasks.push(pnpm.createWorkspacesFile(options.target, addonInfo, testAppInfo)); + tasks.push(pnpm.handleImperfections(addonInfo, testAppInfo)); } if (options.releaseIt) { diff --git a/src/pnpm.js b/src/pnpm.js index 01e96f86..05f740d3 100644 --- a/src/pnpm.js +++ b/src/pnpm.js @@ -2,6 +2,7 @@ const fs = require('fs/promises'); const path = require('path'); +const fse = require('fs-extra'); /** * @typedef {import('./types').AddonInfo} AddonInfo @@ -19,6 +20,32 @@ async function createWorkspacesFile(targetPath, addonInfo, testAppInfo) { await fs.writeFile(path.join(targetPath, 'pnpm-workspace.yaml'), content); } +/** + * + * @param {AddonInfo} addonInfo + * @param {TestAppInfo} testAppInfo + */ +async function handleImperfections(addonInfo, testAppInfo) { + /** + * https://github.com/pnpm/pnpm/issues/4965#issuecomment-1405264290 + * + * for dependencies in a monorepo, AND when peerDependencies need to be resolved correctly, + * the dependencies must use `dependenciesMeta.*.injected: true`, + * + * more info here: + * https://pnpm.io/package_json#dependenciesmetainjected + */ + let testAppPackageJsonPath = path.join(testAppInfo.location, 'package.json'); + let testAppPackageJson = await fse.readJSON(testAppPackageJsonPath); + + testAppPackageJson.dependenciesMeta = { + [addonInfo.name.dashed]: { + injected: true, + }, + }; +} + module.exports = { createWorkspacesFile, + handleImperfections, };