(sourceMaps)
| 59 | } |
| 60 | |
| 61 | function makeLibFiles(sourceMaps) { |
| 62 | // NB: we need to make a copy of babelOpts, since babel sets some defaults on it |
| 63 | const babelOpts = () => ({ |
| 64 | plugins: [], |
| 65 | presets: [ |
| 66 | [ '@babel/preset-env', |
| 67 | { modules: 'commonjs' } ] |
| 68 | ], |
| 69 | ast: false, |
| 70 | sourceMaps: sourceMaps, |
| 71 | }); |
| 72 | |
| 73 | fse.ensureDirSync(paths.libDirBase); |
| 74 | |
| 75 | const outFiles = []; |
| 76 | |
| 77 | const handleDir = (vendorRewrite, inPathBase, filename) => Promise.resolve() |
| 78 | .then(() => { |
| 79 | const outPath = path.join(paths.libDirBase, path.relative(inPathBase, filename)); |
| 80 | |
| 81 | if (path.extname(filename) !== '.js') { |
| 82 | return; // skip non-javascript files |
| 83 | } |
| 84 | return Promise.resolve() |
| 85 | .then(() => ensureDir(path.dirname(outPath))) |
| 86 | .then(() => { |
| 87 | const opts = babelOpts(); |
| 88 | // Adjust for the fact that we move the core files relative |
| 89 | // to the vendor directory |
| 90 | if (vendorRewrite) { |
| 91 | opts.plugins.push(["import-redirect", |
| 92 | {"root": paths.libDirBase, |
| 93 | "redirect": { "vendor/(.+)": "./vendor/$1"}}]); |
| 94 | } |
| 95 | |
| 96 | return babelTransformFile(filename, opts) |
| 97 | .then((res) => { |
| 98 | console.log(`Writing ${outPath}`); |
| 99 | const {map} = res; |
| 100 | let {code} = res; |
| 101 | if (sourceMaps === true) { |
| 102 | // append URL for external source map |
| 103 | code += `\n//# sourceMappingURL=${path.basename(outPath)}.map\n`; |
| 104 | } |
| 105 | outFiles.push(`${outPath}`); |
| 106 | return writeFile(outPath, code) |
| 107 | .then(() => { |
| 108 | if (sourceMaps === true || sourceMaps === 'both') { |
| 109 | console.log(` and ${outPath}.map`); |
| 110 | outFiles.push(`${outPath}.map`); |
| 111 | return writeFile(`${outPath}.map`, JSON.stringify(map)); |
| 112 | } |
| 113 | }); |
| 114 | }); |
| 115 | }); |
| 116 | }); |
| 117 | |
| 118 | Promise.resolve() |
no test coverage detected