Skip to content

Commit

Permalink
fix(core): revert changes made to the Manifest by set version
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jul 27, 2022
1 parent e19690a commit d99a8b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,21 @@ describe(`Protocols`, () => {
},
),
);

test(
`it should not add a 'packageManager' field to a Yarn classic project`,
makeTemporaryEnv(
{
dependencies: {
[`yarn-1-project`]: startPackageServer().then(url => `${url}/repositories/yarn-1-project.git`),
},
},
async ({path, run, source}) => {
await expect(run(`install`)).resolves.toBeTruthy();

await expect(source(`require('yarn-1-project/package.json').packageManager`)).resolves.toBeUndefined();
},
),
);
});
});
9 changes: 9 additions & 0 deletions packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,20 @@ export async function prepareExternalProject(cwd: PortablePath, outputPath: Port
? [`workspace`, workspace]
: [];

// `set version` will update the Manifest to contain a `packageManager` field with the latest
// Yarn version which causes the results to change depending on when this command was run,
// therefore we revert any change made to it.
const manifestPath = ppath.join(cwd, Filename.manifest);
const manifestBuffer = await xfs.readFilePromise(manifestPath);

// Makes sure that we'll be using Yarn 1.x
const version = await execUtils.pipevp(process.execPath, [process.argv[1], `set`, `version`, `classic`, `--only-if-needed`], {cwd, env, stdin, stdout, stderr, end: execUtils.EndStrategy.ErrorCode});
if (version.code !== 0)
return version.code;

// Revert any changes made to the Manifest by `set version`.
await xfs.writeFilePromise(manifestPath, manifestBuffer);

// Otherwise Yarn 1 will pack the .yarn directory :(
await xfs.appendFilePromise(ppath.join(cwd, `.npmignore` as PortablePath), `/.yarn\n`);

Expand Down

0 comments on commit d99a8b4

Please sign in to comment.