/* IF YOU ARE READING THIS, YOU ARE VIEWING THE BUILT JS FROM THE SOURCE TYPESCRIPT AT ../ts/ . DO NOT MODIFY. */ import { importFromStringSync } from "module-from-string"; import { sveltePreprocess } from "svelte-preprocess"; import { rollup } from "rollup"; import svelte from "rollup-plugin-svelte"; import alias from "@rollup/plugin-alias"; import commonjs from "@rollup/plugin-commonjs"; import { nodeResolve } from "@rollup/plugin-node-resolve"; import virtual from "@rollup/plugin-virtual"; import swc from "@rollup/plugin-swc"; import path from "node:path"; class Builder { path; props; locals; compiled; ssr; workingDir; preprocess; pathAliases; root; digest; constructor(path2, root, props, locals, client, server, ssr, workingDir, preprocess, pathAliases, digest) { this.path = path2; this.root = root; this.props = Object.assign(props, props, locals); this.locals = locals; this.compiled = { client, server }; this.ssr = ssr; this.workingDir = workingDir; this.preprocess = preprocess; this.pathAliases = pathAliases; this.digest = digest; } async bundle(generate) { let entry = null; if (generate == "ssr") { entry = ` import App from "${this.path}"; import { render } from "svelte/server"; const rendered = render(App, { props: JSON.parse('${JSON.stringify(this.props)}') }) export default rendered; `; } else { entry = ` import App from "${this.path}"; import { hydrate } from "svelte"; function hydrateApp() { const app = hydrate(App, { target: document.getElementById("hydratee-${this.digest}"), props: JSON.parse('${JSON.stringify(this.props)}') }) app.flushSync(); } export default hydrateApp; `; } const bundle = (await (await rollup({ input: "entry", output: { format: "esm", sourcemap: true }, watch: { skipWrite: true }, plugins: [ // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 virtual({ entry }), // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 svelte({ compilerOptions: { generate, css: "injected", hydratable: true }, emitCss: false, preprocess: sveltePreprocess(this.preprocess), onwarn: (warning) => { throw warning; } }), // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 alias({ entries: Object.entries(this.pathAliases || {}).map((k, v) => { return new Object({ find: k, replacement: v }); }) }), // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 commonjs(), nodeResolve({ browser: true, exportConditions: ["svelte"], extensions: [".svelte"] }), // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 swc({ swc: { jsc: { target: "es6", minify: { format: { comments: "all" } } }, minify: true, sourceMaps: true, inlineSourcesContent: true } }) ] })).generate({ format: "esm", sourcemap: true })).output; bundle[0].map.sources = bundle[0].map.sources.map((el) => { return path.relative(this.path, this.root) + "/" + path.relative(this.root, el); }); return `//# sourceMappingURL=${bundle[0].map.toUrl()} //# sourceURL=${path.relative(this.path, this.root) + "/" + path.relative(this.root, this.path)} ${bundle[0].code}`.trim(); } async client() { return this.compiled?.client || await this.bundle("dom"); } // standardizeClient (code: string): string { // const ast = recast.parse(code) // let name: string | undefined // recast.visit(ast, { // visitExportNamedDeclaration: (path) => { // const stagingName: any = path.node?.specifiers?.[0].local?.name // name = typeof stagingName !== 'string' ? '' : stagingName // path.prune() // return false // } // }) // recast.visit(ast, { // visitIdentifier: (path) => { // if (path.node.name === name) { // path.node.name = 'App' // } // return false // } // }) // return recast.print(ast).code // }s async server() { const output = this.compiled?.server || await this.bundle("ssr"); const { html, css, head } = importFromStringSync(output).default; return { output, html, head, css: css?.code }; } async build() { try { const serv = this.ssr ? await this.server() : null; const cli = await this.client(); const comp = { client: cli, server: serv?.output }; return { client: cli, server: serv, compiled: comp }; } catch (e) { return { error: e }; } } } var builder_default = Builder; export { builder_default as default };