Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///
import { existsSync } from 'fs'
import fs = require('mz/fs')
import test = require('tape')
import nock = require('nock')
import createFetcher from '@pnpm/tarball-fetcher'
import path = require('path')
import tempy = require('tempy')
import { streamParser, LogBase } from '@pnpm/logger'
import ssri = require('ssri')
const tarballPath = path.join(__dirname, 'tars', 'babel-helper-hoist-variables-6.24.1.tgz')
const tarballSize = 1279
const tarballIntegrity = 'sha1-HssnaJydJVE+rbyZFKc/VAi+enY='
const registry = 'http://example.com/'
const fetch = createFetcher({
registry,
rawNpmConfig: {
registry,
},
fetchRetries: 1,
fetchRetryMintimeout: 0,
fetchRetryMaxtimeout: 100,
})
test('fail when tarball size does not match content-length', async t => {
const scope = nock(registry)
.get('/foo.tgz')
.times(2)
.replyWithFile(200, tarballPath, {
'Content-Length': (1024 * 1024).toString(),
})
registry,
{
reqheaders: {
'authorization': 'Bearer ofjergrg349gj3f2'
}
}
)
.get('/foo.tgz')
.replyWithFile(200, tarballPath, {
'Content-Length': tarballSize.toString(),
})
process.chdir(tempy.directory())
t.comment(`testing in ${process.cwd()}`)
const fetch = createFetcher({
alwaysAuth: true,
registry,
rawNpmConfig: {
registry,
'//example.com/:_authToken': 'ofjergrg349gj3f2',
},
fetchRetries: 1,
fetchRetryMintimeout: 0,
fetchRetryMaxtimeout: 100,
})
const unpackTo = path.resolve('unpacked')
const cachedTarballLocation = path.resolve('cached')
const resolution = {
registry,
tarball: 'http://example.com/foo.tgz',
'use strict'
const createFetcher = require('@pnpm/tarball-fetcher').default
process.chdir(__dirname)
const registry = 'https://registry.npmjs.org/'
const fetch = createFetcher({
registry,
rawConfig: {
registry,
},
})
const resolution = {
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
}
fetch.tarball(resolution, 'dist/unpacked', {
cachedTarballLocation: 'dist/cache.tgz',
prefix: process.cwd(),
})
.then(index => console.log(Object.keys(index)))
.catch(err => {
console.error(err)
async function main() {
const registry = 'https://registry.npmjs.org/'
const rawConfig = { registry }
const store = '.store'
const resolve = createResolver({
rawConfig,
store,
metaCache: new Map(),
})
const fetchers = createFetcher({
alwaysAuth: true,
registry,
strictSsl: true,
rawConfig,
})
const storeCtrl = await createStore(resolve, fetchers, {
networkConcurrency: 1,
store,
})
const port = 5813
const hostname = '127.0.0.1';
const server = createServer(storeCtrl, {
port,
hostname,
})