@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
59 lines (57 loc) • 2.17 kB
JavaScript
import { resolvePath } from './chunk-JX6IT2MW.js';
import { bundle } from './chunk-6BLGLCSK.js';
import { __name } from './chunk-43IZMM3W.js';
import defu from 'defu';
async function resolveType(context, entry, options = {}) {
const path = await resolvePath(context, entry.file);
if (!path || !context.vfs.existsSync(path)) {
throw new Error(`Module not found: "${entry.file}". Please check the path and try again.`);
}
const result = await bundle(context, defu({
entry: [
path
],
override: {
write: false,
sourcemap: false,
splitting: false,
treeShaking: false
},
compiler: {
reflectionLevel: "verbose"
}
}, options));
if (result.errors.length > 0) {
throw new Error(`Failed to transpile ${entry.file}: ${result.errors.map((error) => error.text).join(", ")}`);
}
if (result.warnings.length > 0) {
context.log("warn", `Warnings while transpiling ${entry.file}: ${result.warnings.map((warning) => warning.text).join(", ")}`);
}
if (!result.outputFiles || result.outputFiles.length === 0) {
throw new Error(`No output files generated for ${entry.file}. Please check the configuration and try again.`);
}
const resolvedTypes = await Promise.all(result.outputFiles.map(async (outputFile) => {
const resolved2 = await context.resolver.evalModule(outputFile.text, {
filename: outputFile.path,
forceTranspile: true
});
let exportName = entry.name;
if (!exportName) {
exportName = "default";
}
return resolved2[exportName] ?? resolved2[`__\u03A9${exportName}`];
}));
const resolved = resolvedTypes.filter(Boolean)[0];
if (!resolved) {
throw new Error(`No valid reflection types found in ${entry.file}${entry.name ? `#${entry.name}` : ""}. Please check the file and try again.`);
}
return resolved;
}
__name(resolveType, "resolveType");
async function reflectType(context, entry, options = {}) {
return (void 0)(await resolveType(context, entry, options));
}
__name(reflectType, "reflectType");
export { reflectType, resolveType };
//# sourceMappingURL=chunk-KPH2A35W.js.map
//# sourceMappingURL=chunk-KPH2A35W.js.map