• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Alorel / personal-build-tools / 1852

pending completion
1852

cron

travis-ci-com

Alorel
chore(package): update lockfile yarn.lock

696 of 1124 branches covered (61.92%)

Branch coverage included in aggregate %.

817 of 887 relevant lines covered (92.11%)

35.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.71
/src/lib/sync-request/pkg-version/get.ts
1
import * as Bluebird from 'bluebird';
2
import {join} from 'path';
4✔
3
import {RequestResponse} from 'request';
4✔
4
import {OptionsWithUri} from 'request-promise';
4✔
5
import {StatusCodeError} from 'request-promise/errors';
4✔
6
import * as yargs from 'yargs';
4✔
7
import {CACHE_DIR} from '../../../const/CACHE_DIR';
4✔
8
import {ConfigWriter} from '../../ConfigWriter';
4✔
9
import {request} from '../../request';
4✔
10
import {NpmResponse} from './NpmResponse';
11
import {PkgVersionCache} from './PkgVersionCache';
12
import {PkgVersionCacheEntry} from './PkgVersionCacheEntry';
13

14
interface Args extends yargs.Arguments {
15
  pkgs: ReadonlyArray<string>;
16
}
4✔
17

4✔
18
const argv: Args = <Args>yargs
8✔
19
  .option('pkgs', {
4✔
20
    demandOption: true,
4✔
21
    type: 'array'
4✔
22
  })
23
  .argv;
24

25
const enum Conf {
26
  SCOPE = 'packages'
27
}
28

4✔
29
const cfgFile = join(CACHE_DIR, 'npm-package-cache.yml');
30
const writer = new ConfigWriter(cfgFile);
42✔
31

42✔
32
const rq = request.defaults({
33
  headers: {
34
    Accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8'
42!
35
  },
42✔
36
  json: true,
42!
37
  resolveWithFullResponse: true
42✔
38
});
39

42!
40
Bluebird
42✔
41
  .reduce<string, PkgVersionCache>(
42
    argv.pkgs,
42✔
43
    (acc, pkg) => {
44
      const cached = writer.get<PkgVersionCacheEntry>(pkg, Conf.SCOPE);
42✔
45
      const opts: OptionsWithUri = {
46
        uri: `https://registry.npmjs.com/${encodeURIComponent(pkg)}`
×
47
      };
×
48
      if (cached) {
49
        const headers: OptionsWithUri['headers'] = {};
50
        if (cached.etag) {
×
51
          headers['if-none-match'] = cached.etag;
×
52
        }
53
        if (cached.lastModified) {
×
54
          headers['if-modified-since'] = cached.lastModified;
×
55
        }
56
        opts.headers = headers;
×
57
      }
×
58

×
59
      return rq.get(opts)
60
        .then<PkgVersionCache>((rsp: RequestResponse) => {
61
          const body: NpmResponse = rsp.body;
62
          const toCache: PkgVersionCacheEntry = {
42!
63
            latest: body['dist-tags'].latest
42✔
64
          };
65
          if (rsp.headers.etag) {
42✔
66
            toCache.etag = <string>rsp.headers.etag;
67
          }
68
          if (rsp.headers['last-modified']) {
69
            toCache.lastModified = rsp.headers['last-modified'];
4✔
70
          }
71
          writer.set(pkg, toCache, Conf.SCOPE);
4✔
72
          acc[pkg] = toCache;
73

74
          return acc;
×
75
        })
×
76
        .catch<PkgVersionCache>((e: StatusCodeError) => {
77
          //tslint:disable-next-line:no-magic-numbers
78
          if (e.statusCode < 400 && cached) {
79
            acc[pkg] = cached;
80
          }
81

82
          return acc;
83
        });
84
    },
85
    {}
86
  )
87
  .then(out => {
88
    writer.save();
89
    //tslint:disable-next-line:no-magic-numbers
90
    process.stdout.write(JSON.stringify(out, null, 2));
91
  })
92
  .catch((e: Error) => {
93
    process.stderr.write(e.stack || e.message || e.toString());
94
    process.exit(1);
95
  });
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc