@wrench/roll-typescript
Version:
plugin for bundling TypeScript with support of modular output and declaration bundle
40 lines (39 loc) • 1.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const util_1 = require("../util");
const report_host_1 = require("./report-host");
const overrides = ["getCommonSourceDirectory"];
let current;
function emitByProgram(program, host, fileName, dtsOnly) {
const { ts } = host;
const emit = current = {
fileName,
sourceFile: program.getSourceFile(fileName),
files: [],
};
if (emit.sourceFile) {
const origin = lodash_1.pick(program, overrides);
const injects = lodash_1.pick(host, overrides);
Object.assign(program, injects);
try {
const r = program.emit(emit.sourceFile, writeFile, void 0, dtsOnly, host.transform);
report_host_1.reportDiagnostics(host, r.diagnostics);
}
finally {
Object.assign(program, origin);
}
}
else {
const template = ts.Diagnostics.File_0_not_found;
const diagnostic = ts.createCompilerDiagnostic(template, fileName);
host.reportDiagnostic(diagnostic);
}
return emit;
}
exports.emitByProgram = emitByProgram;
function writeFile(name, text, writeByteOrderMark) {
const key = util_1.extname(name).toLowerCase().split(".").join("");
const file = { name, text, writeByteOrderMark };
current.files.push(file);
current[key] = file;
}