MCPcopy Create free account
hub / github.com/ampproject/amphtml / getFileBabelOptions

Function getFileBabelOptions

build-system/common/esbuild-babel.js:233–254  ·  view source on GitHub ↗

* @param {!Object} babelOptions * @param {string} filename * @return {!Object}

(babelOptions, filename)

Source from the content-addressed store, hash-verified

231 * @return {!Object}
232 */
233function 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
256module.exports = {
257 getEsbuildBabelPlugin,

Callers 1

setupFunction · 0.85

Calls 2

filterMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected