Skip to content
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 packageDateLimit option to only-install package version that have release date before the specified one #8395

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
095a8b6
Makes the CLI 2 forwarding stricter (#7931)
arcanis Feb 24, 2020
344d24c
Prevents exiting the process on sigint through yarn-path (#7957)
arcanis Mar 6, 2020
4d6f909
v1.22.1
arcanis Mar 6, 2020
35286b9
Fixes empty yarnrc files
arcanis Mar 7, 2020
460e0ee
v1.22.2
arcanis Mar 7, 2020
4456237
Tweaks tests to pass
arcanis Mar 7, 2020
3fe6ef5
Tweaks tests to pass
arcanis Mar 7, 2020
92a539c
v1.22.3
arcanis Mar 7, 2020
88e30b0
More tweaks
arcanis Mar 9, 2020
e5327c5
v1.22.4
arcanis Mar 9, 2020
69f154b
Add `--package-date-limit` option to only-install package version tha…
nthachus Aug 14, 2020
9fd9771
Install `lowestVersion` when `packageDateLimit` was specified outside…
nthachus Aug 24, 2020
1f5524c
fix(pack): sort files to produce identical output on Windows and Unix…
merceyz May 21, 2020
8c1e278
Store local yarn versions as .cjs files (#8145)
bgotink May 25, 2020
cf4e1d3
Spawn yarn .cjs files also using process.execPath (#8144)
bgotink May 25, 2020
acda92a
Don't print headers with yarn init -2
arcanis Aug 27, 2020
a3b963c
v1.22.5
arcanis Aug 27, 2020
7ea37b8
Adds a preinstall script (#8343)
arcanis Sep 26, 2020
a538e26
pmm -> corepack
arcanis Sep 26, 2020
41bf3f1
Makes the policy install silent with -2
arcanis Sep 27, 2020
53be704
Bumps the version
arcanis Sep 28, 2020
b4f5243
Bumps the version
arcanis Sep 28, 2020
7b255fd
Makes the script tolerant to failures
arcanis Sep 28, 2020
f8803d1
Bumps version
arcanis Sep 28, 2020
7fa00f4
Avoids file descriptors altogether
arcanis Sep 28, 2020
f7a900b
Bumps version
arcanis Sep 28, 2020
9f975ac
Fixes for sh
arcanis Sep 28, 2020
785cda8
Bumps version
arcanis Sep 28, 2020
40e7d1e
Merge from version `1.22.4-0`:
nthachus Oct 14, 2020
6580c8e
Merge remote-tracking branch 'upstream/master'
nthachus Oct 14, 2020
d3c8c97
Merge remote-tracking branch 'upstream/1.22-stable' into 1.22-stable
nthachus Oct 14, 2020
e6500db
Correct unit tests for CircleCI
nthachus Oct 14, 2020
663a153
Fix error on CircleCI `test-pkg-tests-linux-node12` with node <12.18.3
nthachus Oct 15, 2020
5be09c3
Merge branch '1.22-stable' to fix CircleCI errors
nthachus Oct 15, 2020
14d3f9b
Fix `info` unit test errors because the latest `yarn` (v1.22.10) cont…
nthachus Oct 16, 2020
64d8508
Increase `jasmine` timeout to fix `index` unit tests
nthachus Oct 18, 2020
469dfd0
Merge remote-tracking branch 'upstream/master'
thachnn Aug 7, 2022
2d244eb
Merge remote-tracking branch 'upstream/master'
thachnn Mar 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -130,7 +130,7 @@ jobs:
test-pkg-tests-linux-node12:
<<: *docker_defaults
docker:
- image: node:12
- image: node:12.18.2
<<: *pkg_tests
test-pkg-tests-linux-node10:
<<: *docker_defaults
Expand Down
1 change: 1 addition & 0 deletions __tests__/commands/_helpers.js
Expand Up @@ -98,6 +98,7 @@ export function makeConfigFromDirectory(cwd: string, reporter: Reporter, flags:
enableDefaultRc: !flags.noDefaultRc,
extraneousYarnrcFiles: flags.useYarnrc,
modulesFolder: flags.modulesFolder ? path.join(cwd, flags.modulesFolder) : undefined,
packageDateLimit: flags.packageDateLimit,
},
reporter,
);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/info.js
Expand Up @@ -44,7 +44,7 @@ const expectedKeys = [
];

// yarn now ships as built, single JS files so it has no dependencies and no scripts
const unexpectedKeys = ['dependencies', 'devDependencies', 'scripts'];
const unexpectedKeys = ['dependencies', 'devDependencies']; // 'scripts' removed from v1.23

beforeEach(() => {
// the mocked requests have stripped metadata, don't use it in the following tests
Expand Down
17 changes: 17 additions & 0 deletions __tests__/commands/install/package-date-limit.js
@@ -0,0 +1,17 @@
/* @flow */

import {getPackageVersion, runInstall} from '../_helpers.js';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

test.concurrent('installing with --package-date-limit should install the specified version of a package', () => {
return runInstall({packageDateLimit: '2018-05-01T00:00:00.000Z'}, 'install-by-package-date-limit', async config => {
expect(await getPackageVersion(config, 'trough')).toEqual('1.0.2');
});
});

test.concurrent('installing without --package-date-limit should install the latest version of a package', () => {
return runInstall({}, 'install-by-package-date-limit', async config => {
expect(await getPackageVersion(config, 'trough')).toEqual('1.0.4');
});
});
@@ -0,0 +1,5 @@
{
"dependencies": {
"trough": ">1.0.0 <1.0.5"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion __tests__/index.js
Expand Up @@ -16,7 +16,7 @@ const semver = require('semver');
let ver = process.versions.node;
ver = ver.split('-')[0];

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;

if (!existsSync(path.resolve(__dirname, '../lib'))) {
throw new Error('These tests require `yarn build` to have been run first.');
Expand Down
6 changes: 5 additions & 1 deletion __tests__/integration.js
Expand Up @@ -70,7 +70,11 @@ addTest('https://github.com/bestander/chrome-app-livereload.git'); // no package
addTest('bestander/chrome-app-livereload'); // no package.json, github, tarball

if (process.platform !== 'win32') {
addTest('https://github.com/yarnpkg/yarn/releases/download/v0.18.1/yarn-v0.18.1.tar.gz'); // tarball
addTest(
'https://github.com/yarnpkg/yarn/releases/download/v0.18.1/yarn-v0.18.1.tar.gz', // tarball
{strictPeers: false},
['--no-node-version-check', '--ignore-engines'],
);
addTest('react-scripts@1.0.13', {strictPeers: true}, ['--no-node-version-check', '--ignore-engines']); // many peer dependencies, there shouldn't be any peerDep warnings
}

Expand Down
3 changes: 3 additions & 0 deletions packages/pkg-tests/package.json
Expand Up @@ -27,6 +27,9 @@
"jest": {
"modulePathIgnorePatterns": [
"<rootDir>/pkg-tests-fixtures/packages/"
],
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!pkg-tests-)"
]
}
}
2 changes: 1 addition & 1 deletion packages/pkg-tests/pkg-tests-specs/sources/pnp.js
Expand Up @@ -1438,7 +1438,7 @@ module.exports = makeTemporaryEnv => {
makeTemporaryEnv(
{
dependencies: {
[`resolve`]: `https://github.com/browserify/resolve.git`,
[`resolve`]: `https://github.com/browserify/resolve.git#v1.16.1`,
},
resolutions: {
[`path-parse`]: `https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz`,
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/config.js
Expand Up @@ -38,6 +38,7 @@ const CONFIG_KEYS = [
'cacheFolder',
'tempFolder',
'production',
'packageDateLimit',
];

export function hasWrapper(flags: Object, args: Array<string>): boolean {
Expand Down
2 changes: 2 additions & 0 deletions src/cli/index.js
Expand Up @@ -135,6 +135,7 @@ export async function main({
commander.option('--no-node-version-check', 'do not warn when using a potentially unsupported Node version');
commander.option('--focus', 'Focus on a single workspace by installing remote copies of its sibling workspaces.');
commander.option('--otp <otpcode>', 'one-time password for two factor authentication');
commander.option('--package-date-limit <time>', 'only install package version that have release date before this');

// if -v is the first command, then always exit after returning the version
if (args[0] === '-v') {
Expand Down Expand Up @@ -554,6 +555,7 @@ export async function main({
updateChecksums: commander.updateChecksums,
focus: commander.focus,
otp: commander.otp,
packageDateLimit: commander.packageDateLimit,
})
.then(() => {
// lockfile check must happen after config.init sets lockfileFolder
Expand Down
4 changes: 4 additions & 0 deletions src/config.js
Expand Up @@ -70,6 +70,7 @@ export type ConfigOptions = {
focus?: boolean,

otp?: string,
packageDateLimit?: ?string,
};

type PackageMetadata = {
Expand Down Expand Up @@ -205,6 +206,7 @@ export default class Config {
autoAddIntegrity: boolean;

otp: ?string;
packageDateLimit: ?string;

/**
* Execute a promise produced by factory if it doesn't exist in our cache with
Expand Down Expand Up @@ -344,6 +346,8 @@ export default class Config {
networkTimeout: this.networkTimeout,
});

this.packageDateLimit = opts.packageDateLimit || String(this.getOption('package-date-limit') || '') || null;

this.globalFolder = opts.globalFolder || String(this.getOption('global-folder', true));
if (this.globalFolder === 'undefined') {
this.globalFolder = constants.GLOBAL_MODULE_DIRECTORY;
Expand Down
22 changes: 21 additions & 1 deletion src/resolvers/registries/npm-resolver.js
Expand Up @@ -24,6 +24,7 @@ type RegistryResponse = {
name: string,
versions: {[key: string]: Manifest},
'dist-tags': {[key: string]: string},
time?: ?{[key: string]: ?string},
};

export default class NpmResolver extends RegistryResolver {
Expand All @@ -48,6 +49,25 @@ export default class NpmResolver extends RegistryResolver {
range = body['dist-tags'][range];
}

// Only install package version that have release date before a specified one.
// That date string must match JSON format, e.g. 2020-08-14T04:47:38.210Z
if (config.packageDateLimit && body.time) {
const releaseDates = body.time;
let closestVersion = null;
(semver: Object).rsort(Object.keys(body.versions)).some(v => {
if (releaseDates[v] && semver.satisfies(v, range)) {
closestVersion = v;
if (releaseDates[v] < config.packageDateLimit) {
return true;
}
}
return false;
});
if (closestVersion) {
return body.versions[closestVersion];
}
}

// If the latest tag in the registry satisfies the requested range, then use that.
// Otherwise we will fall back to semver maxSatisfying.
// This mimics logic in NPM. See issue #3560
Expand Down Expand Up @@ -94,7 +114,7 @@ export default class NpmResolver extends RegistryResolver {

const escapedName = NpmRegistry.escapeName(this.name);
const desiredRange = desiredVersion || this.range;
const body = await this.config.registries.npm.request(escapedName);
const body = await this.config.registries.npm.request(escapedName, {unfiltered: !!this.config.packageDateLimit});

if (body) {
return NpmResolver.findVersionInRegistryResponse(this.config, escapedName, desiredRange, body, this.request);
Expand Down