@salesforce/vite-plugin-webapp-experimental 1.95.0 → 1.96.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAWlD,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CA0N3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,KAAK,EAAqB,MAAM,EAAiB,MAAM,MAAM,CAAC;AAUrE,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CA8P3E"}
package/dist/index.js CHANGED
@@ -2,8 +2,6 @@ import { loadManifest, getOrgInfo } from "@salesforce/webapp-experimental/app";
2
2
  import { getDesignModeScriptContent } from "@salesforce/webapp-experimental/design";
3
3
  import { createProxyHandler, injectLivePreviewScript } from "@salesforce/webapp-experimental/proxy";
4
4
  import { declare } from "@babel/helper-plugin-utils";
5
- import { readdirSync } from "node:fs";
6
- import { basename } from "node:path";
7
5
  const reactDesignTimeLocatorBabelPlugin = declare((api) => {
8
6
  api.assertVersion(7);
9
7
  const t = api.types;
@@ -74,24 +72,6 @@ const reactDesignTimeLocatorBabelPlugin = declare((api) => {
74
72
  });
75
73
  const DEFAULT_PORT = 5173;
76
74
  const DEFAULT_API_VERSION = "65.0";
77
- const DEFAULT_NAMESPACE = "c";
78
- function getAppName(rootPath) {
79
- try {
80
- const files = readdirSync(rootPath);
81
- const metaFile = files.find((f) => f.endsWith(".webapplication-meta.xml"));
82
- if (metaFile) {
83
- return metaFile.replace(".webapplication-meta.xml", "");
84
- }
85
- } catch {
86
- }
87
- return basename(rootPath);
88
- }
89
- function getNamespace() {
90
- return DEFAULT_NAMESPACE;
91
- }
92
- function buildProdBasePath(namespace, appName) {
93
- return `/lwr/application/ai/${namespace}-${appName}`;
94
- }
95
75
  function getCodeBuilderBasePath(proxyUri, port) {
96
76
  try {
97
77
  const url = new URL(proxyUri.replace("{{port}}", port.toString()));
@@ -101,18 +81,6 @@ function getCodeBuilderBasePath(proxyUri, port) {
101
81
  return `/absproxy/${port}`;
102
82
  }
103
83
  }
104
- function getBasePath(mode, codeBuilderProxyUrl2, port, rootPath) {
105
- const isProd = mode === "production";
106
- if (isProd) {
107
- const appName = getAppName(rootPath);
108
- const namespace = getNamespace();
109
- return buildProdBasePath(namespace, appName);
110
- }
111
- if (!codeBuilderProxyUrl2) {
112
- return "";
113
- }
114
- return getCodeBuilderBasePath(codeBuilderProxyUrl2, port);
115
- }
116
84
  function getDevServerTarget(codeBuilderProxyUrl2, port) {
117
85
  if (codeBuilderProxyUrl2) {
118
86
  return getCodeBuilderBasePath(codeBuilderProxyUrl2, port);
@@ -129,14 +97,14 @@ function webappsPlugin(options = {}) {
129
97
  };
130
98
  let orgInfo;
131
99
  let manifest;
100
+ let environment;
132
101
  let proxyHandler;
133
102
  let designModeEnabled = options.designMode ?? false;
134
103
  const corePlugin = {
135
104
  name: "@salesforce/vite-plugin-webapp-experimental:core",
136
105
  enforce: "pre",
137
- async config(config, env) {
138
- const rootPath = config.root ?? process.cwd();
139
- let version = DEFAULT_API_VERSION;
106
+ async config(_config, env) {
107
+ let version;
140
108
  try {
141
109
  orgInfo = await getOrgInfo(options.orgAlias);
142
110
  version = orgInfo?.apiVersion || DEFAULT_API_VERSION;
@@ -148,16 +116,16 @@ function webappsPlugin(options = {}) {
148
116
  }
149
117
  const isCodeBuilder = !!codeBuilderProxyUrl;
150
118
  const define = {
151
- __SF_API_VERSION__: JSON.stringify(version),
152
- __SF_SERVER_BASE_PATH__: JSON.stringify("")
119
+ __SF_API_VERSION__: JSON.stringify(version)
153
120
  };
154
- if (isCodeBuilder && env.mode !== "production") {
155
- const basePath = getCodeBuilderBasePath(codeBuilderProxyUrl, getPort());
156
- define["__SF_SERVER_BASE_PATH__"] = JSON.stringify(basePath);
121
+ if (env.mode !== "production") {
122
+ const basePath = isCodeBuilder ? getCodeBuilderBasePath(codeBuilderProxyUrl, getPort()) : "/";
123
+ const normalizedBasePath = basePath.endsWith("/") ? basePath : `${basePath}/`;
124
+ environment = { basePath: normalizedBasePath, apiPath: "/" };
157
125
  }
158
126
  return {
159
127
  define,
160
- base: getBasePath(env.mode, codeBuilderProxyUrl, getPort(), rootPath),
128
+ base: "./",
161
129
  server: {
162
130
  port: getPort(),
163
131
  // Code Builder specific configuration
@@ -173,8 +141,13 @@ function webappsPlugin(options = {}) {
173
141
  const rootPath = config.root ?? process.cwd();
174
142
  manifest = await loadManifest(`${rootPath}/webapplication.json`);
175
143
  const target = getDevServerTarget(codeBuilderProxyUrl, config.server.port ?? DEFAULT_PORT);
176
- const basePath = getBasePath(config.mode, codeBuilderProxyUrl, getPort(), rootPath);
177
- proxyHandler = createProxyHandler(manifest, orgInfo, target, basePath, proxyOptions);
144
+ proxyHandler = createProxyHandler(
145
+ manifest,
146
+ orgInfo,
147
+ target,
148
+ environment?.basePath,
149
+ proxyOptions
150
+ );
178
151
  } catch (error) {
179
152
  console.error(`[webapps-plugin] Initialization failed:`, error);
180
153
  }
@@ -208,24 +181,42 @@ function webappsPlugin(options = {}) {
208
181
  const updatedManifest = await loadManifest(file);
209
182
  if (updatedManifest) {
210
183
  manifest = updatedManifest;
211
- const rootPath = server.config.root ?? process.cwd();
212
184
  const target = getDevServerTarget(
213
185
  codeBuilderProxyUrl,
214
186
  server.config.server.port ?? DEFAULT_PORT
215
187
  );
216
- const basePath = getBasePath(
217
- server.config.mode,
218
- codeBuilderProxyUrl,
219
- getPort(),
220
- rootPath
188
+ proxyHandler = createProxyHandler(
189
+ manifest,
190
+ orgInfo,
191
+ target,
192
+ environment?.basePath,
193
+ proxyOptions
221
194
  );
222
- proxyHandler = createProxyHandler(manifest, orgInfo, target, basePath, proxyOptions);
223
195
  server.ws.send({
224
196
  type: "full-reload",
225
197
  path: "*"
226
198
  });
227
199
  }
228
200
  }
201
+ },
202
+ transformIndexHtml: {
203
+ order: "pre",
204
+ handler() {
205
+ const results = [];
206
+ if (environment) {
207
+ results.push({
208
+ tag: "base",
209
+ attrs: { href: environment.basePath },
210
+ injectTo: "head-prepend"
211
+ });
212
+ results.push({
213
+ tag: "script",
214
+ children: `(function() { globalThis.SFDC_ENV = { basePath: "${environment.basePath}", apiPath: "${environment.apiPath}" }; })();`,
215
+ injectTo: "body"
216
+ });
217
+ }
218
+ return results;
219
+ }
229
220
  }
230
221
  };
231
222
  const designPlugin = {
@@ -290,14 +281,20 @@ function webappsPlugin(options = {}) {
290
281
  if (!result?.code) return null;
291
282
  return { code: result.code, map: result.map };
292
283
  },
293
- transformIndexHtml(html) {
294
- html = injectLivePreviewScript(html);
295
- if (designModeEnabled) {
296
- const designScriptTag = '<script src="/_sfdc/design-mode-interactions.js"><\/script>';
297
- return html.replace("</body>", `${designScriptTag}
298
- </body>`);
284
+ transformIndexHtml: {
285
+ order: "pre",
286
+ handler(html) {
287
+ html = injectLivePreviewScript(html);
288
+ const tags = [];
289
+ if (designModeEnabled) {
290
+ tags.push({
291
+ tag: "script",
292
+ attrs: { src: "/_sfdc/design-mode-interactions.js" },
293
+ injectTo: "body"
294
+ });
295
+ }
296
+ return { html, tags };
299
297
  }
300
- return html;
301
298
  }
302
299
  };
303
300
  return [designPlugin, corePlugin];
package/dist/utils.d.ts CHANGED
@@ -22,14 +22,6 @@ export declare function getAppName(rootPath: string): string;
22
22
  * @returns The namespace (currently always "c")
23
23
  */
24
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;
33
25
  /**
34
26
  * Calculate the code builder base path from the proxy URI (CODE_BUILDER_FRAMEWORK_PROXY_URI) and dev server port
35
27
  * @param proxyUri - The full proxy URI (e.g., https://name.iad.001.sf.code-builder.platform.salesforce.com/absproxy/{{port}})
@@ -37,22 +29,6 @@ export declare function buildProdBasePath(namespace: string, appName: string): s
37
29
  * @returns The parsed path with port (e.g., /absproxy/5173/)
38
30
  */
39
31
  export declare function getCodeBuilderBasePath(proxyUri: string, 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;
56
32
  export declare function getDevServerTarget(codeBuilderProxyUrl: string | undefined, port: number): string;
57
33
  export declare function getPort(): number;
58
34
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
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"}
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;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED,wBAAgB,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAMvF;AAED,wBAAgB,OAAO,WAEtB"}
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.95.0",
4
+ "version": "1.96.0",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@babel/core": "^7.28.4",
30
30
  "@babel/helper-plugin-utils": "^7.28.3",
31
- "@salesforce/webapp-experimental": "^1.95.0"
31
+ "@salesforce/webapp-experimental": "^1.96.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/babel__core": "^7.20.5",