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

gitly

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitly - npm Package Compare versions

Comparing version 1.1.10 to 2.0.0

lib/utils/gitly.d.ts

3

lib/main.d.ts

@@ -1,3 +0,4 @@

export { default as fetch } from './utils/fetch';
export { default } from './utils/gitly';
export { default as download } from './utils/download';
export { default as extract } from './utils/extract';
export { default as parse } from './utils/parse';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.extract = exports.fetch = void 0;
var fetch_1 = require("./utils/fetch");
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.default; } });
exports.parse = exports.extract = exports.download = exports.default = void 0;
var gitly_1 = require("./utils/gitly");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return gitly_1.default; } });
var download_1 = require("./utils/download");
Object.defineProperty(exports, "download", { enumerable: true, get: function () { return download_1.default; } });
var extract_1 = require("./utils/extract");

@@ -7,0 +9,0 @@ Object.defineProperty(exports, "extract", { enumerable: true, get: function () { return extract_1.default; } });

@@ -6,8 +6,8 @@ "use strict";

const shelljs_1 = require("shelljs");
const download_1 = require("../download");
const extract_1 = require("../extract");
const fetch_1 = require("../fetch");
describe('utils/extract', () => {
const destination = path_1.join(__dirname, 'output', 'extract', 'example');
const options = {
temp: path_1.join(__dirname, 'output', 'extract', '.gitcopy')
temp: path_1.join(__dirname, 'output', 'extract', '.gitcopy'),
};

@@ -25,3 +25,3 @@ beforeEach(async () => {

// tslint:disable-next-line: no-floating-promises
const path = await fetch_1.default('lukeed/gittar', options);
const path = await download_1.default('lukeed/gittar', options);
expect(path).toBeTruthy();

@@ -32,3 +32,3 @@ expect(fs_1.existsSync(path)).toBe(true);

// tslint:disable-next-line: no-floating-promises
const source = await fetch_1.default('lukeed/gittar#v0.1.1', options);
const source = await download_1.default('lukeed/gittar#v0.1.1', options);
const path = await extract_1.default(source, destination, options);

@@ -41,3 +41,3 @@ expect(fs_1.existsSync(source)).toBe(true);

it('should extract "https://github.com/lukeed/gittar"', async () => {
const source = await fetch_1.default('https://github.com/lukeed/gittar', options);
const source = await download_1.default('https://github.com/lukeed/gittar', options);
const path = await extract_1.default(source, destination, options);

@@ -50,3 +50,3 @@ expect(fs_1.existsSync(source)).toBe(true);

it('should extract "https://github.com/lukeed/gittar#v0.1.1"', async () => {
const source = await fetch_1.default('https://github.com/lukeed/gittar#v0.1.1', options);
const source = await download_1.default('https://github.com/lukeed/gittar#v0.1.1', options);
const path = await extract_1.default(source, destination, options);

@@ -59,3 +59,3 @@ expect(fs_1.existsSync(source)).toBe(true);

it('should extract "github.com/lukeed/gittar"', async () => {
const source = await fetch_1.default('github.com/lukeed/gittar', options);
const source = await download_1.default('github.com/lukeed/gittar', options);
const path = await extract_1.default(source, destination, options);

@@ -68,3 +68,3 @@ expect(fs_1.existsSync(source)).toBe(true);

it('should extract "github.com/lukeed/gittar#v0.1.1"', async () => {
const source = await fetch_1.default('github.com/lukeed/gittar#v0.1.1', options);
const source = await download_1.default('github.com/lukeed/gittar#v0.1.1', options);
const path = await extract_1.default(source, destination, options);

@@ -77,3 +77,3 @@ expect(fs_1.existsSync(source)).toBe(true);

it('should extract "github:lukeed/gittar"', async () => {
const source = await fetch_1.default('github:lukeed/gittar', options);
const source = await download_1.default('github:lukeed/gittar', options);
const path = await extract_1.default(source, destination, options);

@@ -86,3 +86,3 @@ expect(fs_1.existsSync(source)).toBe(true);

it('should extract "github:lukeed/gittar#v0.1.1"', async () => {
const source = await fetch_1.default('github:lukeed/gittar#v0.1.1', options);
const source = await download_1.default('github:lukeed/gittar#v0.1.1', options);
const path = await extract_1.default(source, destination, options);

@@ -89,0 +89,0 @@ expect(fs_1.existsSync(source)).toBe(true);

@@ -6,7 +6,7 @@ "use strict";

const shelljs_1 = require("shelljs");
const download_1 = require("../download");
const error_1 = require("../error");
const fetch_1 = require("../fetch");
describe('utils/fetch (no cache)', () => {
const options = {
temp: path_1.join(__dirname, 'output', 'fetch', '.gitcopy')
temp: path_1.join(__dirname, 'output', 'fetch', '.gitcopy'),
};

@@ -21,3 +21,3 @@ beforeEach(async () => {

expect.assertions(2);
const path = await fetch_1.default('lukeed/gittar', options);
const path = await download_1.default('lukeed/gittar', options);
expect(path).toBeTruthy();

@@ -28,3 +28,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('lukeed/gittar#v0.1.1', options);
const path = await download_1.default('lukeed/gittar#v0.1.1', options);
expect(path).toBeTruthy();

@@ -35,3 +35,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('https://github.com/lukeed/gittar', options);
const path = await download_1.default('https://github.com/lukeed/gittar', options);
expect(path).toBeTruthy();

@@ -42,3 +42,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('https://github.com/lukeed/gittar#v0.1.1', options);
const path = await download_1.default('https://github.com/lukeed/gittar#v0.1.1', options);
expect(path).toBeTruthy();

@@ -49,3 +49,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('github.com/lukeed/gittar', options);
const path = await download_1.default('github.com/lukeed/gittar', options);
expect(path).toBeTruthy();

@@ -56,3 +56,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('github.com/lukeed/gittar#v0.1.1', options);
const path = await download_1.default('github.com/lukeed/gittar#v0.1.1', options);
expect(path).toBeTruthy();

@@ -63,3 +63,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('github:lukeed/gittar', options);
const path = await download_1.default('github:lukeed/gittar', options);
expect(path).toBeTruthy();

@@ -70,3 +70,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('github:lukeed/gittar#v0.1.1', options);
const path = await download_1.default('github:lukeed/gittar#v0.1.1', options);
expect(path).toBeTruthy();

@@ -77,3 +77,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(2);
const path = await fetch_1.default('gitlab:Rich-Harris/buble#v0.15.2', options);
const path = await download_1.default('gitlab:Rich-Harris/buble#v0.15.2', options);
expect(path).toBeTruthy();

@@ -84,3 +84,3 @@ expect(fs_1.existsSync(path)).toBe(true);

expect.assertions(1);
expect(await fetch_1.default('github:doesnotexist123xyz/gittar#v0.1.1')).toEqual('');
expect(await download_1.default('github:doesnotexist123xyz/gittar#v0.1.1')).toEqual('');
});

@@ -90,4 +90,4 @@ it('should throw an error when a repo is not found (with options', async () => {

try {
await fetch_1.default('github:doesnotexist123xyz/gittar#v0.1.1', {
throw: true
await download_1.default('github:doesnotexist123xyz/gittar#v0.1.1', {
throw: true,
});

@@ -103,3 +103,3 @@ }

temp: path_1.join(__dirname, 'output', 'fetch', 'cache'),
cache: true
cache: true,
};

@@ -110,3 +110,3 @@ const isCached = (ms) => Date.now() - ms <= 15;

// Prefetch
const path = await fetch_1.default('lukeed/gittar', { temp: options.temp });
const path = await download_1.default('lukeed/gittar', { temp: options.temp });
expect(fs_1.existsSync(path)).toBe(true);

@@ -119,3 +119,3 @@ });

const start = Date.now();
const path = await fetch_1.default('lukeed/gittar', options);
const path = await download_1.default('lukeed/gittar', options);
expect(isCached(start)).toBe(true);

@@ -122,0 +122,0 @@ expect(path).toBeTruthy();

@@ -1,1 +0,14 @@

export default function download(url: string, file: string): Promise<string>;
import GitlyOptions from '../interfaces/options';
/**
* Download the tar file from the repository
* and store it in a temporary directory
* @param repository The repository to download
*
* @example
* ```js
* // ..
* const path = await download('iwatakeshi/git-copy')
* // ...
* ```
*/
export default function download(repository: string, options?: GitlyOptions): Promise<string>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("axios");
const stream = require("stream");
const util_1 = require("util");
const error_1 = require("./error");
const write_1 = require("./write");
const pipeline = util_1.promisify(stream.pipeline);
async function download(url, file) {
const response = await axios_1.default.get(url, {
responseType: 'stream', validateStatus: status => status >= 200 && status < 500
});
const { statusText: message, status: code } = response;
if (code >= 400)
throw new error_1.GitlyDownloadError(message, code);
else if (code >= 300 && code < 400) {
return download(response.headers.location, file);
const execute_1 = require("./execute");
const exists_1 = require("./exists");
const fetch_1 = require("./fetch");
const offline_1 = require("./offline");
const parse_1 = require("./parse");
const tar_1 = require("./tar");
/**
* Download the tar file from the repository
* and store it in a temporary directory
* @param repository The repository to download
*
* @example
* ```js
* // ..
* const path = await download('iwatakeshi/git-copy')
* // ...
* ```
*/
async function download(repository, options = {}) {
const info = parse_1.default(repository, options);
const file = tar_1.getFile(info, options);
const url = tar_1.getUrl(info, options);
const local = async () => exists_1.default(file);
const remote = async () => fetch_1.default(url, file);
let order = [local, remote];
if ((await offline_1.isOffline()) || options.cache) {
order = [local];
}
else
await pipeline(response.data, await write_1.default(file));
return file;
else if (options.force || info.type === 'master') {
order = [remote, local];
}
try {
const result = await execute_1.default(order);
if (typeof result === 'boolean') {
return file;
}
return result;
}
catch (error) {
if (options.throw) {
throw error;
}
}
return '';
}
exports.default = download;
import GitlyOptions from '../interfaces/options';
declare const _default: (path: string, options?: GitlyOptions) => Promise<boolean>;
export default _default;
export default function exists(path: string, options?: GitlyOptions): Promise<boolean>;

@@ -7,3 +7,3 @@ "use strict";

const tar_1 = require("./tar");
exports.default = async (path, options = {}) => {
async function exists(path, options = {}) {
if (!path_1.isAbsolute(path)) {

@@ -15,5 +15,7 @@ path = tar_1.getFile(parse_1.default(path), options);

return true;
// eslint-disable-next-line no-empty
}
catch (_) { }
return false;
};
}
exports.default = exists;

@@ -19,7 +19,9 @@ "use strict";

try {
let filter = (options.extract && options.extract.filter) ? options.extract.filter :
(_path, _stat) => true;
const filter = options.extract && options.extract.filter
? options.extract.filter
: () => true;
await mkdir(destination, { recursive: true });
await tar_1.extract({ strip: 1, filter, file: source, cwd: destination });
return destination;
// eslint-disable-next-line no-empty
}

@@ -26,0 +28,0 @@ catch (_) { }

@@ -1,16 +0,1 @@

import GitlyOptions from '../interfaces/options';
declare const _default: (repository: string, options?: GitlyOptions) => Promise<string>;
/**
* Fetch the tar file from the repository
* and store it in a temporary directory
* @param repository The repository to download
* @param options
*
* @example
* ```js
* // ..
* const path = await fetch('iwatakeshi/git-copy')
* // ...
* ```
*/
export default _default;
export default function fetch(url: string, file: string): Promise<string>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const download_1 = require("./download");
const execute_1 = require("./execute");
const exists_1 = require("./exists");
const offline_1 = require("./offline");
const parse_1 = require("./parse");
const tar_1 = require("./tar");
/**
* Fetch the tar file from the repository
* and store it in a temporary directory
* @param repository The repository to download
* @param options
*
* @example
* ```js
* // ..
* const path = await fetch('iwatakeshi/git-copy')
* // ...
* ```
*/
exports.default = async (repository, options = {}) => {
const info = parse_1.default(repository, options);
const file = tar_1.getFile(info, options);
const url = tar_1.getUrl(info, options);
const local = async () => exists_1.default(file);
const remote = async () => download_1.default(url, file);
let order = [local, remote];
if (await offline_1.isOffline() || options.cache) {
order = [local];
const axios_1 = require("axios");
const stream = require("stream");
const util_1 = require("util");
const error_1 = require("./error");
const write_1 = require("./write");
const pipeline = util_1.promisify(stream.pipeline);
async function fetch(url, file) {
const response = await axios_1.default.get(url, {
responseType: 'stream',
validateStatus: (status) => status >= 200 && status < 500,
});
const { statusText: message, status: code } = response;
if (code >= 400)
throw new error_1.GitlyDownloadError(message, code);
else if (code >= 300 && code < 400) {
return fetch(response.headers.location, file);
}
else if (options.force || info.type === 'master') {
order = [remote, local];
}
try {
const result = await execute_1.default(order);
if (typeof result === 'boolean') {
return file;
}
return result;
}
catch (error) {
if (options.throw) {
throw error;
}
}
return '';
};
else
await pipeline(response.data, await write_1.default(file));
return file;
}
exports.default = fetch;

@@ -10,2 +10,3 @@ "use strict";

return false;
// eslint-disable-next-line no-empty
}

@@ -12,0 +13,0 @@ catch (_) { }

@@ -19,10 +19,10 @@ "use strict";

exports.default = (url, options = {}) => {
let { url: normalized, host } = normalizeURL(url, options);
const { url: normalized, host } = normalizeURL(url, options);
// Parse the url
const result = url_1.parse(normalized);
const paths = (result.path || '').split('/').filter(p => !!p);
const paths = (result.path || '').split('/').filter((p) => !!p);
const owner = paths.shift() || '';
const repository = paths.shift() || '';
return {
protocol: (result.protocol || 'https').replace(/\:/g, ''),
protocol: (result.protocol || 'https').replace(/:/g, ''),
host: result.host || host || 'github.com',

@@ -35,3 +35,3 @@ hostname: (result.hostname || host || 'github').replace(/\.(\S+)/, ''),

owner,
type: (result.hash || '#master').substr(1)
type: (result.hash || '#master').substr(1),
};

@@ -44,10 +44,10 @@ };

url = url.replace('.git', '');
const httpRegex = /http(s)?\:\/\//;
const httpRegex = /http(s)?:\/\//;
const tldRegex = /[\S]+\.([\D]+)/;
let host = options.host || '';
if (/([\S]+)\:.+/.test(url) && !httpRegex.test(url)) {
if (/([\S]+):.+/.test(url) && !httpRegex.test(url)) {
/**
* Matches host:owner/repo
*/
const matches = url.match(/([\S]+)\:.+/);
const matches = url.match(/([\S]+):.+/);
// Get the host

@@ -75,3 +75,3 @@ host = matches ? matches[1] : '';

match = matches[1];
let domain = (options.host || 'github');
let domain = options.host || 'github';
domain = domain.replace(`.${match}`, '');

@@ -78,0 +78,0 @@ url = `https://${domain}.${match}/${url}`;

/// <reference types="node" />
/// <reference types="graceful-fs" />
declare const _default: (path: string) => Promise<import("fs").WriteStream>;
import { WriteStream } from 'fs';
/**

@@ -8,2 +7,2 @@ * Create a folder and return a writable stream.

*/
export default _default;
export default function write(path: string): Promise<WriteStream>;

@@ -10,6 +10,7 @@ "use strict";

*/
exports.default = async (path) => {
async function write(path) {
path = path_1.normalize(path);
await mkdir(path_1.dirname(path), { recursive: true });
return fs_1.createWriteStream(path);
};
}
exports.default = write;
{
"name": "gitly",
"version": "1.1.10",
"version": "2.0.0",
"description": "An API to download and/or extract git repositories",

@@ -13,16 +13,22 @@ "main": "lib/main.js",

"dependencies": {
"axios": "^0.20.0",
"axios": "^0.21.0",
"tar": "^6.0.5"
},
"devDependencies": {
"@oclif/tslint": "^3.1.1",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.14",
"@types/shelljs": "^0.8.8",
"@types/tar": "^4.0.3",
"jest": "^26.4.2",
"@types/tar": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"eslint": "^7.16.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.7.9",
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-unicorn": "^24.0.0",
"jest": "^26.6.3",
"shelljs": "^0.8.4",
"ts-jest": "^26.4.0",
"tslint": "^6.1.3",
"typescript": "^4.0.3"
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
},

@@ -35,4 +41,4 @@ "scripts": {

"test": "jest",
"lint": "tslint -p . -t stylish",
"lint:fix": "tslint -p . -t stylish --fix"
"lint": "eslint -c .eslintrc.js --ext .ts src",
"lint:fix": "yarn lint --fix"
},

@@ -39,0 +45,0 @@ "types": "lib/main.d.ts",

@@ -11,4 +11,2 @@ # gitly

This project is the spiritual successor of [gittar](https://github.com/lukeed/gittar) written in TypeScript.

@@ -18,21 +16,23 @@

Since v1.0+
```typescript
import { fetch, extract } = from 'gitly'
import { download, extract } = from 'gitly'
console.log(await fetch('iwatakeshi/gitly'))
console.log(await download('iwatakeshi/gitly'))
// -> ~/.gitly/github/iwatakeshi/gitly/master.tar.gz
console.log(await fetch('iwatakeshi/gitly#v1.0.0'))
console.log(await download('iwatakeshi/gitly#v1.0.0'))
// -> ~/.gitly/github/iwatakeshi/gitly/v1.0.0.tar.gz
console.log(await fetch('https://github.com/iwatakeshi/gitly'))
console.log(await download('https://github.com/iwatakeshi/gitly'))
// -> ~/.gitly/github/iwatakeshi/gitly/master.tar.gz
console.log(await fetch('gitlab:Rich-Harris/buble#v0.15.2'))
console.log(await download('gitlab:Rich-Harris/buble#v0.15.2'))
// -> ~/.gitly/gitlab/Rich-Harris/buble/v0.15.2.tar.gz
console.log(await fetch('Rich-Harris/buble', { host: 'gitlab' }))
console.log(await download('Rich-Harris/buble', { host: 'gitlab' }))
// -> ~/.gitly/gitlab/Rich-Harris/buble/master.tar.gz
const source = 'path to downloaded zip file (can be obtained by fetch())'
const source = 'path to downloaded zip file (can be obtained by download())'
const destination = '/path/to/foobar'

@@ -44,2 +44,11 @@

Since v2.0+
```typescript
import gitly from 'gitly'
console.log(await gitly('iwatakeshi/gitly', '/path/to/extracted/folder/'))
// -> ['~/.gitly/github/iwatakeshi/gitly/master.tar.gz', '/path/to/extracted/folder/']
```
## Options

@@ -58,3 +67,3 @@

/**
* Throw an error when fetching (default: undefined)
* Throw an error when downloading (default: undefined)
*/

@@ -61,0 +70,0 @@ throw?: boolean

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