Skip to content

Commit d99a8b4

Browse files
committed
fix(core): revert changes made to the Manifest by set version
1 parent e19690a commit d99a8b4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/acceptance-tests/pkg-tests-specs/sources/protocols/git.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,21 @@ describe(`Protocols`, () => {
246246
},
247247
),
248248
);
249+
250+
test(
251+
`it should not add a 'packageManager' field to a Yarn classic project`,
252+
makeTemporaryEnv(
253+
{
254+
dependencies: {
255+
[`yarn-1-project`]: startPackageServer().then(url => `${url}/repositories/yarn-1-project.git`),
256+
},
257+
},
258+
async ({path, run, source}) => {
259+
await expect(run(`install`)).resolves.toBeTruthy();
260+
261+
await expect(source(`require('yarn-1-project/package.json').packageManager`)).resolves.toBeUndefined();
262+
},
263+
),
264+
);
249265
});
250266
});

packages/yarnpkg-core/sources/scriptUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,20 @@ export async function prepareExternalProject(cwd: PortablePath, outputPath: Port
250250
? [`workspace`, workspace]
251251
: [];
252252

253+
// `set version` will update the Manifest to contain a `packageManager` field with the latest
254+
// Yarn version which causes the results to change depending on when this command was run,
255+
// therefore we revert any change made to it.
256+
const manifestPath = ppath.join(cwd, Filename.manifest);
257+
const manifestBuffer = await xfs.readFilePromise(manifestPath);
258+
253259
// Makes sure that we'll be using Yarn 1.x
254260
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});
255261
if (version.code !== 0)
256262
return version.code;
257263

264+
// Revert any changes made to the Manifest by `set version`.
265+
await xfs.writeFilePromise(manifestPath, manifestBuffer);
266+
258267
// Otherwise Yarn 1 will pack the .yarn directory :(
259268
await xfs.appendFilePromise(ppath.join(cwd, `.npmignore` as PortablePath), `/.yarn\n`);
260269

0 commit comments

Comments
 (0)