@salesforce/storefront-next-dev 1.3.2 → 1.4.0-alpha.0

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.js CHANGED
@@ -25,6 +25,27 @@ const LEVEL_PRIORITY = {
25
25
  info: 2,
26
26
  debug: 3
27
27
  };
28
+ /**
29
+ * Type guard for a {@link LogLevel} name. Uses `Object.hasOwn` (not `in`) so
30
+ * inherited properties like `toString` don't falsely validate an env value.
31
+ */
32
+ function isLogLevel(value) {
33
+ return Object.hasOwn(LEVEL_PRIORITY, value);
34
+ }
35
+ /**
36
+ * Managed Runtime injects `MRT_LOG_LEVEL` as a numeric string from its own
37
+ * `LogLevel` enum (`0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL`), not a
38
+ * level name — so it must be mapped, not matched against {@link LEVEL_PRIORITY}'s
39
+ * keys. `TRACE` and `FATAL` clamp to the closest level this logger supports.
40
+ */
41
+ const MRT_NUMERIC_TO_LEVEL = {
42
+ "0": "debug",
43
+ "1": "debug",
44
+ "2": "info",
45
+ "3": "warn",
46
+ "4": "error",
47
+ "5": "error"
48
+ };
28
49
  let overrideLevel;
29
50
  /**
30
51
  * Returns true when the `DEBUG` env var targets sfnext or is a general enable flag.
@@ -48,8 +69,10 @@ function debugEnablesSfnext() {
48
69
  }
49
70
  function resolveLevel() {
50
71
  if (overrideLevel) return overrideLevel;
51
- const envLevel = process.env.MRT_LOG_LEVEL ?? process.env.SFCC_LOG_LEVEL;
52
- if (envLevel && envLevel in LEVEL_PRIORITY) return envLevel;
72
+ const mrtLevel = process.env.MRT_LOG_LEVEL;
73
+ if (mrtLevel && mrtLevel in MRT_NUMERIC_TO_LEVEL) return MRT_NUMERIC_TO_LEVEL[mrtLevel];
74
+ const sfccLevel = process.env.SFCC_LOG_LEVEL;
75
+ if (sfccLevel && isLogLevel(sfccLevel)) return sfccLevel;
53
76
  if (debugEnablesSfnext()) return "debug";
54
77
  if (process.env.NODE_ENV === "production") return "warn";
55
78
  return "info";
@@ -2111,17 +2134,42 @@ function i18nPlugin(config) {
2111
2134
  name: "storefront-next:i18n",
2112
2135
  apply: "build",
2113
2136
  config(viteConfig) {
2114
- const output = viteConfig.build?.rollupOptions?.output;
2115
- if (Array.isArray(output)) return;
2116
- const existingManualChunks = output?.manualChunks;
2117
- return { build: { rollupOptions: { output: { manualChunks(id, meta) {
2118
- const localeMatch = id.match(pattern);
2119
- if (localeMatch) return `locales-${localeMatch[1]}`;
2120
- if (typeof existingManualChunks === "function") return existingManualChunks.call(this, id, meta);
2121
- if (existingManualChunks && typeof existingManualChunks === "object") {
2122
- for (const [name, ids] of Object.entries(existingManualChunks)) if (ids.includes(id)) return name;
2123
- }
2124
- } } } } };
2137
+ const wrapManualChunks = (output) => {
2138
+ if (Array.isArray(output)) return;
2139
+ const existingManualChunks = output?.manualChunks;
2140
+ return function(id, meta) {
2141
+ const localeMatch = id.match(pattern);
2142
+ if (localeMatch) return `locales-${localeMatch[1]}`;
2143
+ if (typeof existingManualChunks === "function") return existingManualChunks.call(this, id, meta);
2144
+ if (existingManualChunks && typeof existingManualChunks === "object") {
2145
+ for (const [name, ids] of Object.entries(existingManualChunks)) if (ids.includes(id)) return name;
2146
+ }
2147
+ };
2148
+ };
2149
+ if (viteConfig.environments?.client) {
2150
+ const rootOutput = viteConfig.build?.rollupOptions?.output;
2151
+ const clientOutput = viteConfig.environments.client.build?.rollupOptions?.output ?? rootOutput;
2152
+ const ssrOutput = viteConfig.environments.ssr?.build?.rollupOptions?.output ?? rootOutput;
2153
+ const clientManualChunks = wrapManualChunks(clientOutput);
2154
+ const ssrManualChunks = wrapManualChunks(ssrOutput);
2155
+ if (!clientManualChunks && !ssrManualChunks) return;
2156
+ return { environments: {
2157
+ ...clientManualChunks && { client: { build: { rollupOptions: { output: {
2158
+ ...clientOutput,
2159
+ manualChunks: clientManualChunks
2160
+ } } } } },
2161
+ ...ssrManualChunks && { ssr: { build: { rollupOptions: { output: {
2162
+ ...ssrOutput,
2163
+ manualChunks: ssrManualChunks
2164
+ } } } } }
2165
+ } };
2166
+ }
2167
+ const manualChunks = wrapManualChunks(viteConfig.build?.rollupOptions?.output);
2168
+ if (!manualChunks) return;
2169
+ return { build: { rollupOptions: { output: {
2170
+ ...viteConfig.build?.rollupOptions?.output,
2171
+ manualChunks
2172
+ } } } };
2125
2173
  }
2126
2174
  };
2127
2175
  }