-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer using exclusively Corepack when possible (#4254)
* Uses exclusively Corepack by default * Fixes tests * Implements --yarn-path * Updates documentation * Fixes types * Fixes types * Uses yarnPath by default if Corepack isnt enabled * Adds tests * Reverts parts of the changes * Fixes broken plugin tests * Fixes windows set version from file * Fixes merge conflicts
- Loading branch information
Showing
7 changed files
with
278 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
releases: | ||
"@yarnpkg/cli": major | ||
"@yarnpkg/plugin-essentials": major | ||
|
||
declined: | ||
- "@yarnpkg/plugin-compat" | ||
- "@yarnpkg/plugin-constraints" | ||
- "@yarnpkg/plugin-dlx" | ||
- "@yarnpkg/plugin-init" | ||
- "@yarnpkg/plugin-interactive-tools" | ||
- "@yarnpkg/plugin-nm" | ||
- "@yarnpkg/plugin-npm-cli" | ||
- "@yarnpkg/plugin-pack" | ||
- "@yarnpkg/plugin-patch" | ||
- "@yarnpkg/plugin-pnp" | ||
- "@yarnpkg/plugin-pnpm" | ||
- "@yarnpkg/plugin-stage" | ||
- "@yarnpkg/plugin-typescript" | ||
- "@yarnpkg/plugin-version" | ||
- "@yarnpkg/plugin-workspace-tools" | ||
- "@yarnpkg/builder" | ||
- "@yarnpkg/core" | ||
- "@yarnpkg/doctor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
packages/acceptance-tests/pkg-tests-specs/sources/commands/set/version.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import {xfs, ppath, PortablePath, Filename} from '@yarnpkg/fslib'; | ||
|
||
const yarnrcRegexp = /^yarnPath:/; | ||
|
||
describe(`Commands`, () => { | ||
describe(`set version`, () => { | ||
test( | ||
`it shouldn't set yarnPath if corepack is enabled and the version is semver`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: `/path/to/corepack`}, | ||
}, async ({path, run, source}) => { | ||
await run(`set`, `version`, `3.0.0`); | ||
await check(path, {corepackVersion: `3.0.0`, usePath: false}); | ||
}), | ||
); | ||
|
||
test( | ||
`it should set yarnPath if corepack is disabled, even when the version is semver`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: undefined}, | ||
}, async ({path, run, source}) => { | ||
await run(`set`, `version`, `3.0.0`); | ||
await check(path, {corepackVersion: `3.0.0`, usePath: true}); | ||
}), | ||
); | ||
|
||
test( | ||
`it should always set yarnPath if one already exists`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: `/path/to/corepack`}, | ||
}, async ({path, run, source}) => { | ||
// To force yarnPath to be set; followed by a sanity check | ||
await run(`set`, `version`, `3.0.0`, {env: {COREPACK_ROOT: undefined}}); | ||
await check(path, {corepackVersion: `3.0.0`, usePath: true}); | ||
|
||
await run(`set`, `version`, `3.0.0`); | ||
await check(path, {corepackVersion: `3.0.0`, usePath: true}); | ||
}), | ||
); | ||
|
||
test( | ||
`it should always set yarnPath if --yarn-path is set`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: `/path/to/corepack`}, | ||
}, async ({path, run, source}) => { | ||
await run(`set`, `version`, `3.0.0`, `--yarn-path`); | ||
await check(path, {corepackVersion: `3.0.0`, usePath: true}); | ||
}), | ||
); | ||
|
||
test( | ||
`it should never set yarnPath if --no-yarn-path is set`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: undefined}, | ||
}, async ({path, run, source}) => { | ||
await run(`set`, `version`, `3.0.0`, `--no-yarn-path`); | ||
await check(path, {corepackVersion: `3.0.0`, usePath: false}); | ||
}), | ||
); | ||
|
||
test( | ||
`it should prevent using --no-yarn-path with arbitrary files`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: undefined}, | ||
}, async ({path, run, source}) => { | ||
const yarnIndirection = ppath.join(path, `custom-yarn.cjs` as Filename); | ||
await xfs.writeFilePromise(yarnIndirection, ``); | ||
|
||
await expect(run(`set`, `version`, yarnIndirection, `--no-yarn-path`)).rejects.toThrow(); | ||
}), | ||
); | ||
|
||
test( | ||
`it should set yarnPath if the version is an arbitrary file`, | ||
makeTemporaryEnv({}, { | ||
env: {COREPACK_ROOT: undefined}, | ||
}, async ({path, run, source}) => { | ||
const yarnIndirection = ppath.join(path, `custom-yarn.cjs` as Filename); | ||
await xfs.writeFilePromise(yarnIndirection, ``); | ||
|
||
await run(`set`, `version`, yarnIndirection); | ||
await check(path, {corepackVersion: /[0-9]+\./, usePath: true}); | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
async function check(path: PortablePath, checks: {corepackVersion: string | RegExp, usePath: boolean}) { | ||
const releasesPath = ppath.join(path, `.yarn/releases` as PortablePath); | ||
const yarnrcPath = ppath.join(path, Filename.rc); | ||
const manifestPath = ppath.join(path, Filename.manifest); | ||
|
||
let releases: Array<string> | null; | ||
try { | ||
releases = await xfs.readdirPromise(releasesPath); | ||
} catch (err) { | ||
if (err.code === `ENOENT`) { | ||
releases = null; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
|
||
let yarnrcFile; | ||
try { | ||
yarnrcFile = await xfs.readFilePromise(yarnrcPath, `utf8`); | ||
} catch (err) { | ||
if (err.code === `ENOENT`) { | ||
yarnrcFile = ``; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
|
||
if (checks.usePath) | ||
expect(releases).toHaveLength(1); | ||
else | ||
expect(releases).toEqual(null); | ||
|
||
if (checks.usePath) | ||
expect(yarnrcFile).toMatch(yarnrcRegexp); | ||
else | ||
expect(yarnrcFile).not.toMatch(yarnrcRegexp); | ||
|
||
await expect(xfs.readJsonPromise(manifestPath)).resolves.toMatchObject({ | ||
packageManager: checks.corepackVersion instanceof RegExp | ||
? expect.stringMatching(`yarn@${checks.corepackVersion.source}`) | ||
: `yarn@${checks.corepackVersion}`, | ||
}); | ||
} |
Oops, something went wrong.