@make-mjs/main
Version:
32 lines (31 loc) • 1.12 kB
JavaScript
import { objectExtends } from "@tsfun/object/index.mjs";
import { replacePathExtension } from "@make-mjs/utils/index.mjs";
import { DEFAULT_PARSER_OPTIONS, transformCode } from "@make-mjs/code/index.mjs";
import { getModuleContainer } from "../utils/get-module-container.mjs";
export const DEFAULT_PATH_TRANSFORM_FUNC = path => replacePathExtension(path, '.mjs');
export async function* transform(options) {
const {
files,
getNewPath = DEFAULT_PATH_TRANSFORM_FUNC,
codeTransformOptions = {}
} = options;
for await (const {
path,
content
} of files) {
const newPath = getNewPath(path);
const parserOptions = { ...(codeTransformOptions.parserOptions || DEFAULT_PARSER_OPTIONS),
sourceFilename: path
};
const newCodeTransOpts = objectExtends(codeTransformOptions, {
moduleContainer: Array.from(getModuleContainer(path)),
parserOptions
});
const transformResult = await transformCode(content, newCodeTransOpts);
yield {
path: newPath,
content: transformResult.code
};
}
}
export default transform; //# sourceMappingURL=transform.js.map