@salesforce/vite-plugin-webapp-experimental 1.11.1 → 1.11.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAUlD,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAoIzE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAUlD,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAiIzE"}
package/dist/index.js CHANGED
@@ -14,10 +14,10 @@ export default function webappsPlugin(options = {}) {
14
14
  let orgInfo;
15
15
  let manifest;
16
16
  let proxyHandler;
17
- const getBasePathBound = (mode) => getBasePath(mode, codeBuilderProxyUrl, getPort());
18
17
  return {
19
18
  name: "@salesforce/vite-plugin-webapp-experimental",
20
- async config(_config, env) {
19
+ async config(config, env) {
20
+ const rootPath = config.root ?? process.cwd();
21
21
  // Note: At this stage we may not have the correct manifest path yet,
22
22
  // so we only load the org info to get the API version
23
23
  // Development server configuration
@@ -43,7 +43,7 @@ export default function webappsPlugin(options = {}) {
43
43
  }
44
44
  return {
45
45
  define,
46
- base: getBasePath(env.mode, codeBuilderProxyUrl, getPort()),
46
+ base: getBasePath(env.mode, codeBuilderProxyUrl, getPort(), rootPath),
47
47
  server: {
48
48
  port: getPort(),
49
49
  // Code Builder specific configuration
@@ -57,9 +57,11 @@ export default function webappsPlugin(options = {}) {
57
57
  },
58
58
  async configResolved(config) {
59
59
  try {
60
- manifest = await loadManifest(`${config.root ?? process.cwd()}/webapplication.json`);
60
+ const rootPath = config.root ?? process.cwd();
61
+ manifest = await loadManifest(`${rootPath}/webapplication.json`);
61
62
  const target = getDevServerTarget(codeBuilderProxyUrl, config.server.port ?? DEFAULT_PORT);
62
- proxyHandler = createProxyHandler(manifest, orgInfo, target, getBasePathBound(config.mode), proxyOptions);
63
+ const basePath = getBasePath(config.mode, codeBuilderProxyUrl, getPort(), rootPath);
64
+ proxyHandler = createProxyHandler(manifest, orgInfo, target, basePath, proxyOptions);
63
65
  }
64
66
  catch (error) {
65
67
  console.error(`[webapps-plugin] Initialization failed:`, error);
@@ -101,8 +103,10 @@ export default function webappsPlugin(options = {}) {
101
103
  // Update context with new manifest
102
104
  manifest = updatedManifest;
103
105
  // Recreate proxy handler with updated appContext
106
+ const rootPath = server.config.root ?? process.cwd();
104
107
  const target = getDevServerTarget(codeBuilderProxyUrl, server.config.server.port ?? DEFAULT_PORT);
105
- proxyHandler = createProxyHandler(manifest, orgInfo, target, getBasePathBound(server.config.mode), proxyOptions);
108
+ const basePath = getBasePath(server.config.mode, codeBuilderProxyUrl, getPort(), rootPath);
109
+ proxyHandler = createProxyHandler(manifest, orgInfo, target, basePath, proxyOptions);
106
110
  server.ws.send({
107
111
  type: "full-reload",
108
112
  path: "*",
package/dist/utils.d.ts CHANGED
@@ -5,6 +5,31 @@
5
5
  */
6
6
  export declare const DEFAULT_PORT = 5173;
7
7
  export declare const DEFAULT_API_VERSION = "65.0";
8
+ export declare const DEFAULT_NAMESPACE = "c";
9
+ /**
10
+ * Get the app name from a *.webapplication-meta.xml file in the root path.
11
+ * Falls back to the directory name if no matching file is found.
12
+ *
13
+ * @param rootPath - The root directory to search for the webapplication-meta.xml file
14
+ * @returns The app name
15
+ */
16
+ export declare function getAppName(rootPath: string): string;
17
+ /**
18
+ * Get the namespace for the app.
19
+ * Currently returns the default namespace ("c") since rootPath points to the
20
+ * webapp directory (where vite.config lives), not the sfdx project root.
21
+ *
22
+ * @returns The namespace (currently always "c")
23
+ */
24
+ export declare function getNamespace(): string;
25
+ /**
26
+ * Build the production base path from namespace and app name.
27
+ *
28
+ * @param namespace - The Salesforce namespace (e.g., "c")
29
+ * @param appName - The app name (e.g., "myapp")
30
+ * @returns The production base path (e.g., "/lwr/application/ai/c-myapp")
31
+ */
32
+ export declare function buildProdBasePath(namespace: string, appName: string): string;
8
33
  /**
9
34
  * Calculate the code builder base path from the proxy URI (CODE_BUILDER_FRAMEWORK_PROXY_URI) and dev server port
10
35
  * @param proxyUri - The full proxy URI (e.g., https://name.iad.001.sf.code-builder.platform.salesforce.com/absproxy/{{port}})
@@ -12,7 +37,22 @@ export declare const DEFAULT_API_VERSION = "65.0";
12
37
  * @returns The parsed path with port (e.g., /absproxy/5173/)
13
38
  */
14
39
  export declare function getCodeBuilderBasePath(proxyUri: string, port: number): string;
15
- export declare function getBasePath(mode: string, codeBuilderProxyUrl: string | undefined, port: number): string;
40
+ /**
41
+ * Get the base path for the webapp based on mode and environment.
42
+ *
43
+ * For production mode, resolves the app name and namespace from the rootPath
44
+ * and returns a path like "/lwr/application/ai/{namespace}-{appName}".
45
+ *
46
+ * For development mode with Code Builder, returns the proxy path.
47
+ * For local development, returns an empty string.
48
+ *
49
+ * @param mode - The Vite mode ("production", "development", etc.)
50
+ * @param codeBuilderProxyUrl - The Code Builder proxy URL (if running in Code Builder)
51
+ * @param port - The dev server port
52
+ * @param rootPath - The project root path (used to resolve app name and namespace)
53
+ * @returns The base path
54
+ */
55
+ export declare function getBasePath(mode: string, codeBuilderProxyUrl: string | undefined, port: number, rootPath: string): string;
16
56
  export declare function getDevServerTarget(codeBuilderProxyUrl: string | undefined, port: number): string;
17
57
  export declare function getPort(): number;
18
58
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAY9F;AAED,wBAAgB,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAMvF;AAED,wBAAgB,OAAO,WAEtB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYnD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,mBAAmB,EAAE,MAAM,GAAG,SAAS,EACvC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACd,MAAM,CAeR;AAED,wBAAgB,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAMvF;AAED,wBAAgB,OAAO,WAEtB"}
package/dist/utils.js CHANGED
@@ -3,8 +3,53 @@
3
3
  * All rights reserved.
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
+ import { readdirSync } from "node:fs";
7
+ import { basename } from "node:path";
6
8
  export const DEFAULT_PORT = 5173;
7
9
  export const DEFAULT_API_VERSION = "65.0";
10
+ export const DEFAULT_NAMESPACE = "c";
11
+ /**
12
+ * Get the app name from a *.webapplication-meta.xml file in the root path.
13
+ * Falls back to the directory name if no matching file is found.
14
+ *
15
+ * @param rootPath - The root directory to search for the webapplication-meta.xml file
16
+ * @returns The app name
17
+ */
18
+ export function getAppName(rootPath) {
19
+ try {
20
+ const files = readdirSync(rootPath);
21
+ const metaFile = files.find((f) => f.endsWith(".webapplication-meta.xml"));
22
+ if (metaFile) {
23
+ // Extract name from "myapp.webapplication-meta.xml" -> "myapp"
24
+ return metaFile.replace(".webapplication-meta.xml", "");
25
+ }
26
+ }
27
+ catch {
28
+ // Fall through to directory name
29
+ }
30
+ return basename(rootPath);
31
+ }
32
+ /**
33
+ * Get the namespace for the app.
34
+ * Currently returns the default namespace ("c") since rootPath points to the
35
+ * webapp directory (where vite.config lives), not the sfdx project root.
36
+ *
37
+ * @returns The namespace (currently always "c")
38
+ */
39
+ export function getNamespace() {
40
+ // TODO: In the future, we could traverse up from rootPath to find sfdx-project.json
41
+ return DEFAULT_NAMESPACE;
42
+ }
43
+ /**
44
+ * Build the production base path from namespace and app name.
45
+ *
46
+ * @param namespace - The Salesforce namespace (e.g., "c")
47
+ * @param appName - The app name (e.g., "myapp")
48
+ * @returns The production base path (e.g., "/lwr/application/ai/c-myapp")
49
+ */
50
+ export function buildProdBasePath(namespace, appName) {
51
+ return `/lwr/application/ai/${namespace}-${appName}`;
52
+ }
8
53
  /**
9
54
  * Calculate the code builder base path from the proxy URI (CODE_BUILDER_FRAMEWORK_PROXY_URI) and dev server port
10
55
  * @param proxyUri - The full proxy URI (e.g., https://name.iad.001.sf.code-builder.platform.salesforce.com/absproxy/{{port}})
@@ -21,15 +66,33 @@ export function getCodeBuilderBasePath(proxyUri, port) {
21
66
  return `/absproxy/${port}`; // Default code builder proxy path
22
67
  }
23
68
  }
24
- export function getBasePath(mode, codeBuilderProxyUrl, port) {
69
+ /**
70
+ * Get the base path for the webapp based on mode and environment.
71
+ *
72
+ * For production mode, resolves the app name and namespace from the rootPath
73
+ * and returns a path like "/lwr/application/ai/{namespace}-{appName}".
74
+ *
75
+ * For development mode with Code Builder, returns the proxy path.
76
+ * For local development, returns an empty string.
77
+ *
78
+ * @param mode - The Vite mode ("production", "development", etc.)
79
+ * @param codeBuilderProxyUrl - The Code Builder proxy URL (if running in Code Builder)
80
+ * @param port - The dev server port
81
+ * @param rootPath - The project root path (used to resolve app name and namespace)
82
+ * @returns The base path
83
+ */
84
+ export function getBasePath(mode, codeBuilderProxyUrl, port, rootPath) {
25
85
  const isProd = mode === "production";
26
86
  if (isProd) {
27
- return "/lwr/application/ai/vibe-static";
87
+ const appName = getAppName(rootPath);
88
+ const namespace = getNamespace();
89
+ return buildProdBasePath(namespace, appName);
28
90
  }
91
+ // Development mode
29
92
  if (!codeBuilderProxyUrl) {
30
93
  return "";
31
94
  }
32
- // Code Builder: extract path from proxy URI and include port
95
+ // A4V / Code Builder: extract path from proxy URI and include port
33
96
  return getCodeBuilderBasePath(codeBuilderProxyUrl, port);
34
97
  }
35
98
  export function getDevServerTarget(codeBuilderProxyUrl, port) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/vite-plugin-webapp-experimental",
3
3
  "description": "[experimental] Vite plugin for Salesforce Web Applications",
4
- "version": "1.11.1",
4
+ "version": "1.11.2",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "test:coverage": "vitest run --coverage"
27
27
  },
28
28
  "dependencies": {
29
- "@salesforce/webapp-experimental": "^1.11.1"
29
+ "@salesforce/webapp-experimental": "^1.11.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "vite": "^7.0.0",
@@ -41,5 +41,5 @@
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "c53d97d9ed0a1ab973de50ad5839c1115d3e557b"
44
+ "gitHead": "d2bb8a908eca2cff75f421769bf8dbb0a36f698f"
45
45
  }