diff --git a/packages/tarball-resolver/LICENSE b/packages/tarball-resolver/LICENSE new file mode 100644 index 0000000000..328ee580c8 --- /dev/null +++ b/packages/tarball-resolver/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017-2019 Zoltan Kochan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/tarball-resolver/README.md b/packages/tarball-resolver/README.md new file mode 100644 index 0000000000..913694e4db --- /dev/null +++ b/packages/tarball-resolver/README.md @@ -0,0 +1,37 @@ +# @pnpm/tarball-resolver + +> Resolver for tarball dependencies + + +[![npm version](https://img.shields.io/npm/v/@pnpm/tarball-resolver.svg)](https://www.npmjs.com/package/@pnpm/tarball-resolver) + + +## Installation + +```sh +npm i -S @pnpm/tarball-resolver +``` + +## Usage + + +```js +'use strict' +const resolveFromTarball = require('@pnpm/tarball-resolver').default + +resolveFromTarball({pref: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'}) + .then(resolveResult => console.log(JSON.stringify(resolveResult, null, 2))) + //> { + // "id": "registry.npmjs.org/is-array/-/is-array-1.0.1", + // "normalizedPref": "http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz", + // "resolution": { + // "tarball": "http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz" + // }, + // "resolvedVia": "url" + // } +``` + + +## License + +[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io/) diff --git a/packages/tarball-resolver/example.js b/packages/tarball-resolver/example.js new file mode 100644 index 0000000000..fd8788cfa4 --- /dev/null +++ b/packages/tarball-resolver/example.js @@ -0,0 +1,5 @@ +'use strict' +const resolveFromTarball = require('@pnpm/tarball-resolver').default + +resolveFromTarball({pref: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'}) + .then(resolveResult => console.log(JSON.stringify(resolveResult, null, 2))) diff --git a/packages/tarball-resolver/package.json b/packages/tarball-resolver/package.json new file mode 100644 index 0000000000..377abd8229 --- /dev/null +++ b/packages/tarball-resolver/package.json @@ -0,0 +1,50 @@ +{ + "name": "@pnpm/tarball-resolver", + "version": "1.0.1", + "description": "Resolver for tarball dependencies", + "main": "lib/index.js", + "typings": "lib/index.d.ts", + "files": [ + "lib" + ], + "engines": { + "node": ">=8" + }, + "scripts": { + "lint": "tslint -c tslint.json --project .", + "tsc": "rimraf lib && tsc", + "test": "npm run tsc && npm run lint && ts-node test --type-check && mos t", + "md": "mos", + "prepublishOnly": "npm run tsc" + }, + "repository": "https://github.com/pnpm/pnpm/blob/master/packages/tarball-resolver", + "author": "Zoltan Kochan (https://www.kochan.io/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/pnpm/pnpm/issues" + }, + "homepage": "https://github.com/pnpm/pnpm/blob/master/packages/tarball-resolver#readme", + "dependencies": { + "@pnpm/resolver-base": "^2.0.0" + }, + "devDependencies": { + "@pnpm/tarball-resolver": "link:", + "@pnpm/tslint-config": "0.0.0", + "@types/tape": "^4.2.31", + "mos": "^2.0.0-alpha.3", + "mos-plugin-readme": "^1.0.4", + "rimraf": "^2.6.2", + "tape": "^4.8.0", + "ts-node": "^8.0.2", + "tslint": "^5.8.0", + "typescript": "^3.0.0" + }, + "mos": { + "plugins": [ + "readme" + ], + "installation": { + "useShortAlias": true + } + } +} diff --git a/packages/tarball-resolver/src/index.ts b/packages/tarball-resolver/src/index.ts new file mode 100644 index 0000000000..0a8e9762ed --- /dev/null +++ b/packages/tarball-resolver/src/index.ts @@ -0,0 +1,23 @@ +import { ResolveResult } from '@pnpm/resolver-base' + +export default async function resolveTarball ( + wantedDependency: {pref: string}, +): Promise { + if (!wantedDependency.pref.startsWith('http:') && !wantedDependency.pref.startsWith('https:')) { + return null + } + + return { + id: wantedDependency.pref + .replace(/^.*:\/\/(git@)?/, '') + .replace(/\.tgz$/, ''), + // TODO BREAKING CHANGE: uncomment the following: (or never remove extensions) + // .replace(/\.tar.gz$/, ''), + // .replace(/\.tar$/, ''), + normalizedPref: wantedDependency.pref, + resolution: { + tarball: wantedDependency.pref, + }, + resolvedVia: 'url', + } +} diff --git a/packages/tarball-resolver/test/index.ts b/packages/tarball-resolver/test/index.ts new file mode 100644 index 0000000000..fd3de2426c --- /dev/null +++ b/packages/tarball-resolver/test/index.ts @@ -0,0 +1,47 @@ +import test = require('tape') +import resolveFromTarball from '@pnpm/tarball-resolver' + +test('tarball from npm registry', async t => { + const resolutionResult = await resolveFromTarball({pref: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'}) + + t.deepEqual(resolutionResult, { + id: 'registry.npmjs.org/is-array/-/is-array-1.0.1', + normalizedPref: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz', + resolution: { + tarball: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz', + }, + resolvedVia: 'url', + }) + + t.end() +}) + +test('tarball not from npm registry', async t => { + const resolutionResult = await resolveFromTarball({pref: 'https://github.com/hegemonic/taffydb/tarball/master'}) + + t.deepEqual(resolutionResult, { + id: 'github.com/hegemonic/taffydb/tarball/master', + normalizedPref: 'https://github.com/hegemonic/taffydb/tarball/master', + resolution: { + tarball: 'https://github.com/hegemonic/taffydb/tarball/master', + }, + resolvedVia: 'url', + }) + + t.end() +}) + +test('tarballs from GitHub (is-negative)', async t => { + const resolutionResult = await resolveFromTarball({pref: 'https://github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz'}) + + t.deepEqual(resolutionResult, { + id: 'github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz', + normalizedPref: 'https://github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz', + resolution: { + tarball: 'https://github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz', + }, + resolvedVia: 'url', + }) + + t.end() +}) diff --git a/packages/tarball-resolver/tsconfig.json b/packages/tarball-resolver/tsconfig.json new file mode 100644 index 0000000000..88257b3393 --- /dev/null +++ b/packages/tarball-resolver/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "removeComments": false, + "preserveConstEnums": true, + "sourceMap": true, + "declaration": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "suppressImplicitAnyIndexErrors": true, + "allowSyntheticDefaultImports": true, + "strictNullChecks": true, + "target": "es2017", + "outDir": "lib", + "module": "commonjs", + "moduleResolution": "node" + }, + "include": [ + "src/**/*.ts", + "typings/**/*.d.ts" + ], + "atom": { + "rewriteTsconfig": true + } +} diff --git a/packages/tarball-resolver/tslint.json b/packages/tarball-resolver/tslint.json new file mode 100644 index 0000000000..568acfabec --- /dev/null +++ b/packages/tarball-resolver/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "@pnpm/tslint-config" +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7d2a62237..0256043f72 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -196,7 +196,7 @@ importers: '@pnpm/git-resolver': 'link:../git-resolver' '@pnpm/local-resolver': 'link:../local-resolver' '@pnpm/npm-resolver': 'link:../npm-resolver' - '@pnpm/tarball-resolver': 1.0.1 + '@pnpm/tarball-resolver': 'link:../tarball-resolver' devDependencies: '@pnpm/default-resolver': 'link:' '@pnpm/logger': 2.1.0 @@ -2032,6 +2032,32 @@ importers: tslint: 5.13.1 typescript: 3.3.3333 unpack-stream: 4.0.2 + packages/tarball-resolver: + dependencies: + '@pnpm/resolver-base': 'link:../resolver-base' + devDependencies: + '@pnpm/tarball-resolver': 'link:' + '@pnpm/tslint-config': 'link:../../utils/tslint-config' + '@types/tape': 4.2.33 + mos: 2.0.0-alpha.3 + mos-plugin-readme: 1.0.4 + rimraf: 2.6.3 + tape: 4.10.1 + ts-node: 8.0.2_typescript@3.3.3333 + tslint: 5.13.1_typescript@3.3.3333 + typescript: 3.3.3333 + specifiers: + '@pnpm/resolver-base': ^2.0.0 + '@pnpm/tarball-resolver': 'link:' + '@pnpm/tslint-config': 0.0.0 + '@types/tape': ^4.2.31 + mos: ^2.0.0-alpha.3 + mos-plugin-readme: ^1.0.4 + rimraf: ^2.6.2 + tape: ^4.8.0 + ts-node: ^8.0.2 + tslint: ^5.8.0 + typescript: ^3.0.0 packages/types: devDependencies: '@pnpm/tslint-config': 'link:../../utils/tslint-config' @@ -2528,14 +2554,6 @@ packages: node: '>=4' resolution: integrity: sha512-sGNnrjzNgzizIAiVIuXBQYWY8XvNBGUFbjEftIzKuXB/++Dr/JVinjLijm6iql7WDHolEf90pMNcBkL8Ni139w== - /@pnpm/tarball-resolver/1.0.1: - dependencies: - '@pnpm/resolver-base': 2.1.0 - dev: false - engines: - node: '>=6' - resolution: - integrity: sha512-OFe7/5RZ+/mEBpsH+gMMNIY73uEwCDdcCaSR2KzeNj+ydbthoIsSKzoXrfbCcMwEL8Nf4Ztk498VutR/qxp+yA== /@pnpm/types/2.0.0: engines: node: '>=6'