* @param {!Object} babelOptions * @param {string} filename * @return {!Object}
(babelOptions, filename)
| 231 | * @return {!Object} |
| 232 | */ |
| 233 | function getFileBabelOptions(babelOptions, filename) { |
| 234 | // Patch for leaving files within node_modules as esm, since esbuild will break when trying |
| 235 | // to process a module file that contains CJS exports. This function is called after |
| 236 | // babel.loadOptions, therefore all of the plugins from preset-env have already been applied. |
| 237 | // and must be disabled individually. |
| 238 | if (filename.includes('node_modules')) { |
| 239 | const plugins = babelOptions.plugins.filter( |
| 240 | ({key}) => !CJS_TRANSFORMS.has(key) |
| 241 | ); |
| 242 | babelOptions = {...babelOptions, plugins}; |
| 243 | } |
| 244 | |
| 245 | // The amp runner automatically sets cwd to the `amphtml` directory. |
| 246 | const root = process.cwd(); |
| 247 | const filenameRelative = path.relative(root, filename); |
| 248 | |
| 249 | return { |
| 250 | ...babelOptions, |
| 251 | filename, |
| 252 | filenameRelative, |
| 253 | }; |
| 254 | } |
| 255 | |
| 256 | module.exports = { |
| 257 | getEsbuildBabelPlugin, |