index.js (2376B)
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 rollupBabel = require("rollup-plugin-babel"); 9 10 const TARGET_NAME = "rollup-babel7"; 11 12 module.exports = exports = async function(tests, dirname) { 13 const fixtures = []; 14 for (const [name, input] of tests) { 15 if (/typescript-|-cjs/.test(name)) { 16 continue; 17 } 18 19 const testFnName = _.camelCase(`${TARGET_NAME}-${name}`); 20 const babelEnv = !name.match(/-es6/); 21 22 const scriptPath = path.join(dirname, "output", TARGET_NAME, `${name}.js`); 23 24 console.log(`Building ${TARGET_NAME} test ${name}`); 25 26 const bundle = await rollup.rollup({ 27 input: "fake-bundle-root", 28 plugins: [ 29 // Our input file may export more than the default, but we 30 // want to enable 'exports: "default",' so we need the root 31 // import to only have a default export. 32 { 33 resolveId: id => (id === "fake-bundle-root" ? id : undefined), 34 load: id => 35 id === "fake-bundle-root" 36 ? `import test from "${input}"; export default test;` 37 : undefined 38 }, 39 rollupBabel({ 40 babelrc: false, 41 plugins: [ 42 require.resolve("@babel/plugin-transform-class-properties") 43 ], 44 presets: [ 45 require.resolve("@babel/preset-flow"), 46 babelEnv 47 ? [require.resolve("@babel/preset-env"), { modules: false }] 48 : null 49 ].filter(Boolean) 50 }), 51 { 52 ongenerate(out, data) { 53 data.map.sources = data.map.sources.map(source => 54 source.replace(/^fixtures[\\/]/, `${TARGET_NAME}://./`) 55 ); 56 } 57 } 58 ].filter(Boolean) 59 }); 60 61 await bundle.write({ 62 file: path.basename(scriptPath), 63 dir: path.dirname(scriptPath), 64 format: "iife", 65 name: testFnName, 66 sourcemap: true, 67 exports: "default" 68 }); 69 70 fixtures.push({ 71 name, 72 testFnName: testFnName, 73 scriptPath, 74 assets: [scriptPath, `${scriptPath}.map`] 75 }); 76 } 77 78 return { 79 target: TARGET_NAME, 80 fixtures 81 }; 82 };