rari 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { a as headers, i as rariRouter, n as defineRariOptions, o as RariResponse, r as rari, t as defineRariConfig } from "./vite-CNKYWQs-.mjs";
1
+ import { a as headers, i as rariRouter, n as defineRariOptions, o as RariResponse, r as rari, t as defineRariConfig } from "./vite-CT18_z0c.mjs";
2
2
  import { i as writeManifest, n as generateAppRouteManifest, r as loadManifest, t as AppRouteGenerator } from "./app-routes-BjA_L5R4.mjs";
3
3
  import { c as createHttpRuntimeClient, d as clearPropsCacheForComponent, f as extractMetadata, g as hasServerSideDataFetching, h as extractStaticParams, i as HttpRuntimeClient, m as extractServerPropsWithCache, p as extractServerProps, u as clearPropsCache } from "./runtime-client-CGCu6fmO.mjs";
4
4
  import "./loading-component-map-UZ-MQYv0.mjs";
5
- import "./server-build-BVvKXTME.mjs";
5
+ import "./server-build-Cvj5EwXx.mjs";
6
6
 
7
7
  export { AppRouteGenerator, HttpRuntimeClient, RariResponse, clearPropsCache, clearPropsCacheForComponent, createHttpRuntimeClient, defineRariConfig, defineRariOptions, extractMetadata, extractServerProps, extractServerPropsWithCache, extractStaticParams, generateAppRouteManifest, hasServerSideDataFetching, headers, loadManifest, rari, rariRouter, writeManifest };
@@ -1,3 +1,3 @@
1
- import { n as createServerBuildPlugin, r as scanDirectory, t as ServerComponentBuilder } from "./server-build-BVvKXTME.mjs";
1
+ import { n as createServerBuildPlugin, r as scanDirectory, t as ServerComponentBuilder } from "./server-build-Cvj5EwXx.mjs";
2
2
 
3
3
  export { ServerComponentBuilder, createServerBuildPlugin, scanDirectory };
@@ -361,7 +361,7 @@ const ${importName} = (props) => {
361
361
  await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2), "utf-8");
362
362
  return manifest;
363
363
  }
364
- async buildSingleComponent(inputPath, outputPath, _component) {
364
+ async buildSingleComponent(inputPath, outputPath, _component, returnCode = false) {
365
365
  const componentId = this.getComponentId(path.relative(this.projectRoot, inputPath));
366
366
  const originalCode = await fs.promises.readFile(inputPath, "utf-8");
367
367
  const clientTransformedCode = this.transformClientImports(originalCode, inputPath);
@@ -484,6 +484,7 @@ const ${importName} = (props) => {
484
484
  code = code.replace(/import\s+\{[^}]*\}\s+from\s+['"]node:[^'"]+['"];?\s*/g, "// Node.js built-ins are available in Deno runtime\n");
485
485
  const finalTransformedCode = this.createSelfRegisteringModule(code, componentId);
486
486
  await fs.promises.writeFile(outputPath, finalTransformedCode, "utf-8");
487
+ if (returnCode) return finalTransformedCode;
487
488
  }
488
489
  if (result.errors.length > 0) {
489
490
  console.error("ESBuild errors:", result.errors);
@@ -736,7 +737,7 @@ function registerClientReference(clientReference, id, exportName) {
736
737
  }
737
738
  const bundleDir = path.dirname(fullBundlePath);
738
739
  await fs.promises.mkdir(bundleDir, { recursive: true });
739
- const builtCode = await this.buildSingleComponentOptimized(filePath, fullBundlePath, componentData);
740
+ const builtCode = await this.buildSingleComponent(filePath, fullBundlePath, componentData, true);
740
741
  this.buildCache.set(filePath, {
741
742
  code: builtCode,
742
743
  timestamp: Date.now(),
@@ -749,140 +750,6 @@ function registerClientReference(clientReference, id, exportName) {
749
750
  success: true
750
751
  };
751
752
  }
752
- async buildSingleComponentOptimized(inputPath, outputPath, _component) {
753
- const componentId = this.getComponentId(path.relative(this.projectRoot, inputPath));
754
- const originalCode = await fs.promises.readFile(inputPath, "utf-8");
755
- const clientTransformedCode = this.transformClientImports(originalCode, inputPath);
756
- const componentGlobalCode = this.isPageComponent(inputPath) ? this.transformComponentImportsToGlobal(clientTransformedCode) : clientTransformedCode;
757
- const transformedCode = this.transformNodeImports(componentGlobalCode);
758
- const ext = path.extname(inputPath);
759
- let loader;
760
- if (ext === ".tsx") loader = "tsx";
761
- else if (ext === ".ts") loader = "ts";
762
- else if (ext === ".jsx") loader = "jsx";
763
- else loader = "js";
764
- try {
765
- const result = await build({
766
- stdin: {
767
- contents: transformedCode,
768
- resolveDir: path.dirname(inputPath),
769
- sourcefile: inputPath,
770
- loader
771
- },
772
- bundle: true,
773
- platform: "neutral",
774
- target: "es2022",
775
- format: "esm",
776
- external: [],
777
- mainFields: ["module", "main"],
778
- conditions: [
779
- "import",
780
- "module",
781
- "default"
782
- ],
783
- jsx: "transform",
784
- jsxFactory: "React.createElement",
785
- jsxFragment: "React.Fragment",
786
- define: {
787
- "global": "globalThis",
788
- "process.env.NODE_ENV": "\"production\""
789
- },
790
- loader: {
791
- ".ts": "ts",
792
- ".tsx": "tsx",
793
- ".js": "js",
794
- ".jsx": "jsx"
795
- },
796
- resolveExtensions: [
797
- ".ts",
798
- ".tsx",
799
- ".js",
800
- ".jsx"
801
- ],
802
- minify: false,
803
- minifyIdentifiers: false,
804
- sourcemap: false,
805
- metafile: false,
806
- write: false,
807
- plugins: [
808
- {
809
- name: "replace-react-imports",
810
- setup(build$1) {
811
- build$1.onLoad({ filter: /runtime-client.*\.js$/ }, async (args) => {
812
- let contents = await (await import("node:fs/promises")).readFile(args.path, "utf-8");
813
- contents = contents.replace(/import\s+React\d*(?:\s*,\s*\{[^}]*\})?\s+from\s+['"]react['"];?/g, "// React is available as globalThis.React");
814
- contents = contents.replace(/React2/g, "React");
815
- return {
816
- contents,
817
- loader: "js"
818
- };
819
- });
820
- }
821
- },
822
- {
823
- name: "auto-external",
824
- setup(build$1) {
825
- build$1.onResolve({ filter: /^[^./]/ }, async (args) => {
826
- if (args.path === "react" || args.path === "react-dom" || args.path === "react/jsx-runtime" || args.path === "react/jsx-dev-runtime") return {
827
- path: args.path,
828
- external: true
829
- };
830
- if (args.path === "rari/client") return null;
831
- return {
832
- path: args.path,
833
- external: true
834
- };
835
- });
836
- }
837
- },
838
- {
839
- name: "resolve-server-functions",
840
- setup(build$1) {
841
- build$1.onResolve({ filter: /^\.\.?\/.*(functions|actions)/ }, async (args) => {
842
- const resolvedPath = path.resolve(path.dirname(args.importer), args.path);
843
- for (const ext$1 of [
844
- ".ts",
845
- ".js",
846
- ".tsx",
847
- ".jsx",
848
- "/index.ts",
849
- "/index.js"
850
- ]) {
851
- const fullPath = resolvedPath + ext$1;
852
- if (fs.existsSync(fullPath)) return { path: fullPath };
853
- }
854
- return null;
855
- });
856
- }
857
- }
858
- ],
859
- banner: { js: `// Rari Server Component Bundle
860
- // Generated at: ${(/* @__PURE__ */ new Date()).toISOString()}
861
- // Original file: ${path.relative(this.projectRoot, inputPath)}
862
- ` }
863
- });
864
- if (result.outputFiles && result.outputFiles.length > 0) {
865
- let code = result.outputFiles[0].text;
866
- code = code.replace(/import\s+\{[^}]*\}\s+from\s+['"]react\/jsx-runtime['"];?\s*/g, "// jsx/jsxs are available as globals\n");
867
- code = code.replace(/import\s+\{[^}]*\}\s+from\s+['"]react\/jsx-dev-runtime['"];?\s*/g, "// jsx/jsxs are available as globals\n");
868
- code = code.replace(/import\s+React\d*(?:\s*,\s*\{[^}]*\})?\s+from\s+['"]react['"];?\s*/g, "// React is available as globalThis.React\n");
869
- code = code.replace(/import\s+\{[^}]*\}\s+from\s+['"]react['"];?\s*/g, "// React is available as globalThis.React\n");
870
- code = code.replace(/import\s+\w+\s+from\s+['"]node:[^'"]+['"];?\s*/g, "// Node.js built-ins are available in Deno runtime\n");
871
- code = code.replace(/import\s+\{[^}]*\}\s+from\s+['"]node:[^'"]+['"];?\s*/g, "// Node.js built-ins are available in Deno runtime\n");
872
- const finalTransformedCode = this.createSelfRegisteringModule(code, componentId);
873
- await fs.promises.writeFile(outputPath, finalTransformedCode, "utf-8");
874
- return finalTransformedCode;
875
- }
876
- if (result.errors.length > 0) {
877
- console.error("ESBuild errors:", result.errors);
878
- throw new Error(`ESBuild compilation failed with ${result.errors.length} errors`);
879
- }
880
- throw new Error("No output generated from ESBuild");
881
- } catch (error) {
882
- console.error(`ESBuild failed for ${inputPath}:`, error);
883
- throw error;
884
- }
885
- }
886
753
  manifestCache = null;
887
754
  manifestDirty = false;
888
755
  async updateManifestForComponent(componentId, filePath, bundlePath) {