Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

Alorel / personal-build-tools / 367

23 Oct 2018 - 20:45 coverage increased (+5.02%) to 78.602%
367

Pull #33

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
fix travis typecheck script
Pull Request #33: Build

374 of 617 branches covered (60.62%)

Branch coverage included in aggregate %.

288 of 325 new or added lines in 9 files covered. (88.62%)

178 existing lines in 29 files now uncovered.

1470 of 1729 relevant lines covered (85.02%)

38.24 hits per line

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

88.1
/src/lib/build/cmd.ts
1
import * as fs from 'fs';
2
import {cloneDeep, merge, pull} from 'lodash';
14×
3
import {EOL} from 'os';
14×
4
import {join} from 'path';
14×
5
import {rollup} from 'rollup';
14×
6
import * as rollupTsPlugin$ from 'rollup-plugin-typescript2';
14×
7
import {minify as uglify} from 'uglify-es';
14×
8
import * as yargs from 'yargs';
14×
9
import {mkTsconfig} from '../../fns/mkTsconfig';
14×
10
import {BuildTarget} from '../../interfaces/BuildTarget';
14×
11
import {CLISerialiser} from '../cli-serialiser';
14×
12
import {Log} from '../Log';
14×
13
import {tmp} from '../tmp';
14×
14

14×
15
type Opts = yargs.Arguments & {
14×
16
  dist: string;
17
  formats: BuildTarget[];
42×
18
  ignoredExternals: string[];
19
  opts: any;
14×
20
  tsconfig: any;
21
};
22

23
function coerce(v: any): any {
24
  return CLISerialiser.unserialise(v);
25
}
26

27
const argv: Opts = <any>yargs
28
  .option('opts', {
29
    coerce,
30
    demandOption: true,
31
    type: 'string'
32
  })
33
  .option('dist', {
34
    demandOption: true,
35
    type: 'string'
36
  })
37
  .option('ignored-externals', {
38
    coerce,
39
    demandOption: true,
40
    type: 'string'
41
  })
42
  .option('tsconfig', {
43
    coerce,
44
    demandOption: true,
14×
45
    type: 'string'
14×
46
  })
14×
47
  .option('formats', {
14×
48
    demandOption: true,
14×
49
    type: 'array'
14×
50
  })
51
  .argv;
14×
52

53
delete argv.opts.output.format;
54
delete argv.opts.output.dir;
55
delete argv.opts.output.file;
56

57
const rollupTsPlugin: any = rollupTsPlugin$;
58
const incUmd = argv.formats.includes(BuildTarget.UMD);
59
const inc5 = argv.formats.includes(BuildTarget.FESM5);
60

14×
61
function mkRollupTsConfig(overrides?: any): any {
14×
62
  return {
14×
63
    cacheRoot: tmp.dirSync({unsafeCleanup: true}).name,
8×
64
    tsconfigOverride: merge(
8×
65
      cloneDeep(argv.tsconfig),
66
      mkTsconfig(overrides),
67
      {
68
        compilerOptions: {
69
          module: 'es2015'
8×
70
        }
4×
71
      }
4×
72
    )
Branches [[3, 1]] missed. 4×
73
  };
4×
74
}
4×
75

76
const bundleDir = join(process.cwd(), argv.dist, '_bundle');
4×
77

4×
78
(async () => {
4×
79
  if (incUmd || inc5) {
4×
80
    const baseOpts: any = cloneDeep(argv.opts);
81
    baseOpts.plugins.push(rollupTsPlugin(mkRollupTsConfig({
82
      compilerOptions: {
83
        target: 'es5'
4×
84
      }
4×
85
    })));
Branches [[5, 0]] missed. 4×
NEW
86
    if (incUmd) {
!
87
      const opts = cloneDeep(baseOpts);
88

89
      const unminifiedFile = join(bundleDir, 'umd.js');
4×
90
      if (Array.isArray(opts.external) && opts.external.includes('tslib')) {
4×
91
        Log.info(`Removing ${argv.ignoredExternals.join(', ')} from UMD bundle's externals`);
2×
92
        pull(opts.external, ...argv.ignoredExternals);
93
      }
4×
94

95
      Log.info('Compiling UMD');
4×
96
      const rolled = await rollup(opts);
97

Branches [[7, 1]] missed. 8×
98
      Log.info('Writing UMD');
8×
99
      await rolled.write(merge(cloneDeep(opts.output), {
8×
100
        file: unminifiedFile,
8×
101
        format: 'umd'
8×
102
      }));
103

104
      Log.info('Minifying UMD');
105
      const uglified = uglify(fs.readFileSync(unminifiedFile, 'utf8'));
8×
106

107
      if (uglified.error) {
108
        throw uglified.error;
Branches [[8, 1]] missed. 6×
109
      } else {
6×
110
        let output = uglified.code;
6×
111
        if (opts.output.banner) {
6×
112
          output = <string>opts.output.banner + output;
113
        }
114
        fs.writeFileSync(join(bundleDir, 'umd.min.js'), output);
115
      }
116

6×
117
      Log.success('Finished UMD');
6×
118
    }
6×
119
    if (inc5) {
120
      Log.info('Compiling FESM5');
121
      const rolled = await rollup(baseOpts);
122

6×
123
      Log.info('Writing FESM5');
124
      await rolled.write(merge(cloneDeep(baseOpts.output), {
NEW
125
        file: join(bundleDir, 'fesm5.js'),
Branches [[9, 0], [9, 1], [9, 2]] missed. !
NEW
126
        format: 'esm'
!
127
      }));
128

129
      Log.success('Finished FESM5');
130
    }
131
  } else if (argv.formats.includes(BuildTarget.FESM2015)) {
132
    Log.info('Compiling FESM2015');
133

134
    const opts = cloneDeep(argv.opts);
135
    opts.plugins.push(rollupTsPlugin(mkRollupTsConfig({
136
      compilerOptions: {
137
        target: 'esnext'
138
      }
139
    })));
140
    const rolled = await rollup(opts);
141

142
    Log.info('Writing FESM2015');
143
    await rolled.write(merge(cloneDeep(opts.output), {
144
      file: join(bundleDir, 'fesm2015.js'),
145
      format: 'esm'
146
    }));
147

148
    Log.success('Finished FESM2015');
149
  }
150
})().catch((e: Error) => {
151
  process.stderr.write((e.stack || e.toString() || e.message) + EOL, () => {
152
    process.exit(1);
153
  });
154
});
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc