-
-
Notifications
You must be signed in to change notification settings - Fork 239
feat: add limited support for devEngines
#643
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b36c7f0
feat: add limited support for `devEngines`
aduh95 073440e
Update error message
aduh95 e9f6adf
change throw into warn
aduh95 6754521
increase coverage and improve error path
aduh95 b25cc77
Merge branch 'main' into dev-engines-part1
aduh95 32cca55
fix test when version is a URL
aduh95 8a53d7d
add limited support for `onFail`
aduh95 21f9fec
docs
aduh95 a86f6d3
Merge branch 'main'
aduh95 54be297
doc what happens when only `devEngines` is defined
aduh95 bf09e9a
fix tests
aduh95 b5c28a8
increase coverage
aduh95 8994e0a
clarify return value is `pm`
aduh95 81419f3
Update error message
aduh95 b6e8a4f
Update sources/commands/Base.ts
aduh95 c982089
Merge branch 'main' into dev-engines-part1
aduh95 e28e3c0
Add more tests for `corepack up` and `corepack use`
aduh95 573b688
validate range in `corepack use`
aduh95 a952550
Merge branch 'main' into dev-engines-part1
aduh95 32407e7
fixup
aduh95 f761471
fixup
aduh95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -113,6 +113,35 @@ use in the archive). | |
| } | ||
| ``` | ||
|
|
||
| #### `devEngines.packageManager` | ||
|
|
||
| When a `devEngines.packageManager` field is defined, and is an object containing | ||
| a `"name"` field (can also optionally contain `version` and `onFail` fields), | ||
| Corepack will use it to validate you're using a compatible package manager. | ||
|
|
||
| Depending on the value of `devEngines.packageManager.onFail`: | ||
|
|
||
| - if set to `ignore`, Corepack won't print any warning or error. | ||
| - if unset or set to `error`, Corepack will throw an error in case of a mismatch. | ||
| - if set to `warn` or some other value, Corepack will print a warning in case | ||
| of mismatch. | ||
|
|
||
| If the top-level `packageManager` field is missing, Corepack will use the | ||
| package manager defined in `devEngines.packageManager` – in which case you must | ||
| provide a specific version in `devEngines.packageManager.version`, ideally with | ||
| a hash, as explained in the previous section: | ||
|
|
||
| ```json | ||
| { | ||
| "devEngines":{ | ||
| "packageManager": { | ||
| "name": "yarn", | ||
| "version": "3.2.3+sha224.953c8233f7a92884eee2de69a1b92d1f2ec1655e66d08071ba9a02fa" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Known Good Releases | ||
|
|
||
| When running Corepack within projects that don't list a supported package | ||
|
|
@@ -246,6 +275,7 @@ it. | |
|
|
||
| Unlike `corepack use` this command doesn't take a package manager name nor a | ||
| version range, as it will always select the latest available version from the | ||
| range specified in `devEngines.packageManager.version`, or fallback to the | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about top-level
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what |
||
| same major line. Should you need to upgrade to a new major, use an explicit | ||
| `corepack use {name}@latest` call (or simply `corepack use {name}`). | ||
|
|
||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,24 +11,83 @@ beforeEach(async () => { | |
| }); | ||
|
|
||
| describe(`UpCommand`, () => { | ||
| it(`should upgrade the package manager from the current project`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json`), { | ||
| packageManager: `[email protected]`, | ||
| }); | ||
| describe(`should update the "packageManager" field from the current project`, () => { | ||
| it(`to the same major if no devEngines range`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json`), { | ||
| packageManager: `[email protected]`, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`up`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stderr: ``, | ||
| }); | ||
|
|
||
| await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({ | ||
| packageManager: `[email protected]+sha512.8dd9fedc5451829619e526c56f42609ad88ae4776d9d3f9456d578ac085115c0c2f0fb02bb7d57fd2e1b6e1ac96efba35e80a20a056668f61c96934f67694fd0`, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`up`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stderr: ``, | ||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stdout: `2.4.3\n`, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it(`to whichever range devEngines defines`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json`), { | ||
| packageManager: `[email protected]`, | ||
| devEngines: { | ||
| packageManager: { | ||
| name: `yarn`, | ||
| version: `1.x || 2.x`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`up`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stderr: ``, | ||
| }); | ||
|
|
||
| await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({ | ||
| packageManager: `[email protected]+sha512.8dd9fedc5451829619e526c56f42609ad88ae4776d9d3f9456d578ac085115c0c2f0fb02bb7d57fd2e1b6e1ac96efba35e80a20a056668f61c96934f67694fd0`, | ||
| await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({ | ||
| packageManager: `[email protected]+sha512.8dd9fedc5451829619e526c56f42609ad88ae4776d9d3f9456d578ac085115c0c2f0fb02bb7d57fd2e1b6e1ac96efba35e80a20a056668f61c96934f67694fd0`, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stdout: `2.4.3\n`, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it(`to whichever range devEngines defines even if onFail is set to ignore`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json`), { | ||
| packageManager: `[email protected]`, | ||
| devEngines: { | ||
| packageManager: { | ||
| name: `yarn`, | ||
| version: `1.x || 2.x`, | ||
| onFail: `ignore`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`up`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stderr: ``, | ||
| }); | ||
|
|
||
| await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({ | ||
| packageManager: `[email protected]+sha512.8dd9fedc5451829619e526c56f42609ad88ae4776d9d3f9456d578ac085115c0c2f0fb02bb7d57fd2e1b6e1ac96efba35e80a20a056668f61c96934f67694fd0`, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stdout: `2.4.3\n`, | ||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stdout: `2.4.3\n`, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the first sentence of this section.
Because it sounds like this
devEngines.packageManageris ignored when there is a top levelpackageManager, right?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's never ignored. As said in the first paragraph of this section, if it is defined to something Corepack recognises, it will throw/warn/do nothing (depending of the value of
onFail) if the user is trying to use an incompatible package manager (i.e. if the one defined inpackage.json#packageManagerdoes not match the one defined inpackage.json#devEngines.packageManagerfor when the user is using a Corepack shim)