aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-cli/rollup.config.js
blob: 3674ede247480f8fd0be71b5721916f22899fad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// rollup.config.js
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json";
import builtins from "builtin-modules";
import pkg from "./package.json";
import sourcemaps from "rollup-plugin-sourcemaps";
import path from "path";
import replace from "@rollup/plugin-replace";
import child_process from 'child_process';

const printedVersion = `${pkg.version}-${getGitRevision()}`

export default {
  input: "lib/index.js",
  output: {
    file: pkg.main,
    format: "cjs",
    sourcemap: true,
    sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
      // Transform to source map paths to virtual path.  Otherwise,
      // error messages would contain paths that look like they should exist (relative to
      // the bundle) but don't.
      const res = path.normalize(
        path.join("/_walletsrc/packages/taler-wallet-cli/src/", relativeSourcePath),
      );
      return res;
    },
  },
  external: builtins,
  plugins: [
    replace({
      __VERSION__: printedVersion,
    }),

    nodeResolve({
      preferBuiltins: true,
      exportConditions: ["node"],
    }),

    sourcemaps(),

    commonjs({
      sourceMap: true,
      transformMixedEsModules: true,
    }),

    json(),
  ],
};

function getGitRevision() {
  return child_process.execSync(`git rev-parse --short HEAD`, {
    encoding: 'utf-8',
    windowsHide: true,
  }).trim();
}