@rsc-kit/core 0.30.31 → 0.30.33

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/vite.d.ts CHANGED
@@ -493,6 +493,12 @@ export declare function compileStep(root: string): {
493
493
  compile?: string;
494
494
  binary?: string;
495
495
  };
496
+ /**
497
+ * A compile script that runs the build before compiling, with no
498
+ * compile:binary beside it: a deploy that runs the build and then the step
499
+ * the marker names builds twice.
500
+ */
501
+ export declare function compileRebuilds(root: string): boolean;
496
502
  /**
497
503
  * The app's process bootstrap, if it has one: `instrumentation.ts` beside
498
504
  * `app/`, the name Next uses so a reader arriving from there knows what it
package/dist/vite.js CHANGED
@@ -2896,31 +2896,46 @@ function discover(dir) {
2896
2896
  */
2897
2897
  /**
2898
2898
  * The app's single-binary step, as its package.json declares it: the script
2899
- * named compile, and the file its --outfile writes. Read from the app's own
2899
+ * that compiles, and the file its --outfile writes. Read from the app's own
2900
2900
  * script, so a deploy runs what the app runs and never assumes a path. None
2901
2901
  * when the app has no such script - a server it starts with node or bun.
2902
+ *
2903
+ * compile:binary when the app has one: it compiles the output already there,
2904
+ * so a deploy that has just run the build does not run it again inside
2905
+ * compile. Otherwise compile, which usually builds first.
2902
2906
  */
2903
- /** The app's compile script, which names the platform a binary is built for. */
2904
- function compileScript(root) {
2907
+ function binaryScript(root) {
2905
2908
  try {
2906
- return JSON.parse(readFileSync(join(root, "package.json"), "utf-8")).scripts?.compile;
2909
+ const scripts = JSON.parse(readFileSync(join(root, "package.json"), "utf-8")).scripts;
2910
+ for (const name of ["compile:binary", "compile"]) {
2911
+ if (scripts?.[name])
2912
+ return { name, script: scripts[name] };
2913
+ }
2907
2914
  }
2908
2915
  catch {
2909
- return undefined;
2916
+ // No package.json, or not one we can read: no compile step.
2910
2917
  }
2918
+ return undefined;
2919
+ }
2920
+ /** The app's compile script, which names the platform a binary is built for. */
2921
+ function compileScript(root) {
2922
+ return binaryScript(root)?.script;
2911
2923
  }
2912
2924
  export function compileStep(root) {
2913
- try {
2914
- const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf-8"));
2915
- const script = pkg.scripts?.compile;
2916
- if (!script)
2917
- return {};
2918
- const outfile = /--outfile[= ]+("[^"]+"|'[^']+'|\S+)/.exec(script)?.[1]?.replace(/^["']|["']$/g, "");
2919
- return outfile ? { compile: "compile", binary: outfile } : { compile: "compile" };
2920
- }
2921
- catch {
2925
+ const step = binaryScript(root);
2926
+ if (!step)
2922
2927
  return {};
2923
- }
2928
+ const outfile = /--outfile[= ]+("[^"]+"|'[^']+'|\S+)/.exec(step.script)?.[1]?.replace(/^["']|["']$/g, "");
2929
+ return outfile ? { compile: step.name, binary: outfile } : { compile: step.name };
2930
+ }
2931
+ /**
2932
+ * A compile script that runs the build before compiling, with no
2933
+ * compile:binary beside it: a deploy that runs the build and then the step
2934
+ * the marker names builds twice.
2935
+ */
2936
+ export function compileRebuilds(root) {
2937
+ const step = binaryScript(root);
2938
+ return step?.name === "compile" && /\bvite\s+build\b/.test(step.script);
2924
2939
  }
2925
2940
  /** The root layout's metadataBase as the loaded app has it, whatever it was computed from. */
2926
2941
  async function loadedMetadataBase(engine, manifest) {
@@ -7529,6 +7544,12 @@ export function rscKit(options = {}) {
7529
7544
  const message = native.missingMessage(tree.missing, target, native.hostPlatform());
7530
7545
  if (process.env.npm_lifecycle_event === "compile")
7531
7546
  throw new Error(message);
7547
+ // A compile step that runs after this build - compile:binary,
7548
+ // or a deploy's - must fail too, and bun build reads nothing of
7549
+ // the build but this entry: it names the message as an import
7550
+ // that cannot resolve, and stops there. Relative, so it is never
7551
+ // looked up as a package.
7552
+ writeFileSync(join(nitro.options.output.serverDir, "compile.mjs"), `import ${JSON.stringify("./" + message.replace(/\s+/g, " "))};\n`);
7532
7553
  log(message.replace(/^\[rsc-kit\] /, "").replace("The binary is compiled", "A binary compiled now would be"));
7533
7554
  return;
7534
7555
  }
@@ -8253,6 +8274,10 @@ export function rscKit(options = {}) {
8253
8274
  const none = marker && !marker.shells.length && !marker.static.length;
8254
8275
  log(`edge: ${none ? "edge.json lists no page: every one is under middleware" : "left out of edge.json, under middleware"}, which runs per request: ${guarded.join(", ")}`);
8255
8276
  }
8277
+ if (output !== "export" && compileRebuilds(projectRoot)) {
8278
+ log("compile runs vite build again, so a deploy that builds and then compiles builds twice. " +
8279
+ "Move the bun build --compile part into a compile:binary script, which the marker then names, and have compile run vite build && bun run compile:binary.");
8280
+ }
8256
8281
  // What this build produced, where a deploy can read it without parsing
8257
8282
  // vite.config.ts - which can turn export on through RSC_OUTPUT, or
8258
8283
  // compute it - or knowing where rsc-kit keeps things inside .output.