-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Changes from 1 commit
b36c7f0
073440e
e9f6adf
6754521
b25cc77
32cca55
8a53d7d
21f9fec
a86f6d3
54be297
bf09e9a
b5c28a8
8994e0a
81419f3
b6e8a4f
c982089
e28e3c0
573b688
a952550
32407e7
f761471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,16 +16,33 @@ beforeEach(async () => { | |
| process.env.COREPACK_DEFAULT_TO_LATEST = `0`; | ||
| }); | ||
|
|
||
| it(`should refuse to download a package manager if the hash doesn't match`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
| packageManager: `yarn@1.22.4+sha1.deadbeef`, | ||
| describe(`should refuse to download a package manager if the hash doesn't match`, () => { | ||
| it(`the one defined in "devEngines.packageManager" field`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
| devEngines: { | ||
| packageManager: {name: `yarn`, version: `1.22.4+sha1.deadbeef`}, | ||
|
aduh95 marked this conversation as resolved.
|
||
| }, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 1, | ||
| stderr: expect.stringContaining(`Mismatch hashes`), | ||
| stdout: ``, | ||
| }); | ||
| }); | ||
| }); | ||
| it(`the one defined in "packageManager" field`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
| packageManager: `yarn@1.22.4+sha1.deadbeef`, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 1, | ||
| stderr: /Mismatch hashes/, | ||
| stdout: ``, | ||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 1, | ||
| stderr: expect.stringContaining(`Mismatch hashes`), | ||
| stdout: ``, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
@@ -150,6 +167,16 @@ for (const [name, version, expectedVersion = version.split(`+`, 1)[0]] of tested | |
| stderr: ``, | ||
| stdout: `${expectedVersion}\n`, | ||
| }); | ||
|
|
||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
| devEngines: {packageManager: {name, version}}, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [name, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stderr: ``, | ||
| stdout: `${expectedVersion}\n`, | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
|
|
@@ -231,6 +258,82 @@ it(`should ignore the packageManager field when found within a node_modules vend | |
| }); | ||
| }); | ||
|
|
||
| it(`should use hash from "packageManager" even when "devEngines" defines a different one`, async () => { | ||
|
aduh95 marked this conversation as resolved.
|
||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as PortablePath), { | ||
| packageManager: `yarn@3.0.0-rc.2+sha1.11111`, | ||
| devEngines: { | ||
| packageManager: { | ||
| name: `yarn`, | ||
| version: `3.0.0-rc.2+sha1.22222`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 1, | ||
| stderr: expect.stringContaining(`Mismatch hashes. Expected 11111, got`), | ||
| stdout: ``, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe(`should accept range in devEngines only if a specific version is provided`, () => { | ||
|
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. This behavior breaks existing projects which only define a range in |
||
| it(`either in package.json#packageManager field`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as PortablePath), { | ||
| devEngines: { | ||
| packageManager: { | ||
| name: `pnpm`, | ||
| version: `6.x`, | ||
| }, | ||
| }, | ||
| }); | ||
| await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 1, | ||
| stderr: `Invalid package manager specification in package.json (pnpm@6.x); expected a semver version\n`, | ||
| stdout: ``, | ||
| }); | ||
|
|
||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as PortablePath), { | ||
| devEngines: { | ||
| packageManager: { | ||
| name: `pnpm`, | ||
| version: `6.x`, | ||
| }, | ||
| }, | ||
| packageManager: `pnpm@6.6.2+sha224.eb5c0acad3b0f40ecdaa2db9aa5a73134ad256e17e22d1419a2ab073`, | ||
| }); | ||
| await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 0, | ||
| stderr: ``, | ||
| stdout: `6.6.2\n`, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe(`should reject if range in devEngines does not match version provided`, () => { | ||
| it(`in package.json#packageManager field`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as PortablePath), { | ||
| devEngines: { | ||
| packageManager: { | ||
| name: `pnpm`, | ||
| version: `10.x`, | ||
| }, | ||
| }, | ||
| packageManager: `pnpm@6.6.2+sha1.7b4d6b176c1b93b5670ed94c24babb7d80c13854`, | ||
| }); | ||
| await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ | ||
| exitCode: 1, | ||
| stderr: `"packageManager" field is set to "pnpm@6.6.2+sha1.7b4d6b176c1b93b5670ed94c24babb7d80c13854" which does not match the value defined in "devEngines.packageManager" for "pnpm" of "10.x"\n`, | ||
| stdout: ``, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it(`should use the closest matching packageManager field`, async () => { | ||
| await xfs.mktempPromise(async cwd => { | ||
| await xfs.mkdirPromise(ppath.join(cwd, `foo` as PortablePath), {recursive: true}); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.