@rsc-kit/core 0.22.3 → 0.22.4

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
@@ -382,6 +382,20 @@ export interface KnownAction {
382
382
  * its own - is its character code, so no two paths share an alias.
383
383
  */
384
384
  export declare function toAlias(name: string): string;
385
+ /**
386
+ * How the generated entry imports instrumentation.ts, as `__instrumentation`.
387
+ *
388
+ * The entry reads both hooks, and a file may export either, both or neither.
389
+ * Only the ones it exports are named: read off a namespace import, a hook the
390
+ * file does not have is a bundler warning on every build (IMPORT_IS_UNDEFINED,
391
+ * "Import `shutdown` will always be undefined") - the app told off for a file
392
+ * written exactly as documented. The rest are simply absent from the object.
393
+ */
394
+ export declare function instrumentationImport(instrumentation: {
395
+ file: string;
396
+ hasRegister: boolean;
397
+ hasShutdown: boolean;
398
+ } | null): string;
385
399
  /**
386
400
  * The worker the dev server serves at /sw.js: it removes the one a production
387
401
  * run left on this origin, and the caches with it, then reloads each page it
package/dist/vite.js CHANGED
@@ -33,7 +33,6 @@ import { ownHosts } from "./hostRouting.js";
33
33
  import { unrollBarrelImports } from "./barrelImports.js";
34
34
  import { serverRendererMessage, SERVER_RENDERER, ssrProxyModule, UseSsrError, withoutSsrDirective } from "./useSsr.js";
35
35
  import { httpHostCalls } from "./hostCalls.js";
36
- import { bytecodeNote } from "./bytecodeCheck.js";
37
36
  import { clientPackages, importsServerRenderer, packageDir as installedPackageDir, packageEntryInGraph, polyfillsToTrace, traceableByName } from "./clientPackages.js";
38
37
  // Resolved once per rscKit() call. One build runs in one process, so these are
39
38
  // module state rather than threaded through every helper.
@@ -2486,6 +2485,30 @@ function instrumentationFile() {
2486
2485
  }
2487
2486
  return null;
2488
2487
  }
2488
+ /**
2489
+ * How the generated entry imports instrumentation.ts, as `__instrumentation`.
2490
+ *
2491
+ * The entry reads both hooks, and a file may export either, both or neither.
2492
+ * Only the ones it exports are named: read off a namespace import, a hook the
2493
+ * file does not have is a bundler warning on every build (IMPORT_IS_UNDEFINED,
2494
+ * "Import `shutdown` will always be undefined") - the app told off for a file
2495
+ * written exactly as documented. The rest are simply absent from the object.
2496
+ */
2497
+ export function instrumentationImport(instrumentation) {
2498
+ const type = "{ register?: () => unknown; shutdown?: () => unknown }";
2499
+ if (!instrumentation)
2500
+ return `const __instrumentation: ${type} = {}`;
2501
+ const hooks = [
2502
+ ...(instrumentation.hasRegister ? ["register"] : []),
2503
+ ...(instrumentation.hasShutdown ? ["shutdown"] : []),
2504
+ ];
2505
+ const from = JSON.stringify(instrumentation.file);
2506
+ // No hooks: still imported, first, for what its import does.
2507
+ if (hooks.length === 0)
2508
+ return `import ${from}\nconst __instrumentation: ${type} = {}`;
2509
+ return (`import { ${hooks.map((hook) => `${hook} as __instrumentation_${hook}`).join(", ")} } from ${from}\n` +
2510
+ `const __instrumentation: ${type} = { ${hooks.map((hook) => `${hook}: __instrumentation_${hook}`).join(", ")} }`);
2511
+ }
2489
2512
  function generateEntryRsc(fallbackOrigin = "") {
2490
2513
  const instrumentation = instrumentationFile();
2491
2514
  // The 404 page, if the app has one, and the layouts it renders inside.
@@ -2552,11 +2575,7 @@ ${
2552
2575
  // First, before any page: an import's side effects run in import order,
2553
2576
  // and a package configured here has to be configured before a page module
2554
2577
  // that reads it at evaluation time.
2555
- instrumentation?.hasRegister || instrumentation?.hasShutdown
2556
- ? `import * as __instrumentation from ${JSON.stringify(instrumentation.file)}`
2557
- : instrumentation
2558
- ? `import ${JSON.stringify(instrumentation.file)}\nconst __instrumentation: { register?: () => unknown; shutdown?: () => unknown } = {}`
2559
- : "const __instrumentation: { register?: () => unknown; shutdown?: () => unknown } = {}"}
2578
+ instrumentationImport(instrumentation)}
2560
2579
  import { SegmentBoundary } from ${JSON.stringify(join(packageDir, "js/SegmentBoundary"))}
2561
2580
  import { LoadingBoundary } from ${JSON.stringify(join(packageDir, "js/LoadingBoundary"))}
2562
2581
  import { DocumentTitle } from ${JSON.stringify(join(packageDir, "js/DocumentTitle"))}
@@ -6059,16 +6078,6 @@ export function rscKit(options = {}) {
6059
6078
  log(`stored pages: ${copied} files uploaded as assets, read through the ASSETS binding`);
6060
6079
  });
6061
6080
  }
6062
- // Said at the end of a bun build, only when true: which module keeps
6063
- // `bun build --compile --bytecode` from applying, and where. Bun
6064
- // itself names no file and exits 0. See bytecodeCheck.ts.
6065
- if (nitro.options.preset === "bun") {
6066
- nitro.hooks.hook("compiled", () => {
6067
- const note = bytecodeNote(nitro.options.output.serverDir);
6068
- if (note)
6069
- log(note);
6070
- });
6071
- }
6072
6081
  // External at Nitro's layer too. The Vite build leaves these as
6073
6082
  // imports, and Nitro would then bundle them into its own chunks -
6074
6083
  // which for a native package fails at load, and for a polyfill like