Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hashicorp/js-releases

Package Overview
Dependencies
Maintainers
28
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hashicorp/js-releases - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

jest.config.js

19

CHANGELOG.md

@@ -0,1 +1,20 @@

# 1.6.1 (2022-07-22)
BUG FIXES:
* Fix error on picking latest vault releases by @markmartirosian in https://github.com/hashicorp/js-releases/pull/56
INTERNAL:
* Migrate test from mocha to jest by @dbanck in https://github.com/hashicorp/js-releases/pull/58
* Bump prettier from 2.6.2 to 2.7.1 by @dependabot in https://github.com/hashicorp/js-releases/pull/54
* Bump @types/semver from 7.3.9 to 7.3.10 by @dependabot in https://github.com/hashicorp/js-releases/pull/55
* Bump typescript from 4.6.3 to 4.7.4 by @dependabot in https://github.com/hashicorp/js-releases/pull/57
* Bump @types/jest from 28.1.4 to 28.1.5 by @dependabot in https://github.com/hashicorp/js-releases/pull/59
* Bump @types/node from 14.18.21 to 14.18.22 by @dependabot in https://github.com/hashicorp/js-releases/pull/62
* Bump jest from 28.1.2 to 28.1.3 by @dependabot in https://github.com/hashicorp/js-releases/pull/60
* Bump ts-jest from 28.0.5 to 28.0.6 by @dependabot in https://github.com/hashicorp/js-releases/pull/61
* Bump ts-jest from 28.0.6 to 28.0.7 by @dependabot in https://github.com/hashicorp/js-releases/pull/63
* Bump @types/jest from 28.1.5 to 28.1.6 by @dependabot in https://github.com/hashicorp/js-releases/pull/64
# 1.6.0 (2022-06-14)

@@ -2,0 +21,0 @@

@@ -20,3 +20,18 @@ interface Build {

}
export interface ResponseVersion {
builds: {
arch: string;
filename: string;
name: string;
os: string;
url: string;
version: string;
}[];
name: string;
shasums: string;
shasums_signature: string;
shasums_signatures: string[];
version: string;
}
export declare function getRelease(product: string, version?: string, userAgent?: string, includePrerelease?: boolean): Promise<Release>;
export {};

16

out/index.js

@@ -259,13 +259,13 @@ "use strict";

const response = yield (0, utils_1.request)(indexUrl, { headers });
let release;
const versions = Object.assign({}, ...Object.keys(response.versions)
.filter((key) => semver.valid(key) !== null)
.map((key) => ({ [key]: response.versions[key] })));
if (!validVersion) {
// pick the latest release (prereleases will be skipped for safety, set an explicit version instead)
const releaseVersions = Object.keys(response.versions).filter((v) => !semver.prerelease(v));
version = releaseVersions.sort((a, b) => semver.rcompare(a, b))[0];
release = new Release(response.versions[version]);
const releaseVersion = Object.keys(versions)
.filter((v) => !semver.prerelease(v))
.sort((a, b) => semver.rcompare(a, b))[0];
return new Release(versions[releaseVersion]);
}
else {
release = matchVersion(response.versions, validVersion, includePrerelease);
}
return release;
return matchVersion(versions, validVersion, includePrerelease);
});

@@ -272,0 +272,0 @@ }

@@ -17,5 +17,6 @@ "use strict";

const index_1 = require("./index");
const utils = require("./utils");
describe('LS installer', () => {
let release;
before(() => {
beforeAll(() => {
release = new index_1.Release({

@@ -59,4 +60,84 @@ name: 'terraform-ls',

});
})).timeout(20 * 1000); // increase timeout for file download
}), 20 * 1000);
});
describe('getRelease', () => {
const name = 'vault';
it('should return latest releases when called without a version', () => __awaiter(void 0, void 0, void 0, function* () {
const request = jest.spyOn(utils, 'request').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
return ({
name,
versions: {
'0.11.0': { name, version: '0.11.0' },
'1.5.0': { name, version: '1.5.0' },
'1.2.7': { name, version: '1.2.7' },
},
});
}));
const release = yield (0, index_1.getRelease)(name);
expect(request).toHaveBeenCalledWith('https://releases.hashicorp.com/vault/index.json', { headers: null });
expect(request).toHaveBeenCalledTimes(1);
expect(release).toBeInstanceOf(index_1.Release);
expect(release.name).toBe(name);
expect(release.version).toBe('1.5.0');
}));
it('should return the matching version', () => __awaiter(void 0, void 0, void 0, function* () {
jest.spyOn(utils, 'request').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
return ({
name,
versions: {
'0.11.0': { name, version: '0.11.0' },
'1.2.7': { name, version: '1.2.7' },
'1.5.0': { name, version: '1.5.0' },
},
});
}));
const version = '1.2.7';
const release = yield (0, index_1.getRelease)(name, version);
expect(release).toBeInstanceOf(index_1.Release);
expect(release.name).toBe(name);
expect(release.version).toBe(version);
}));
it('should throw if no version is found', () => __awaiter(void 0, void 0, void 0, function* () {
jest.spyOn(utils, 'request').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
return ({
name,
versions: {},
});
}));
const version = '1.2.7';
yield expect((0, index_1.getRelease)(name, version)).rejects.toThrow('No matching version found');
}));
it('should filter invalid versions', () => __awaiter(void 0, void 0, void 0, function* () {
jest.spyOn(utils, 'request').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
return ({
name,
versions: {
'1.2.6.1+ent': { name, version: '1.2.6.1+ent' },
'1.2.7': { name, version: '1.2.7' },
'1.5.0': { name, version: '1.5.0' },
'1.6.6.1+ent': { name, version: '1.6.6.1+ent' },
},
});
}));
const release = yield (0, index_1.getRelease)(name);
expect(release).toBeInstanceOf(index_1.Release);
expect(release.name).toBe(name);
expect(release.version).toBe('1.5.0');
}));
it('should return latest if passed an invalid version', () => __awaiter(void 0, void 0, void 0, function* () {
jest.spyOn(utils, 'request').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
return ({
name,
versions: {
'1.2.7': { name, version: '1.2.7' },
'1.6.0': { name, version: '1.6.0' },
},
});
}));
const release = yield (0, index_1.getRelease)(name, '1.6.6.1+ent');
expect(release).toBeInstanceOf(index_1.Release);
expect(release.name).toBe(name);
expect(release.version).toBe('1.6.0');
}));
});
//# sourceMappingURL=index.test.js.map
{
"name": "@hashicorp/js-releases",
"version": "1.6.0",
"version": "1.6.1",
"description": "Download packages from releases.hashicorp.com",

@@ -10,3 +10,3 @@ "main": "./out/index.js",

"watch": "tsc -b -w",
"test": "mocha",
"test": "jest",
"prepare": "npm run-script test && npm run-script compile",

@@ -28,3 +28,2 @@ "prettier": "prettier \"**/*.+(js|json|ts)\"",

"dependencies": {
"@types/semver": "^7.3.1",
"axios": "^0.25.0",

@@ -37,8 +36,10 @@ "https-proxy-agent": "^5.0.1",

"devDependencies": {
"@types/mocha": "^9.1.0",
"@types/jest": "^28.1.4",
"@types/node": "^14.18.10",
"@types/semver": "^7.3.1",
"@types/yauzl": "^2.9.2",
"mocha": "^9.2.0",
"jest": "^28.1.2",
"prettier": "^2.5.1",
"tempy": "^1.0.1",
"ts-jest": "^28.0.5",
"ts-node": "^9.1.1",

@@ -45,0 +46,0 @@ "typescript": "^4.2.4"

@@ -6,3 +6,4 @@ import * as assert from 'assert';

import { Release } from './index';
import { getRelease, Release } from './index';
import * as utils from './utils';

@@ -12,3 +13,3 @@ describe('LS installer', () => {

before(() => {
beforeAll(() => {
release = new Release({

@@ -48,14 +49,103 @@ name: 'terraform-ls',

it('should download the release', async () => {
const build = release.getBuild('darwin', 'amd64');
const tmpDir = tempy.directory();
const zipFile = path.resolve(tmpDir, `terraform-ls_v${release.version}.zip`);
it(
'should download the release',
async () => {
const build = release.getBuild('darwin', 'amd64');
const tmpDir = tempy.directory();
const zipFile = path.resolve(tmpDir, `terraform-ls_v${release.version}.zip`);
await release.download(build.url, zipFile, 'js-releases/mocha-test');
await release.verify(zipFile, build.filename);
await release.download(build.url, zipFile, 'js-releases/mocha-test');
await release.verify(zipFile, build.filename);
fs.rmSync(tmpDir, {
recursive: true,
});
}).timeout(20 * 1000); // increase timeout for file download
fs.rmSync(tmpDir, {
recursive: true,
});
},
20 * 1000, // increase timeout for file download
);
});
describe('getRelease', () => {
const name = 'vault';
it('should return latest releases when called without a version', async () => {
const request = jest.spyOn(utils, 'request').mockImplementation(async () => ({
name,
versions: {
'0.11.0': { name, version: '0.11.0' },
'1.5.0': { name, version: '1.5.0' },
'1.2.7': { name, version: '1.2.7' },
},
}));
const release = await getRelease(name);
expect(request).toHaveBeenCalledWith('https://releases.hashicorp.com/vault/index.json', { headers: null });
expect(request).toHaveBeenCalledTimes(1);
expect(release).toBeInstanceOf(Release);
expect(release.name).toBe(name);
expect(release.version).toBe('1.5.0');
});
it('should return the matching version', async () => {
jest.spyOn(utils, 'request').mockImplementation(async () => ({
name,
versions: {
'0.11.0': { name, version: '0.11.0' },
'1.2.7': { name, version: '1.2.7' },
'1.5.0': { name, version: '1.5.0' },
},
}));
const version = '1.2.7';
const release = await getRelease(name, version);
expect(release).toBeInstanceOf(Release);
expect(release.name).toBe(name);
expect(release.version).toBe(version);
});
it('should throw if no version is found', async () => {
jest.spyOn(utils, 'request').mockImplementation(async () => ({
name,
versions: {},
}));
const version = '1.2.7';
await expect(getRelease(name, version)).rejects.toThrow('No matching version found');
});
it('should filter invalid versions', async () => {
jest.spyOn(utils, 'request').mockImplementation(async () => ({
name,
versions: {
'1.2.6.1+ent': { name, version: '1.2.6.1+ent' },
'1.2.7': { name, version: '1.2.7' },
'1.5.0': { name, version: '1.5.0' },
'1.6.6.1+ent': { name, version: '1.6.6.1+ent' },
},
}));
const release = await getRelease(name);
expect(release).toBeInstanceOf(Release);
expect(release.name).toBe(name);
expect(release.version).toBe('1.5.0');
});
it('should return latest if passed an invalid version', async () => {
jest.spyOn(utils, 'request').mockImplementation(async () => ({
name,
versions: {
'1.2.7': { name, version: '1.2.7' },
'1.6.0': { name, version: '1.6.0' },
},
}));
const release = await getRelease(name, '1.6.6.1+ent');
expect(release).toBeInstanceOf(Release);
expect(release.name).toBe(name);
expect(release.version).toBe('1.6.0');
});
});

@@ -260,2 +260,18 @@ import * as crypto from 'crypto';

export interface ResponseVersion {
builds: {
arch: string;
filename: string;
name: string;
os: string;
url: string;
version: string;
}[];
name: string;
shasums: string;
shasums_signature: string;
shasums_signatures: string[];
version: string;
}
// includePrerelease: Set to suppress the default behavior of excluding prerelease tagged versions

@@ -272,16 +288,24 @@ // from ranges unless they are explicitly opted into.

const headers = userAgent ? { 'User-Agent': userAgent } : null;
const response = await request(indexUrl, { headers });
let release: Release;
const response = await request<{ name: string; versions: Record<string, ResponseVersion> }>(indexUrl, { headers });
const versions: Record<string, ResponseVersion> = Object.assign(
{},
...Object.keys(response.versions)
.filter((key) => semver.valid(key) !== null)
.map((key) => ({ [key]: response.versions[key] })),
);
if (!validVersion) {
// pick the latest release (prereleases will be skipped for safety, set an explicit version instead)
const releaseVersions = Object.keys(response.versions).filter((v) => !semver.prerelease(v));
version = releaseVersions.sort((a, b) => semver.rcompare(a, b))[0];
release = new Release(response.versions[version]);
} else {
release = matchVersion(response.versions, validVersion, includePrerelease);
const releaseVersion = Object.keys(versions)
.filter((v) => !semver.prerelease(v))
.sort((a, b) => semver.rcompare(a, b))[0];
return new Release(versions[releaseVersion]);
}
return release;
return matchVersion(versions, validVersion, includePrerelease);
}
function matchVersion(versions: Release[], range: string, includePrerelease?: boolean): Release {
function matchVersion(versions: Record<string, ResponseVersion>, range: string, includePrerelease?: boolean): Release {
// If a prerelease version range is given, it will only match in that series (0.14-rc0, 0.14-rc1)

@@ -288,0 +312,0 @@ // unless includePrerelease is set to true

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc