@salesforce/storefront-next-dev 0.1.0 → 0.1.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/dist/cli.js CHANGED
@@ -17,6 +17,7 @@ import express from "express";
17
17
  import { createRequestHandler } from "@react-router/express";
18
18
  import { existsSync, readFileSync, unlinkSync } from "node:fs";
19
19
  import { basename, extname as extname$1, join, resolve } from "node:path";
20
+ import { pathToFileURL as pathToFileURL$1 } from "node:url";
20
21
  import { createProxyMiddleware } from "http-proxy-middleware";
21
22
  import compression from "compression";
22
23
  import zlib$1 from "node:zlib";
@@ -33,7 +34,7 @@ import prompts from "prompts";
33
34
  import { z } from "zod";
34
35
 
35
36
  //#region package.json
36
- var version = "0.1.0";
37
+ var version = "0.1.1";
37
38
 
38
39
  //#endregion
39
40
  //#region src/utils/logger.ts
@@ -976,6 +977,16 @@ const ServerModeFeatureMap = {
976
977
 
977
978
  //#endregion
978
979
  //#region src/server/index.ts
980
+ /** Relative path to the middleware registry TypeScript source (development). Must match appDirectory + server dir + filename used by buildMiddlewareRegistry plugin. */
981
+ const RELATIVE_MIDDLEWARE_REGISTRY_SOURCE = "src/server/middleware-registry.ts";
982
+ /** Extensions to try for the built middlewares module (ESM first, then CJS for backwards compatibility). */
983
+ const MIDDLEWARE_REGISTRY_BUILT_EXTENSIONS = [
984
+ ".mjs",
985
+ ".js",
986
+ ".cjs"
987
+ ];
988
+ /** All paths to try when loading the built middlewares (base + extension). */
989
+ const RELATIVE_MIDDLEWARE_REGISTRY_BUILT_PATHS = ["bld/server/middleware-registry", "build/server/middleware-registry"].flatMap((base) => MIDDLEWARE_REGISTRY_BUILT_EXTENSIONS.map((ext) => `${base}${ext}`));
979
990
  /**
980
991
  * Create a unified Express server for development, preview, or production mode
981
992
  */
@@ -993,13 +1004,22 @@ async function createServer$1(options) {
993
1004
  const bundlePath = getBundlePath(bundleId);
994
1005
  app.use(bundlePath, createStaticMiddleware(bundleId, projectDirectory));
995
1006
  }
996
- const middlewareRegistryPath = resolve(projectDirectory, "src/server/middleware-registry.ts");
997
- if (existsSync(middlewareRegistryPath)) {
998
- const registry = await importTypescript(middlewareRegistryPath, { projectDirectory });
999
- if (registry.customMiddlewares && Array.isArray(registry.customMiddlewares)) registry.customMiddlewares.forEach((middleware) => {
1000
- app.use(middleware);
1001
- });
1007
+ let registry = null;
1008
+ if (mode === "development") {
1009
+ const middlewareRegistryPath = resolve(projectDirectory, RELATIVE_MIDDLEWARE_REGISTRY_SOURCE);
1010
+ if (existsSync(middlewareRegistryPath)) registry = await importTypescript(middlewareRegistryPath, { projectDirectory });
1011
+ } else {
1012
+ const possiblePaths = RELATIVE_MIDDLEWARE_REGISTRY_BUILT_PATHS.map((p) => resolve(projectDirectory, p));
1013
+ let builtRegistryPath = null;
1014
+ for (const path$1 of possiblePaths) if (existsSync(path$1)) {
1015
+ builtRegistryPath = path$1;
1016
+ break;
1017
+ }
1018
+ if (builtRegistryPath) registry = await import(pathToFileURL$1(builtRegistryPath).href);
1002
1019
  }
1020
+ if (registry?.customMiddlewares && Array.isArray(registry.customMiddlewares)) registry.customMiddlewares.forEach((entry) => {
1021
+ app.use(entry.handler);
1022
+ });
1003
1023
  if (mode === "development" && vite) app.use(vite.middlewares);
1004
1024
  if (enableProxy) app.use(config.commerce.api.proxy, createCommerceProxyMiddleware(config));
1005
1025
  app.use(createHostHeaderMiddleware());
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["ExtensionMeta","ExtensionConfig","Record","default"],"sources":["../src/plugins/staticRegistry.ts","../src/plugins/eventInstrumentationValidator.ts","../src/plugin.ts","../src/plugins/transformPlugins.ts","../src/types.ts","../src/commands/push.ts","../src/server/config.ts","../src/server/modes.ts","../src/server/index.ts","../src/extensibility/extension-config.d.ts","../src/extensibility/trim-extensions.ts","../src/cartridge-services/generate-cartridge.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport type ExtensionMeta = {\n name: string;\n description: string;\n installationInstructions: string;\n uninstallationInstructions: string;\n folder: string;\n dependencies: string[];\n defaultOn?: boolean;\n};\n\ndeclare const ExtensionConfig: {\n extensions: Record<string, ExtensionMeta>;\n};\n\nexport default ExtensionConfig;\n"],"mappings":";;;;;;;;;;AOeY,UPsCK,0BAAA,COtCK;EAKL;;;;ECYA,aAAA,CAAA,EAAc,MAAA;EAAgB;;;;;;EAAD,YAAA,CAAA,EAAA,MAAA;EA0BxB;;;;EAA6C,kBAAA,CAAA,EAAA,MAAA;;;;AC3CnE;EAUcC,WAAAA,CAAAA,EAAAA,OAEb;;;;ACJqD;EAW9B,OAAA,CAAA,EAAA,OAAc;;;;;;;;APRtB,UFFC,mCAAA,CEWc;;;;ACc/B;;;;AChBA;;;;ACXA;AAoBA;AAuDA;;;;AClFA;AAKA;;;;;;;AJMA;;UDKiB,2BAAA;;AEkBjB;;;;AChBA;;;;ACXA;AAoBA;AAuDA;;;;AClFA;AAKA;;;;ACYA;;;EAQa,kBAAA,CAAA,EAAA,OAAA;EAMF;;;;AAYX;;;;EAAmE,cAAA,CAAA,ENO9C,0BMP8C;;;;AC3CnE;AAQE;;;;ECGG,6BAAmB,CAAA,ERiDY,mCQjDH,GAAA,KAAA;AAAA;;;;;;;;AC8pBjC;AAwBA;AA8CA;;;;;;;;;;iBT7pBgB,qBAAA,UAA8B,8BAAmC;;;iBCvEjE,gCAAA,CAAA;;;yBASe;;EHkBd,SAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EAAA,MAA0B,CAAA,EAAA;;;;AC7B3C,CAAA;;;;UGyB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AAY;AAoB7B;AAuDsB,iBK6pBA,gBAAA,CL7pBqD,gBAAR,EAAO,MAAA,EAAA,iBAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EKgqB5D,uBLhqB4D,CAAA,EKiqBvE,OLjqBuE,CKiqB/D,sBLjqB+D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":["ExtensionMeta","ExtensionConfig","Record","default"],"sources":["../src/plugins/staticRegistry.ts","../src/plugins/eventInstrumentationValidator.ts","../src/plugin.ts","../src/plugins/transformPlugins.ts","../src/types.ts","../src/commands/push.ts","../src/server/config.ts","../src/server/modes.ts","../src/server/index.ts","../src/extensibility/extension-config.d.ts","../src/extensibility/trim-extensions.ts","../src/cartridge-services/generate-cartridge.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport type ExtensionMeta = {\n name: string;\n description: string;\n installationInstructions: string;\n uninstallationInstructions: string;\n folder: string;\n dependencies: string[];\n defaultOn?: boolean;\n};\n\ndeclare const ExtensionConfig: {\n extensions: Record<string, ExtensionMeta>;\n};\n\nexport default ExtensionConfig;\n"],"mappings":";;;;;;;;;;AOeY,UPsCK,0BAAA,COtCK;EAKL;;;;EC8BA,aAAA,CAAA,EAAc,MAAA;EAAgB;;;;;;EAAD,YAAA,CAAA,EAAA,MAAA;EA0BxB;;;;EAA6C,kBAAA,CAAA,EAAA,MAAA;;;;AC7DnE;EAUcC,WAAAA,CAAAA,EAAAA,OAEb;;;;ACJqD;EAW9B,OAAA,CAAA,EAAA,OAAc;;;;;;;;APRtB,UFFC,mCAAA,CEWc;;;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;;;UGiBnB,aAAA,SAAsB,QAAQ;;QAErC;EJHO;;;WISJ;EHzBS;;;SG+BX;EF1CM;EAoBD,KAAA,CAAA,EEyBJ,WFzBI;EAuDM;;;;AClFtB;AAKA;iBCwDsB,YAAA,UAAsB,gBAAgB,QAAQ;;;;;;;;;ARvBpE;;;;AC7BA;;;;ACQA;AAkEgB,KOnFJD,aAAAA,GPmFyB;;;;ECxErB,0BAAA,EAAA,MAAA;;;;ACuBhB,CAAA;cKxBcC;cACEC,eAAeF;AJO/B,CAAA;;;KKPK,mBAAA,GAAsB;iBAQH,cAAA,yCAEC,QAAQ,+CACJ;;;;;;AVgBZ,UWmoBA,uBAAA,CXnoB0B;;;;AC7B3C;;;;ACQA;AAkEA;;;;ACxEA;;;;ACuBA;;;;AChBsB,UM+qBL,sBAAA,CN/qBiC;;;;ECXjC,UAAA,EAAA,MAAY;AAoB7B;AAuDsB,iBK6pBA,gBAAA,CL7pBqD,gBAAR,EAAO,MAAA,EAAA,iBAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EKgqB5D,uBLhqB4D,CAAA,EKiqBvE,OLjqBuE,CKiqB/D,sBLjqB+D,CAAA"}
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ import chalk from "chalk";
18
18
  import express from "express";
19
19
  import { createRequestHandler } from "@react-router/express";
20
20
  import { existsSync as existsSync$1, readFileSync as readFileSync$1, unlinkSync } from "node:fs";
21
+ import { pathToFileURL as pathToFileURL$1 } from "node:url";
21
22
  import { createProxyMiddleware } from "http-proxy-middleware";
22
23
  import compression from "compression";
23
24
  import zlib from "node:zlib";
@@ -245,18 +246,21 @@ const MODULE_TO_PATCH = "react-router";
245
246
  */
246
247
  const patchReactRouterPlugin = () => {
247
248
  let isTestMode = false;
249
+ let isDevMode = false;
248
250
  return {
249
251
  name: "odyssey:patch-react-router",
250
252
  enforce: "pre",
251
253
  config(_config, { mode }) {
252
254
  isTestMode = mode === "test";
255
+ isDevMode = mode === "development";
253
256
  },
254
257
  configEnvironment(name) {
255
258
  if (isTestMode) return;
259
+ if (isDevMode) return;
256
260
  if (name === "ssr") return { resolve: { noExternal: ["react-router"] } };
257
261
  },
258
262
  resolveId(id, importer) {
259
- if (isTestMode) return null;
263
+ if (isTestMode || isDevMode) return null;
260
264
  if (id === MODULE_TO_PATCH) {
261
265
  if (importer === VIRTUAL_MODULE_ID || importer?.includes("storefront-next-dev")) return null;
262
266
  return VIRTUAL_MODULE_ID;
@@ -264,7 +268,7 @@ const patchReactRouterPlugin = () => {
264
268
  return null;
265
269
  },
266
270
  load(id) {
267
- if (isTestMode) return null;
271
+ if (isTestMode || isDevMode) return null;
268
272
  if (id === VIRTUAL_MODULE_ID) return `
269
273
  export * from 'react-router';
270
274
  export { Scripts } from '@salesforce/storefront-next-dev/react-router/Scripts';
@@ -942,6 +946,79 @@ const eventInstrumentationValidatorPlugin = (config = {}) => {
942
946
  };
943
947
  };
944
948
 
949
+ //#endregion
950
+ //#region src/plugins/buildMiddlewareRegistry.ts
951
+ /** Source filename for the middleware registry (project source). */
952
+ const MIDDLEWARE_REGISTRY_SOURCE_FILE = "middleware-registry.ts";
953
+ /** Subdirectory under build output where the compiled registry is written (must match server/index.ts expectations). */
954
+ const SERVER_OUT_SUBDIR = "server";
955
+ /**
956
+ * Vite plugin that builds the middleware registry file for production.
957
+ *
958
+ * This plugin reads the template's middleware registry from the app's server directory
959
+ * (e.g. `src/server/middleware-registry.ts` when appDirectory is `./src`) and compiles it
960
+ * into the build output's server directory so the production server (Managed Runtime)
961
+ * can load the custom Express middlewares.
962
+ *
963
+ * Compilation uses tsdown (single TypeScript file → ESM) instead of a full Vite build.
964
+ * Paths are derived from the React Router plugin context (appDirectory, buildDirectory)
965
+ * when available; there are no env vars for these paths in this package.
966
+ *
967
+ * If the middleware registry file does not exist, the plugin silently skips the build step.
968
+ *
969
+ * @returns {Plugin} A Vite plugin that compiles the middleware registry for production
970
+ *
971
+ * @example
972
+ * // In vite.config.ts
973
+ * export default defineConfig({
974
+ * plugins: [
975
+ * buildMiddlewareRegistryPlugin()
976
+ * ]
977
+ * })
978
+ */
979
+ const buildMiddlewareRegistryPlugin = () => {
980
+ let resolvedConfig;
981
+ let buildDirectory;
982
+ /** App source directory (e.g. 'src' or './src') from React Router config. */
983
+ let appDirectory;
984
+ return {
985
+ name: "odyssey:build-middleware-registry",
986
+ apply: "build",
987
+ configResolved(config) {
988
+ resolvedConfig = config;
989
+ const rr = config.__reactRouterPluginContext?.reactRouterConfig ?? {};
990
+ buildDirectory = rr.buildDirectory ?? resolve$1(config.root, "build");
991
+ appDirectory = rr.appDirectory ?? "src";
992
+ },
993
+ buildApp: {
994
+ order: "post",
995
+ handler: async () => {
996
+ const projectRoot = resolvedConfig.root;
997
+ const middlewareRegistryPath = resolve$1(projectRoot, appDirectory, SERVER_OUT_SUBDIR, MIDDLEWARE_REGISTRY_SOURCE_FILE);
998
+ if (!existsSync(middlewareRegistryPath)) return;
999
+ const { build } = await import("tsdown");
1000
+ const serverOutDir = resolve$1(projectRoot, buildDirectory, SERVER_OUT_SUBDIR);
1001
+ await build({
1002
+ cwd: projectRoot,
1003
+ entry: { [MIDDLEWARE_REGISTRY_SOURCE_FILE.replace(/\.ts$/, "")]: middlewareRegistryPath },
1004
+ outDir: serverOutDir,
1005
+ format: ["esm"],
1006
+ platform: "node",
1007
+ outExtensions: () => ({
1008
+ js: ".mjs",
1009
+ dts: ".d.ts"
1010
+ }),
1011
+ dts: false,
1012
+ clean: false,
1013
+ hash: false,
1014
+ noExternal: [/.*/],
1015
+ external: [/^node:/]
1016
+ });
1017
+ }
1018
+ }
1019
+ };
1020
+ };
1021
+
945
1022
  //#endregion
946
1023
  //#region src/plugin.ts
947
1024
  /**
@@ -979,7 +1056,8 @@ function storefrontNextPlugins(config = {}) {
979
1056
  fixReactRouterManifestUrlsPlugin(),
980
1057
  patchReactRouterPlugin(),
981
1058
  transformPluginPlaceholderPlugin(),
982
- watchConfigFilesPlugin()
1059
+ watchConfigFilesPlugin(),
1060
+ buildMiddlewareRegistryPlugin()
983
1061
  ];
984
1062
  if (staticRegistry?.componentPath && staticRegistry?.registryPath) plugins.push(staticRegistryPlugin(staticRegistry));
985
1063
  if (eventInstrumentationValidator !== false) plugins.push(eventInstrumentationValidatorPlugin(eventInstrumentationValidator));
@@ -989,7 +1067,7 @@ function storefrontNextPlugins(config = {}) {
989
1067
 
990
1068
  //#endregion
991
1069
  //#region package.json
992
- var version = "0.1.0";
1070
+ var version = "0.1.1";
993
1071
 
994
1072
  //#endregion
995
1073
  //#region src/utils/logger.ts
@@ -1763,6 +1841,16 @@ const ServerModeFeatureMap = {
1763
1841
 
1764
1842
  //#endregion
1765
1843
  //#region src/server/index.ts
1844
+ /** Relative path to the middleware registry TypeScript source (development). Must match appDirectory + server dir + filename used by buildMiddlewareRegistry plugin. */
1845
+ const RELATIVE_MIDDLEWARE_REGISTRY_SOURCE = "src/server/middleware-registry.ts";
1846
+ /** Extensions to try for the built middlewares module (ESM first, then CJS for backwards compatibility). */
1847
+ const MIDDLEWARE_REGISTRY_BUILT_EXTENSIONS = [
1848
+ ".mjs",
1849
+ ".js",
1850
+ ".cjs"
1851
+ ];
1852
+ /** All paths to try when loading the built middlewares (base + extension). */
1853
+ const RELATIVE_MIDDLEWARE_REGISTRY_BUILT_PATHS = ["bld/server/middleware-registry", "build/server/middleware-registry"].flatMap((base) => MIDDLEWARE_REGISTRY_BUILT_EXTENSIONS.map((ext) => `${base}${ext}`));
1766
1854
  /**
1767
1855
  * Create a unified Express server for development, preview, or production mode
1768
1856
  */
@@ -1780,13 +1868,22 @@ async function createServer(options) {
1780
1868
  const bundlePath = getBundlePath(bundleId);
1781
1869
  app.use(bundlePath, createStaticMiddleware(bundleId, projectDirectory));
1782
1870
  }
1783
- const middlewareRegistryPath = resolve(projectDirectory, "src/server/middleware-registry.ts");
1784
- if (existsSync$1(middlewareRegistryPath)) {
1785
- const registry = await importTypescript(middlewareRegistryPath, { projectDirectory });
1786
- if (registry.customMiddlewares && Array.isArray(registry.customMiddlewares)) registry.customMiddlewares.forEach((middleware) => {
1787
- app.use(middleware);
1788
- });
1871
+ let registry = null;
1872
+ if (mode === "development") {
1873
+ const middlewareRegistryPath = resolve(projectDirectory, RELATIVE_MIDDLEWARE_REGISTRY_SOURCE);
1874
+ if (existsSync$1(middlewareRegistryPath)) registry = await importTypescript(middlewareRegistryPath, { projectDirectory });
1875
+ } else {
1876
+ const possiblePaths = RELATIVE_MIDDLEWARE_REGISTRY_BUILT_PATHS.map((p) => resolve(projectDirectory, p));
1877
+ let builtRegistryPath = null;
1878
+ for (const path$2 of possiblePaths) if (existsSync$1(path$2)) {
1879
+ builtRegistryPath = path$2;
1880
+ break;
1881
+ }
1882
+ if (builtRegistryPath) registry = await import(pathToFileURL$1(builtRegistryPath).href);
1789
1883
  }
1884
+ if (registry?.customMiddlewares && Array.isArray(registry.customMiddlewares)) registry.customMiddlewares.forEach((entry) => {
1885
+ app.use(entry.handler);
1886
+ });
1790
1887
  if (mode === "development" && vite) app.use(vite.middlewares);
1791
1888
  if (enableProxy) app.use(config.commerce.api.proxy, createCommerceProxyMiddleware(config));
1792
1889
  app.use(createHostHeaderMiddleware());