lib/svelte/js/builder.js in actionview-svelte-handler-0.5.7 vs lib/svelte/js/builder.js in actionview-svelte-handler-0.6.0

- old
+ new

@@ -4,71 +4,96 @@ DO NOT MODIFY. */ import { readable } from "svelte/store"; import { importFromStringSync } from "module-from-string"; -import * as esbuild from "esbuild"; -import sveltePlugin from "esbuild-svelte"; import { sveltePreprocess } from "svelte-preprocess"; import * as recast from "recast"; +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"; class Builder { path; props; locals; compiled; ssr; workingDir; preprocess; - constructor(path, props, locals, client, server, ssr, workingDir, preprocess) { + pathAliases; + constructor(path, props, locals, client, server, ssr, workingDir, preprocess, pathAliases) { this.path = path; - this.props = readable(props); + this.props = readable(Object.assign(props, locals, props)); this.locals = locals; this.compiled = { client, server }; this.ssr = ssr; this.workingDir = workingDir; this.preprocess = preprocess; + this.pathAliases = pathAliases; } - async bundle(generate, sveltePath = "svelte") { - const bundle = await esbuild.build({ - entryPoints: [this.path], - mainFields: ["svelte", "browser", "module", "main"], - conditions: ["svelte", "browser"], - absWorkingDir: this.workingDir, - write: false, - outfile: "component.js", - bundle: true, - format: "esm", - metafile: true, + async bundle(generate) { + const bundle = (await (await rollup({ + input: "entry", + output: { + format: "esm", + sourcemap: false + }, + watch: { + skipWrite: true + }, plugins: [ - // @ts-expect-error - sveltePlugin({ + // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 + virtual({ + entry: `import App from '${this.path}'; export default App` + }), + // @ts-expect-error see https://github.com/rollup/plugins/issues/1662 + svelte({ compilerOptions: { generate, css: "injected", - hydratable: true, - sveltePath + hydratable: true }, + emitCss: false, preprocess: sveltePreprocess(this.preprocess), - filterWarnings: (warning) => { - if (warning.code === "missing-declaration" && warning.message.includes("'props'")) { - return false; + onwarn: (warning, handler) => { + if (warning.code === "missing-declaration" && warning.message.includes("'props'")) return; + handler(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" } - return true; } }) ] - }); - const throwables = [].concat(bundle.errors, bundle.warnings); - if (throwables.length > 0) { - throw throwables[0]; - } - return bundle.outputFiles[0].text; + })).generate({ format: "esm", sourcemap: "inline" })).output; + return bundle[0].code; } async client() { - return this.compiled?.client || this.standardizeClient(await this.bundle("dom", "https://esm.sh/svelte")); + return this.compiled?.client || this.standardizeClient(await this.bundle("dom")); } standardizeClient(code) { const ast = recast.parse(code); let name; recast.visit(ast, {