@salesforce/storefront-next-dev 1.3.0 → 1.3.1

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/README.md CHANGED
@@ -57,9 +57,9 @@ export default defineConfig({
57
57
  });
58
58
  ```
59
59
 
60
- #### Page Designer critical-region preload manifest
60
+ #### Page Designer regional preload manifest
61
61
 
62
- Set `staticRegistry.preloadManifest` to `true` when the application renders page-level Page Designer regions with `<Region critical>`. During a production application build, the plugin correlates statically discovered `@Component` modules with the finalized Vite client manifest, embeds a compact resource manifest in the server bundle, and enables Vite's standard client manifest. Development builds expose an empty preload manifest; normal registry loading still works.
62
+ Set `staticRegistry.preloadManifest` to `true` when the application emits resource hints for server-rendered Page Designer regions. During a production application build, the plugin correlates statically discovered `@Component` modules with the finalized Vite client manifest, embeds a compact resource manifest in the server bundle, and enables Vite's standard client manifest. Development builds expose an empty preload manifest; normal registry loading still works.
63
63
 
64
64
  The preload manifest is disabled by default for SDK consumers. It can also be configured explicitly:
65
65
 
@@ -74,16 +74,12 @@ storefrontNextPlugin({
74
74
  path: 'page-designer-preload-manifest.json',
75
75
  // Fail the build unless these type IDs were discovered and mapped.
76
76
  requiredTypeIds: ['hero'],
77
- compression: {
78
- brotli: { quality: 9 }, // integer from 0 through 11
79
- gzip: { level: 6 }, // integer from 0 through 9
80
- },
81
77
  },
82
78
  },
83
79
  });
84
80
  ```
85
81
 
86
- Defaults are `page-designer-preload-manifest.json`, Brotli quality `9`, and Gzip level `6`. Duplicate Page Designer `typeId` values fail manifest generation. A discovered component that cannot be correlated to a client chunk produces a build warning, or a build error when its ID appears in `requiredTypeIds`.
82
+ The default path is `page-designer-preload-manifest.json`. Duplicate Page Designer `typeId` values fail manifest generation. A discovered component that cannot be correlated to a client chunk produces a build warning, or a build error when its ID appears in `requiredTypeIds`.
87
83
 
88
84
  ### React Router Preset
89
85
 
package/dist/index.d.ts CHANGED
@@ -3,18 +3,9 @@ import { Plugin, ResolvedConfig } from "vite";
3
3
 
4
4
  //#region src/plugins/pageDesignerPreloadManifest.d.ts
5
5
 
6
- interface PageDesignerPreloadCompressionConfig {
7
- brotli?: {
8
- quality?: number;
9
- };
10
- gzip?: {
11
- level?: number;
12
- };
13
- }
14
6
  interface PageDesignerPreloadManifestConfig {
15
7
  path?: string;
16
8
  requiredTypeIds?: string[];
17
- compression?: PageDesignerPreloadCompressionConfig;
18
9
  }
19
10
  //#endregion
20
11
  //#region src/plugins/staticRegistry.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugins/pageDesignerPreloadManifest.ts","../src/plugins/staticRegistry.ts","../src/plugins/eventInstrumentationValidator.ts","../src/storefront-next-targets.ts","../src/plugins/transformTargets.ts","../src/plugins/uiTargetDevMode.ts","../src/plugins/hybridProxy.ts","../src/plugins/ecdnMatcher.ts"],"sourcesContent":[],"mappings":";;;;;UAiCiB,oCAAA;EIJD,MAAA,CAAA,EAAA;;;;ICHC,KAAA,CAAA,EAAA,MAAA;EA4BD,CAAA;;ULhBC,iCAAA;;EMuBA,eAAA,CAAA,EAAA,MAAA,EAAA;EAyZD,WAAA,CAAA,EN7aE,oCM6ayB;;;;;;ACxU3C;;UN3EiB,0BAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA+Be;;;;;;AE3DhC;AAkEA;UD/EiB,mCAAA;;;AEGjB;;;;ACHA;AA4BA;;;;ACOA;AAyZA;;;;;;;AH7WA;;;UAlEiB,2BAAA;ECVD;;;;ACHhB;AA4BA;;;;ACOA;AAyZA;;;;ACxUA;;;;;;;;;;;;;;;;;;mBJrEqB;;;;;;;;;kCAUe;;;;;;;;;;;;;;;;;;;;;iBAsBpB,qBAAA,UAA8B,8BAAmC;;;iBC5EjE,gCAAA,CAAA;;;EJIC,cAAA,CAAA,MAAA,EIMc,cJNd,CAAA,EAAoC,IAAA;EAKpC,UAAA,EAAA,EAAA,IAAA;;;;EC6BA,CAAA,GAAA,IAAA;;;;;AE5BjB;AAkEA;;;;AC5EA;;;UCHiB,qBAAA;EAAA;AA4BjB;;;;ACOA;AAyZA;;;;ACxUA;YFtGc;;;;;;;;;;;;;iBAcE,qBAAA,WAAgC,wBAAwB;;;;UCOvD,wBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyZD,iBAAA,UAA2B,2BAA2B;;;;;;;;;;;;;;;;;;;;;;iBCxUtD,iBAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugins/pageDesignerPreloadManifest.ts","../src/plugins/staticRegistry.ts","../src/plugins/eventInstrumentationValidator.ts","../src/storefront-next-targets.ts","../src/plugins/transformTargets.ts","../src/plugins/uiTargetDevMode.ts","../src/plugins/hybridProxy.ts","../src/plugins/ecdnMatcher.ts"],"sourcesContent":[],"mappings":";;;;;AI6BgB,UJGC,iCAAA,CIOc;;;;;;;AGuG/B;;;UN3EiB,0BAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA+Be;;;;;AE3DhC;AAkEA;;UD/EiB,mCAAA;;AEGjB;;;;ECHiB;AA4BjB;;;;ECOiB;AAyZjB;;;;ACxUA;;;;;;;AHjHgB,UDUC,2BAAA,CCV+B;;;;ACHhD;AA4BA;;;;ACOA;AAyZA;;;;ACxUA;;;;;;;;;;;;;;;;;;;mBJrEqB;;;;;;;;;kCAUe;;;;;;;;;;;;;;;;;;;;;iBAsBpB,qBAAA,UAA8B,8BAAmC;;;iBC5EjE,gCAAA,CAAA;;;EJGC,cAAA,CAAA,MAAA,EIOc,cJPmB,CAAA,EAAA,IAAA;;;;ICmCjC,GAAA,EAAA,IAAA;;;;;AE5BjB;AAkEA;;;;AC5EA;;;;ACHiB,UAAA,qBAAA,CAcH;EAcE;;;;ECOC;AAyZjB;;;;ACxUA;;YFtGc;;;;;;;;;;;;;iBAcE,qBAAA,WAAgC,wBAAwB;;;;UCOvD,wBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyZD,iBAAA,UAA2B,2BAA2B;;;;;;;;;;;;;;;;;;;;;;iBCxUtD,iBAAA"}
package/dist/index.js CHANGED
@@ -12,7 +12,6 @@ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "
12
12
  import { glob } from "glob";
13
13
  import { Node, Project, ts } from "ts-morph";
14
14
  import { spawnSync } from "child_process";
15
- import { brotliCompressSync, constants, gzipSync } from "node:zlib";
16
15
  import fs$1, { existsSync as existsSync$1, readFileSync as readFileSync$1 } from "node:fs";
17
16
  import { deadCodeElimination, findReferencedIdentifiers } from "babel-dead-code-elimination";
18
17
  import httpProxy from "http-proxy";
@@ -893,26 +892,15 @@ function assertViteManifestStructure(value) {
893
892
  if (!("file" in record) || typeof record.file !== "string" || record.file.length === 0) throw new Error(`Invalid standard Vite manifest: record "${key}" must have a non-empty string "file"`);
894
893
  }
895
894
  }
896
- function integerInRange(value, path$2, min, max, fallback) {
897
- if (value === void 0) return fallback;
898
- if (!Number.isInteger(value) || value < min || value > max) throw new Error(`${path$2} must be an integer between ${min} and ${max}`);
899
- return value;
900
- }
901
895
  function normalizePageDesignerPreloadManifestConfig(config) {
902
896
  const options = typeof config === "object" ? config : {};
903
897
  return {
904
898
  path: options.path ?? "page-designer-preload-manifest.json",
905
- requiredTypeIds: [...new Set(options.requiredTypeIds ?? [])].sort(),
906
- compression: {
907
- brotli: { quality: integerInRange(options.compression?.brotli?.quality, "preloadManifest.compression.brotli.quality", 0, 11, 9) },
908
- gzip: { level: integerInRange(options.compression?.gzip?.level, "preloadManifest.compression.gzip.level", 0, 9, 6) }
909
- }
899
+ requiredTypeIds: [...new Set(options.requiredTypeIds ?? [])].sort()
910
900
  };
911
901
  }
912
- function createEmptyPageDesignerPreloadManifest(config) {
902
+ function createEmptyPageDesignerPreloadManifest() {
913
903
  return {
914
- version: 1,
915
- compression: config.compression,
916
904
  resources: [],
917
905
  components: {}
918
906
  };
@@ -924,20 +912,11 @@ function normalizeSourceId(projectRoot, id) {
924
912
  if (withoutQuery.startsWith(`${normalizedRoot}/`)) return withoutQuery.slice(normalizedRoot.length + 1);
925
913
  return withoutQuery.startsWith("/") ? relative(projectRoot, withoutQuery).replace(/\\/g, "/") : withoutQuery;
926
914
  }
927
- function outputBytes(output) {
928
- if (output.type === "chunk") return Buffer.from(output.code);
929
- return Buffer.isBuffer(output.source) ? output.source : Buffer.from(output.source);
930
- }
931
- function describeResource(file, kind, bundle, config) {
932
- const output = bundle[file];
933
- if (!output) throw new Error(`Vite manifest references missing emitted resource "${file}"`);
934
- const bytes = outputBytes(output);
915
+ function describeResource(file, kind, bundle) {
916
+ if (!bundle[file]) throw new Error(`Vite manifest references missing emitted resource "${file}"`);
935
917
  return {
936
918
  file,
937
- kind,
938
- bytes: bytes.byteLength,
939
- estimatedBrotliBytes: brotliCompressSync(bytes, { params: { [constants.BROTLI_PARAM_QUALITY]: config.compression.brotli.quality } }).byteLength,
940
- estimatedGzipBytes: gzipSync(bytes, { level: config.compression.gzip.level }).byteLength
919
+ kind
941
920
  };
942
921
  }
943
922
  function assertUniqueTypeIds(components) {
@@ -1004,9 +983,7 @@ function buildPageDesignerPreloadManifest(components, viteManifest, bundle, proj
1004
983
  const resourceIndices = Object.fromEntries(resourceFiles.map((file, index) => [file, index]));
1005
984
  const toIndices = (files) => files.map((file) => resourceIndices[file]);
1006
985
  return {
1007
- version: 1,
1008
- compression: config.compression,
1009
- resources: resourceFiles.map((file) => describeResource(file, resourceKinds.get(file), bundle, config)),
986
+ resources: resourceFiles.map((file) => describeResource(file, resourceKinds.get(file), bundle)),
1010
987
  components: Object.fromEntries(Object.entries(componentFiles).map(([typeId, files]) => [typeId, {
1011
988
  ...files.styles ? { styles: toIndices(files.styles) } : {},
1012
989
  ...files.entries ? { entries: toIndices(files.entries) } : {},
@@ -1027,9 +1004,9 @@ function parseViteManifestAsset(bundle) {
1027
1004
  return parsed;
1028
1005
  }
1029
1006
  function validateEmbeddedPageDesignerPreloadManifest(value) {
1030
- if (!value || typeof value !== "object" || value.version !== 1) throw new Error("Page Designer preload manifest is missing, malformed, or uses an unsupported version");
1007
+ if (!value || typeof value !== "object") throw new Error("Page Designer preload manifest is missing or malformed");
1031
1008
  const candidate = value;
1032
- if (!candidate.compression || !Array.isArray(candidate.resources) || !candidate.components || typeof candidate.components !== "object") throw new Error("Page Designer preload manifest is incomplete");
1009
+ if (!Array.isArray(candidate.resources) || !candidate.components || typeof candidate.components !== "object") throw new Error("Page Designer preload manifest is incomplete");
1033
1010
  }
1034
1011
 
1035
1012
  //#endregion
@@ -1160,25 +1137,22 @@ function generateRegistryCode(components, registryIdentifier = "registry") {
1160
1137
  export function initializeRegistry(targetRegistry = ${registryIdentifier}): void {
1161
1138
  // No components found with @Component decorators
1162
1139
  }
1163
-
1164
- /** Load selected component modules and register their concrete exports before SSR. */
1165
- export async function loadAndRegisterRegistryComponents(
1166
- typeIds: Iterable<string>,
1167
- targetRegistry = ${registryIdentifier}
1168
- ): Promise<void> {
1169
- await Promise.all([...new Set(typeIds)].map((id) => targetRegistry.loadAndRegister(id)));
1170
- }
1171
1140
  `;
1172
- const registrations = sorted.map(({ id, relativePath, hasLoader, hasClientLoader, hasFallback }) => {
1141
+ const importers = sorted.map(({ relativePath }) => ` () => import('${relativePath}'),`).join("\n");
1142
+ const registrations = sorted.map(({ id, hasLoader, hasClientLoader, hasFallback }, index) => {
1173
1143
  if (hasLoader || hasClientLoader || hasFallback) {
1174
1144
  const metadata = [];
1175
1145
  if (hasLoader) metadata.push(`loader: 'loader'`);
1176
1146
  if (hasClientLoader) metadata.push(`clientLoader: 'clientLoader'`);
1177
1147
  if (hasFallback) metadata.push(`fallback: 'fallback'`);
1178
- return ` targetRegistry.registerImporter('${id}', () => import('${relativePath}'), { ${metadata.join(", ")} });`;
1179
- } else return ` targetRegistry.registerImporter('${id}', () => import('${relativePath}'));`;
1148
+ return ` targetRegistry.registerImporter('${id}', staticRegistryImporters[${index}], { ${metadata.join(", ")} });`;
1149
+ } else return ` targetRegistry.registerImporter('${id}', staticRegistryImporters[${index}]);`;
1180
1150
  }).join("\n");
1181
1151
  return `
1152
+ const staticRegistryImporters = [
1153
+ ${importers}
1154
+ ] as const;
1155
+
1182
1156
  /**
1183
1157
  * Initialize the static component registry.
1184
1158
  * This function is auto-generated by the staticRegistry Vite plugin.
@@ -1190,18 +1164,6 @@ export async function loadAndRegisterRegistryComponents(
1190
1164
  export function initializeRegistry(targetRegistry = ${registryIdentifier}): void {
1191
1165
  ${registrations}
1192
1166
  }
1193
-
1194
- /**
1195
- * Load selected component modules and register their concrete exports before SSR.
1196
- * This keeps the component boundary out of the initial Suspense shell while
1197
- * preserving nested data-loading Suspense boundaries and their fallbacks.
1198
- */
1199
- export async function loadAndRegisterRegistryComponents(
1200
- typeIds: Iterable<string>,
1201
- targetRegistry = ${registryIdentifier}
1202
- ): Promise<void> {
1203
- await Promise.all([...new Set(typeIds)].map((id) => targetRegistry.loadAndRegister(id)));
1204
- }
1205
1167
  `;
1206
1168
  }
1207
1169
  /**
@@ -1312,8 +1274,8 @@ const staticRegistryPlugin = (config = {}) => {
1312
1274
  },
1313
1275
  load(id) {
1314
1276
  if (!normalizedPreloadConfig || id !== RESOLVED_PAGE_DESIGNER_PRELOAD_MANIFEST_ID) return;
1315
- if (!isProductionBuild) return `export default ${JSON.stringify(createEmptyPageDesignerPreloadManifest(normalizedPreloadConfig))};`;
1316
- if (this.environment?.name === "client") return `export default ${JSON.stringify(createEmptyPageDesignerPreloadManifest(normalizedPreloadConfig))};`;
1277
+ if (!isProductionBuild) return `export default ${JSON.stringify(createEmptyPageDesignerPreloadManifest())};`;
1278
+ if (this.environment?.name === "client") return `export default ${JSON.stringify(createEmptyPageDesignerPreloadManifest())};`;
1317
1279
  validateEmbeddedPageDesignerPreloadManifest(embeddedManifest);
1318
1280
  return `export default ${JSON.stringify(embeddedManifest)};`;
1319
1281
  },