tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

index.js (2099B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 const path = require("path");
      6 const _ = require("lodash");
      7 const rollup = require("rollup");
      8 const rollupTypescript = require("rollup-plugin-typescript2");
      9 
     10 const TARGET_NAME = "rollup";
     11 
     12 module.exports = exports = async function(tests, dirname) {
     13  const fixtures = [];
     14  for (const [name, input] of tests) {
     15    if (/babel-|-cjs/.test(name)) {
     16      continue;
     17    }
     18 
     19    const testFnName = _.camelCase(`${TARGET_NAME}-${name}`);
     20 
     21    const scriptPath = path.join(dirname, "output", TARGET_NAME, `${name}.js`);
     22 
     23    console.log(`Building ${TARGET_NAME} test ${name}`);
     24 
     25    const bundle = await rollup.rollup({
     26      input: "fake-bundle-root",
     27      plugins: [
     28        // Our input file may export more than the default, but we
     29        // want to enable 'exports: "default",' so we need the root
     30        // import to only have a default export.
     31        {
     32          resolveId: id => (id === "fake-bundle-root" ? id : undefined),
     33          load: id =>
     34            id === "fake-bundle-root"
     35              ? `import test from "${input}"; export default test;`
     36              : undefined
     37        },
     38        {
     39          ongenerate(out, data) {
     40            data.map.sources = data.map.sources.map(source =>
     41              source.replace(/^fixtures[\\/]/, `${TARGET_NAME}://./`)
     42            );
     43          }
     44        },
     45        rollupTypescript({
     46          check: false,
     47          tsconfigDefaults: {
     48            target: "es6",
     49          },
     50        }),
     51      ].filter(Boolean)
     52    });
     53 
     54    await bundle.write({
     55      file: path.basename(scriptPath),
     56      dir: path.dirname(scriptPath),
     57      format: "iife",
     58      name: testFnName,
     59      // sourceMapFile: ""
     60      sourcemap: true,
     61      exports: "default"
     62    });
     63 
     64    fixtures.push({
     65      name,
     66      testFnName,
     67      scriptPath,
     68      assets: [scriptPath, `${scriptPath}.map`]
     69    });
     70  }
     71 
     72  return {
     73    target: TARGET_NAME,
     74    fixtures
     75  };
     76 };