-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add "latest" flag to "yarn upgrade" #3510
Changes from 2 commits
02e0477
c48806c
89fa8d4
5d79e03
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 |
---|---|---|
|
@@ -102,6 +102,70 @@ test.concurrent('upgrades from fixed version to latest', (): Promise<void> => { | |
}); | ||
}); | ||
|
||
test.concurrent('upgrades to latest matching package.json semver when no package name passed', (): Promise<void> => { | ||
return runUpgrade([], {}, 'range-to-latest', async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
const lockEntryIndex = lockfile.indexOf('left-pad@<=1.1.1:'); | ||
|
||
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.1'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '<=1.1.1'}); | ||
}); | ||
}); | ||
|
||
test.concurrent('--latest upgrades to latest ignoring package.json when no package name passed', (): Promise<void> => { | ||
return runUpgrade([], {latest: true}, 'range-to-latest', async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
const lockEntryIndex = lockfile.indexOf('left-pad@^1.1.3:'); | ||
|
||
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile.indexOf('left-pad@<=1.1.1:')).toEqual(-1); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.3'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '^1.1.3'}); | ||
}); | ||
}); | ||
|
||
test.concurrent('upgrades to latest matching semver when package name passed with version', (): Promise<void> => { | ||
return runUpgrade(['left-pad@~1.1.2'], {}, 'range-to-latest', async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
const lockEntryIndex = lockfile.indexOf('left-pad@~1.1.2:'); | ||
|
||
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.3'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '~1.1.2'}); | ||
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. You can use |
||
}); | ||
}); | ||
|
||
test.concurrent('--latest upgrades to passed in version when package name passed with version', (): Promise<void> => { | ||
return runUpgrade(['left-pad@1.1.2'], {latest: true}, 'range-to-latest', async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
const lockEntryIndex = lockfile.indexOf('left-pad@1.1.2:'); | ||
|
||
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile.indexOf('left-pad@<=1.1.1:')).toEqual(-1); | ||
expect(lockfile.indexOf('left-pad@^1.1.3:')).toEqual(-1); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.2'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '1.1.2'}); | ||
}); | ||
}); | ||
|
||
test.concurrent('upgrades to latest ignoring package.json semver when package name passed', (): Promise<void> => { | ||
return runUpgrade(['left-pad'], {}, 'range-to-latest', async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
const lockEntryIndex = lockfile.indexOf('left-pad@^1.1.3:'); | ||
|
||
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile.indexOf('left-pad@<=1.1.1:')).toEqual(-1); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.3'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '^1.1.3'}); | ||
}); | ||
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 doesn't feel right ... shouldn't we have to pass the 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 test actually passes in current Yarn without my modifications (in other words, this is how Yarn has worked for a while). This is testing the command There is some discussion around that confusing behavior in 3384 3266 3204 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. I just re-read my comment and decided it's confusing... In clearer terms, the way Yarn 0.24 - 0.26 all work currently is that if your package.json is:
Then I didn't change that behavior.
There is currently, and with this PR, still no way to 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. Yep, you're right. I feel like this should be considered as a bug ... otherwise there's no way to upgrade a specific package inside its allowed boundaries :/ can you open a separate PR where we could discuss this? 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. I spawned #3603 as a discussion issue and added you as an assignee. |
||
}); | ||
|
||
test.concurrent('upgrades dependency packages not in registry', (): Promise<void> => { | ||
const packages = ['yarn-test-git-repo', 'e2e-test-repo']; | ||
return runUpgrade(packages, {}, 'package-not-in-registry', async (config): ?Promise<void> => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ export function setFlags(commander: Object) { | |
// TODO: support some flags that install command has | ||
commander.usage('upgrade [flags]'); | ||
commander.option('-S, --scope <scope>', 'upgrade packages under the specified scope'); | ||
commander.option('-L, --latest', 'upgrade packages to the latest version, ignoring version ranges in package.json'); | ||
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. do we really need the 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. OK, was just following the convention of the other flags. I'll remove that |
||
} | ||
|
||
export function hasWrapper(): boolean { | ||
|
@@ -20,7 +21,8 @@ export function hasWrapper(): boolean { | |
export const requireLockfile = true; | ||
|
||
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> { | ||
const lockfile = args.length ? await Lockfile.fromDirectory(config.cwd, reporter) : new Lockfile(); | ||
const useLockfile = args.length || flags.latest; | ||
const lockfile = useLockfile ? await Lockfile.fromDirectory(config.cwd, reporter) : new Lockfile(); | ||
const { | ||
dependencies, | ||
devDependencies, | ||
|
@@ -50,6 +52,11 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |
} else { | ||
throw new MessageError(reporter.lang('scopeNotValid')); | ||
} | ||
} else if (flags.latest && args.length === 0) { | ||
addArgs = Object.keys(allDependencies) | ||
.map(dependency => { | ||
return getDependency(allDependencies, dependency); | ||
}); | ||
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. nit: you don't need the curly braces and the return here. |
||
} else { | ||
addArgs = args.map(dependency => { | ||
return getDependency(allDependencies, dependency); | ||
|
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.
You shouldn't use
left-pad
for this test, otherwise it will break if they release a new version. I think you can useyarn-test
(cc @kittens ?)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.
Hmm, I actually thought the packages used during tests were all loaded from the 'offline mirror' directory of
__tests__/fixtures/request-cache/...
but it does like like just the left-pad tgz files are in there, not the metadata. So all these tests are actually resolving real metadata? that seems fragile...I needed a package that had enough diverse version numbers to cover all these upgrade cases, and left-pad was the first one I found that worked.
Is there someplace I can see what version of
yarn-test
exist?(side-note, it might be useful to document how these tests actually work and should be constructed, for new developers who want to contribute. It took me a while the first time I needed to add one.)
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.
Think so. That's why our tests practically never completely pass: we always end up timeouting at least one of them 😞 Probably should fix this at some point! I thought maybe we could set up some sort of fake registry with only the few endpoints required, that would extract its data from a repository local folder.
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.
We can discuss this in #3455
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.
The metadata for
left-pad
is taken from the__tests__/fixtures/request-cache/
directory, so a new version pushed to the live registry would not break the test. These tests actually pass with no internet connection.