Example of a transformation script for declaring a moment module import:

PHOTO EMBED

Mon Mar 28 2022 11:43:01 GMT+0000 (Coordinated Universal Time)

Saved by @GoodRequest. #javascript

const parser = 'babel'

function transformer (file, api) {
   const j = api.jscodeshift;
   const root = j(file.source);

   // find declaration for "moment" import
   return root.find(j.ImportDeclaration, { source: { value: 'moment'}}).forEach(path => {
	   path.value.source.value = 'dayjs'
   }).toSource();
}

module.exports = transformer
module.exports.parser = parser
content_copyCOPY