tor-browser

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

index.js (2394B)


      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 util = require("util");
      7 const _ = require("lodash");
      8 const webpack = require("webpack");
      9 
     10 const TARGET_NAME = "webpack4-babel6";
     11 
     12 module.exports = exports = async function(tests, dirname) {
     13  const fixtures = [];
     14  for (const [name, input] of tests) {
     15    if (/typescript-/.test(name)) {
     16      continue;
     17    }
     18 
     19    const testFnName = _.camelCase(`${TARGET_NAME}-${name}`);
     20    const evalMaps = name.match(/-eval/);
     21    const babelEnv = !name.match(/-es6/);
     22    const babelModules = name.match(/-cjs/);
     23 
     24    console.log(`Building ${TARGET_NAME} test ${name}`);
     25 
     26    const scriptPath = path.join(dirname, "output", TARGET_NAME, `${name}.js`);
     27    const result = await util.promisify(webpack)({
     28      mode: "development",
     29      context: path.dirname(input),
     30      entry: `./${path.basename(input)}`,
     31      output: {
     32        path: path.dirname(scriptPath),
     33        filename: path.basename(scriptPath),
     34 
     35        devtoolModuleFilenameTemplate: `${TARGET_NAME}://./${name}/[resource-path]`,
     36 
     37        libraryTarget: "var",
     38        library: testFnName,
     39        libraryExport: "default"
     40      },
     41      devtool: evalMaps ? "eval-source-map" : "source-map",
     42      module: {
     43        rules: [
     44          {
     45            test: /\.js$/,
     46            exclude: /node_modules/,
     47            loader: require.resolve("babel-loader"),
     48            options: {
     49              babelrc: false,
     50              presets: [
     51                babelEnv
     52                  ? [
     53                      require.resolve("babel-preset-env"),
     54                      { modules: babelModules ? "commonjs" : false }
     55                    ]
     56                  : null
     57              ].filter(Boolean),
     58              plugins: [
     59                require.resolve("babel-plugin-transform-flow-strip-types"),
     60                require.resolve("babel-plugin-transform-class-properties")
     61              ]
     62            }
     63          }
     64        ].filter(Boolean)
     65      }
     66    });
     67 
     68    fixtures.push({
     69      name,
     70      testFnName: testFnName,
     71      scriptPath,
     72      assets: [scriptPath, evalMaps ? null : `${scriptPath}.map`].filter(
     73        Boolean
     74      )
     75    });
     76  }
     77 
     78  return {
     79    target: TARGET_NAME,
     80    fixtures
     81  };
     82 };