unbag
Version:
一个专门用来开发npm工具的包
45 lines (44 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TransformActionTaskBabel = void 0;
var _index = require("../index.cjs");
var _core = require("@babel/core");
const TransformActionTaskBabel = options => {
const {
babel: babelOptions,
extMapping
} = options;
return (0, _index.defineTransformActionTask)(async params => {
const {
inputDir,
filePaths
} = params;
const matchedExtnames = Object.keys(extMapping);
const filePathsFiltered = filePaths.filter(filePath => {
if (matchedExtnames.includes(filePath.extname)) {
return true;
}
return false;
});
const outputFiles = await Promise.all(filePathsFiltered.map(async filePath => {
const absoluteFilePath = filePath.toAbsolutePath({
rel: inputDir
});
const jsFile = await (0, _core.transformFileAsync)(absoluteFilePath.content, {
...babelOptions
});
const targetExtName = extMapping[filePath.extname];
return {
from: filePath,
to: filePath.replaceExtname(targetExtName),
type: _index.TransformActionTaskOutFileType.Transformed,
content: jsFile?.code || "",
sourcemap: void 0
};
}));
return outputFiles;
});
};
exports.TransformActionTaskBabel = TransformActionTaskBabel;