Skip to content
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

Add dependenciesMeta.*.injected: true to test-app #107

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions src/pnpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs/promises');
const path = require('path');
const fse = require('fs-extra');

/**
* @typedef {import('./types').AddonInfo} AddonInfo
Expand All @@ -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,
},
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never written back to the file, isn't it?

Also, we already have a place to extend the file here, maybe we can handle this in one place?

}

module.exports = {
createWorkspacesFile,
handleImperfections,
};