From b555b3790bcaed05097b1b4098a1c1f38f384bd5 Mon Sep 17 00:00:00 2001 From: Aral Roca Date: Sun, 24 Mar 2024 10:23:40 +0100 Subject: [PATCH] feat: simplify and fix preact --- README.md | 1 - examples/preact/README.md | 16 +++ examples/preact/package.json | 19 +++ examples/preact/src/build.ts | 16 +++ .../src/components/dynamic-component.tsx | 7 ++ .../src/components/static-component.tsx | 7 ++ examples/preact/src/index.tsx | 27 +++++ examples/preact/src/prerender.tsx | 12 ++ examples/preact/tsconfig.json | 22 ++++ package.json | 5 +- package/index.ts | 48 ++------ tests/brisa/plugin.test.tsx | 101 +++++++--------- tests/preact/components.tsx | 2 - tests/preact/config.tsx | 1 - tests/preact/plugin.test.tsx | 92 +++++++------- tests/preact/tsconfig.json | 26 ++-- tests/react/plugin.test.tsx | 114 ++++++++---------- 17 files changed, 286 insertions(+), 230 deletions(-) create mode 100644 examples/preact/README.md create mode 100644 examples/preact/package.json create mode 100644 examples/preact/src/build.ts create mode 100644 examples/preact/src/components/dynamic-component.tsx create mode 100644 examples/preact/src/components/static-component.tsx create mode 100644 examples/preact/src/index.tsx create mode 100644 examples/preact/src/prerender.tsx create mode 100644 examples/preact/tsconfig.json diff --git a/README.md b/README.md index 30df1cc..63afd66 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,6 @@ Configuration example: ```tsx import prerenderMacroPlugin, { type PrerenderConfig } from "prerender-macro"; import { render } from "preact-render-to-string"; -import { h } from "preact"; export const prerenderConfig = { render: async (Component, props) => { diff --git a/examples/preact/README.md b/examples/preact/README.md new file mode 100644 index 0000000..2fc1ef8 --- /dev/null +++ b/examples/preact/README.md @@ -0,0 +1,16 @@ +# `prerender-macro` Preact Example + +This is an example with React SSR without hotreloading and with a build process. + +To test it: + +- `bun install` +- `bun run start` +- Open http://localhost:1234 to see the result +- Look at `dist/index.js` to verify how the static parts have been converted to HTML in string. + +The static component is translated to html in string in build-time: + +```tsx +"
Static Component \uD83E\uDD76 Random number = 0.41381527597071954
"; +``` diff --git a/examples/preact/package.json b/examples/preact/package.json new file mode 100644 index 0000000..114a9db --- /dev/null +++ b/examples/preact/package.json @@ -0,0 +1,19 @@ +{ + "name": "preact-example", + "private": true, + "module": "build.tsx", + "type": "module", + "scripts": { + "start": "bun run src/build.ts && bun run dist/index.js" + }, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "5.4.3" + }, + "dependencies": { + "prerender-macro": "workspace:*", + "preact-render-to-string": "6.4.1" + } +} diff --git a/examples/preact/src/build.ts b/examples/preact/src/build.ts new file mode 100644 index 0000000..636131a --- /dev/null +++ b/examples/preact/src/build.ts @@ -0,0 +1,16 @@ +import { join } from "node:path"; +import prerenderMacro from "prerender-macro"; + +const { success, logs } = await Bun.build({ + entrypoints: [join(import.meta.dir, "index.tsx")], + outdir: join(import.meta.dir, "..", "dist"), + target: "bun", + plugins: [ + prerenderMacro({ + prerenderConfigPath: join(import.meta.dir, "prerender.tsx"), + }), + ], +}); + +if (success) console.log("Build complete ✅"); +else console.error("Build failed ❌", logs); diff --git a/examples/preact/src/components/dynamic-component.tsx b/examples/preact/src/components/dynamic-component.tsx new file mode 100644 index 0000000..e892a15 --- /dev/null +++ b/examples/preact/src/components/dynamic-component.tsx @@ -0,0 +1,7 @@ +export default function DynamicComponent({ name }: { name: string }) { + return ( +
+ {name} Component 🔥 Random number = {Math.random()} +
+ ); +} diff --git a/examples/preact/src/components/static-component.tsx b/examples/preact/src/components/static-component.tsx new file mode 100644 index 0000000..a4db70e --- /dev/null +++ b/examples/preact/src/components/static-component.tsx @@ -0,0 +1,7 @@ +export default function StaticComponent({ name }: { name: string }) { + return ( +
+ {name} Component 🥶 Random number = {Math.random()} +
+ ); +} diff --git a/examples/preact/src/index.tsx b/examples/preact/src/index.tsx new file mode 100644 index 0000000..1003a62 --- /dev/null +++ b/examples/preact/src/index.tsx @@ -0,0 +1,27 @@ +import DynamicComponent from "./components/dynamic-component"; +import StaticComponent from "./components/static-component" with { type: "prerender" }; +import { render } from "preact-render-to-string"; + +Bun.serve({ + port: 1234, + fetch: async () => { + return new Response( + render( + + + Prerender Macro | Preact example + + + + + + Refresh + + , + ), + { headers: new Headers({ "Content-Type": "text/html" }) }, + ); + }, +}); + +console.log("Server running at http://localhost:1234"); diff --git a/examples/preact/src/prerender.tsx b/examples/preact/src/prerender.tsx new file mode 100644 index 0000000..4bedb9b --- /dev/null +++ b/examples/preact/src/prerender.tsx @@ -0,0 +1,12 @@ +import { render } from "preact-render-to-string"; +import type { PrerenderConfig } from "prerender-macro"; + +export const prerenderConfig = { + render: async (Component, props) => { + return ( +
) }} + /> + ); + }, +} satisfies PrerenderConfig; diff --git a/examples/preact/tsconfig.json b/examples/preact/tsconfig.json new file mode 100644 index 0000000..58037fb --- /dev/null +++ b/examples/preact/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "jsxImportSource": "preact", + "jsx": "react-jsx", + "baseUrl": ".", + "lib": ["dom", "dom.iterable", "esnext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "skipLibCheck": true, + "paths": { + "react": ["node_modules/preact/compat"], + "react-dom": ["./node_modules/preact/compat/"] + }, + "typeRoots": ["src/types", "./node_modules/@types"] + }, + "resolve": { + "extensions": [".js", ".jsx", ".ts", ".tsx", ".json", ".svg", ".css"] + }, + "include": ["src"] +} diff --git a/package.json b/package.json index c07a95b..b105343 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prerender-macro", - "version": "0.0.6", + "version": "0.0.7", "module": "package/index.ts", "type": "module", "devDependencies": { @@ -21,7 +21,8 @@ "test:react": "cd tests/react && bun test && cd ../..", "test:preact": "cd tests/preact && bun test && cd ../..", "demo:react": "cd examples/react && bun start", - "demo:brisa": "cd examples/brisa && bun start" + "demo:brisa": "cd examples/brisa && bun start", + "demo:preact": "cd examples/preact && bun start" }, "workspaces": [ "package", diff --git a/package/index.ts b/package/index.ts index cb40086..861bfb6 100644 --- a/package/index.ts +++ b/package/index.ts @@ -1,13 +1,9 @@ -import type { BunPlugin, TranspilerOptions } from "bun"; +import type { BunPlugin } from "bun"; import { dirname } from "node:path"; import ts from "typescript"; -let transpiler = new Bun.Transpiler({ loader: "tsx" }); -const JSX_RUNTIME = ["jsx-runtime", "jsx-dev-runtime"]; - export type PluginConfig = { prerenderConfigPath: string; - tsconfig?: TranspilerOptions["tsconfig"]; }; export type PrerenderConfig = { @@ -18,6 +14,13 @@ export type PrerenderConfig = { postRender?: (htmlString: string) => JSX.Element; }; +export type TranspilerOptions = { + code: string; + path: string; + pluginConfig: PluginConfig; + prerenderConfig?: PrerenderConfig; +}; + export default function plugin(pluginConfig: PluginConfig) { if (!pluginConfig?.prerenderConfigPath) { throw new Error("prerender-macro: prerenderConfigPath config is required"); @@ -53,12 +56,7 @@ export function transpile({ path, pluginConfig, prerenderConfig, -}: { - code: string; - path: string; - pluginConfig: PluginConfig; - prerenderConfig?: PrerenderConfig; -}) { +}: TranspilerOptions) { const sourceFile = createSourceFile(code); const importsWithPrerender = getImportsWithPrerender(sourceFile, path); @@ -73,11 +71,9 @@ export function transpile({ prerenderConfig, ) as ts.SourceFile; - const modifiedCode = ts + return ts .createPrinter() .printNode(ts.EmitHint.Unspecified, modifiedAst, sourceFile); - - return runMacros(modifiedCode); } function createSourceFile(code: string) { @@ -301,30 +297,6 @@ function replaceJSXToMacroCall( ); } -function runMacros(code: string) { - // This is totally necessary to execute the Bun macros - let codeAfterMacros = transpiler.transformSync(code); - - // WORKAROUND: Find the JSX runtime to add the import - // Issue: https://github.com/oven-sh/bun/issues/7499 - if (!globalThis.jsxRuntime) { - for (let key of globalThis.Loader.registry.keys()) { - if (JSX_RUNTIME.some((k) => key.includes(k))) { - globalThis.jsxRuntime = key; - break; - } - } - } - - // WORKAROUND: Add the JSX runtime import - // Issue: https://github.com/oven-sh/bun/issues/7499 - if (globalThis.jsxRuntime) { - codeAfterMacros = `import {jsx, jsxDEV, jsxs, Fragment} from "${globalThis.jsxRuntime}";\n${codeAfterMacros}`; - } - - return codeAfterMacros; -} - declare global { var jsxRuntime: string | undefined; } diff --git a/tests/brisa/plugin.test.tsx b/tests/brisa/plugin.test.tsx index 07d9d78..88f6d5f 100644 --- a/tests/brisa/plugin.test.tsx +++ b/tests/brisa/plugin.test.tsx @@ -1,14 +1,16 @@ import { join } from "node:path"; import { describe, it, expect } from "bun:test"; -import { transpile } from "prerender-macro"; +import { transpile, type TranspilerOptions } from "prerender-macro"; -const toInline = (s: string) => s.replace(/\s*\n\s*/g, ""); -const normalizeQuotes = (s: string) => toInline(s).replaceAll("'", '"'); +const format = (s: string) => s.replace(/\s*\n\s*/g, "").replaceAll("'", '"'); const configPath = join(import.meta.dir, "config.tsx"); const currentFile = import.meta.url.replace("file://", ""); +const bunTranspiler = new Bun.Transpiler({ loader: "tsx" }); -const jsxRuntimePath = import.meta.resolveSync("brisa/jsx-dev-runtime"); -const importJSXRuntime = `import {jsx, jsxDEV, jsxs, Fragment} from "${jsxRuntimePath}";`; +function transpileAndRunMacros(config: TranspilerOptions) { + // Bun transpiler is needed here to run the macros + return format(bunTranspiler.transformSync(transpile(config))); +} describe("Brisa", () => { describe("plugin", () => { @@ -26,14 +28,12 @@ describe("Brisa", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = normalizeQuotes(code); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(bunTranspiler.transformSync(code)); expect(output).toBe(expected); }); @@ -51,15 +51,12 @@ describe("Brisa", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(` import Foo from "./components"; import {Bar} from "./components"; @@ -88,15 +85,12 @@ describe("Brisa", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(` import {Bar} from "./components"; import Foo from "./components"; @@ -125,15 +119,12 @@ describe("Brisa", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(` import {Bar} from "./components"; import Foo from "./components"; @@ -156,15 +147,12 @@ describe("Brisa", () => { return ; } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(` import {Bar} from "./components"; export default function Test() { @@ -183,15 +171,12 @@ describe("Brisa", () => { return ; } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(` import Foo from "./components"; export default function Test() { diff --git a/tests/preact/components.tsx b/tests/preact/components.tsx index edf755b..c14f224 100644 --- a/tests/preact/components.tsx +++ b/tests/preact/components.tsx @@ -1,5 +1,3 @@ -import { h } from "preact"; - export default function Foo({ name = "foo", nested = {}, diff --git a/tests/preact/config.tsx b/tests/preact/config.tsx index 0d7822a..4bedb9b 100644 --- a/tests/preact/config.tsx +++ b/tests/preact/config.tsx @@ -1,5 +1,4 @@ import { render } from "preact-render-to-string"; -import { h } from "preact"; import type { PrerenderConfig } from "prerender-macro"; export const prerenderConfig = { diff --git a/tests/preact/plugin.test.tsx b/tests/preact/plugin.test.tsx index 481bf45..449afe9 100644 --- a/tests/preact/plugin.test.tsx +++ b/tests/preact/plugin.test.tsx @@ -1,10 +1,16 @@ import { join } from "node:path"; import { describe, it, expect } from "bun:test"; -import { transpile } from "prerender-macro"; +import { TranspilerOptions, transpile } from "prerender-macro"; const format = (s: string) => s.replace(/\s*\n\s*/g, "").replaceAll("'", '"'); const configPath = join(import.meta.dir, "config.tsx"); const currentFile = import.meta.url.replace("file://", ""); +const bunTranspiler = new Bun.Transpiler({ loader: "tsx" }); + +function transpileAndRunMacros(config: TranspilerOptions) { + // Bun transpiler is needed here to run the macros + return format(bunTranspiler.transformSync(transpile(config))); +} describe("Preact", () => { describe("plugin", () => { @@ -22,14 +28,12 @@ describe("Preact", () => { ); } `; - const output = format( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); - const expected = format(code); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); + const expected = format(bunTranspiler.transformSync(code)); expect(output).toBe(expected); }); @@ -47,13 +51,11 @@ describe("Preact", () => { ); } `; - const output = format( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); const expected = format(` import Foo from "./components"; import {Bar} from "./components"; @@ -63,7 +65,7 @@ describe("Preact", () => { children: [{type: "div",props: { dangerouslySetInnerHTML: {__html: "
Foo, foo!
" }}, - key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 4,__i: -1,__u: 0},jsxDEV(Bar, {}, undefined, false, undefined, this)]}, undefined, true, undefined, this); + key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: -3,__i: -1,__u: 0,__source: undefined,__self: undefined},jsxDEV(Bar, {}, undefined, false, undefined, this)]}, undefined, true, undefined, this); } `); @@ -84,13 +86,11 @@ describe("Preact", () => { ); } `; - const output = format( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); const expected = format(` import {Bar} from "./components"; import Foo from "./components"; @@ -101,7 +101,7 @@ describe("Preact", () => { type: "div",props: {dangerouslySetInnerHTML: { __html: "
Bar, bar!
" } - },key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 8,__i: -1,__u: 0}]}, undefined, true, undefined, this); + },key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: -6,__i: -1,__u: 0,__source: undefined,__self: undefined}]}, undefined, true, undefined, this); } `); @@ -122,13 +122,11 @@ describe("Preact", () => { ); } `; - const output = format( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); const expected = format(` import {Bar} from "./components"; import Foo from "./components"; @@ -139,7 +137,7 @@ describe("Preact", () => { type: "div",props: {dangerouslySetInnerHTML: { __html: "
Bar, bar!
" } - },key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 12,__i: -1,__u: 0}]}, undefined, true, undefined, this); + },key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: -9,__i: -1,__u: 0,__source: undefined,__self: undefined}]}, undefined, true, undefined, this); } `); @@ -154,18 +152,16 @@ describe("Preact", () => { return ; } `; - const output = format( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); const expected = format(` import {Bar} from "./components"; export default function Test() { - return {type: "div",props: {dangerouslySetInnerHTML: {__html: "
Bar, bar!
"}},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 16,__i: -1,__u: 0}; + return {type: "div",props: {dangerouslySetInnerHTML: {__html: "
Bar, bar!
"}},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: -12,__i: -1,__u: 0,__source: undefined,__self: undefined}; } `); @@ -180,18 +176,16 @@ describe("Preact", () => { return ; } `; - const output = format( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - }), - ); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + }); const expected = format(` import Foo from "./components"; export default function Test() { - return {type: "div",props: {dangerouslySetInnerHTML: {__html: "
Foo, Preact works!
"}},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 20,__i: -1,__u: 0}; + return {type: "div",props: {dangerouslySetInnerHTML: {__html: "
Foo, Preact works!
"}},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: -15,__i: -1,__u: 0,__source: undefined,__self: undefined}; } `); diff --git a/tests/preact/tsconfig.json b/tests/preact/tsconfig.json index 76503a8..8308cb6 100644 --- a/tests/preact/tsconfig.json +++ b/tests/preact/tsconfig.json @@ -1,26 +1,22 @@ { "compilerOptions": { + "jsxImportSource": "preact", + "jsx": "react-jsx", "baseUrl": ".", "lib": ["dom", "dom.iterable", "esnext"], "module": "esnext", "target": "esnext", "moduleResolution": "bundler", "moduleDetection": "force", - "allowImportingTsExtensions": true, - "noEmit": true, - "composite": true, - "strict": true, - "downlevelIteration": true, "skipLibCheck": true, - "jsx": "react", - "jsxFactory": "h", - "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, - "allowJs": true, - "verbatimModuleSyntax": true, - "noFallthroughCasesInSwitch": true, "paths": { - "@/*": ["*"] - } - } + "react": ["node_modules/preact/compat"], + "react-dom": ["./node_modules/preact/compat/"] + }, + "typeRoots": ["src/types", "./node_modules/@types"] + }, + "resolve": { + "extensions": [".js", ".jsx", ".ts", ".tsx", ".json", ".svg", ".css"] + }, + "include": ["."] } diff --git a/tests/react/plugin.test.tsx b/tests/react/plugin.test.tsx index f07c403..de768af 100644 --- a/tests/react/plugin.test.tsx +++ b/tests/react/plugin.test.tsx @@ -1,15 +1,18 @@ import { join } from "node:path"; import { describe, it, expect } from "bun:test"; -import { transpile } from "prerender-macro"; +import { transpile, type TranspilerOptions } from "prerender-macro"; import { prerenderConfig } from "./config"; -const toInline = (s: string) => s.replace(/\s*\n\s*/g, ""); -const normalizeQuotes = (s: string) => toInline(s).replaceAll("'", '"'); +const format = (s: string) => s.replace(/\s*\n\s*/g, "").replaceAll("'", '"'); const configPath = join(import.meta.dir, "config.tsx"); const currentFile = import.meta.url.replace("file://", ""); -const jsxRuntimePath = import.meta.resolveSync("react/jsx-dev-runtime"); -const importJSXRuntime = `import {jsx, jsxDEV, jsxs, Fragment} from "${jsxRuntimePath}";`; const importConfig = `import {prerenderConfig} from "${configPath}";`; +const bunTranspiler = new Bun.Transpiler({ loader: "tsx" }); + +function transpileAndRunMacros(config: TranspilerOptions) { + // Bun transpiler is needed here to run the macros + return format(bunTranspiler.transformSync(transpile(config))); +} describe("React", () => { describe("plugin", () => { @@ -27,15 +30,13 @@ describe("React", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - prerenderConfig, - }), - ); - const expected = normalizeQuotes(code); + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + prerenderConfig, + }); + const expected = format(bunTranspiler.transformSync(code)); expect(output).toBe(expected); }); @@ -53,16 +54,13 @@ describe("React", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - prerenderConfig, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + prerenderConfig, + }); + const expected = format(` ${importConfig} import Foo from "./components"; import {Bar} from "./components"; @@ -93,16 +91,13 @@ describe("React", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - prerenderConfig, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + prerenderConfig, + }); + const expected = format(` ${importConfig} import {Bar} from "./components"; import Foo from "./components"; @@ -134,16 +129,13 @@ describe("React", () => { ); } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - prerenderConfig, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + prerenderConfig, + }); + const expected = format(` ${importConfig} import {Bar} from "./components"; import Foo from "./components"; @@ -169,16 +161,13 @@ describe("React", () => { return ; } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - prerenderConfig, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + prerenderConfig, + }); + const expected = format(` ${importConfig} import {Bar} from "./components"; @@ -200,16 +189,13 @@ describe("React", () => { return ; } `; - const output = normalizeQuotes( - transpile({ - code, - path: currentFile, - pluginConfig: { prerenderConfigPath: configPath }, - prerenderConfig, - }), - ); - const expected = normalizeQuotes(` - ${importJSXRuntime} + const output = transpileAndRunMacros({ + code, + path: currentFile, + pluginConfig: { prerenderConfigPath: configPath }, + prerenderConfig, + }); + const expected = format(` ${importConfig} import Foo from "./components";