@salesforce/vite-plugin-ui-bundle 12.11.0 → 12.12.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":"createCorePlugins.d.ts","sourceRoot":"","sources":["../../src/core/createCorePlugins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAA6B,MAAM,EAAiB,MAAM,MAAM,CAAC;AAW7E,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAkC,KAAK,gBAAgB,EAAoB,MAAM,OAAO,CAAC;AAEhG,sEAAsE;AACtE,UAAU,uBAAwB,SAAQ,mBAAmB;IAC5D,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACtD,CACG;IACA,mEAAmE;IACnE,eAAe,EAAE,IAAI,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACA,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACjB,CACH,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACzB,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACnC;AA0BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,GAAE,iBAAsB,EAC/B,KAAK,GAAE,SAAc,GACnB,MAAM,EAAE,CAyLV"}
1
+ {"version":3,"file":"createCorePlugins.d.ts","sourceRoot":"","sources":["../../src/core/createCorePlugins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAGX,MAAM,EAGN,MAAM,MAAM,CAAC;AAYd,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,OAAO,CAAC;AAEf,sEAAsE;AACtE,UAAU,uBAAwB,SAAQ,mBAAmB;IAC5D,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACtD,CACG;IACA,mEAAmE;IACnE,eAAe,EAAE,IAAI,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACA,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACjB,CACH,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACzB,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACnC;AA0BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,GAAE,iBAAsB,EAC/B,KAAK,GAAE,SAAc,GACnB,MAAM,EAAE,CAuSV"}
@@ -39,4 +39,10 @@ export declare function buildEnvTags(html: string, env: Environment, originalUrl
39
39
  html: string;
40
40
  tags: HtmlTagDescriptor[];
41
41
  };
42
+ /**
43
+ * Serve-time counterpart of {@link buildEnvTags} for `vite preview`, which serves the
44
+ * built `index.html` without running Vite's `transformIndexHtml` hook. Applies the same
45
+ * `<base href>` + `SFDC_ENV` tags to the HTML string directly.
46
+ */
47
+ export declare function injectEnvTags(html: string, env: Environment, originalUrl: string | undefined, resolveBasePath?: BasePathResolver): string;
42
48
  //# sourceMappingURL=env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/core/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,O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M,gBAAgB,EAAE,gBAA8D,CAAC;AAE9F;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,eAAe,GAAE,gBAAmC,GAClD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,iBAAiB,EAAE,CAAA;CAAE,CAoC7C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,eAAe,GAAE,gBAAmC,GAClD,MAAM,CAqBR"}
@@ -1,11 +1,13 @@
1
- import { loadManifest, getOrgInfo } from "@salesforce/ui-bundle/app";
1
+ import { readFile } from "node:fs/promises";
2
+ import path, { dirname, join, basename } from "node:path";
3
+ import { loadManifest, getOrgInfo, loadDevProxyConfig } from "@salesforce/ui-bundle/app";
2
4
  import { injectLivePreviewScript, createProxyHandler } from "@salesforce/ui-bundle/proxy";
3
5
  import fs, { existsSync, readFileSync, readdirSync } from "node:fs";
4
- import path, { dirname, join, basename } from "node:path";
5
6
  import { ASSETS_ROOT, resolveAssetRef, CSS_URL_TOKEN_SOURCE } from "@salesforce/ui-design-mode/authoring/host";
6
7
  import { getRuntimeScriptContent } from "@salesforce/ui-design-mode/runtime";
7
8
  import reactDesignTimeLocatorBabelPlugin from "@salesforce/ui-design-mode/source-locator/react";
8
9
  const DEFAULT_PORT = 5173;
10
+ const DEFAULT_PREVIEW_PORT = 4173;
9
11
  const DEFAULT_API_VERSION = "65.0";
10
12
  const DEFAULT_NAMESPACE = "c";
11
13
  function getAppName(rootPath) {
@@ -341,6 +343,22 @@ function buildEnvTags(html, env, originalUrl, resolveBasePath = identityResolver
341
343
  });
342
344
  return { html, tags };
343
345
  }
346
+ function injectEnvTags(html, env, originalUrl, resolveBasePath = identityResolver) {
347
+ const { html: transformed, tags } = buildEnvTags(html, env, originalUrl, resolveBasePath);
348
+ let headTags = "";
349
+ let bodyTags = "";
350
+ for (const tag of tags) {
351
+ const rendered = tag.tag === "base" ? `<base href="${escapeAttr(String(tag.attrs.href))}">` : `<script>${String(tag.children)}<\/script>`;
352
+ if (tag.injectTo === "head-prepend") headTags += rendered;
353
+ else bodyTags += rendered;
354
+ }
355
+ let out = transformed.replace(/<head(\s[^>]*)?>/i, (open) => `${open}${headTags}`);
356
+ out = /<\/body>/i.test(out) ? out.replace(/<\/body>/i, (close) => `${bodyTags}${close}`) : `${out}${bodyTags}`;
357
+ return out;
358
+ }
359
+ function escapeAttr(value) {
360
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
361
+ }
344
362
  function getAllowedHostsForCodeBuilder(proxyUrl) {
345
363
  const CODEBUILDER_WHITELISTED_HOSTS = ["localhost", "127.0.0.1"];
346
364
  if (proxyUrl) {
@@ -369,6 +387,89 @@ function createCorePlugins(options = {}, hooks = {}) {
369
387
  let environment;
370
388
  let proxyHandler;
371
389
  let codeBuilderProxyUrl;
390
+ async function applyDevProxyConfig(rootPath) {
391
+ try {
392
+ const devConfig = await loadDevProxyConfig(
393
+ `${rootPath}/ui-bundle.dev.json`
394
+ );
395
+ if (devConfig) {
396
+ proxyOptions.devPaths = { corePaths: devConfig.corePaths };
397
+ }
398
+ } catch (error) {
399
+ console.error(`[ui-bundle-plugin] Failed to load ui-bundle.dev.json:`, error);
400
+ }
401
+ }
402
+ function mountProxyMiddleware(server) {
403
+ server.middlewares.use(async (req, res, next) => {
404
+ if (proxyHandler) {
405
+ try {
406
+ await proxyHandler(req, res, next);
407
+ } catch (error) {
408
+ console.error("[ui-bundle-plugin] Proxy handler error:", error);
409
+ next();
410
+ }
411
+ } else {
412
+ if (req.url?.startsWith("/services")) {
413
+ res.writeHead(503, { "Content-Type": "application/json" });
414
+ res.end(
415
+ JSON.stringify({
416
+ error: "SERVICE_UNAVAILABLE",
417
+ message: "Proxy not initialized."
418
+ })
419
+ );
420
+ return;
421
+ }
422
+ next();
423
+ }
424
+ });
425
+ }
426
+ function createPreviewEnvMiddleware(server) {
427
+ return async (req, res, next) => {
428
+ if (!environment || req.method !== "GET" && req.method !== "HEAD") {
429
+ next();
430
+ return;
431
+ }
432
+ const base = environment.basePath.replace(/\/$/, "");
433
+ let pathname;
434
+ try {
435
+ ({ pathname } = new URL(req.url ?? "/", "http://localhost"));
436
+ pathname = decodeURIComponent(pathname);
437
+ } catch {
438
+ next();
439
+ return;
440
+ }
441
+ const relPath = pathname.startsWith(base) ? pathname.slice(base.length) : pathname;
442
+ if (!relPath.endsWith(".html") || req.headers["sec-fetch-dest"] === "script") {
443
+ next();
444
+ return;
445
+ }
446
+ const { root, build } = server.config;
447
+ const outDir = path.resolve(root, build.outDir);
448
+ const filePath = path.resolve(outDir, `.${relPath}`);
449
+ if (!filePath.startsWith(outDir + path.sep)) {
450
+ next();
451
+ return;
452
+ }
453
+ try {
454
+ const html = injectEnvTags(
455
+ await readFile(filePath, "utf-8"),
456
+ environment,
457
+ req.originalUrl ?? req.url,
458
+ resolveBasePath
459
+ );
460
+ res.writeHead(200, {
461
+ "Content-Type": "text/html",
462
+ "Content-Length": Buffer.byteLength(html)
463
+ });
464
+ res.end(req.method === "HEAD" ? void 0 : html);
465
+ } catch (error) {
466
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
467
+ console.error("[ui-bundle-plugin] Failed to serve preview HTML:", error);
468
+ }
469
+ next();
470
+ }
471
+ };
472
+ }
372
473
  const corePlugin = {
373
474
  name: "@salesforce/vite-plugin-ui-bundle:core",
374
475
  enforce: "pre",
@@ -391,8 +492,9 @@ function createCorePlugins(options = {}, hooks = {}) {
391
492
  __SF_API_VERSION__: JSON.stringify(version)
392
493
  };
393
494
  let base = "./";
394
- if (env.mode !== "production") {
395
- const basePath = isCodeBuilder ? getCodeBuilderBasePath(codeBuilderProxyUrl, getPort()) : "/";
495
+ if (env.mode !== "production" || env.isPreview) {
496
+ const port = env.isPreview ? _config.preview?.port ?? DEFAULT_PREVIEW_PORT : getPort();
497
+ const basePath = isCodeBuilder ? getCodeBuilderBasePath(codeBuilderProxyUrl, port) : "/";
396
498
  environment = { basePath, apiPath: basePath, orgUrl: orgInfo?.instanceUrl };
397
499
  if (isCodeBuilder) {
398
500
  base = basePath;
@@ -419,6 +521,9 @@ function createCorePlugins(options = {}, hooks = {}) {
419
521
  environment.appName = getAppName(rootPath);
420
522
  }
421
523
  manifest = await loadManifest(`${rootPath}/ui-bundle.json`);
524
+ if (!options.disableOrgProxy) {
525
+ await applyDevProxyConfig(rootPath);
526
+ }
422
527
  const target = getDevServerTarget(codeBuilderProxyUrl, config.server.port ?? DEFAULT_PORT);
423
528
  proxyHandler = createProxyHandler(
424
529
  manifest,
@@ -432,28 +537,18 @@ function createCorePlugins(options = {}, hooks = {}) {
432
537
  }
433
538
  },
434
539
  configureServer(server) {
435
- server.middlewares.use(async (req, res, next) => {
436
- if (proxyHandler) {
437
- try {
438
- await proxyHandler(req, res, next);
439
- } catch (error) {
440
- console.error("[ui-bundle-plugin] Proxy handler error:", error);
441
- next();
442
- }
443
- } else {
444
- if (req.url?.startsWith("/services")) {
445
- res.writeHead(503, { "Content-Type": "application/json" });
446
- res.end(
447
- JSON.stringify({
448
- error: "SERVICE_UNAVAILABLE",
449
- message: "Proxy not initialized."
450
- })
451
- );
452
- return;
453
- }
454
- next();
455
- }
456
- });
540
+ mountProxyMiddleware(server);
541
+ },
542
+ // Mirror the proxy middleware onto `vite preview` so the built output in
543
+ // static/dist/ can be tested against the org too — vite preview ignores the
544
+ // dev server's middleware, so it must be mounted here as well.
545
+ configurePreviewServer(server) {
546
+ mountProxyMiddleware(server);
547
+ const injectEnv = createPreviewEnvMiddleware(server);
548
+ server.middlewares.use(injectEnv);
549
+ return () => {
550
+ server.middlewares.use(injectEnv);
551
+ };
457
552
  },
458
553
  async handleHotUpdate({ file, server }) {
459
554
  if (file.endsWith("ui-bundle.json")) {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createCorePlugins } from "./createCorePlugins-DP3NMfXw.js";
1
+ import { c as createCorePlugins } from "./createCorePlugins-CC0qwAbX.js";
2
2
  function uiBundlePlugin(options = {}) {
3
3
  return createCorePlugins(options);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { c as createCorePlugins } from "../createCorePlugins-DP3NMfXw.js";
1
+ import { c as createCorePlugins } from "../createCorePlugins-CC0qwAbX.js";
2
2
  function resolveLanguageFromUrl(url, supported) {
3
3
  const [defaultLang, ...nonDefault] = supported;
4
4
  if (defaultLang === void 0) return void 0;
package/dist/utils.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
6
  export declare const DEFAULT_PORT = 5173;
7
+ export declare const DEFAULT_PREVIEW_PORT = 4173;
7
8
  export declare const DEFAULT_API_VERSION = "65.0";
8
9
  export declare const DEFAULT_NAMESPACE = "c";
9
10
  /**
@@ -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;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAwBrD;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"}
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,oBAAoB,OAAO,CAAC;AACzC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAwBrD;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-ui-bundle",
3
3
  "description": "Vite plugin for Salesforce UI Bundles",
4
- "version": "12.11.0",
4
+ "version": "12.12.0",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/core": "^7.29.6",
34
- "@salesforce/ui-bundle": "^12.11.0",
35
- "@salesforce/ui-design-mode": "12.11.0"
34
+ "@salesforce/ui-bundle": "^12.12.0",
35
+ "@salesforce/ui-design-mode": "12.12.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/babel__core": "^7.20.5",